-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathaddon.cpp
More file actions
110 lines (101 loc) · 4.06 KB
/
addon.cpp
File metadata and controls
110 lines (101 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (c) 2017 Intel Corporation. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <node_api.h>
#include <rcutils/logging.h>
#include "clock_event.hpp"
#include "macros.h"
#include "rcl_action_client_bindings.h"
#include "rcl_action_goal_bindings.h"
#include "rcl_action_server_bindings.h"
#include "rcl_bindings.h"
#include "rcl_client_bindings.h"
#include "rcl_context_bindings.h"
#include "rcl_graph_bindings.h"
#include "rcl_guard_condition_bindings.h"
#include "rcl_handle.h"
#include "rcl_lifecycle_bindings.h"
#include "rcl_logging_bindings.h"
#include "rcl_names_bindings.h"
#include "rcl_node_bindings.h"
#include "rcl_publisher_bindings.h"
#include "rcl_serialization_bindings.h"
#include "rcl_service_bindings.h"
#include "rcl_subscription_bindings.h"
#include "rcl_time_point_bindings.h"
#include "rcl_timer_bindings.h"
#if ROS_VERSION > 2205 // ROS2 > Humble
#include "rcl_event_handle_bindings.h"
#include "rcl_type_description_service_bindings.h"
#endif
#include "rcl_utilities.h"
#include "ref_napi_bindings.h"
#include "shadow_node.h"
bool IsRunningInElectronRenderer(const Napi::Env& env) {
Napi::Object global = env.Global();
Napi::Object process = global.Get("process").As<Napi::Object>();
Napi::Value processType = process.Get("type");
return processType.StrictEquals(Napi::String::New(env, "renderer"));
}
Napi::Object InitModule(Napi::Env env, Napi::Object exports) {
// workaround process name mangling by chromium
//
// rcl logging uses `program_invocation_name` to determine the log file,
// chromium mangles the program name to include all args, this causes a
// ENAMETOOLONG error when starting ros. Workaround is to replace the first
// occurence of ' -' with the null terminator. see:
// https://unix.stackexchange.com/questions/432419/unexpected-non-null-encoding-of-proc-pid-cmdline
#if defined(__linux__) && defined(__GLIBC__)
if (IsRunningInElectronRenderer(env)) {
auto prog_name = program_invocation_name;
auto end = strstr(prog_name, " -");
assert(end);
prog_name[end - prog_name] = 0;
}
#endif
rclnodejs::StoreEnv(env);
// Init the C++ bindings.
rclnodejs::InitBindings(env, exports);
rclnodejs::InitActionClientBindings(env, exports);
rclnodejs::InitActionGoalBindings(env, exports);
rclnodejs::InitActionServerBindings(env, exports);
rclnodejs::InitClientBindings(env, exports);
rclnodejs::InitClockEventBindings(env, exports);
rclnodejs::InitContextBindings(env, exports);
rclnodejs::InitGraphBindings(env, exports);
rclnodejs::InitGuardConditionBindings(env, exports);
rclnodejs::InitLoggingBindings(env, exports);
rclnodejs::InitNamesBindings(env, exports);
rclnodejs::InitNodeBindings(env, exports);
rclnodejs::InitPublisherBindings(env, exports);
rclnodejs::InitServiceBindings(env, exports);
rclnodejs::InitSubscriptionBindings(env, exports);
rclnodejs::InitTimePointBindings(env, exports);
rclnodejs::InitTimerBindings(env, exports);
#if ROS_VERSION > 2205 // ROS2 > Humble
rclnodejs::InitTypeDescriptionServiceBindings(env, exports);
rclnodejs::InitEventHandleBindings(env, exports);
#endif
rclnodejs::InitLifecycleBindings(env, exports);
rclnodejs::InitSerializationBindings(env, exports);
rclnodejs::ShadowNode::Init(env, exports);
rclnodejs::RclHandle::Init(env, exports);
exports.Set("ref", rclnodejs::InitRefNapi(env));
#ifdef DEBUG_ON
int result = rcutils_logging_set_logger_level(PACKAGE_NAME,
RCUTILS_LOG_SEVERITY_DEBUG);
RCUTILS_UNUSED(result);
#endif
return exports;
}
NODE_API_MODULE(rclnodejs, InitModule)