Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ class Client extends Entity {
introspectionState
);
}

/**
* Get the logger name for this client.
* @returns {string} The logger name for this client.
*/
get loggerName() {
return rclnodejs.getNodeLoggerName(this._nodeHandle);
}
}

module.exports = Client;
9 changes: 9 additions & 0 deletions lib/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const Entity = require('./entity.js');
class Publisher extends Entity {
constructor(handle, typeClass, topic, options, node, eventCallbacks) {
super(handle, typeClass, options);
this._node = node;
if (node && eventCallbacks) {
this._events = eventCallbacks.createEventHandlers(this.handle);
node._events.push(...this._events);
Expand Down Expand Up @@ -126,6 +127,14 @@ class Publisher extends Entity {
set events(events) {
this._events = events;
}

/**
* Get the logger name for this publisher.
* @returns {string} The logger name for this publisher.
*/
get loggerName() {
return rclnodejs.getNodeLoggerName(this._node.handle);
}
}

module.exports = Publisher;
8 changes: 8 additions & 0 deletions lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ class Service extends Entity {
getOptions() {
return rclnodejs.getOptions(this._handle);
}

/**
* Get the logger name for this service.
* @returns {string} The logger name for this service.
*/
get loggerName() {
return rclnodejs.getNodeLoggerName(this._nodeHandle);
}
}

module.exports = Service;
9 changes: 9 additions & 0 deletions lib/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Subscription extends Entity {
this._topic = topic;
this._callback = callback;
this._isRaw = options.isRaw || false;
this._node = node;

if (node && eventCallbacks) {
this._events = eventCallbacks.createEventHandlers(this.handle);
Expand Down Expand Up @@ -168,6 +169,14 @@ class Subscription extends Entity {
set events(events) {
this._events = events;
}

/**
* Get the logger name for this subscription.
* @returns {string} The logger name for this subscription.
*/
get loggerName() {
return rclnodejs.getNodeLoggerName(this._node.handle);
}
}

module.exports = Subscription;
7 changes: 7 additions & 0 deletions test/test-publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ describe('rclnodejs publisher test suite', function () {
assert.strictEqual(publisher.subscriptionCount, 1);
});

it('Test loggerName', function () {
const node = rclnodejs.createNode('publisher_node');
const String = 'std_msgs/msg/String';
const publisher = node.createPublisher(String, 'topic');
assert.strictEqual(typeof publisher.loggerName, 'string');
});

it('Wait for all acked', function () {
const node = rclnodejs.createNode('publisher_node');
const String = 'std_msgs/msg/String';
Expand Down
18 changes: 18 additions & 0 deletions test/test-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,22 @@ describe('Test service class', function () {
);
node.destroy();
});

it('Test loggerName', function () {
const node = rclnodejs.createNode('test_node');
const AddTwoInts = 'example_interfaces/srv/AddTwoInts';
const service = node.createService(
AddTwoInts,
'add_two_ints',
{ qos: rclnodejs.QoS.profileSystemDefault },
(request, response) => {
let result = response.template;
result.sum = request.a + request.b;
}
);
const client = node.createClient(AddTwoInts, 'single_ps_channel2');
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable AddTwoInts is not defined in this scope. It should be defined as a string like 'example_interfaces/srv/AddTwoInts' to match the service type used above.

Suggested change
const client = node.createClient(AddTwoInts, 'single_ps_channel2');
const client = node.createClient('example_interfaces/srv/AddTwoInts', 'single_ps_channel2');

Copilot uses AI. Check for mistakes.

assert.strictEqual(typeof service.loggerName, 'string');
assert.strictEqual(typeof client.loggerName, 'string');
});
});
7 changes: 7 additions & 0 deletions test/test-subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ describe('rclnodejs subscription test suite', function () {
const subscription = node.createSubscription(String, 'topic', (msg) => {});
assert.strictEqual(subscription.publisherCount, 1);
});

it('Test loggerName', function () {
const node = rclnodejs.createNode('publisher_node');
const String = 'std_msgs/msg/String';
const subscription = node.createSubscription(String, 'topic', (msg) => {});
assert.strictEqual(typeof subscription.loggerName, 'string');
});
});
4 changes: 4 additions & 0 deletions test/types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ expectType<boolean>(publisher.waitForAllAcked(BigInt(1000)));
node.createPublisher(TYPE_CLASS, TOPIC, publisher.options, (event: object) => {
const receivedEvent = event;
});
expectType<string>(publisher.loggerName);

// ---- LifecyclePublisher ----
const lifecyclePublisher = lifecycleNode.createLifecyclePublisher(
Expand Down Expand Up @@ -221,6 +222,7 @@ expectType<boolean>(subscription.isDestroyed());
expectType<boolean>(subscription.setContentFilter(contentFilter));
expectType<boolean>(subscription.clearContentFilter());
expectType<boolean>(subscription.hasContentFilter());
expectType<string>(subscription.loggerName);

// ---- Service ----
const service = node.createService(
Expand All @@ -241,6 +243,7 @@ expectType<void>(
);
expectType<boolean>(service.isDestroyed());
expectType<object>(service.getOptions());
expectType<string>(service.loggerName);

// ---- Client ----
const client = node.createClient(
Expand All @@ -259,6 +262,7 @@ expectType<void>(
)
);
expectType<boolean>(client.isDestroyed());
expectType<string>(client.loggerName);

// ---- Timer ----
const timerCallback = () => {};
Expand Down
5 changes: 5 additions & 0 deletions types/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ declare module 'rclnodejs' {
serviceEventPubQOS: QoS,
introspectionState: ServiceIntrospectionStates
): void;

/**
* Get the logger name for this client.
*/
readonly loggerName: string;
}

namespace Client {
Expand Down
5 changes: 5 additions & 0 deletions types/publisher.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ declare module 'rclnodejs' {
* @return {boolean} `true` if all published message data is acknowledged before the timeout, otherwise `false`.
*/
waitForAllAcked(timeout: bigint): boolean;

/**
* Get the logger name for this publisher.
*/
readonly loggerName: string;
}
}
5 changes: 5 additions & 0 deletions types/service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,10 @@ declare module 'rclnodejs' {
* @return The options of this service.
*/
getOptions(): object;

/**
* Get the logger name for this service.
*/
readonly loggerName: string;
}
}
5 changes: 5 additions & 0 deletions types/subscription.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,10 @@ declare module 'rclnodejs' {
* @returns The number of publishers
*/
publisherCount(): number;

/**
* Get the logger name for this subscription.
*/
readonly loggerName: string;
}
}
Loading