Skip to content

Commit 382f780

Browse files
Make time_source pub(crate), remove unused APIs
Signed-off-by: Luca Della Vedova <[email protected]>
1 parent ed583f6 commit 382f780

File tree

3 files changed

+23
-31
lines changed

3 files changed

+23
-31
lines changed

rclrs/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub use rcl_bindings::rmw_request_id_t;
4343
pub use service::*;
4444
pub use subscription::*;
4545
pub use time::*;
46-
pub use time_source::*;
46+
use time_source::*;
4747
pub use wait::*;
4848

4949
/// Polls the node for new messages and executes the corresponding callbacks.

rclrs/src/node/builder.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::sync::{Arc, Mutex};
44
use crate::rcl_bindings::*;
55
use crate::{
66
node::call_string_getter_with_handle, resolve_parameter_overrides, ClockType, Context, Node,
7-
RclrsError, TimeSource, ToResult,
7+
QoSProfile, RclrsError, TimeSource, ToResult, QOS_PROFILE_CLOCK,
88
};
99

1010
/// A builder for creating a [`Node`][1].
@@ -18,6 +18,7 @@ use crate::{
1818
/// - `arguments: []`
1919
/// - `enable_rosout: true`
2020
/// - `clock_type: ClockType::RosTime`
21+
/// - `clock_qos: QOS_PROFILE_CLOCK`
2122
///
2223
/// # Example
2324
/// ```
@@ -48,6 +49,7 @@ pub struct NodeBuilder {
4849
arguments: Vec<String>,
4950
enable_rosout: bool,
5051
clock_type: ClockType,
52+
clock_qos: QoSProfile,
5153
}
5254

5355
impl NodeBuilder {
@@ -95,6 +97,7 @@ impl NodeBuilder {
9597
arguments: vec![],
9698
enable_rosout: true,
9799
clock_type: ClockType::RosTime,
100+
clock_qos: QOS_PROFILE_CLOCK,
98101
}
99102
}
100103

@@ -233,6 +236,12 @@ impl NodeBuilder {
233236
self
234237
}
235238

239+
/// Sets the QoSProfile for the clock subscription.
240+
pub fn clock_qos(mut self, clock_qos: QoSProfile) -> Self {
241+
self.clock_qos = clock_qos;
242+
self
243+
}
244+
236245
/// Builds the node instance.
237246
///
238247
/// Node name and namespace validation is performed in this method.
@@ -287,7 +296,10 @@ impl NodeBuilder {
287296
guard_conditions_mtx: Mutex::new(vec![]),
288297
services_mtx: Mutex::new(vec![]),
289298
subscriptions_mtx: Mutex::new(vec![]),
290-
_time_source: TimeSource::new(weak.clone(), self.clock_type),
299+
_time_source: TimeSource::builder(weak.clone(), self.clock_type)
300+
.clock_qos(self.clock_qos)
301+
.build()
302+
.unwrap(),
291303
_parameter_map,
292304
}))
293305
}

