Skip to content

Commit 2fb2561

Browse files
committed
Pass rcl_clock_t from Node to ActionServer
This is needed to initialize the rcl_action_server_t. In rclcpp, the clock ends up stored in the Server itself (by way of ServerBase and ServerBaseImpl); we'll see if that ends up being necessary here.
1 parent ef45142 commit 2fb2561

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

rclrs/src/action.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{error::ToResult, rcl_bindings::*, NodeHandle, RclrsError, ENTITY_LIFECYCLE_MUTEX};
1+
use crate::{error::ToResult, rcl_bindings::*, Clock, NodeHandle, RclrsError, ENTITY_LIFECYCLE_MUTEX};
22
use std::{
33
ffi::CString,
44
sync::{atomic::AtomicBool, Arc, Mutex, MutexGuard},
@@ -203,7 +203,7 @@ where
203203
T: rosidl_runtime_rs::Action,
204204
{
205205
/// Creates a new action server.
206-
pub(crate) fn new(node_handle: Arc<NodeHandle>, topic: &str) -> Result<Self, RclrsError>
206+
pub(crate) fn new(node_handle: Arc<NodeHandle>, clock: Clock, topic: &str) -> Result<Self, RclrsError>
207207
where
208208
T: rosidl_runtime_rs::Action,
209209
{
@@ -221,6 +221,8 @@ where
221221

222222
{
223223
let mut rcl_node = node_handle.rcl_node.lock().unwrap();
224+
let rcl_clock = clock.rcl_clock();
225+
let mut rcl_clock = rcl_clock.lock().unwrap();
224226
let _lifecycle_lock = ENTITY_LIFECYCLE_MUTEX.lock().unwrap();
225227
unsafe {
226228
// SAFETY:
@@ -233,7 +235,7 @@ where
233235
rcl_action_server_init(
234236
&mut rcl_action_server,
235237
&mut *rcl_node,
236-
todo!("pass in a rcl_clock_t"),
238+
&mut *rcl_clock,
237239
type_support,
238240
topic_c_string.as_ptr(),
239241
&action_server_options,

rclrs/src/clock.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ impl Clock {
8888
self.kind
8989
}
9090

91+
/// Returns the clock's `rcl_clock_t`.
92+
pub(crate) fn rcl_clock(&self) -> Arc<Mutex<rcl_clock_t>> {
93+
Arc::clone(&self.rcl_clock)
94+
}
95+
9196
/// Returns the current clock's timestamp.
9297
pub fn now(&self) -> Time {
9398
let mut clock = self.rcl_clock.lock().unwrap();

rclrs/src/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl Node {
239239
where
240240
T: rosidl_runtime_rs::Action,
241241
{
242-
let action_server = Arc::new(ActionServer::<T>::new(Arc::clone(&self.handle), topic)?);
242+
let action_server = Arc::new(ActionServer::<T>::new(Arc::clone(&self.handle), self.get_clock(), topic)?);
243243
// self.servers
244244
// .push(Arc::downgrade(&server) as Weak<dyn ClientBase>);
245245
Ok(action_server)

0 commit comments

Comments
 (0)