react-native-nitro-modules 0.31.9 → 0.32.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NitroModules.podspec +1 -0
- package/android/build.gradle +1 -1
- package/android/src/main/cpp/core/JAnyMap.cpp +120 -0
- package/android/src/main/cpp/core/JAnyMap.hpp +20 -56
- package/android/src/main/cpp/platform/NitroLogger.cpp +3 -1
- package/android/src/main/java/com/margelo/nitro/core/AnyMap.kt +16 -7
- package/cpp/core/AnyMap.hpp +2 -2
- package/cpp/core/HybridObject.cpp +10 -10
- package/cpp/entrypoint/InstallNitro.cpp +2 -2
- package/cpp/jsi/JSICache.cpp +10 -5
- package/cpp/jsi/JSICache.hpp +6 -0
- package/cpp/jsi/JSIConverter+AnyMap.hpp +4 -3
- package/cpp/jsi/JSIConverter+Date.hpp +8 -10
- package/cpp/jsi/JSIConverter+Exception.hpp +5 -5
- package/cpp/jsi/JSIConverter+Function.hpp +4 -1
- package/cpp/jsi/JSIConverter+Promise.hpp +8 -14
- package/cpp/jsi/JSIConverter+UnorderedMap.hpp +2 -1
- package/cpp/jsi/JSIHelpers.hpp +1 -1
- package/cpp/platform/NitroLogger.hpp +3 -1
- package/cpp/prototype/HybridObjectPrototype.cpp +28 -28
- package/cpp/threading/Dispatcher.cpp +5 -5
- package/cpp/utils/BorrowingReference.hpp +6 -6
- package/cpp/utils/CommonGlobals.cpp +215 -0
- package/cpp/utils/CommonGlobals.hpp +158 -0
- package/cpp/utils/NitroDefines.hpp +1 -1
- package/cpp/utils/PropNameIDCache.cpp +38 -0
- package/cpp/utils/PropNameIDCache.hpp +44 -0
- package/cpp/utils/{WeakReference+Owning.hpp → WeakReference+Borrowing.hpp} +1 -1
- package/cpp/utils/WeakReference.hpp +1 -1
- package/ios/platform/NitroLogger.cpp +37 -0
- package/ios/platform/ThreadUtils.cpp +43 -0
- package/package.json +1 -2
- package/cpp/utils/ObjectUtils.cpp +0 -172
- package/cpp/utils/ObjectUtils.hpp +0 -94
- package/ios/platform/NitroLogger.mm +0 -36
- package/ios/platform/ThreadUtils.mm +0 -46
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//
|
|
2
|
+
// NitroLogger.cpp
|
|
3
|
+
// react-native-nitro
|
|
4
|
+
//
|
|
5
|
+
// Created by Marc Rousavy on 14.07.24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#include "NitroLogger.hpp"
|
|
9
|
+
#include "NitroDefines.hpp"
|
|
10
|
+
#include <os/log.h>
|
|
11
|
+
|
|
12
|
+
namespace margelo::nitro {
|
|
13
|
+
|
|
14
|
+
void Logger::nativeLog([[maybe_unused]] LogLevel level, //
|
|
15
|
+
[[maybe_unused]] const char* NON_NULL tag, //
|
|
16
|
+
[[maybe_unused]] const std::string& message) {
|
|
17
|
+
#ifdef NITRO_DEBUG
|
|
18
|
+
static os_log_t logger = os_log_create("com.margelo.nitro", "nitro");
|
|
19
|
+
|
|
20
|
+
switch (level) {
|
|
21
|
+
case LogLevel::Debug:
|
|
22
|
+
os_log_debug(logger, "[%s] %s", tag, message.c_str());
|
|
23
|
+
break;
|
|
24
|
+
case LogLevel::Info:
|
|
25
|
+
os_log_info(logger, "[%s] %s", tag, message.c_str());
|
|
26
|
+
break;
|
|
27
|
+
case LogLevel::Warning:
|
|
28
|
+
os_log_error(logger, "[%s] %s", tag, message.c_str());
|
|
29
|
+
break;
|
|
30
|
+
case LogLevel::Error:
|
|
31
|
+
os_log_error(logger, "[%s] %s", tag, message.c_str());
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
#endif
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//
|
|
2
|
+
// ThreadUtils.cpp
|
|
3
|
+
// react-native-nitro
|
|
4
|
+
//
|
|
5
|
+
// Created by Marc Rousavy on 14.07.24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#include "ThreadUtils.hpp"
|
|
9
|
+
#include <dispatch/dispatch.h>
|
|
10
|
+
#include <pthread.h>
|
|
11
|
+
#include <sstream>
|
|
12
|
+
#include <thread>
|
|
13
|
+
|
|
14
|
+
namespace margelo::nitro {
|
|
15
|
+
|
|
16
|
+
std::string ThreadUtils::getThreadName() {
|
|
17
|
+
// Try using pthread APIs
|
|
18
|
+
char threadName[64] = {};
|
|
19
|
+
int pthreadResult = pthread_getname_np(pthread_self(), threadName, sizeof(threadName));
|
|
20
|
+
if (pthreadResult == 0 && threadName[0] != '\0') {
|
|
21
|
+
// We have a pthread name
|
|
22
|
+
return std::string(threadName);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Try getting DispatchQueue name
|
|
26
|
+
const char* queueName = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL);
|
|
27
|
+
if (queueName != nullptr && queueName[0] != '\0') {
|
|
28
|
+
// We are on a DispatchQueue with a name
|
|
29
|
+
return std::string(queueName);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Fall back to std::this_thread
|
|
33
|
+
std::stringstream stream;
|
|
34
|
+
stream << std::this_thread::get_id();
|
|
35
|
+
std::string threadId = stream.str();
|
|
36
|
+
return std::string("Thread #") + threadId;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
void ThreadUtils::setThreadName(const std::string& name) {
|
|
40
|
+
pthread_setname_np(name.c_str());
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
} // namespace margelo::nitro
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-modules",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0-beta.0",
|
|
4
4
|
"description": "Insanely fast native C++, Swift or Kotlin modules with a statically compiled binding layer to JSI.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -59,7 +59,6 @@
|
|
|
59
59
|
"registry": "https://registry.npmjs.org/"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
|
-
"postinstall": "bun build || exit 0;",
|
|
63
62
|
"write-native-version": "version=$(node -p \"require('./package.json').version\") && sed -i '' \"s/#define NITRO_VERSION \\\".*\\\"/#define NITRO_VERSION \\\"$version\\\"/\" ./cpp/utils/NitroDefines.hpp",
|
|
64
63
|
"postversion": "bun run write-native-version",
|
|
65
64
|
"build": "rm -rf lib && bun typecheck && bob build",
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// ObjectUtils.cpp
|
|
3
|
-
// react-native-nitro
|
|
4
|
-
//
|
|
5
|
-
// Created by Marc Rousavy on 17.10.25.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
#include "ObjectUtils.hpp"
|
|
9
|
-
#include "JSICache.hpp"
|
|
10
|
-
#include "JSIHelpers.hpp"
|
|
11
|
-
#include "NitroDefines.hpp"
|
|
12
|
-
|
|
13
|
-
#if __has_include(<React-cxxreact/cxxreact/ReactNativeVersion.h>)
|
|
14
|
-
#include <React-cxxreact/cxxreact/ReactNativeVersion.h>
|
|
15
|
-
#if REACT_NATIVE_VERSION_MINOR >= 78
|
|
16
|
-
#define ENABLE_NATIVE_OBJECT_CREATE
|
|
17
|
-
#endif
|
|
18
|
-
#endif
|
|
19
|
-
|
|
20
|
-
namespace margelo::nitro {
|
|
21
|
-
|
|
22
|
-
using namespace facebook;
|
|
23
|
-
|
|
24
|
-
std::unordered_map<jsi::Runtime*, ObjectUtils::FunctionCache> ObjectUtils::_cache;
|
|
25
|
-
|
|
26
|
-
const char* ObjectUtils::getKnownGlobalPropertyNameString(KnownGlobalPropertyName name) {
|
|
27
|
-
switch (name) {
|
|
28
|
-
case KnownGlobalPropertyName::DISPATCHER:
|
|
29
|
-
return "__nitroDispatcher";
|
|
30
|
-
case KnownGlobalPropertyName::JSI_CACHE:
|
|
31
|
-
return "__nitroJsiCache";
|
|
32
|
-
case KnownGlobalPropertyName::NITRO_MODULES_PROXY:
|
|
33
|
-
return "NitroModulesProxy";
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
jsi::Object ObjectUtils::create(jsi::Runtime& runtime, const jsi::Value& prototype, bool allowCache) {
|
|
38
|
-
#ifdef ENABLE_NATIVE_OBJECT_CREATE
|
|
39
|
-
return jsi::Object::create(runtime, prototype);
|
|
40
|
-
#else
|
|
41
|
-
BorrowingReference<jsi::Function> createFn = getGlobalFunction(
|
|
42
|
-
runtime, "Object.create",
|
|
43
|
-
[](jsi::Runtime& runtime) {
|
|
44
|
-
return runtime.global().getPropertyAsObject(runtime, "Object").getPropertyAsFunction(runtime, "create");
|
|
45
|
-
},
|
|
46
|
-
allowCache);
|
|
47
|
-
return createFn->call(runtime, prototype).getObject(runtime);
|
|
48
|
-
#endif
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
void ObjectUtils::defineGlobal(jsi::Runtime& runtime, KnownGlobalPropertyName name, jsi::Value&& value, bool allowCache) {
|
|
52
|
-
const char* nameString = getKnownGlobalPropertyNameString(name);
|
|
53
|
-
|
|
54
|
-
#ifdef NITRO_DEBUG
|
|
55
|
-
// In debug, let's perform additional safety checks.
|
|
56
|
-
if (runtime.global().hasProperty(runtime, nameString)) [[unlikely]] {
|
|
57
|
-
throw std::runtime_error("Failed to set `global." + std::string(nameString) + "` - it already exists for Runtime \"" +
|
|
58
|
-
getRuntimeId(runtime) + "\"! Did you call `defineGlobal(\"" + std::string(nameString) +
|
|
59
|
-
"\")` twice? Did you link Nitro Modules twice?");
|
|
60
|
-
}
|
|
61
|
-
defineProperty(runtime, runtime.global(), nameString,
|
|
62
|
-
PlainPropertyDescriptor{.configurable = false, .enumerable = true, .value = std::move(value), .writable = false},
|
|
63
|
-
allowCache);
|
|
64
|
-
#else
|
|
65
|
-
// In release, just set the property.
|
|
66
|
-
runtime.global().setProperty(runtime, nameString, std::move(value));
|
|
67
|
-
#endif
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
void ObjectUtils::defineProperty(jsi::Runtime& runtime, const jsi::Object& object, const char* propertyName,
|
|
71
|
-
PlainPropertyDescriptor&& descriptor, bool allowCache) {
|
|
72
|
-
BorrowingReference<jsi::Function> definePropertyFn = getGlobalFunction(
|
|
73
|
-
runtime, "Object.defineProperty",
|
|
74
|
-
[](jsi::Runtime& runtime) {
|
|
75
|
-
return runtime.global().getPropertyAsObject(runtime, "Object").getPropertyAsFunction(runtime, "defineProperty");
|
|
76
|
-
},
|
|
77
|
-
allowCache);
|
|
78
|
-
|
|
79
|
-
jsi::String nameJs = jsi::String::createFromAscii(runtime, propertyName);
|
|
80
|
-
|
|
81
|
-
jsi::Object descriptorJs(runtime);
|
|
82
|
-
descriptorJs.setProperty(runtime, "configurable", jsi::Value(descriptor.configurable));
|
|
83
|
-
descriptorJs.setProperty(runtime, "enumerable", jsi::Value(descriptor.enumerable));
|
|
84
|
-
descriptorJs.setProperty(runtime, "value", std::move(descriptor.value));
|
|
85
|
-
descriptorJs.setProperty(runtime, "writable", jsi::Value(descriptor.writable));
|
|
86
|
-
|
|
87
|
-
definePropertyFn->call(runtime, object, std::move(nameJs), std::move(descriptorJs));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
void ObjectUtils::defineProperty(jsi::Runtime& runtime, const jsi::Object& object, const char* propertyName,
|
|
91
|
-
ComputedReadonlyPropertyDescriptor&& descriptor, bool allowCache) {
|
|
92
|
-
BorrowingReference<jsi::Function> definePropertyFn = getGlobalFunction(
|
|
93
|
-
runtime, "Object.defineProperty",
|
|
94
|
-
[](jsi::Runtime& runtime) {
|
|
95
|
-
return runtime.global().getPropertyAsObject(runtime, "Object").getPropertyAsFunction(runtime, "defineProperty");
|
|
96
|
-
},
|
|
97
|
-
allowCache);
|
|
98
|
-
|
|
99
|
-
jsi::String nameJs = jsi::String::createFromAscii(runtime, propertyName);
|
|
100
|
-
|
|
101
|
-
jsi::Object descriptorJs(runtime);
|
|
102
|
-
descriptorJs.setProperty(runtime, "configurable", jsi::Value(descriptor.configurable));
|
|
103
|
-
descriptorJs.setProperty(runtime, "enumerable", jsi::Value(descriptor.enumerable));
|
|
104
|
-
descriptorJs.setProperty(runtime, "get", std::move(descriptor.get));
|
|
105
|
-
|
|
106
|
-
definePropertyFn->call(runtime, object, std::move(nameJs), std::move(descriptorJs));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
void ObjectUtils::defineProperty(jsi::Runtime& runtime, const jsi::Object& object, const char* propertyName,
|
|
110
|
-
ComputedPropertyDescriptor&& descriptor, bool allowCache) {
|
|
111
|
-
BorrowingReference<jsi::Function> definePropertyFn = getGlobalFunction(
|
|
112
|
-
runtime, "Object.defineProperty",
|
|
113
|
-
[](jsi::Runtime& runtime) {
|
|
114
|
-
return runtime.global().getPropertyAsObject(runtime, "Object").getPropertyAsFunction(runtime, "defineProperty");
|
|
115
|
-
},
|
|
116
|
-
allowCache);
|
|
117
|
-
|
|
118
|
-
jsi::String nameJs = jsi::String::createFromAscii(runtime, propertyName);
|
|
119
|
-
|
|
120
|
-
jsi::Object descriptorJs(runtime);
|
|
121
|
-
descriptorJs.setProperty(runtime, "configurable", jsi::Value(descriptor.configurable));
|
|
122
|
-
descriptorJs.setProperty(runtime, "enumerable", jsi::Value(descriptor.enumerable));
|
|
123
|
-
descriptorJs.setProperty(runtime, "get", std::move(descriptor.get));
|
|
124
|
-
descriptorJs.setProperty(runtime, "set", std::move(descriptor.set));
|
|
125
|
-
|
|
126
|
-
definePropertyFn->call(runtime, object, std::move(nameJs), std::move(descriptorJs));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
void ObjectUtils::freeze(jsi::Runtime& runtime, const jsi::Object& object, bool allowCache) {
|
|
130
|
-
BorrowingReference<jsi::Function> freezeFn = getGlobalFunction(
|
|
131
|
-
runtime, "Object.freeze",
|
|
132
|
-
[](jsi::Runtime& runtime) {
|
|
133
|
-
return runtime.global().getPropertyAsObject(runtime, "Object").getPropertyAsFunction(runtime, "freeze");
|
|
134
|
-
},
|
|
135
|
-
allowCache);
|
|
136
|
-
|
|
137
|
-
freezeFn->call(runtime, object);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
BorrowingReference<jsi::Function> ObjectUtils::getGlobalFunction(jsi::Runtime& runtime, const char* key,
|
|
141
|
-
std::function<jsi::Function(jsi::Runtime&)> getFunction, bool allowCache) {
|
|
142
|
-
if (allowCache) [[likely]] {
|
|
143
|
-
// Let's try to find the function in cache
|
|
144
|
-
FunctionCache& functionCache = _cache[&runtime];
|
|
145
|
-
std::string stringKey = key;
|
|
146
|
-
auto iterator = functionCache.find(stringKey);
|
|
147
|
-
if (iterator != functionCache.end()) {
|
|
148
|
-
// We found it! Let's check if the reference is still valid...
|
|
149
|
-
BorrowingReference<jsi::Function> function = iterator->second;
|
|
150
|
-
if (function != nullptr) [[likely]] {
|
|
151
|
-
// It's still alive - let's use it from cache!
|
|
152
|
-
return function;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
// We haven't found the function with the given key in cache - so let's get it:
|
|
157
|
-
jsi::Function function = getFunction(runtime);
|
|
158
|
-
if (allowCache) [[likely]] {
|
|
159
|
-
// Let's throw it in cache!
|
|
160
|
-
FunctionCache& functionCache = _cache[&runtime];
|
|
161
|
-
JSICacheReference jsiCache = JSICache::getOrCreateCache(runtime);
|
|
162
|
-
BorrowingReference<jsi::Function> sharedFunction = jsiCache.makeShared(std::move(function));
|
|
163
|
-
functionCache[std::string(key)] = sharedFunction;
|
|
164
|
-
return sharedFunction;
|
|
165
|
-
} else {
|
|
166
|
-
// We are not allowed to use cache - so let's just wrap it in a BorrowingReference to match the return type.
|
|
167
|
-
jsi::Function* heapFunction = new jsi::Function(std::move(function));
|
|
168
|
-
return BorrowingReference<jsi::Function>(heapFunction);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
} // namespace margelo::nitro
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// ObjectUtils.hpp
|
|
3
|
-
// react-native-nitro
|
|
4
|
-
//
|
|
5
|
-
// Created by Marc Rousavy on 17.10.25.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
#pragma once
|
|
9
|
-
|
|
10
|
-
#include "BorrowingReference.hpp"
|
|
11
|
-
#include <jsi/jsi.h>
|
|
12
|
-
#include <unordered_map>
|
|
13
|
-
|
|
14
|
-
namespace margelo::nitro {
|
|
15
|
-
|
|
16
|
-
using namespace facebook;
|
|
17
|
-
|
|
18
|
-
struct PlainPropertyDescriptor {
|
|
19
|
-
bool configurable;
|
|
20
|
-
bool enumerable;
|
|
21
|
-
jsi::Value value;
|
|
22
|
-
bool writable;
|
|
23
|
-
};
|
|
24
|
-
struct ComputedReadonlyPropertyDescriptor {
|
|
25
|
-
bool configurable;
|
|
26
|
-
bool enumerable;
|
|
27
|
-
jsi::Function get;
|
|
28
|
-
};
|
|
29
|
-
struct ComputedPropertyDescriptor {
|
|
30
|
-
bool configurable;
|
|
31
|
-
bool enumerable;
|
|
32
|
-
jsi::Function get;
|
|
33
|
-
jsi::Function set;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
enum class KnownGlobalPropertyName { DISPATCHER, JSI_CACHE, NITRO_MODULES_PROXY };
|
|
37
|
-
|
|
38
|
-
class ObjectUtils {
|
|
39
|
-
public:
|
|
40
|
-
ObjectUtils() = delete;
|
|
41
|
-
~ObjectUtils() = delete;
|
|
42
|
-
|
|
43
|
-
public:
|
|
44
|
-
/**
|
|
45
|
-
* Create a new `jsi::Object` with the given `prototype`.
|
|
46
|
-
* Uses a native implementation if possible.
|
|
47
|
-
*/
|
|
48
|
-
static jsi::Object create(jsi::Runtime& runtime, const jsi::Value& prototype, bool allowCache = true);
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Define a global value for the given Runtime.
|
|
52
|
-
* In debug, this performs additional safety checks such as freezing the property.
|
|
53
|
-
*/
|
|
54
|
-
static void defineGlobal(jsi::Runtime& runtime, KnownGlobalPropertyName name, jsi::Value&& value, bool allowCache = true);
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Define a plain property on the given `object` with the given `propertyName`.
|
|
58
|
-
* The `descriptor` defines the attributes of this property.
|
|
59
|
-
*/
|
|
60
|
-
static void defineProperty(jsi::Runtime& runtime, const jsi::Object& object, const char* propertyName,
|
|
61
|
-
PlainPropertyDescriptor&& descriptor, bool allowCache = true);
|
|
62
|
-
/**
|
|
63
|
-
* Define a plain property on the given `object` with the given `propertyName`.
|
|
64
|
-
* The `descriptor` defines the attributes of this property.
|
|
65
|
-
*/
|
|
66
|
-
static void defineProperty(jsi::Runtime& runtime, const jsi::Object& object, const char* propertyName,
|
|
67
|
-
ComputedReadonlyPropertyDescriptor&& descriptor, bool allowCache = true);
|
|
68
|
-
/**
|
|
69
|
-
* Define a plain property on the given `object` with the given `propertyName`.
|
|
70
|
-
* The `descriptor` defines the attributes of this property.
|
|
71
|
-
*/
|
|
72
|
-
static void defineProperty(jsi::Runtime& runtime, const jsi::Object& object, const char* propertyName,
|
|
73
|
-
ComputedPropertyDescriptor&& descriptor, bool allowCache = true);
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Freezes all values of the given `object`.
|
|
77
|
-
*/
|
|
78
|
-
static void freeze(jsi::Runtime& runtime, const jsi::Object& object, bool allowCache = true);
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Get a string name for a known global property name.
|
|
82
|
-
*/
|
|
83
|
-
static const char* getKnownGlobalPropertyNameString(KnownGlobalPropertyName name);
|
|
84
|
-
|
|
85
|
-
private:
|
|
86
|
-
using FunctionCache = std::unordered_map<std::string, BorrowingReference<jsi::Function>>;
|
|
87
|
-
static std::unordered_map<jsi::Runtime*, FunctionCache> _cache;
|
|
88
|
-
|
|
89
|
-
static BorrowingReference<jsi::Function> getGlobalFunction(jsi::Runtime& runtime, const char* key,
|
|
90
|
-
std::function<jsi::Function(jsi::Runtime&)> getFunction,
|
|
91
|
-
bool allowCache = true);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
} // namespace margelo::nitro
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// NitroLogger.mm
|
|
3
|
-
// react-native-nitro
|
|
4
|
-
//
|
|
5
|
-
// Created by Marc Rousavy on 14.07.24.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
#include "NitroLogger.hpp"
|
|
9
|
-
#include "NitroDefines.hpp"
|
|
10
|
-
#include <Foundation/Foundation.h>
|
|
11
|
-
|
|
12
|
-
namespace margelo::nitro {
|
|
13
|
-
|
|
14
|
-
const char* levelToString(LogLevel level) {
|
|
15
|
-
switch (level) {
|
|
16
|
-
case LogLevel::Debug:
|
|
17
|
-
return "DEBUG";
|
|
18
|
-
case LogLevel::Info:
|
|
19
|
-
return "INFO";
|
|
20
|
-
case LogLevel::Warning:
|
|
21
|
-
return "WARNING";
|
|
22
|
-
case LogLevel::Error:
|
|
23
|
-
return "ERROR";
|
|
24
|
-
default:
|
|
25
|
-
throw std::invalid_argument("Invalid LogLevel!");
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
void Logger::nativeLog([[maybe_unused]] LogLevel level, [[maybe_unused]] const char* tag, [[maybe_unused]] const std::string& message) {
|
|
30
|
-
#ifdef NITRO_DEBUG
|
|
31
|
-
const char* logLevel = levelToString(level);
|
|
32
|
-
NSLog(@"[%s] [Nitro.%s] %s", logLevel, tag, message.c_str());
|
|
33
|
-
#endif
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
} // namespace margelo::nitro
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// ThreadUtils.mm
|
|
3
|
-
// react-native-nitro
|
|
4
|
-
//
|
|
5
|
-
// Created by Marc Rousavy on 14.07.24.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
#include "ThreadUtils.hpp"
|
|
9
|
-
#include <pthread.h>
|
|
10
|
-
#include <sstream>
|
|
11
|
-
#include <thread>
|
|
12
|
-
|
|
13
|
-
// ObjC import
|
|
14
|
-
#import <Foundation/Foundation.h>
|
|
15
|
-
|
|
16
|
-
namespace margelo::nitro {
|
|
17
|
-
|
|
18
|
-
std::string ThreadUtils::getThreadName() {
|
|
19
|
-
// Try using NSThread APIs
|
|
20
|
-
NSString* threadName = NSThread.currentThread.name;
|
|
21
|
-
if (threadName != nil && threadName.length > 0) {
|
|
22
|
-
return threadName.UTF8String;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Try using DispatchQueue APIs as fallback
|
|
26
|
-
#pragma clang diagnostic push
|
|
27
|
-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
28
|
-
dispatch_queue_t queue = dispatch_get_current_queue();
|
|
29
|
-
#pragma clang diagnostic pop
|
|
30
|
-
const char* label = dispatch_queue_get_label(queue);
|
|
31
|
-
if (label != nullptr) {
|
|
32
|
-
return label;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Fall back to this_thread ID
|
|
36
|
-
std::stringstream stream;
|
|
37
|
-
stream << std::this_thread::get_id();
|
|
38
|
-
std::string threadId = stream.str();
|
|
39
|
-
return "Thread #" + threadId;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
void ThreadUtils::setThreadName(const std::string& name) {
|
|
43
|
-
pthread_setname_np(name.c_str());
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
} // namespace margelo::nitro
|