-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||||||||||||
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; | ||||||||||||
} | ||||||||||||
|
||||||||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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] 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.