Skip to content
This repository has been archived by the owner on Oct 7, 2021. It is now read-only.

refactor to support init options and context #246

Merged
merged 3 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion rmw_opensplice_cpp/src/rmw_guard_condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,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,
opensplice_cpp_identifier,
// TODO(wjwwood): replace this with RMW_RET_INCORRECT_RMW_IMPLEMENTATION when refactored
return NULL);
rmw_guard_condition_t * guard_condition = rmw_guard_condition_allocate();
if (!guard_condition) {
RMW_SET_ERROR_MSG("failed to allocate guard condition");
Expand Down
79 changes: 78 additions & 1 deletion rmw_opensplice_cpp/src/rmw_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,97 @@
#include <dds_dcps.h>

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

#include "identifier.hpp"

// The extern "C" here enforces that overloading is not used.
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 = opensplice_cpp_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,
opensplice_cpp_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);
wjwwood marked this conversation as resolved.
Show resolved Hide resolved
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
init_options,
init_options->implementation_identifier,
opensplice_cpp_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)
{
RMW_CHECK_ARGUMENT_FOR_NULL(options, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_ARGUMENT_FOR_NULL(context, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
options,
options->implementation_identifier,
opensplice_cpp_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
context->instance_id = options->instance_id;
context->implementation_identifier = opensplice_cpp_identifier;
context->impl = nullptr;

DDS::DomainParticipantFactory_var dp_factory = DDS::DomainParticipantFactory::get_instance();
if (!dp_factory) {
RMW_SET_ERROR_MSG("failed to get domain participant factory");
return RMW_RET_ERROR;
}
return RMW_RET_OK;
}

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,
opensplice_cpp_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"
25 changes: 12 additions & 13 deletions rmw_opensplice_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,20 @@ 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)
{
if (!name) {
RMW_SET_ERROR_MSG("name is null");
return nullptr;
}
if (!namespace_) {
RMW_SET_ERROR_MSG("namespace_ is null");
return nullptr;
}
if (!security_options) {
RMW_SET_ERROR_MSG("security_options is null");
return nullptr;
}
RCUTILS_CHECK_ARGUMENT_FOR_NULL(context, nullptr);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
init context,
context->implementation_identifier,
opensplice_cpp_identifier,
// TODO(wjwwood): replace this with RMW_RET_INCORRECT_RMW_IMPLEMENTATION when refactored
return nullptr);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(name, nullptr);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(namespace_, nullptr);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(security_options, nullptr);
if (security_options->enforce_security) {
RMW_SET_ERROR_MSG("OpenSplice doesn't support DDS Security");
return nullptr;
Expand Down Expand Up @@ -203,7 +202,7 @@ rmw_create_node(
goto fail;
}

graph_guard_condition = rmw_create_guard_condition();
graph_guard_condition = rmw_create_guard_condition(context);
if (!graph_guard_condition) {
// error message already set
goto fail;
Expand Down