rclrs/src/time_source.rs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ use std::sync::{Arc, Mutex, RwLock, Weak};
66
/// Time source for a node that drives the attached clock.
77
/// If the node's `use_sim_time` parameter is set to `true`, the `TimeSource` will subscribe
88
/// to the `/clock` topic and drive the attached clock
9-
pub struct TimeSource {
9+
pub(crate) struct TimeSource {
1010
_node: Weak<Node>,
1111
_clock: RwLock<Clock>,
1212
_clock_source: Arc<Mutex<Option<ClockSource>>>,
1313
_requested_clock_type: ClockType,
1414
_clock_qos: QoSProfile,
15-
// TODO(luca) implement clock threads, for now will run in main thread
16-
_use_clock_thread: bool,
1715
_clock_subscription: Option<Arc<Subscription<ClockMsg>>>,
1816
_last_received_time: Arc<Mutex<Option<i64>>>,
1917
}
@@ -25,47 +23,35 @@ pub struct TimeSource {
2523
///
2624
/// The default values for optional fields are:
2725
/// - `clock_qos: QOS_PROFILE_CLOCK`[3]
28-
/// - `use_clock_thread: true`
2926
///
3027
///
3128
/// [1]: crate::TimeSource
3229
/// [2]: crate::TimeSource::builder
3330
/// [3]: crate::QOS_PROFILE_CLOCK
34-
pub struct TimeSourceBuilder {
31+
pub(crate) struct TimeSourceBuilder {
3532
node: Weak<Node>,
3633
clock_qos: QoSProfile,
37-
use_clock_thread: bool,
3834
clock_type: ClockType,
3935
}
4036

4137
impl TimeSourceBuilder {
4238
/// Creates a builder for a time source that drives the given clock for the given node.
43-
pub fn new(node: Weak<Node>, clock_type: ClockType) -> Self {
39+
pub(crate) fn new(node: Weak<Node>, clock_type: ClockType) -> Self {
4440
Self {
4541
node,
4642
clock_qos: QOS_PROFILE_CLOCK,
47-
use_clock_thread: true,
4843
clock_type,
4944
}
5045
}
5146

5247
/// Sets the QoS for the `/clock` topic.
53-
pub fn clock_qos(mut self, clock_qos: QoSProfile) -> Self {
48+
pub(crate) fn clock_qos(mut self, clock_qos: QoSProfile) -> Self {
5449
self.clock_qos = clock_qos;
5550
self
5651
}
5752

58-
/// Sets use_clock_thread.
59-
///
60-
/// If set to `true`, the clock callbacks will run in a separate thread.
61-
/// NOTE: Currently unimplemented
62-
pub fn use_clock_thread(mut self, use_clock_thread: bool) -> Self {
63-
self.use_clock_thread = use_clock_thread;
64-
self
65-
}
66-
6753
/// Builds the `TimeSource` and attaches the provided `Node` and `Clock`.
68-
pub fn build(self) -> Result<TimeSource, RclrsError> {
54+
pub(crate) fn build(self) -> Result<TimeSource, RclrsError> {
6955
let clock = match self.clock_type {
7056
ClockType::RosTime | ClockType::SystemTime => Clock::system(),
7157
ClockType::SteadyTime => Clock::steady(),
@@ -76,7 +62,6 @@ impl TimeSourceBuilder {
7662
_clock_source: Arc::new(Mutex::new(None)),
7763
_requested_clock_type: self.clock_type,
7864
_clock_qos: self.clock_qos,
79-
_use_clock_thread: self.use_clock_thread,
8065
_clock_subscription: None,
8166
_last_received_time: Arc::new(Mutex::new(None)),
8267
};
@@ -86,24 +71,19 @@ impl TimeSourceBuilder {
8671
}
8772

8873
impl TimeSource {
89-
/// Creates a new `TimeSource` with default parameters.
90-
pub fn new(node: Weak<Node>, clock_type: ClockType) -> Self {
91-
TimeSourceBuilder::new(node, clock_type).build().unwrap()
92-
}
93-
9474
/// Creates a new `TimeSourceBuilder` with default parameters.
95-
pub fn builder(node: Weak<Node>, clock_type: ClockType) -> TimeSourceBuilder {
75+
pub(crate) fn builder(node: Weak<Node>, clock_type: ClockType) -> TimeSourceBuilder {
9676
TimeSourceBuilder::new(node, clock_type)
9777
}
9878

9979
/// Returns the clock that this TimeSource is controlling.
100-
pub fn get_clock(&self) -> Clock {
80+
pub(crate) fn get_clock(&self) -> Clock {
10181
self._clock.read().unwrap().clone()
10282
}
10383

10484
/// Attaches the given node to to the `TimeSource`, using its interface to read the
10585
/// `use_sim_time` parameter and create the clock subscription.
106-
pub fn attach_node(&mut self, node: Weak<Node>) {
86+
fn attach_node(&mut self, node: Weak<Node>) {
10787
self._node = node;
10888

10989
// TODO(luca) register a parameter callback

0 commit comments

Comments
 (0)