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
9 changes: 9 additions & 0 deletions lib/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,15 @@ class LifecycleNode extends Node {
return rclnodejs.isInitialized(this._stateMachineHandle);
}

/**
* Log the state machine data.
*
* @returns {undefined} void.
*/
print() {
rclnodejs.print(this._stateMachineHandle);
}

/**
* The GetState service handler.
* @param {Object} request - The GetState service request.
Expand Down
12 changes: 12 additions & 0 deletions src/rcl_lifecycle_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,17 @@ Napi::Value IsInitialized(const Napi::CallbackInfo& info) {
return Napi::Boolean::New(env, is_initialized);
}

Napi::Value Print(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
RclHandle* state_machine_handle =
RclHandle::Unwrap(info[0].As<Napi::Object>());
rcl_lifecycle_state_machine_t* state_machine =
reinterpret_cast<rcl_lifecycle_state_machine_t*>(
state_machine_handle->ptr());
rcl_print_state_machine(state_machine);
return env.Undefined();
}

Napi::Object InitLifecycleBindings(Napi::Env env, Napi::Object exports) {
exports.Set("createLifecycleStateMachine",
Napi::Function::New(env, CreateLifecycleStateMachine));
Expand All @@ -396,6 +407,7 @@ Napi::Object InitLifecycleBindings(Napi::Env env, Napi::Object exports) {
exports.Set("getLifecycleShutdownTransitionLabel",
Napi::Function::New(env, GetLifecycleShutdownTransitionLabel));
exports.Set("isInitialized", Napi::Function::New(env, IsInitialized));
exports.Set("print", Napi::Function::New(env, Print));
return exports;
}

Expand Down
6 changes: 6 additions & 0 deletions test/test-lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,10 @@ describe('LifecycleNode test suite', function () {
assert.equal(serviceMsgs.length, 0, 'Unexpected lifecycle services found');
testNode.destroy();
});

it('lifecycleNode initial state', function () {
assert.doesNotThrow(() => {
node.print();
});
});
});
1 change: 1 addition & 0 deletions test/types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ expectType<rclnodejs.lifecycle.State>(lifecycleNode.deactivate());
expectType<rclnodejs.lifecycle.State>(lifecycleNode.cleanup());
expectType<rclnodejs.lifecycle.State>(lifecycleNode.shutdown());
expectType<boolean>(lifecycleNode.isInitialized);
expectType<void>(lifecycleNode.print());

// ---- Publisher ----
const publisher = node.createPublisher(TYPE_CLASS, TOPIC);
Expand Down
7 changes: 7 additions & 0 deletions types/lifecycle.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ declare module 'rclnodejs' {
* @returns {boolean} true if the state machine is initialized; otherwise false.
*/
get isInitialized(): boolean;

/**
* Log the state machine data.
*
* @returns {undefined} void.
*/
print(): void;
}
} // lifecycle namespace
} // rclnodejs namespace
Loading