Skip to content

Commit 3d2f6b7

Browse files
committed
* Replaced NodeHandle within Timer with a ContextHandle
1 parent eb44531 commit 3d2f6b7

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

rclrs/src/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl Node {
357357
F: Fn(&mut Timer) + 'static + Send + Sync,
358358
{
359359
let timer = Arc::new(Mutex::new(Timer::new(
360-
Arc::clone(&self.handle),
360+
Arc::clone(&self.handle.context_handle),
361361
self.get_clock(),
362362
period,
363363
callback,

rclrs/src/timer.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
rcl_timer_is_canceled, rcl_timer_is_ready, rcl_timer_reset, rcl_timer_t,
88
rcutils_get_default_allocator,
99
},
10-
NodeHandle, RclReturnCode, RclrsError, ToResult, ENTITY_LIFECYCLE_MUTEX,
10+
ContextHandle, RclReturnCode, RclrsError, ToResult, ENTITY_LIFECYCLE_MUTEX,
1111
};
1212
use std::{
1313
i64,
@@ -28,7 +28,7 @@ unsafe impl Send for rcl_timer_t {}
2828
pub struct TimerHandle {
2929
rcl_timer: Mutex<rcl_timer_t>,
3030
_clock: Clock,
31-
_node_handle: Arc<NodeHandle>,
31+
_context_handle: Arc<ContextHandle>,
3232
pub(crate) in_use_by_wait_set: Arc<AtomicBool>,
3333
}
3434

@@ -81,7 +81,7 @@ impl Timer {
8181
/// Creates a new `Timer` with the given period and callback.
8282
/// Periods greater than i64::MAX nanoseconds will saturate to i64::MAX.
8383
pub(crate) fn new<F>(
84-
node_handle: Arc<NodeHandle>,
84+
context_handle: Arc<ContextHandle>,
8585
clock: Clock,
8686
period: Duration,
8787
callback: F,
@@ -98,8 +98,8 @@ impl Timer {
9898
let clock_clone = clock.rcl_clock.clone();
9999
let mut rcl_clock = clock_clone.lock().unwrap();
100100

101-
let node_handle_clone = node_handle.clone();
102-
let mut rcl_context = node_handle_clone.context_handle.rcl_context.lock().unwrap();
101+
let context_handle_clone = context_handle.clone();
102+
let mut rcl_context = context_handle_clone.rcl_context.lock().unwrap();
103103

104104
// core::time::Duration will always be >= 0, so no need to check for negatives.
105105
let period_nanos = i64::try_from(period.as_nanos()).unwrap_or(i64::MAX);
@@ -113,7 +113,7 @@ impl Timer {
113113
// * The rcl_timer is zero-initialized as mandated by this function.
114114
// * The rcl_clock is kept alive by the Clock within TimerHandle because it is
115115
// a dependency of the timer.
116-
// * The rcl_context is kept alive by the NodeHandle within TimerHandle because
116+
// * The rcl_context is kept alive by the ContextHandle within TimerHandle because
117117
// it is a dependency of the timer.
118118
// * The period is copied into this function so it can be dropped afterwards.
119119
// * The callback is None / nullptr so doesn't need to be kept alive.
@@ -136,7 +136,7 @@ impl Timer {
136136
handle: TimerHandle {
137137
rcl_timer: Mutex::new(rcl_timer),
138138
_clock: clock,
139-
_node_handle: node_handle,
139+
_context_handle: context_handle,
140140
in_use_by_wait_set: Arc::new(AtomicBool::new(false)),
141141
},
142142
})
@@ -304,17 +304,17 @@ impl TimerBase for Timer {
304304
mod tests {
305305
use std::time::Duration;
306306

307-
use crate::{create_node, Context};
307+
use crate::{Clock, Context};
308308

309309
use super::Timer;
310310

311-
// Pass in a new node name each time to avoid logging conflicts.
312-
fn new_timer(node_name: &str) -> Timer {
313-
let node = create_node(&Context::new([]).unwrap(), node_name).unwrap();
311+
fn new_timer() -> Timer {
312+
let context = Context::new([]).unwrap();
313+
let clock = Clock::system();
314314

315315
let timer = Timer::new(
316-
node.handle.clone(),
317-
node.get_clock(),
316+
context.handle.clone(),
317+
clock,
318318
Duration::from_secs(0),
319319
|_| {},
320320
);
@@ -324,20 +324,20 @@ mod tests {
324324

325325
#[test]
326326
fn creation() {
327-
let _ = new_timer("test_timer_creation");
327+
let _ = new_timer();
328328
}
329329

330330
#[test]
331331
fn is_ready() {
332-
let timer = new_timer("test_timer_is_ready");
332+
let timer = new_timer();
333333

334334
// Calling is_ready will trigger the debug_assert check on the rcl return value.
335335
timer.is_ready();
336336
}
337337

338338
#[test]
339339
fn time_until_next_call() {
340-
let timer = new_timer("test_timer_next_call");
340+
let timer = new_timer();
341341

342342
timer
343343
.time_until_next_call()
@@ -346,15 +346,15 @@ mod tests {
346346

347347
#[test]
348348
fn time_since_last_call() {
349-
let timer = new_timer("test_timer_last_call");
349+
let timer = new_timer();
350350

351351
// Calling time_since_last_call will trigger the debug_assert check on the rcl return value.
352352
timer.time_since_last_call();
353353
}
354354

355355
#[test]
356356
fn update_period() {
357-
let timer = new_timer("test_timer_update_period");
357+
let timer = new_timer();
358358

359359
let new_period = Duration::from_millis(100);
360360

@@ -369,7 +369,7 @@ mod tests {
369369

370370
#[test]
371371
fn cancel_timer() {
372-
let timer = new_timer("test_timer_cancel");
372+
let timer = new_timer();
373373

374374
// Calling is_canceled will trigger the debug_assert check on the rcl return value.
375375
assert!(!timer.is_canceled());
@@ -382,7 +382,7 @@ mod tests {
382382

383383
#[test]
384384
fn reset_canceled_timer() {
385-
let timer = new_timer("test_timer_reset");
385+
let timer = new_timer();
386386
timer.cancel();
387387

388388
// Calling reset will trigger the debug_assert check on the rcl return value.

0 commit comments

Comments
 (0)