From bac3b210d7f8d7409e872762a4804229672dd639 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Tue, 24 Nov 2015 03:45:17 -0800 Subject: [PATCH] add the concept of an rcl instance id it changes with each successful call to rcl_init --- rcl/include/rcl/node.h | 18 ++++++++++++++++++ rcl/include/rcl/rcl.h | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/rcl/include/rcl/node.h b/rcl/include/rcl/node.h index 7c4dee0..9d5f706 100644 --- a/rcl/include/rcl/node.h +++ b/rcl/include/rcl/node.h @@ -161,6 +161,24 @@ rcl_node_get_options(const rcl_node_t * node); rmw_node_t * rcl_node_get_rmw_node_handle(const rcl_node_t * node); +/// Return the associated rcl instance id. +/* This id is stored when rcl_node_init is called and can be compared with the + * value returned by rcl_get_instance_id() to check if this node was created in + * the current rcl context (since the latest call to rcl_init(). + * + * This function can fail, and therefore return 0, if: + * - node is NULL + * - node has not been initialized (the implementation is invalid) + * + * This function will succeed, however, even if rcl_fini has been called since + * the node was created. + * + * \param[in] node pointer to the rcl node + * \return rcl instance id captured at node creation or 0 if there was an error + */ +uint64_t +rcl_node_get_rcl_instance_id(const rcl_node_t * node); + #if __cplusplus } #endif diff --git a/rcl/include/rcl/rcl.h b/rcl/include/rcl/rcl.h index 017a1ea..485375e 100644 --- a/rcl/include/rcl/rcl.h +++ b/rcl/include/rcl/rcl.h @@ -76,6 +76,11 @@ rcl_init(int argc, char ** argv, rcl_allocator_t allocator); rcl_ret_t rcl_fini(); +/// Returns an uint64_t number that is unique for the latest rcl_init call. +/* If called before rcl_init or after rcl_fini then 0 will be returned. */ +uint64_t +rcl_get_instance_id(); + /// Return true until rcl_fini is called, then false. /* This function is thread safe. */ bool