Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset the error on failing to find the C typesupport #274

Merged
merged 2 commits into from
Jan 5, 2021
Merged
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
82 changes: 58 additions & 24 deletions rmw_cyclonedds_cpp/src/TypeSupport2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <utility>
#include <vector>

#include "rcutils/error_handling.h"
#include "rosidl_runtime_c/message_type_support_struct.h"
#include "rosidl_runtime_c/service_type_support_struct.h"

namespace rmw_cyclonedds_cpp
{
class ROSIDLC_StructValueType : public StructValueType
Expand Down Expand Up @@ -68,47 +72,77 @@ class ROSIDLCPP_StructValueType : public StructValueType

std::unique_ptr<StructValueType> make_message_value_type(const rosidl_message_type_support_t * mts)
{
if (auto ts_c = mts->func(mts, TypeGeneratorInfo<TypeGenerator::ROSIDL_C>::get_identifier())) {
if (auto ts_c =
get_message_typesupport_handle(
mts,
TypeGeneratorInfo<TypeGenerator::ROSIDL_C>::get_identifier()))
{
auto members = static_cast<const MetaMessage<TypeGenerator::ROSIDL_C> *>(ts_c->data);
return std::make_unique<ROSIDLC_StructValueType>(members);
} else {
rcutils_error_string_t prev_error_string = rcutils_get_error_string();
rcutils_reset_error();

if (auto ts_cpp =
get_message_typesupport_handle(
mts,
TypeGeneratorInfo<TypeGenerator::ROSIDL_Cpp>::get_identifier()))
{
auto members = static_cast<const MetaMessage<TypeGenerator::ROSIDL_Cpp> *>(ts_cpp->data);
return std::make_unique<ROSIDLCPP_StructValueType>(members);
} else {
rcutils_error_string_t error_string = rcutils_get_error_string();
rcutils_reset_error();

throw std::runtime_error(
std::string("Type support not from this implementation. Got:\n") +
" " + prev_error_string.str + "\n" +
" " + error_string.str + "\n" +
"while fetching it");
}
}
if (auto ts_cpp =
mts->func(mts, TypeGeneratorInfo<TypeGenerator::ROSIDL_Cpp>::get_identifier()))
{
auto members = static_cast<const MetaMessage<TypeGenerator::ROSIDL_Cpp> *>(ts_cpp->data);
return std::make_unique<ROSIDLCPP_StructValueType>(members);
}
throw std::runtime_error(
"could not identify message typesupport " + std::string(mts->typesupport_identifier));
}

std::pair<std::unique_ptr<StructValueType>, std::unique_ptr<StructValueType>>
make_request_response_value_types(const rosidl_service_type_support_t * svc_ts)
{
if (auto tsc =
svc_ts->func(svc_ts, TypeGeneratorInfo<TypeGenerator::ROSIDL_C>::get_identifier()))
get_service_typesupport_handle(
svc_ts,
TypeGeneratorInfo<TypeGenerator::ROSIDL_C>::get_identifier()))
{
auto typed =
static_cast<const TypeGeneratorInfo<TypeGenerator::ROSIDL_C>::MetaService *>(tsc->data);
return {
std::make_unique<ROSIDLC_StructValueType>(typed->request_members_),
std::make_unique<ROSIDLC_StructValueType>(typed->response_members_)
};
} else {
rcutils_error_string_t prev_error_string = rcutils_get_error_string();
rcutils_reset_error();

if (auto tscpp =
get_service_typesupport_handle(
svc_ts,
TypeGeneratorInfo<TypeGenerator::ROSIDL_Cpp>::get_identifier()))
{
auto typed =
static_cast<const TypeGeneratorInfo<TypeGenerator::ROSIDL_Cpp>::MetaService *>(tscpp->data);
return {
std::make_unique<ROSIDLCPP_StructValueType>(typed->request_members_),
std::make_unique<ROSIDLCPP_StructValueType>(typed->response_members_)
};
} else {
rcutils_error_string_t error_string = rcutils_get_error_string();
rcutils_reset_error();

throw std::runtime_error(
std::string("Service type support not from this implementation. Got:\n") +
" " + prev_error_string.str + "\n" +
" " + error_string.str + "\n" +
"while fetching it");
}
}

if (auto tscpp =
svc_ts->func(svc_ts, TypeGeneratorInfo<TypeGenerator::ROSIDL_Cpp>::get_identifier()))
{
auto typed =
static_cast<const TypeGeneratorInfo<TypeGenerator::ROSIDL_Cpp>::MetaService *>(tscpp->data);
return {
std::make_unique<ROSIDLCPP_StructValueType>(typed->request_members_),
std::make_unique<ROSIDLCPP_StructValueType>(typed->response_members_)
};
}

throw std::runtime_error(
"Unidentified service type support: " + std::string(svc_ts->typesupport_identifier));
}

ROSIDLC_StructValueType::ROSIDLC_StructValueType(
Expand Down