Skip to content

Commit

Permalink
refactor to support init options and context (ros2#308)
Browse files Browse the repository at this point in the history
* refactor to support init options and context

Signed-off-by: William Woodall <william@osrfoundation.org>

* style

Signed-off-by: William Woodall <william@osrfoundation.org>

* add missing rmw_shutdown

* fix incorrect check for null

Signed-off-by: William Woodall <william@osrfoundation.org>
Signed-off-by: Devin Bonnie <dbbonnie@amazon.com>
  • Loading branch information
wjwwood authored and dabonnie committed Apr 3, 2019
1 parent 3b0ef8b commit d620f46
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 7 deletions.
10 changes: 9 additions & 1 deletion rmw_connext_cpp/src/rmw_guard_condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "rmw/impl/cpp/macros.hpp"
#include "rmw/rmw.h"

#include "rmw_connext_shared_cpp/guard_condition.hpp"
Expand All @@ -21,8 +22,15 @@
extern "C"
{
rmw_guard_condition_t *
rmw_create_guard_condition()
rmw_create_guard_condition(rmw_context_t * context)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(context, NULL);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
init context,
context->implementation_identifier,
rti_connext_identifier,
// TODO(wjwwood): replace this with RMW_RET_INCORRECT_RMW_IMPLEMENTATION when refactored
return NULL);
return create_guard_condition(rti_connext_identifier);
}

Expand Down
80 changes: 78 additions & 2 deletions rmw_connext_cpp/src/rmw_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,91 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "rmw/rmw.h"
#include "rmw/init.h"

#include "rmw/impl/cpp/macros.hpp"
#include "rmw_connext_shared_cpp/init.hpp"

#include "rmw_connext_cpp/identifier.hpp"

