-
Notifications
You must be signed in to change notification settings - Fork 78
Add GetNumEntities() for action client #1123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -126,28 +126,6 @@ Napi::Value ActionSendGoalRequest(const Napi::CallbackInfo& info) { | |||||||||||
return Napi::Number::New(env, static_cast<int32_t>(sequence_number)); | ||||||||||||
} | ||||||||||||
|
||||||||||||
Napi::Value ActionTakeCancelRequest(const Napi::CallbackInfo& info) { | ||||||||||||
Napi::Env env = info.Env(); | ||||||||||||
|
||||||||||||
RclHandle* action_server_handle = | ||||||||||||
RclHandle::Unwrap(info[0].As<Napi::Object>()); | ||||||||||||
rcl_action_server_t* action_server = | ||||||||||||
reinterpret_cast<rcl_action_server_t*>(action_server_handle->ptr()); | ||||||||||||
rmw_request_id_t* header = | ||||||||||||
reinterpret_cast<rmw_request_id_t*>(malloc(sizeof(rmw_request_id_t))); | ||||||||||||
|
||||||||||||
void* taken_request = info[1].As<Napi::Buffer<char>>().Data(); | ||||||||||||
rcl_ret_t ret = | ||||||||||||
rcl_action_take_cancel_request(action_server, header, taken_request); | ||||||||||||
if (ret != RCL_RET_ACTION_SERVER_TAKE_FAILED) { | ||||||||||||
auto js_obj = RclHandle::NewInstance(env, header, nullptr, | ||||||||||||
[](void* ptr) { free(ptr); }); | ||||||||||||
return js_obj; | ||||||||||||
} | ||||||||||||
|
||||||||||||
return env.Undefined(); | ||||||||||||
} | ||||||||||||
|
||||||||||||
Napi::Value ActionSendResultRequest(const Napi::CallbackInfo& info) { | ||||||||||||
Napi::Env env = info.Env(); | ||||||||||||
|
||||||||||||
|
@@ -211,20 +189,73 @@ Napi::Value ActionTakeStatus(const Napi::CallbackInfo& info) { | |||||||||||
return env.Undefined(); | ||||||||||||
} | ||||||||||||
|
||||||||||||
Napi::Value GetNumEntities(const Napi::CallbackInfo& info) { | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Add a comment outlining the mapping between native entity counts and the JavaScript object keys to improve maintainability and assist future developers in understanding the conversion. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||
Napi::Env env = info.Env(); | ||||||||||||
RclHandle* action_client_handle = | ||||||||||||
RclHandle::Unwrap(info[0].As<Napi::Object>()); | ||||||||||||
rcl_action_client_t* action_client = | ||||||||||||
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr()); | ||||||||||||
|
||||||||||||
size_t num_subscriptions = 0u; | ||||||||||||
size_t num_guard_conditions = 0u; | ||||||||||||
size_t num_timers = 0u; | ||||||||||||
size_t num_clients = 0u; | ||||||||||||
size_t num_services = 0u; | ||||||||||||
|
||||||||||||
rcl_ret_t ret; | ||||||||||||
ret = rcl_action_client_wait_set_get_num_entities( | ||||||||||||
action_client, &num_subscriptions, &num_guard_conditions, &num_timers, | ||||||||||||
&num_clients, &num_services); | ||||||||||||
if (RCL_RET_OK != ret) { | ||||||||||||
rcl_reset_error(); | ||||||||||||
std::string error_text{ | ||||||||||||
"Failed to get number of entities for 'rcl_action_client_t'"}; | ||||||||||||
Comment on lines
+210
to
+212
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider including the actual error code value in the thrown error message to provide better context for debugging failures from rcl_action_client_wait_set_get_num_entities.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||
Napi::Error::New(env, error_text).ThrowAsJavaScriptException(); | ||||||||||||
return env.Undefined(); | ||||||||||||
} | ||||||||||||
Napi::Object entities = Napi::Object::New(env); | ||||||||||||
entities.Set("subscriptionsNumber", | ||||||||||||
Napi::Number::New(env, num_subscriptions)); | ||||||||||||
entities.Set("guardConditionsNumber", | ||||||||||||
Napi::Number::New(env, num_guard_conditions)); | ||||||||||||
entities.Set("timersNumber", Napi::Number::New(env, num_timers)); | ||||||||||||
entities.Set("clientsNumber", Napi::Number::New(env, num_clients)); | ||||||||||||
entities.Set("servicesNumber", Napi::Number::New(env, num_services)); | ||||||||||||
return entities; | ||||||||||||
} | ||||||||||||
|
||||||||||||
Napi::Value ActionSendCancelRequest(const Napi::CallbackInfo& info) { | ||||||||||||
Napi::Env env = info.Env(); | ||||||||||||
|
||||||||||||
RclHandle* action_client_handle = | ||||||||||||
RclHandle::Unwrap(info[0].As<Napi::Object>()); | ||||||||||||
rcl_action_client_t* action_client = | ||||||||||||
reinterpret_cast<rcl_action_client_t*>(action_client_handle->ptr()); | ||||||||||||
void* buffer = info[1].As<Napi::Buffer<char>>().Data(); | ||||||||||||
|
||||||||||||
int64_t sequence_number; | ||||||||||||
THROW_ERROR_IF_NOT_EQUAL( | ||||||||||||
rcl_action_send_cancel_request(action_client, buffer, &sequence_number), | ||||||||||||
RCL_RET_OK, rcl_get_error_string().str); | ||||||||||||
|
||||||||||||
return Napi::Number::New(env, static_cast<int32_t>(sequence_number)); | ||||||||||||
} | ||||||||||||
|
||||||||||||
Napi::Object InitActionClientBindings(Napi::Env env, Napi::Object exports) { | ||||||||||||
exports.Set("actionCreateClient", | ||||||||||||
Napi::Function::New(env, ActionCreateClient)); | ||||||||||||
exports.Set("actionServerIsAvailable", | ||||||||||||
Napi::Function::New(env, ActionServerIsAvailable)); | ||||||||||||
exports.Set("actionSendGoalRequest", | ||||||||||||
Napi::Function::New(env, ActionSendGoalRequest)); | ||||||||||||
exports.Set("actionTakeCancelRequest", | ||||||||||||
Napi::Function::New(env, ActionTakeCancelRequest)); | ||||||||||||
exports.Set("actionSendResultRequest", | ||||||||||||
Napi::Function::New(env, ActionSendResultRequest)); | ||||||||||||
exports.Set("actionTakeFeedback", | ||||||||||||
Napi::Function::New(env, ActionTakeFeedback)); | ||||||||||||
exports.Set("actionTakeStatus", Napi::Function::New(env, ActionTakeStatus)); | ||||||||||||
exports.Set("getNumEntities", Napi::Function::New(env, GetNumEntities)); | ||||||||||||
exports.Set("actionSendCancelRequest", | ||||||||||||
Napi::Function::New(env, ActionSendCancelRequest)); | ||||||||||||
return exports; | ||||||||||||
} | ||||||||||||
|
||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider expanding the doc comment for getNumEntities() to explicitly list the returned object properties (subscriptionsNumber, guardConditionsNumber, timersNumber, clientsNumber, servicesNumber) for better clarity.
Copilot uses AI. Check for mistakes.