@@ -212,4 +212,37 @@ impl Node {
212
212
. filter_map ( Weak :: upgrade)
213
213
. collect ( )
214
214
}
215
+
216
+ /// Returns the ROS domain ID that the node is using.
217
+ ///
218
+ /// The domain ID controls which nodes can send messages to each other, see the [ROS 2 concept article][1].
219
+ /// It can be set through the `ROS_DOMAIN_ID` environment variable.
220
+ ///
221
+ /// [1]: https://docs.ros.org/en/rolling/Concepts/About-Domain-ID.html
222
+ ///
223
+ /// # Example
224
+ /// ```
225
+ /// # use rclrs::{Context, RclReturnCode};
226
+ /// // set default ROS domain ID to 10 here
227
+ /// std::env::set_var("ROS_DOMAIN_ID", "10");
228
+ /// let context = Context::new([])?;
229
+ /// let node = context.create_node("domain_id_node")?;
230
+ /// let domain_id = node.domain_id();
231
+ /// assert_eq!(domain_id, 10);
232
+ /// # Ok::<(), RclReturnCode>(())
233
+ /// ```
234
+ // TODO: If node option is supported,
235
+ // add description about this function is for getting actual domain_id
236
+ // and about override of domain_id via node option
237
+ pub fn domain_id ( & self ) -> usize {
238
+ let handle = & * self . handle . lock ( ) ;
239
+ let mut domain_id: usize = 0 ;
240
+ let ret = unsafe {
241
+ // SAFETY: No preconditions for this function.
242
+ rcl_node_get_domain_id ( handle, & mut domain_id)
243
+ } ;
244
+
245
+ debug_assert_eq ! ( ret, 0 ) ;
246
+ domain_id
247
+ }
215
248
}
0 commit comments