Skip to content

Commit 4ab6985

Browse files
committed
Align / simplify namespace and host package functions
1 parent 3a291af commit 4ab6985

File tree

14 files changed

+157
-173
lines changed

14 files changed

+157
-173
lines changed

packages/host/android/src/main/cpp/OnLoad.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
// Called when the library is loaded
99
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
10-
callstack::nodeapihost::injectIntoWeakNodeApi();
10+
callstack::react_native_node_api::injectIntoWeakNodeApi();
1111
// Register the C++ TurboModule
1212
facebook::react::registerCxxModuleToGlobalModuleMap(
13-
callstack::nodeapihost::CxxNodeApiHostModule::kModuleName,
13+
callstack::react_native_node_api::CxxNodeApiHostModule::kModuleName,
1414
[](std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
15-
return std::make_shared<callstack::nodeapihost::CxxNodeApiHostModule>(
16-
jsInvoker);
15+
return std::make_shared<
16+
callstack::react_native_node_api::CxxNodeApiHostModule>(jsInvoker);
1717
});
1818
return JNI_VERSION_1_6;
1919
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.callstack.node_api_modules
1+
package com.callstack.react_native_node_api
22

33
import com.facebook.hermes.reactexecutor.HermesExecutor
44
import com.facebook.react.BaseReactPackage
@@ -10,7 +10,7 @@ import com.facebook.soloader.SoLoader
1010

1111
import java.util.HashMap
1212

