Skip to content

Commit 15d51b5

Browse files
committed
Syncing current progress
Distro A, OPSEC #4584. You may have additional rights; please see https://rosmilitary.org/faq/?category=ros-2-license
1 parent 046f1b9 commit 15d51b5

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

rclrs/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ fn main() {
109109
println!("cargo:rustc-link-lib=dylib=rcutils");
110110
println!("cargo:rustc-link-lib=dylib=rmw");
111111
println!("cargo:rustc-link-lib=dylib=rmw_implementation");
112+
println!("cargo:rustc-link-lib=dylib=rcl_lifecycle");
112113

113114
let bindings = builder.generate().expect("Unable to generate bindings");
114115

rclrs/src/lifecycle_node.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,12 @@ mod tests {
457457
test_node_builder.enable_communication_interface = true;
458458

459459
let test_node = test_node_builder.build().unwrap();
460-
assert_eq!(lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE, test_node.state_machine.change_state(Transition::TRANSITION_CONFIGURE).unwrap());
461-
assert_eq!(lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE, test_node.state_machine.change_state(Transition::TRANSITION_ACTIVATE).unwrap());
462-
assert_eq!(lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE, test_node.state_machine.change_state(Transition::TRANSITION_DEACTIVATE).unwrap());
463-
assert_eq!(lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED, test_node.state_machine.change_state(Transition::TRANSITION_CLEANUP).unwrap());
460+
println!("{:?}", test_node);
461+
assert_eq!(Transition::TRANSITION_CALLBACK_SUCCESS, test_node.state_machine.change_state(Transition::TRANSITION_CONFIGURE).unwrap());
462+
let q = test_node.state_machine.get_current_state().unwrap();
463+
println!("{:?}", q);
464+
// assert_eq!(lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE, test_node.state_machine.change_state(Transition::TRANSITION_ACTIVATE).unwrap());
465+
// assert_eq!(lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE, test_node.state_machine.change_state(Transition::TRANSITION_DEACTIVATE).unwrap());
466+
// assert_eq!(lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED, test_node.state_machine.change_state(Transition::TRANSITION_CLEANUP).unwrap());
464467
}
465468
}

rclrs/src/lifecycle_node/state.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::{
2121

2222
use crate::{error::ToResult, rcl_bindings::*, RclReturnCode, RclrsError};
2323

24+
#[derive(Debug)]
2425
pub struct State {
2526
id: u8,
2627
label: String,

rclrs/src/lifecycle_node/state_machine.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,17 @@ impl LifecycleMachine {
392392
Ok(transitions)
393393
}
394394

395+
396+
fn get_label_for_return_code(cb_return_code: &u8) -> String {
397+
if cb_return_code == &Transition::TRANSITION_CALLBACK_SUCCESS {
398+
"transition_success".into()
399+
} else if cb_return_code == &Transition::TRANSITION_CALLBACK_FAILURE {
400+
"transition_failure".into()
401+
} else {
402+
"transition_error".into()
403+
}
404+
}
405+
395406
pub(crate) fn change_state(&self, transition_id: u8) -> Result<u8, RclrsError> {
396407
// Make sure that the state machine is initialized before doing anything
397408
let mut state_machine = self.state_machine.lock().unwrap();
@@ -419,26 +430,16 @@ impl LifecycleMachine {
419430
.ok()?
420431
};
421432

422-
let get_label_for_return_code = |cb_return_code: &u8| {
423-
if cb_return_code == &Transition::TRANSITION_CALLBACK_SUCCESS {
424-
"transition_success"
425-
} else if cb_return_code == &Transition::TRANSITION_CALLBACK_FAILURE {
426-
"transition_failure"
427-
} else {
428-
"transition_error"
429-
}
430-
};
431-
432433
// SAFETY: The state machine is not null, since it's initialized
433434
let cb_return_code =
434435
self.execute_callback(unsafe { (*state_machine.current_state).id }, initial_state);
435-
let transition_label = get_label_for_return_code(&cb_return_code);
436+
let transition_label = Self::get_label_for_return_code(&cb_return_code);
436437
let transition_label_cstr = CString::new(transition_label).unwrap(); // Should be fine, since the strings are known to be valid CStrings
437438

438439
// SAFETY: The state machine is not null, since it's initialized
439440
unsafe {
440441
rcl_lifecycle_trigger_transition_by_label(
441-
&mut *state_machine as *mut rcl_lifecycle_state_machine_s,
442+
&mut *state_machine,
442443
transition_label_cstr.as_ptr(),
443444
publish_update,
444445
)

0 commit comments

Comments
 (0)