@@ -19,11 +19,11 @@ use std::{
1919use rosidl_runtime_rs:: Message ;
2020
2121use crate :: {
22- rcl_bindings:: * , Client , ClientBase , ClientOptions , Clock , ContextHandle , GuardCondition ,
23- LogParams , Logger , ParameterBuilder , ParameterInterface , ParameterVariant , Parameters ,
24- Publisher , PublisherOptions , RclrsError , Service , ServiceBase , ServiceOptions , Subscription ,
25- SubscriptionBase , SubscriptionCallback , SubscriptionOptions , TimeSource , ToLogParams ,
26- ENTITY_LIFECYCLE_MUTEX ,
22+ rcl_bindings:: * , Client , ClientBase , ClientOptions , ClientState , Clock , ContextHandle ,
23+ GuardCondition , LogParams , Logger , ParameterBuilder , ParameterInterface , ParameterVariant ,
24+ Parameters , Publisher , PublisherOptions , PublisherState , RclrsError , Service , ServiceBase ,
25+ ServiceOptions , ServiceState , Subscription , SubscriptionBase , SubscriptionCallback ,
26+ SubscriptionOptions , SubscriptionState , TimeSource , ToLogParams , ENTITY_LIFECYCLE_MUTEX ,
2727} ;
2828
2929// SAFETY: The functions accessing this type, including drop(), shouldn't care about the thread
@@ -59,7 +59,7 @@ unsafe impl Send for rcl_node_t {}
5959/// In that sense, the parameters to the node creation functions are only the _default_ namespace and
6060/// name.
6161/// See also the [official tutorial][1] on the command line arguments for ROS nodes, and the
62- /// [`Node ::namespace()`][3] and [`Node ::name()`][4 ] functions for examples.
62+ /// [`NodeState ::namespace()`] and [`NodeState ::name()`] functions for examples.
6363///
6464/// ## Rules for valid names
6565/// The rules for valid node names and node namespaces are explained in
@@ -72,7 +72,17 @@ unsafe impl Send for rcl_node_t {}
7272/// [5]: crate::NodeOptions::new
7373/// [6]: crate::NodeOptions::namespace
7474/// [7]: crate::Executor::create_node
75- pub struct Node {
75+ pub type Node = Arc < NodeState > ;
76+
77+ /// The inner state of a [`Node`].
78+ ///
79+ /// This is public so that you can choose to put it inside a [`Weak`] if you
80+ /// want to be able to refer to a [`Node`] in a non-owning way. It is generally
81+ /// recommended to manage the [`NodeState`] inside of an [`Arc`], and [`Node`]
82+ /// is provided as convenience alias for that.
83+ ///
84+ /// The public API of the [`Node`] type is implemented via `NodeState`.
85+ pub struct NodeState {
7686 pub ( crate ) clients_mtx : Mutex < Vec < Weak < dyn ClientBase > > > ,
7787 pub ( crate ) guard_conditions_mtx : Mutex < Vec < Weak < GuardCondition > > > ,
7888 pub ( crate ) services_mtx : Mutex < Vec < Weak < dyn ServiceBase > > > ,
@@ -128,23 +138,23 @@ impl Drop for NodeHandle {
128138 }
129139}
130140
131- impl Eq for Node { }
141+ impl Eq for NodeState { }
132142
133- impl PartialEq for Node {
143+ impl PartialEq for NodeState {
134144 fn eq ( & self , other : & Self ) -> bool {
135145 Arc :: ptr_eq ( & self . handle , & other. handle )
136146 }
137147}
138148
139- impl fmt:: Debug for Node {
149+ impl fmt:: Debug for NodeState {
140150 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> Result < ( ) , fmt:: Error > {
141151 f. debug_struct ( "Node" )
142152 . field ( "fully_qualified_name" , & self . fully_qualified_name ( ) )
143153 . finish ( )
144154 }
145155}
146156
147- impl Node {
157+ impl NodeState {
148158 /// Returns the clock associated with this node.
149159 pub fn get_clock ( & self ) -> Clock {
150160 self . time_source . get_clock ( )
@@ -202,7 +212,7 @@ impl Node {
202212 /// Returns the fully qualified name of the node.
203213 ///
204214 /// The fully qualified name of the node is the node namespace combined with the node name.
205- /// It is subject to the remappings shown in [`Node ::name()`] and [`Node ::namespace()`].
215+ /// It is subject to the remappings shown in [`NodeState ::name()`] and [`NodeState ::namespace()`].
206216 ///
207217 /// # Example
208218 /// ```
@@ -266,11 +276,11 @@ impl Node {
266276 pub fn create_client < ' a , T > (
267277 self : & Arc < Self > ,
268278 options : impl Into < ClientOptions < ' a > > ,
269- ) -> Result < Arc < Client < T > > , RclrsError >
279+ ) -> Result < Client < T > , RclrsError >
270280 where
271281 T : rosidl_runtime_rs:: Service ,
272282 {
273- let client = Arc :: new ( Client :: < T > :: new ( self , options) ?) ;
283+ let client = Arc :: new ( ClientState :: < T > :: new ( self , options) ?) ;
274284 { self . clients_mtx . lock ( ) . unwrap ( ) } . push ( Arc :: downgrade ( & client) as Weak < dyn ClientBase > ) ;
275285 Ok ( client)
276286 }
@@ -349,11 +359,11 @@ impl Node {
349359 pub fn create_publisher < ' a , T > (
350360 & self ,
351361 options : impl Into < PublisherOptions < ' a > > ,
352- ) -> Result < Arc < Publisher < T > > , RclrsError >
362+ ) -> Result < Publisher < T > , RclrsError >
353363 where
354364 T : Message ,
355365 {
356- let publisher = Arc :: new ( Publisher :: < T > :: new ( Arc :: clone ( & self . handle ) , options) ?) ;
366+ let publisher = Arc :: new ( PublisherState :: < T > :: new ( Arc :: clone ( & self . handle ) , options) ?) ;
357367 Ok ( publisher)
358368 }
359369
@@ -403,12 +413,12 @@ impl Node {
403413 self : & Arc < Self > ,
404414 options : impl Into < ServiceOptions < ' a > > ,
405415 callback : F ,
406- ) -> Result < Arc < Service < T > > , RclrsError >
416+ ) -> Result < Service < T > , RclrsError >
407417 where
408418 T : rosidl_runtime_rs:: Service ,
409419 F : Fn ( & rmw_request_id_t , T :: Request ) -> T :: Response + ' static + Send ,
410420 {
411- let service = Arc :: new ( Service :: < T > :: new ( self , options, callback) ?) ;
421+ let service = Arc :: new ( ServiceState :: < T > :: new ( self , options, callback) ?) ;
412422 { self . services_mtx . lock ( ) . unwrap ( ) }
413423 . push ( Arc :: downgrade ( & service) as Weak < dyn ServiceBase > ) ;
414424 Ok ( service)
@@ -459,11 +469,11 @@ impl Node {
459469 self : & Arc < Self > ,
460470 options : impl Into < SubscriptionOptions < ' a > > ,
461471 callback : impl SubscriptionCallback < T , Args > ,
462- ) -> Result < Arc < Subscription < T > > , RclrsError >
472+ ) -> Result < Subscription < T > , RclrsError >
463473 where
464474 T : Message ,
465475 {
466- let subscription = Arc :: new ( Subscription :: < T > :: new ( self , options, callback) ?) ;
476+ let subscription = Arc :: new ( SubscriptionState :: < T > :: new ( self , options, callback) ?) ;
467477 { self . subscriptions_mtx . lock ( ) }
468478 . unwrap ( )
469479 . push ( Arc :: downgrade ( & subscription) as Weak < dyn SubscriptionBase > ) ;
@@ -583,7 +593,7 @@ impl Node {
583593 }
584594}
585595
586- impl < ' a > ToLogParams < ' a > for & ' a Node {
596+ impl < ' a > ToLogParams < ' a > for & ' a NodeState {
587597 fn to_log_params ( self ) -> LogParams < ' a > {
588598 self . logger ( ) . to_log_params ( )
589599 }
0 commit comments