-
Notifications
You must be signed in to change notification settings - Fork 78
Support type description service #1146
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 4 commits
Commits
Show all changes
5 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
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) 2025, The Robot Web Tools Contributors | ||
// | ||
// 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. | ||
|
||
'use strict'; | ||
|
||
const loader = require('./interface_loader.js'); | ||
const rclnodejs = require('bindings')('rclnodejs'); | ||
const Service = require('./service.js'); | ||
|
||
// This class is used to create a TypeDescriptionService which can be used to | ||
// retrieve information about types used by the node’s publishers, subscribers, | ||
// services or actions. | ||
class TypeDescriptionService { | ||
constructor(node) { | ||
this._node = node; | ||
this._serviceName = this._node.name() + '/get_type_description'; | ||
this._typeDescriptionServiceHandle = rclnodejs.initTypeDescriptionService( | ||
this._node.handle | ||
); | ||
this._typeClass = loader.loadInterface( | ||
'type_description_interfaces/srv/GetTypeDescription' | ||
); | ||
this._typeDescriptionService = null; | ||
} | ||
|
||
start() { | ||
if (this._typeDescriptionService) { | ||
return; | ||
} | ||
|
||
this._typeDescriptionService = new Service( | ||
this._node.handle, | ||
this._typeDescriptionServiceHandle, | ||
this._serviceName, | ||
this._typeClass, | ||
this._node._validateOptions(undefined), | ||
(request, response) => { | ||
const responseToBeSent = new this._typeClass.Response(); | ||
const requestReceived = new this._typeClass.Request(request); | ||
rclnodejs.handleRequest( | ||
this._node.handle, | ||
requestReceived.serialize(), | ||
responseToBeSent.serialize() | ||
); | ||
responseToBeSent.deserialize(responseToBeSent.refObject); | ||
rclnodejs.sendResponse( | ||
this._typeDescriptionServiceHandle, | ||
responseToBeSent.serialize(), | ||
response._header | ||
); | ||
return null; | ||
} | ||
); | ||
this._node._services.push(this._typeDescriptionService); | ||
this._node.syncHandles(); | ||
} | ||
|
||
/** | ||
* Get the node this | ||
* @return {Node} - The supported node. | ||
*/ | ||
get node() { | ||
return this._node; | ||
} | ||
|
||
static toTypeHash(topicTypeHash) { | ||
return `RIHS0${topicTypeHash.version}_${topicTypeHash.value.toString('hex')}`; | ||
} | ||
} | ||
|
||
module.exports = TypeDescriptionService; |
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) 2025, The Robot Web Tools Contributors | ||
// | ||
// 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 "rcl_type_description_service_bindings.h" | ||
|
||
#include <napi.h> | ||
#include <rcl/rcl.h> | ||
#include <rmw/types.h> | ||
|
||
#include "rcl_handle.h" | ||
|
||
namespace rclnodejs { | ||
|
||
Napi::Value InitTypeDescriptionService(const Napi::CallbackInfo& info) { | ||
Napi::Env env = info.Env(); | ||
RclHandle* node_handle = RclHandle::Unwrap(info[0].As<Napi::Object>()); | ||
rcl_node_t* node = reinterpret_cast<rcl_node_t*>(node_handle->ptr()); | ||
rcl_service_t* service = | ||
reinterpret_cast<rcl_service_t*>(malloc(sizeof(rcl_service_t))); | ||
*service = rcl_get_zero_initialized_service(); | ||
rcl_ret_t ret = rcl_node_type_description_service_init(service, node); | ||
if (RCL_RET_OK != ret) { | ||
Napi::Error::New(env, "Failed to initialize type description service") | ||
.ThrowAsJavaScriptException(); | ||
} | ||
|
||
auto service_handle = | ||
RclHandle::NewInstance(env, service, node_handle, [node, env](void* ptr) { | ||
rcl_service_t* service = reinterpret_cast<rcl_service_t*>(ptr); | ||
rcl_ret_t ret = rcl_service_fini(service, node); | ||
if (RCL_RET_OK != ret) { | ||
Napi::Error::New(env, "Failed to destroy type description service") | ||
.ThrowAsJavaScriptException(); | ||
} | ||
free(ptr); | ||
}); | ||
return service_handle; | ||
} | ||
|
||
Napi::Value HandleRequest(const Napi::CallbackInfo& info) { | ||
Napi::Env env = info.Env(); | ||
rcl_node_t* node = reinterpret_cast<rcl_node_t*>( | ||
RclHandle::Unwrap(info[0].As<Napi::Object>())->ptr()); | ||
void* request = info[1].As<Napi::Buffer<char>>().Data(); | ||
void* taken_response = info[2].As<Napi::Buffer<char>>().Data(); | ||
|
||
rmw_request_id_t header; | ||
rcl_node_type_description_service_handle_request( | ||
node, &header, | ||
static_cast< | ||
type_description_interfaces__srv__GetTypeDescription_Request*>( | ||
request), | ||
static_cast< | ||
type_description_interfaces__srv__GetTypeDescription_Response*>( | ||
taken_response)); | ||
return env.Undefined(); | ||
} | ||
|
||
Napi::Object InitTypeDescriptionServiceBindings(Napi::Env env, | ||
Napi::Object exports) { | ||
exports.Set("handleRequest", Napi::Function::New(env, HandleRequest)); | ||
exports.Set("initTypeDescriptionService", | ||
Napi::Function::New(env, InitTypeDescriptionService)); | ||
|
||
return exports; | ||
} | ||
|
||
} // namespace rclnodejs |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2025, The Robot Web Tools Contributors | ||
// | ||
// 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. | ||
|
||
#ifndef SRC_RCL_TYPE_DESCRIPTION_SERVICE_BINDINGS_H_ | ||
#define SRC_RCL_TYPE_DESCRIPTION_SERVICE_BINDINGS_H_ | ||
|
||
#include <napi.h> | ||
|
||
namespace rclnodejs { | ||
|
||
Napi::Object InitTypeDescriptionServiceBindings(Napi::Env env, | ||
Napi::Object exports); | ||
|
||
} | ||
|
||
#endif // SRC_RCL_TYPE_DESCRIPTION_SERVICE_BINDINGS_H_ |
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 | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,6 +18,7 @@ const assert = require('assert'); | |||||||||||||||||
const rclnodejs = require('../index.js'); | ||||||||||||||||||
const assertUtils = require('./utils.js'); | ||||||||||||||||||
const assertThrowsError = assertUtils.assertThrowsError; | ||||||||||||||||||
const DistroUtils = require('../lib/distro.js'); | ||||||||||||||||||
|
||||||||||||||||||
describe('Node extra destroy methods testing', function () { | ||||||||||||||||||
before(function () { | ||||||||||||||||||
|
@@ -89,7 +90,11 @@ describe('Node extra destroy methods testing', function () { | |||||||||||||||||
var node = rclnodejs.createNode('node4'); | ||||||||||||||||||
const AddTwoInts = 'example_interfaces/srv/AddTwoInts'; | ||||||||||||||||||
var service = node.createService(AddTwoInts, 'add_two_ints', () => {}); | ||||||||||||||||||
assert.deepStrictEqual(node._services.length, 7); | ||||||||||||||||||
if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) { | ||||||||||||||||||
assert.deepStrictEqual(node._services.length, 7); | ||||||||||||||||||
} else { | ||||||||||||||||||
assert.deepStrictEqual(node._services.length, 8); | ||||||||||||||||||
} | ||||||||||||||||||
|
if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) { | |
assert.deepStrictEqual(node._services.length, 7); | |
} else { | |
assert.deepStrictEqual(node._services.length, 8); | |
} | |
const initialServiceCount = node._services.length; | |
node.createService(AddTwoInts, 'add_two_ints', () => {}); | |
assert.deepStrictEqual(node._services.length, initialServiceCount + 1); |
Copilot uses AI. Check for mistakes.
Positive FeedbackNegative Feedback
Oops, something went wrong.
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.
The GYP condition uses
ros_version
while the code usesROS_VERSION
. Ensure the variable names and casing align so the new source is correctly included during build.Copilot uses AI. Check for mistakes.