Skip to content

Commit

Permalink
Next phase rcl get_type_description srv (#5)
Browse files Browse the repository at this point in the history
RCL does not initialize the get_type_description service itself, instead providing a full enough API for full language clients to initialize it and register its callback within their threading/execution framework

Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
  • Loading branch information
emersonknapp authored Jun 27, 2023
1 parent 9d345d6 commit 48a611a
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 167 deletions.
67 changes: 64 additions & 3 deletions rcl/include/rcl/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ extern "C"
#include "rcl/types.h"
#include "rcl/visibility_control.h"

#include "type_description_interfaces/srv/get_type_description.h"

extern const char * const RCL_DISABLE_LOANED_MESSAGES_ENV_VAR;

typedef struct rcl_node_impl_s rcl_node_impl_t;
typedef struct rcl_service_s rcl_service_t;

/// Structure which encapsulates a ROS Node.
typedef struct rcl_node_s
Expand Down Expand Up @@ -551,12 +554,15 @@ rcl_get_disable_loaned_message(bool * disable_loaned_message);

/// Initialize the node's ~/get_type_description service.
/**
* This function initializes the node's private ~/get_type_description service
* This function initializes the node's ~/get_type_description service
* which can be used to retrieve information about types used by the node's
* publishers, subscribers, services or actions.
*
* Note that this function will be called in `rcl_init_node` if the node option
* `enable_type_description_service` is set to true.
* Note that this will not register any callback for the service, client-level code
* must register rcl_node_type_description_service_handle_request or a custom callback
* to handle incoming requests, via that client's executor/waitset capabilities.
*
* This will initialize the node's type cache, if it has not been initialized already.
*
* <hr>
* Attribute | Adherence
Expand Down Expand Up @@ -600,6 +606,61 @@ RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t rcl_node_type_description_service_fini(rcl_node_t * node);


/// Returns a pointer to the node's ~/get_type_description service.
/**
* On success, sets service_out to the initialized service.
* rcl_node_type_description_service_init must be called before this.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | No
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[in] node the handle to the node
* \param[out] service_out Handle to pointer that will be set
* \return #RCL_RET_OK if valid service was returned successfully, or
* \return #RCL_RET_NODE_INVALID if node is invalid, or
* \return #RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
* \return #RCL_RET_NOT_INIT if the service hasn't yet been initialized, or
* \return #RCL_RET_ERROR if an unspecified error occurs.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t rcl_node_get_type_description_service(
const rcl_node_t * node,
rcl_service_t ** service_out);


/// Process a single pending request to the GetTypeDescription service.
/**
* This function may be called to handle incoming requests by any client starting the service.
* It is not intended to be called directly by users.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | No
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[in] node the handle to the node
* \param[in] request_header ID of the incoming request
* \param[in] request Request that came in to the service
* \param[out] response Allocated, uninitialized response to the request
* \return void
*/
RCL_PUBLIC
void rcl_node_type_description_service_handle_request(
rcl_node_t * node,
const rmw_request_id_t * request_header,
const type_description_interfaces__srv__GetTypeDescription_Request * request,
type_description_interfaces__srv__GetTypeDescription_Response * response);

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 0 additions & 3 deletions rcl/include/rcl/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ typedef struct rcl_node_options_s

/// Middleware quality of service settings for /rosout.
rmw_qos_profile_t rosout_qos;

/// Register the ~/get_type_description service. Defaults to false.
bool enable_type_description_service;
} rcl_node_options_t;

/// Return the default node options in a rcl_node_options_t.
Expand Down
4 changes: 4 additions & 0 deletions rcl/include/rcl/node_type_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ typedef struct rcl_type_info_t
/**
* This function initializes hash map of the node's type cache such that types
* can be registered and retrieved.
* Note that to correctly capture all types used by a node, this needs to be called
* before any "builtin" publishers or services are created.
*
* <hr>
* Attribute | Adherence
Expand All @@ -52,6 +54,7 @@ typedef struct rcl_type_info_t
* \return #RCL_RET_NODE_INVALID if the given `node` is invalid, or
* \return #RCL_RET_ERROR if an unspecified error occurs.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t rcl_node_type_cache_init(rcl_node_t * node);

Expand Down Expand Up @@ -95,6 +98,7 @@ bool rcl_node_type_cache_is_valid(const rcl_node_t * node);
* \return #RCL_RET_NODE_INVALID if the given `node` is invalid, or
* \return #RCL_RET_ERROR if an unspecified error occurs.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t rcl_node_type_cache_fini(rcl_node_t * node);

Expand Down
Loading

0 comments on commit 48a611a

Please sign in to comment.