Zero init topic names and types (#85)

* initialize topic_names_and_type struct in rcl

* sanity check in get_topic_names_and_types

* uncrustify

* initialize all fields...

* address documentation request

* typo
This commit is contained in:
Mikael Arguedas 2016-10-27 19:00:06 -07:00 committed by GitHub
parent 7661ab2202
commit 32bcd0d760
3 changed files with 28 additions and 3 deletions

View file

@ -32,13 +32,19 @@ extern "C"
typedef rmw_topic_names_and_types_t rcl_topic_names_and_types_t; typedef rmw_topic_names_and_types_t rcl_topic_names_and_types_t;
/// Return a rcl_topic_names_and_types_t struct with members initialized to NULL.
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_topic_names_and_types_t
rcl_get_zero_initialized_topic_names_and_types(void);
/// Return a list of topic names and their types. /// Return a list of topic names and their types.
/* This function returns a list of topic names in the ROS graph and their types. /* This function returns a list of topic names in the ROS graph and their types.
* *
* The node parameter must not be NULL, and must point to a valid node. * The node parameter must not be NULL, and must point to a valid node.
* *
* The topic_names_and_types parameter must not be NULL, and must point to an * The topic_names_and_types parameter must be allocated and zero initialized.
* already allocated rcl_topic_names_and_types_t struct.
* The topic_names_and_types is the output for this function, and contains * The topic_names_and_types is the output for this function, and contains
* allocated memory. * allocated memory.
* Therefore, it should be passed to rcl_destroy_topic_names_and_types() when * Therefore, it should be passed to rcl_destroy_topic_names_and_types() when

View file

@ -80,7 +80,7 @@ rcl_get_zero_initialized_node(void);
* This function will create those external parameter interfaces even if * This function will create those external parameter interfaces even if
* parameters are not used later. * parameters are not used later.
* *
* The rcl_node_t given must be allocated and zero initalized. * The rcl_node_t given must be allocated and zero initialized.
* Passing an rcl_node_t which has already had this function called on it, more * Passing an rcl_node_t which has already had this function called on it, more
* recently than rcl_node_fini, will fail. * recently than rcl_node_fini, will fail.
* An allocated rcl_node_t with uninitialized memory is undefined behavior. * An allocated rcl_node_t with uninitialized memory is undefined behavior.

View file

@ -21,6 +21,13 @@ extern "C"
#include "./common.h" #include "./common.h"
rcl_topic_names_and_types_t
rcl_get_zero_initialized_topic_names_and_types(void)
{
const rcl_topic_names_and_types_t null_topic_names_and_types = {0, NULL, NULL};
return null_topic_names_and_types;
}
rcl_ret_t rcl_ret_t
rcl_get_topic_names_and_types( rcl_get_topic_names_and_types(
const rcl_node_t * node, const rcl_node_t * node,
@ -31,6 +38,18 @@ rcl_get_topic_names_and_types(
return RCL_RET_NODE_INVALID; return RCL_RET_NODE_INVALID;
} }
RCL_CHECK_ARGUMENT_FOR_NULL(topic_names_and_types, RCL_RET_INVALID_ARGUMENT); RCL_CHECK_ARGUMENT_FOR_NULL(topic_names_and_types, RCL_RET_INVALID_ARGUMENT);
if (topic_names_and_types->topic_count != 0) {
RCL_SET_ERROR_MSG("topic count is not zero");
return RCL_RET_INVALID_ARGUMENT;
}
if (topic_names_and_types->topic_names) {
RCL_SET_ERROR_MSG("topic names is not null");
return RCL_RET_INVALID_ARGUMENT;
}
if (topic_names_and_types->type_names) {
RCL_SET_ERROR_MSG("type names is not null");
return RCL_RET_INVALID_ARGUMENT;
}
return rmw_get_topic_names_and_types( return rmw_get_topic_names_and_types(
rcl_node_get_rmw_handle(node), rcl_node_get_rmw_handle(node),
topic_names_and_types topic_names_and_types