Skip to content

Commit 90459a1

Browse files
committed
Move configure client introspection to binding of client
1 parent 2d70163 commit 90459a1

File tree

4 files changed

+51
-30
lines changed

4 files changed

+51
-30
lines changed

lib/client.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,14 @@ class Client extends Entity {
147147
}
148148

149149
let type = this.typeClass.type();
150-
rclnodejs.configureServiceIntrospection(
150+
rclnodejs.configureClientIntrospection(
151151
this.handle,
152152
this._nodeHandle,
153153
clock.handle,
154154
type.interfaceName,
155155
type.pkgName,
156156
qos,
157-
introspectionState,
158-
false
157+
introspectionState
159158
);
160159
}
161160
}

lib/service.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ class Service extends Entity {
138138
type.interfaceName,
139139
type.pkgName,
140140
qos,
141-
introspectionState,
142-
true
141+
introspectionState
143142
);
144143
}
145144

src/rcl_client_bindings.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,43 @@ Napi::Value ServiceServerIsAvailable(const Napi::CallbackInfo& info) {
128128
return Napi::Boolean::New(env, is_available);
129129
}
130130

131+
#if ROS_VERSION > 2205 // 2205 == Humble
132+
Napi::Value ConfigureClientIntrospection(const Napi::CallbackInfo& info) {
133+
Napi::Env env = info.Env();
134+
135+
RclHandle* client_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
136+
rcl_client_t* client = reinterpret_cast<rcl_client_t*>(client_handle->ptr());
137+
RclHandle* node_handle = RclHandle::Unwrap(info[1].As<Napi::Object>());
138+
rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
139+
rcl_clock_t* clock = reinterpret_cast<rcl_clock_t*>(
140+
RclHandle::Unwrap(info[2].As<Napi::Object>())->ptr());
141+
142+
std::string interface_name = info[3].As<Napi::String>().Utf8Value();
143+
std::string package_name = info[4].As<Napi::String>().Utf8Value();
144+
const rosidl_service_type_support_t* ts =
145+
GetServiceTypeSupport(package_name, interface_name);
146+
147+
if (ts) {
148+
rcl_publisher_options_t publisher_ops = rcl_publisher_get_default_options();
149+
auto qos_profile = GetQoSProfile(info[5]);
150+
if (qos_profile) {
151+
publisher_ops.qos = *qos_profile;
152+
}
153+
rcl_service_introspection_state_t state =
154+
static_cast<rcl_service_introspection_state_t>(
155+
info[6].As<Napi::Number>().Uint32Value());
156+
157+
THROW_ERROR_IF_NOT_EQUAL(rcl_client_configure_service_introspection(
158+
client, node, clock, ts, publisher_ops, state),
159+
RCL_RET_OK, rcl_get_error_string().str);
160+
} else {
161+
Napi::Error::New(env, GetErrorMessageAndClear())
162+
.ThrowAsJavaScriptException();
163+
}
164+
return env.Undefined();
165+
}
166+
#endif
167+
131168
Napi::Object InitClientBindings(Napi::Env env, Napi::Object exports) {
132169
exports.Set("createClient", Napi::Function::New(env, CreateClient));
133170
exports.Set("sendRequest", Napi::Function::New(env, SendRequest));
@@ -136,6 +173,10 @@ Napi::Object InitClientBindings(Napi::Env env, Napi::Object exports) {
136173
Napi::Function::New(env, GetClientServiceName));
137174
exports.Set("serviceServerIsAvailable",
138175
Napi::Function::New(env, ServiceServerIsAvailable));
176+
#if ROS_VERSION > 2205 // 2205 == Humble
177+
exports.Set("configureClientIntrospection",
178+
Napi::Function::New(env, ConfigureClientIntrospection));
179+
#endif
139180
return exports;
140181
}
141182

src/rcl_service_bindings.cpp

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ Napi::Value GetServiceServiceName(const Napi::CallbackInfo& info) {
120120
Napi::Value ConfigureServiceIntrospection(const Napi::CallbackInfo& info) {
121121
Napi::Env env = info.Env();
122122

123+
RclHandle* service_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
124+
rcl_service_t* service =
125+
reinterpret_cast<rcl_service_t*>(service_handle->ptr());
123126
RclHandle* node_handle = RclHandle::Unwrap(info[1].As<Napi::Object>());
124127
rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr());
125128

@@ -137,39 +140,18 @@ Napi::Value ConfigureServiceIntrospection(const Napi::CallbackInfo& info) {
137140
if (qos_profile) {
138141
publisher_ops.qos = *qos_profile;
139142
}
140-
141143
rcl_service_introspection_state_t state =
142144
static_cast<rcl_service_introspection_state_t>(
143145
info[6].As<Napi::Number>().Uint32Value());
144146

145-
bool configureForService = info[7].As<Napi::Boolean>();
146-
147-
if (configureForService) {
148-
RclHandle* service_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
149-
rcl_service_t* service =
150-
reinterpret_cast<rcl_service_t*>(service_handle->ptr());
151-
152-
THROW_ERROR_IF_NOT_EQUAL(
153-
rcl_service_configure_service_introspection(service, node, clock, ts,
154-
publisher_ops, state),
155-
RCL_RET_OK, rcl_get_error_string().str);
156-
157-
} else {
158-
RclHandle* client_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
159-
rcl_client_t* client =
160-
reinterpret_cast<rcl_client_t*>(client_handle->ptr());
161-
162-
THROW_ERROR_IF_NOT_EQUAL(
163-
rcl_client_configure_service_introspection(client, node, clock, ts,
164-
publisher_ops, state),
165-
RCL_RET_OK, rcl_get_error_string().str);
166-
}
167-
147+
THROW_ERROR_IF_NOT_EQUAL(
148+
rcl_service_configure_service_introspection(service, node, clock, ts,
149+
publisher_ops, state),
150+
RCL_RET_OK, rcl_get_error_string().str);
168151
} else {
169152
Napi::Error::New(env, GetErrorMessageAndClear())
170153
.ThrowAsJavaScriptException();
171154
}
172-
173155
return env.Undefined();
174156
}
175157
#endif

0 commit comments

Comments
 (0)