13-
class NodeApiModulesPackage : BaseReactPackage() {
13+
class NodeApiHostPackage : BaseReactPackage() {
1414
init {
1515
SoLoader.loadLibrary("node-api-host")
1616
}

packages/host/apple/NodeApiHostModuleProvider.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
#import "WeakNodeApiInjector.hpp"
33

44
#import <ReactCommon/CxxTurboModuleUtils.h>
5-
@interface NodeApiHost : NSObject
5+
@interface NodeApiHostPackage : NSObject
66

77
@end
88

9-
@implementation NodeApiHost
9+
@implementation NodeApiHostPackage
1010
+ (void)load {
11-
callstack::nodeapihost::injectIntoWeakNodeApi();
11+
callstack::react_native_node_api::injectIntoWeakNodeApi();
1212

1313
facebook::react::registerCxxModuleToGlobalModuleMap(
14-
callstack::nodeapihost::CxxNodeApiHostModule::kModuleName,
14+
callstack::react_native_node_api::CxxNodeApiHostModule::kModuleName,
1515
[](std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
16-
return std::make_shared<callstack::nodeapihost::CxxNodeApiHostModule>(
17-
jsInvoker);
16+
return std::make_shared<
17+
callstack::react_native_node_api::CxxNodeApiHostModule>(jsInvoker);
1818
});
1919
}
2020

packages/host/cpp/AddonLoaders.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <dlfcn.h>
88
#include <stdio.h>
99

10-
using callstack::nodeapihost::log_debug;
10+
using callstack::react_native_node_api::log_debug;
1111

1212
struct PosixLoader {
1313
using Module = void *;

packages/host/cpp/CxxNodeApiHostModule.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
using namespace facebook;
66

7-
namespace callstack::nodeapihost {
7+
namespace callstack::react_native_node_api {
88

99
CxxNodeApiHostModule::CxxNodeApiHostModule(
1010
std::shared_ptr<react::CallInvoker> jsInvoker)
@@ -127,8 +127,8 @@ bool CxxNodeApiHostModule::initializeNodeModule(jsi::Runtime &rt,
127127
napi_set_named_property(env, global, addon.generatedName.data(), exports);
128128
assert(status == napi_ok);
129129

130-
callstack::nodeapihost::setCallInvoker(env, callInvoker_);
130+
callstack::react_native_node_api::setCallInvoker(env, callInvoker_);
131131
return true;
132132
}
133133

134-
} // namespace callstack::nodeapihost
134+
} // namespace callstack::react_native_node_api

packages/host/cpp/CxxNodeApiHostModule.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "AddonLoaders.hpp"
88

9-
namespace callstack::nodeapihost {
9+
namespace callstack::react_native_node_api {
1010

1111
class JSI_EXPORT CxxNodeApiHostModule : public facebook::react::TurboModule {
1212
public:
@@ -37,4 +37,4 @@ class JSI_EXPORT CxxNodeApiHostModule : public facebook::react::TurboModule {
3737
bool initializeNodeModule(facebook::jsi::Runtime &rt, NodeAddon &addon);
3838
};
3939

40-
} // namespace callstack::nodeapihost
40+
} // namespace callstack::react_native_node_api

packages/host/cpp/Logger.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,33 @@ enum class LogLevel { Debug, Warning, Error };
1616

1717
constexpr std::string_view levelToString(LogLevel level) {
1818
switch (level) {
19-
case LogLevel::Debug:
20-
return "DEBUG";
21-
case LogLevel::Warning:
22-
return "WARNING";
23-
case LogLevel::Error:
24-
return "ERROR";
25-
default:
26-
return "UNKNOWN";
19+
case LogLevel::Debug:
20+
return "DEBUG";
21+
case LogLevel::Warning:
22+
return "WARNING";
23+
case LogLevel::Error:
24+
return "ERROR";
25+
default:
26+
return "UNKNOWN";
2727
}
2828
}
2929

3030
#if defined(__ANDROID__)
3131
constexpr int androidLogLevel(LogLevel level) {
3232
switch (level) {
33-
case LogLevel::Debug:
34-
return ANDROID_LOG_DEBUG;
35-
case LogLevel::Warning:
36-
return ANDROID_LOG_WARN;
37-
case LogLevel::Error:
38-
return ANDROID_LOG_ERROR;
39-
default:
40-
return ANDROID_LOG_UNKNOWN;
33+
case LogLevel::Debug:
34+
return ANDROID_LOG_DEBUG;
35+
case LogLevel::Warning:
36+
return ANDROID_LOG_WARN;
37+
case LogLevel::Error:
38+
return ANDROID_LOG_ERROR;
39+
default:
40+
return ANDROID_LOG_UNKNOWN;
4141
}
4242
}
4343
#endif
4444

45-
void log_message_internal(LogLevel level, const char* format, va_list args) {
45+
void log_message_internal(LogLevel level, const char *format, va_list args) {
4646
#if defined(__ANDROID__)
4747
__android_log_vprint(androidLogLevel(level), LOG_TAG, format, args);
4848
#elif defined(__APPLE__)
@@ -59,27 +59,27 @@ void log_message_internal(LogLevel level, const char* format, va_list args) {
5959
fprintf(stdout, "\n");
6060
#endif
6161
}
62-
} // anonymous namespace
62+
} // anonymous namespace
6363

64-
namespace callstack::nodeapihost {
64+
namespace callstack::react_native_node_api {
6565

66-
void log_debug(const char* format, ...) {
66+
void log_debug(const char *format, ...) {
6767
// TODO: Disable logging in release builds
6868
va_list args;
6969
va_start(args, format);
7070
log_message_internal(LogLevel::Debug, format, args);
7171
va_end(args);
7272
}
73-
void log_warning(const char* format, ...) {
73+
void log_warning(const char *format, ...) {
7474
va_list args;
7575
va_start(args, format);
7676
log_message_internal(LogLevel::Warning, format, args);
7777
va_end(args);
7878
}
79-
void log_error(const char* format, ...) {
79+
void log_error(const char *format, ...) {
8080
va_list args;
8181
va_start(args, format);
8282
log_message_internal(LogLevel::Error, format, args);
8383
va_end(args);
8484
}
85-
} // namespace callstack::nodeapihost
85+
} // namespace callstack::react_native_node_api

packages/host/cpp/Logger.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
#include <string>
44

5-
namespace callstack::nodeapihost {
6-
void log_debug(const char* format, ...);
7-
void log_warning(const char* format, ...);
8-
void log_error(const char* format, ...);
9-
} // namespace callstack::nodeapihost
5+
namespace callstack::react_native_node_api {
6+
void log_debug(const char *format, ...);
7+
void log_warning(const char *format, ...);
8+
void log_error(const char *format, ...);
9+
} // namespace callstack::react_native_node_api

packages/host/cpp/RuntimeNodeApi.cpp

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include "RuntimeNodeApi.hpp"
2-
#include <string>
32
#include "Logger.hpp"
43
#include "Versions.hpp"
4+
#include <string>
55

66
auto ArrayType = napi_uint8_array;
77

8-
namespace callstack::nodeapihost {
8+
namespace callstack::react_native_node_api {
99

10-
napi_status napi_create_buffer(
11-
napi_env env, size_t length, void** data, napi_value* result) {
10+
napi_status napi_create_buffer(napi_env env, size_t length, void **data,
11+
napi_value *result) {
1212
napi_value buffer;
1313
if (const auto status = napi_create_arraybuffer(env, length, data, &buffer);
1414
status != napi_ok) {
@@ -22,17 +22,15 @@ napi_status napi_create_buffer(
2222
return napi_create_typedarray(env, ArrayType, length, buffer, 0, result);
2323
}
2424

25-
napi_status napi_create_buffer_copy(napi_env env,
26-
size_t length,
27-
const void* data,
28-
void** result_data,
29-
napi_value* result) {
25+
napi_status napi_create_buffer_copy(napi_env env, size_t length,
26+
const void *data, void **result_data,
27+
napi_value *result) {
3028
if (!length || !data || !result) {
3129
return napi_invalid_arg;
3230
}
3331

3432
void *buffer = nullptr;
35-
if (const auto status = callstack::nodeapihost::napi_create_buffer(
33+
if (const auto status = callstack::react_native_node_api::napi_create_buffer(
3634
env, length, &buffer, result);
3735
status != napi_ok) {
3836
return status;
@@ -42,7 +40,7 @@ napi_status napi_create_buffer_copy(napi_env env,
4240
return napi_ok;
4341
}
4442

45-
napi_status napi_is_buffer(napi_env env, napi_value value, bool* result) {
43+
napi_status napi_is_buffer(napi_env env, napi_value value, bool *result) {
4644
if (!result) {
4745
return napi_invalid_arg;
4846
}
@@ -77,8 +75,8 @@ napi_status napi_is_buffer(napi_env env, napi_value value, bool* result) {
7775
return napi_ok;
7876
}
7977

80-
napi_status napi_get_buffer_info(
81-
napi_env env, napi_value value, void** data, size_t* length) {
78+
napi_status napi_get_buffer_info(napi_env env, napi_value value, void **data,
79+
size_t *length) {
8280
if (!data || !length) {
8381
return napi_invalid_arg;
8482
}
@@ -97,19 +95,17 @@ napi_status napi_get_buffer_info(
9795
auto isTypedArray{false};
9896
if (const auto status = napi_is_typedarray(env, value, &isTypedArray);
9997
status == napi_ok && isTypedArray) {
100-
return napi_get_typedarray_info(
101-
env, value, &ArrayType, length, data, nullptr, nullptr);
98+
return napi_get_typedarray_info(env, value, &ArrayType, length, data,
99+
nullptr, nullptr);
102100
}
103101

104102
return napi_ok;
105103
}
106104

107-
napi_status napi_create_external_buffer(napi_env env,
108-
size_t length,
109-
void* data,
110-
node_api_basic_finalize basic_finalize_cb,
111-
void* finalize_hint,
112-
napi_value* result) {
105+
napi_status
106+
napi_create_external_buffer(napi_env env, size_t length, void *data,
107+
node_api_basic_finalize basic_finalize_cb,
108+
void *finalize_hint, napi_value *result) {
113109
napi_value buffer;
114110
if (const auto status = napi_create_external_arraybuffer(
115111
env, data, length, basic_finalize_cb, finalize_hint, &buffer);
@@ -124,25 +120,20 @@ napi_status napi_create_external_buffer(napi_env env,
124120
return napi_create_typedarray(env, ArrayType, length, buffer, 0, result);
125121
}
126122

127-
void napi_fatal_error(const char* location,
128-
size_t location_len,
129-
const char* message,
130-
size_t message_len) {
123+
void napi_fatal_error(const char *location, size_t location_len,
124+
const char *message, size_t message_len) {
131125
if (location && location_len) {
132-
log_error("Fatal Node-API error: %.*s %.*s",
133-
static_cast<int>(location_len),
134-
location,
135-
static_cast<int>(message_len),
136-
message);
126+
log_error("Fatal Node-API error: %.*s %.*s", static_cast<int>(location_len),
127+
location, static_cast<int>(message_len), message);
137128
} else {
138-
log_error(
139-
"Fatal Node-API error: %.*s", static_cast<int>(message_len), message);
129+
log_error("Fatal Node-API error: %.*s", static_cast<int>(message_len),
130+
message);
140131
}
141132
abort();
142133
}
143134

144-
napi_status napi_get_node_version(
145-
node_api_basic_env env, const napi_node_version** result) {
135+
napi_status napi_get_node_version(node_api_basic_env env,
136+
const napi_node_version **result) {
146137
if (!result) {
147138
return napi_invalid_arg;
148139
}
@@ -151,7 +142,7 @@ napi_status napi_get_node_version(
151142
return napi_generic_failure;
152143
}
153144

154-
napi_status napi_get_version(node_api_basic_env env, uint32_t* result) {
145+
napi_status napi_get_version(node_api_basic_env env, uint32_t *result) {
155146
if (!result) {
156147
return napi_invalid_arg;
157148
}
@@ -160,4 +151,4 @@ napi_status napi_get_version(node_api_basic_env env, uint32_t* result) {
160151
return napi_ok;
161152
}
162153

163-
} // namespace callstack::nodeapihost
154+
} // namespace callstack::react_native_node_api

0 commit comments

Comments
 (0)