@@ -6,14 +6,12 @@ use std::sync::{Arc, Mutex, RwLock, Weak};
6
6
/// Time source for a node that drives the attached clock.
7
7
/// If the node's `use_sim_time` parameter is set to `true`, the `TimeSource` will subscribe
8
8
/// to the `/clock` topic and drive the attached clock
9
- pub struct TimeSource {
9
+ pub ( crate ) struct TimeSource {
10
10
_node : Weak < Node > ,
11
11
_clock : RwLock < Clock > ,
12
12
_clock_source : Arc < Mutex < Option < ClockSource > > > ,
13
13
_requested_clock_type : ClockType ,
14
14
_clock_qos : QoSProfile ,
15
- // TODO(luca) implement clock threads, for now will run in main thread
16
- _use_clock_thread : bool ,
17
15
_clock_subscription : Option < Arc < Subscription < ClockMsg > > > ,
18
16
_last_received_time : Arc < Mutex < Option < i64 > > > ,
19
17
}
@@ -25,47 +23,35 @@ pub struct TimeSource {
25
23
///
26
24
/// The default values for optional fields are:
27
25
/// - `clock_qos: QOS_PROFILE_CLOCK`[3]
28
- /// - `use_clock_thread: true`
29
26
///
30
27
///
31
28
/// [1]: crate::TimeSource
32
29
/// [2]: crate::TimeSource::builder
33
30
/// [3]: crate::QOS_PROFILE_CLOCK
34
- pub struct TimeSourceBuilder {
31
+ pub ( crate ) struct TimeSourceBuilder {
35
32
node : Weak < Node > ,
36
33
clock_qos : QoSProfile ,
37
- use_clock_thread : bool ,
38
34
clock_type : ClockType ,
39
35
}
40
36
41
37
impl TimeSourceBuilder {
42
38
/// 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 {
44
40
Self {
45
41
node,
46
42
clock_qos : QOS_PROFILE_CLOCK ,
47
- use_clock_thread : true ,
48
43
clock_type,
49
44
}
50
45
}
51
46
52
47
/// 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 {
54
49
self . clock_qos = clock_qos;
55
50
self
56
51
}
57
52
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
-
67
53
/// 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 > {
69
55
let clock = match self . clock_type {
70
56
ClockType :: RosTime | ClockType :: SystemTime => Clock :: system ( ) ,
71
57
ClockType :: SteadyTime => Clock :: steady ( ) ,
@@ -76,7 +62,6 @@ impl TimeSourceBuilder {
76
62
_clock_source : Arc :: new ( Mutex :: new ( None ) ) ,
77
63
_requested_clock_type : self . clock_type ,
78
64
_clock_qos : self . clock_qos ,
79
- _use_clock_thread : self . use_clock_thread ,
80
65
_clock_subscription : None ,
81
66
_last_received_time : Arc :: new ( Mutex :: new ( None ) ) ,
82
67
} ;
@@ -86,24 +71,19 @@ impl TimeSourceBuilder {
86
71
}
87
72
88
73
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
-
94
74
/// 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 {
96
76
TimeSourceBuilder :: new ( node, clock_type)
97
77
}
98
78
99
79
/// Returns the clock that this TimeSource is controlling.
100
- pub fn get_clock ( & self ) -> Clock {
80
+ pub ( crate ) fn get_clock ( & self ) -> Clock {
101
81
self . _clock . read ( ) . unwrap ( ) . clone ( )
102
82
}
103
83
104
84
/// Attaches the given node to to the `TimeSource`, using its interface to read the
105
85
/// `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 > ) {
107
87
self . _node = node;
108
88
109
89
// TODO(luca) register a parameter callback
0 commit comments