extern "C"
{
rmw_ret_t
rmw_init()
rmw_init_options_init(rmw_init_options_t * init_options, rcutils_allocator_t allocator)
{
RMW_CHECK_ARGUMENT_FOR_NULL(init_options, RMW_RET_INVALID_ARGUMENT);
RCUTILS_CHECK_ALLOCATOR(&allocator, return RMW_RET_INVALID_ARGUMENT);
if (NULL != init_options->implementation_identifier) {
RMW_SET_ERROR_MSG("expected zero-initialized init_options");
return RMW_RET_INVALID_ARGUMENT;
}
init_options->instance_id = 0;
init_options->implementation_identifier = rti_connext_identifier;
init_options->allocator = allocator;
init_options->impl = nullptr;
return RMW_RET_OK;
}

rmw_ret_t
rmw_init_options_copy(const rmw_init_options_t * src, rmw_init_options_t * dst)
{
RMW_CHECK_ARGUMENT_FOR_NULL(src, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_ARGUMENT_FOR_NULL(dst, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
src,
src->implementation_identifier,
rti_connext_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
if (NULL != dst->implementation_identifier) {
RMW_SET_ERROR_MSG("expected zero-initialized dst");
return RMW_RET_INVALID_ARGUMENT;
}
*dst = *src;
return RMW_RET_OK;
}

rmw_ret_t
rmw_init_options_fini(rmw_init_options_t * init_options)
{
RMW_CHECK_ARGUMENT_FOR_NULL(init_options, RMW_RET_INVALID_ARGUMENT);
RCUTILS_CHECK_ALLOCATOR(&(init_options->allocator), return RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
init_options,
init_options->implementation_identifier,
rti_connext_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
*init_options = rmw_get_zero_initialized_init_options();
return RMW_RET_OK;
}

rmw_ret_t
rmw_init(const rmw_init_options_t * options, rmw_context_t * context)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(options, RMW_RET_INVALID_ARGUMENT);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(context, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
options,
options->implementation_identifier,
rti_connext_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
context->instance_id = options->instance_id;
context->implementation_identifier = rti_connext_identifier;
context->impl = nullptr;
return init();
}

rmw_ret_t
rmw_shutdown(rmw_context_t * context)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(context, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
context,
context->implementation_identifier,
rti_connext_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
// context impl is explicitly supposed to be nullptr for now, see rmw_init's code
// RCUTILS_CHECK_ARGUMENT_FOR_NULL(context->impl, RMW_RET_INVALID_ARGUMENT);
*context = rmw_get_zero_initialized_context();
return RMW_RET_OK;
}
} // extern "C"
8 changes: 8 additions & 0 deletions rmw_connext_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ extern "C"
{
rmw_node_t *
rmw_create_node(
rmw_context_t * context,
const char * name,
const char * namespace_,
size_t domain_id,
const rmw_node_security_options_t * security_options)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(context, NULL);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
init context,
context->implementation_identifier,
rti_connext_identifier,
// TODO(wjwwood): replace this with RMW_RET_INCORRECT_RMW_IMPLEMENTATION when refactored
return NULL);
return create_node(
rti_connext_identifier, name, namespace_, domain_id, security_options);
}
Expand Down
97 changes: 93 additions & 4 deletions rmw_connext_dynamic_cpp/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "rmw/error_handling.h"
#include "rmw/get_service_names_and_types.h"
#include "rmw/get_topic_names_and_types.h"
#include "rmw/init.h"
#include "rmw/rmw.h"
#include "rmw/types.h"

Expand Down Expand Up @@ -202,18 +203,99 @@ rmw_get_serialization_format()
}

rmw_ret_t
rmw_init()
rmw_init_options_init(rmw_init_options_t * init_options, rcutils_allocator_t allocator)
{
RMW_CHECK_ARGUMENT_FOR_NULL(init_options, RMW_RET_INVALID_ARGUMENT);
RCUTILS_CHECK_ALLOCATOR(&allocator, return RMW_RET_INVALID_ARGUMENT);
if (NULL != init_options->implementation_identifier) {
RMW_SET_ERROR_MSG("expected zero-initialized init_options");
return RMW_RET_INVALID_ARGUMENT;
}
init_options->instance_id = 0;
init_options->implementation_identifier = rti_connext_dynamic_identifier;
init_options->allocator = allocator;
init_options->impl = nullptr;
return RMW_RET_OK;
}

rmw_ret_t
rmw_init_options_copy(const rmw_init_options_t * src, rmw_init_options_t * dst)
{
RMW_CHECK_ARGUMENT_FOR_NULL(src, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_ARGUMENT_FOR_NULL(dst, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
src,
src->implementation_identifier,
rti_connext_dynamic_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
if (NULL != dst->implementation_identifier) {
RMW_SET_ERROR_MSG("expected zero-initialized dst");
return RMW_RET_INVALID_ARGUMENT;
}
*dst = *src;
return RMW_RET_OK;
}

rmw_ret_t
rmw_init_options_fini(rmw_init_options_t * init_options)
{
RMW_CHECK_ARGUMENT_FOR_NULL(init_options, RMW_RET_INVALID_ARGUMENT);
RCUTILS_CHECK_ALLOCATOR(&(init_options->allocator), return RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
init_options,
init_options->implementation_identifier,
rti_connext_dynamic_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
*init_options = rmw_get_zero_initialized_init_options();
return RMW_RET_OK;
}

rmw_ret_t
rmw_init(const rmw_init_options_t * options, rmw_context_t * context)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(options, RMW_RET_INVALID_ARGUMENT);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(context, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
options,
options->implementation_identifier,
rti_connext_dynamic_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
context->instance_id = options->instance_id;
context->implementation_identifier = rti_connext_dynamic_identifier;
context->impl = nullptr;
return init();
}

rmw_ret_t
rmw_shutdown(rmw_context_t * context)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(context, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
context,
context->implementation_identifier,
rti_connext_dynamic_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
// context impl is explicitly supposed to be nullptr for now, see rmw_init's code
// RCUTILS_CHECK_ARGUMENT_FOR_NULL(context->impl, RMW_RET_INVALID_ARGUMENT);
*context = rmw_get_zero_initialized_context();
return RMW_RET_OK;
}

rmw_node_t *
rmw_create_node(
rmw_context_t * context,
const char * name,
const char * namespace_,
size_t domain_id,
const rmw_node_security_options_t * security_options)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(context, NULL);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
init context,
context->implementation_identifier,
rti_connext_dynamic_identifier,
// TODO(wjwwood): replace this with RMW_RET_INCORRECT_RMW_IMPLEMENTATION when refactored
return NULL);
return create_node(
rti_connext_dynamic_identifier, name, namespace_, domain_id, security_options);
}
Expand Down Expand Up @@ -254,7 +336,7 @@ DDS_TypeCode * _create_type_code(
type_name, untyped_members, typesupport);
}

RMW_SET_ERROR_MSG("Unknown typesupport identifier")
RMW_SET_ERROR_MSG("Unknown typesupport identifier");
return NULL;
}

Expand Down Expand Up @@ -372,7 +454,7 @@ rmw_create_publisher(
// partition operater takes ownership of it.
printf("Original publisher topic name: %s\n", topic_name);
if (rcutils_split_last(topic_name, '/', allocator, &name_tokens) != RCUTILS_RET_OK) {
RMW_SET_ERROR_MSG(rcutils_get_error_string().str)
RMW_SET_ERROR_MSG(rcutils_get_error_string().str);
goto fail;
}
partition_str = NULL;
Expand Down Expand Up @@ -1379,8 +1461,15 @@ rmw_deserialize(
}

rmw_guard_condition_t *
rmw_create_guard_condition()
rmw_create_guard_condition(rmw_context_t * context)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(context, NULL);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
init context,
context->implementation_identifier,
rti_connext_dynamic_identifier,
// TODO(wjwwood): replace this with RMW_RET_INCORRECT_RMW_IMPLEMENTATION when refactored
return NULL);
return create_guard_condition(rti_connext_dynamic_identifier);
}

Expand Down

0 comments on commit d620f46

Please sign in to comment.