Compare commits
4 Commits
runtime_in
...
runtime_in
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10e482ee5c | ||
|
|
c8734b3e1d | ||
|
|
8447d36206 | ||
|
|
969067242b |
@@ -58,13 +58,13 @@ public:
|
||||
const rclcpp::QoS & qos,
|
||||
std::function<void(
|
||||
rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr,
|
||||
std::shared_ptr<const rosidl_runtime_c__type_description__TypeDescription>
|
||||
const rosidl_runtime_c__type_description__TypeDescription &
|
||||
)> callback,
|
||||
const rclcpp::SubscriptionOptionsWithAllocator<AllocatorT> & options,
|
||||
bool use_take_dynamic_message = true)
|
||||
: SubscriptionBase(
|
||||
node_base,
|
||||
*(type_support->get_rosidl_message_type_support()),
|
||||
type_support->get_const_rosidl_message_type_support(),
|
||||
topic_name,
|
||||
options.to_rcl_subscription_options(
|
||||
qos),
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
throw std::runtime_error("DynamicMessageTypeSupport cannot be nullptr!");
|
||||
}
|
||||
|
||||
if (type_support->get_rosidl_message_type_support()->typesupport_identifier !=
|
||||
if (type_support->get_const_rosidl_message_type_support().typesupport_identifier !=
|
||||
rosidl_get_dynamic_typesupport_identifier())
|
||||
{
|
||||
throw std::runtime_error(
|
||||
@@ -163,7 +163,7 @@ private:
|
||||
rclcpp::dynamic_typesupport::DynamicMessageTypeSupport::SharedPtr ts_;
|
||||
std::function<void(
|
||||
rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr,
|
||||
std::shared_ptr<const rosidl_runtime_c__type_description__TypeDescription>
|
||||
const rosidl_runtime_c__type_description__TypeDescription &
|
||||
)> callback_;
|
||||
|
||||
rclcpp::dynamic_typesupport::DynamicSerializationSupport::SharedPtr serialization_support_;
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
{ \
|
||||
ValueT out; \
|
||||
rosidl_dynamic_typesupport_dynamic_data_get_ ## FunctionT ## _value( \
|
||||
rosidl_dynamic_data_.get(), id, &out); \
|
||||
&rosidl_dynamic_data_, id, &out); \
|
||||
return out; \
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
DynamicMessage::set_value<ValueT>(rosidl_dynamic_typesupport_member_id_t id, ValueT value) \
|
||||
{ \
|
||||
rosidl_dynamic_typesupport_dynamic_data_set_ ## FunctionT ## _value( \
|
||||
rosidl_dynamic_data_.get(), id, value); \
|
||||
&rosidl_dynamic_data_, id, value); \
|
||||
}
|
||||
|
||||
#define __DYNAMIC_MESSAGE_SET_VALUE_BY_NAME_FN(ValueT, FunctionT) \
|
||||
@@ -73,7 +73,7 @@
|
||||
{ \
|
||||
rosidl_dynamic_typesupport_member_id_t out; \
|
||||
rosidl_dynamic_typesupport_dynamic_data_insert_ ## FunctionT ## _value( \
|
||||
rosidl_dynamic_data_.get(), value, &out); \
|
||||
&rosidl_dynamic_data_, value, &out); \
|
||||
return out; \
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ std::byte
|
||||
DynamicMessage::get_value<std::byte>(rosidl_dynamic_typesupport_member_id_t id)
|
||||
{
|
||||
unsigned char out;
|
||||
rosidl_dynamic_typesupport_dynamic_data_get_byte_value(get_rosidl_dynamic_data(), id, &out);
|
||||
rosidl_dynamic_typesupport_dynamic_data_get_byte_value(&get_rosidl_dynamic_data(), id, &out);
|
||||
return static_cast<std::byte>(out);
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ DynamicMessage::set_value<std::byte>(
|
||||
rosidl_dynamic_typesupport_member_id_t id, const std::byte value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_set_byte_value(
|
||||
rosidl_dynamic_data_.get(), id, static_cast<unsigned char>(value));
|
||||
&rosidl_dynamic_data_, id, static_cast<unsigned char>(value));
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ DynamicMessage::insert_value<std::byte>(const std::byte value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_member_id_t out;
|
||||
rosidl_dynamic_typesupport_dynamic_data_insert_byte_value(
|
||||
rosidl_dynamic_data_.get(), static_cast<unsigned char>(value), &out);
|
||||
&rosidl_dynamic_data_, static_cast<unsigned char>(value), &out);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ DynamicMessage::get_value<std::string>(rosidl_dynamic_typesupport_member_id_t id
|
||||
size_t buf_length;
|
||||
char * buf = nullptr;
|
||||
rosidl_dynamic_typesupport_dynamic_data_get_string_value(
|
||||
get_rosidl_dynamic_data(), id, &buf, &buf_length);
|
||||
&get_rosidl_dynamic_data(), id, &buf, &buf_length);
|
||||
auto out = std::string(buf, buf_length);
|
||||
delete buf;
|
||||
return out;
|
||||
@@ -191,7 +191,7 @@ DynamicMessage::get_value<std::u16string>(rosidl_dynamic_typesupport_member_id_t
|
||||
size_t buf_length;
|
||||
char16_t * buf = nullptr;
|
||||
rosidl_dynamic_typesupport_dynamic_data_get_wstring_value(
|
||||
get_rosidl_dynamic_data(), id, &buf, &buf_length);
|
||||
&get_rosidl_dynamic_data(), id, &buf, &buf_length);
|
||||
auto out = std::u16string(buf, buf_length);
|
||||
delete buf;
|
||||
return out;
|
||||
@@ -220,7 +220,7 @@ DynamicMessage::set_value<std::string>(
|
||||
rosidl_dynamic_typesupport_member_id_t id, const std::string value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_set_string_value(
|
||||
rosidl_dynamic_data_.get(), id, value.c_str(), value.size());
|
||||
&rosidl_dynamic_data_, id, value.c_str(), value.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -230,7 +230,7 @@ DynamicMessage::set_value<std::u16string>(
|
||||
rosidl_dynamic_typesupport_member_id_t id, const std::u16string value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_set_wstring_value(
|
||||
rosidl_dynamic_data_.get(), id, value.c_str(), value.size());
|
||||
&rosidl_dynamic_data_, id, value.c_str(), value.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -256,7 +256,7 @@ DynamicMessage::insert_value<std::string>(const std::string value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_member_id_t out;
|
||||
rosidl_dynamic_typesupport_dynamic_data_insert_string_value(
|
||||
rosidl_dynamic_data_.get(), value.c_str(), value.size(), &out);
|
||||
&rosidl_dynamic_data_, value.c_str(), value.size(), &out);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ DynamicMessage::insert_value<std::u16string>(const std::u16string value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_member_id_t out;
|
||||
rosidl_dynamic_typesupport_dynamic_data_insert_wstring_value(
|
||||
rosidl_dynamic_data_.get(), value.c_str(), value.size(), &out);
|
||||
&rosidl_dynamic_data_, value.c_str(), value.size(), &out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
const std::string & default_value) \
|
||||
{ \
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_ ## FunctionT ## _member( \
|
||||
rosidl_dynamic_type_builder_.get(), \
|
||||
&rosidl_dynamic_type_builder_, \
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size()); \
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
const std::string & default_value) \
|
||||
{ \
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_ ## FunctionT ## _array_member( \
|
||||
rosidl_dynamic_type_builder_.get(), \
|
||||
&rosidl_dynamic_type_builder_, \
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(), \
|
||||
array_length); \
|
||||
}
|
||||
@@ -67,7 +67,7 @@
|
||||
{ \
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_ ## FunctionT ## \
|
||||
_unbounded_sequence_member( \
|
||||
rosidl_dynamic_type_builder_.get(), \
|
||||
&rosidl_dynamic_type_builder_, \
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size()); \
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
const std::string & default_value) \
|
||||
{ \
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_ ## FunctionT ## _bounded_sequence_member( \
|
||||
rosidl_dynamic_type_builder_.get(), \
|
||||
&rosidl_dynamic_type_builder_, \
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(), \
|
||||
sequence_bound); \
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#ifndef RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_HPP_
|
||||
#define RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_HPP_
|
||||
|
||||
#include <rcl/allocator.h>
|
||||
#include <rcl/types.h>
|
||||
#include <rosidl_dynamic_typesupport/types.h>
|
||||
|
||||
@@ -26,21 +27,18 @@
|
||||
#include "rclcpp/macros.hpp"
|
||||
#include "rclcpp/visibility_control.hpp"
|
||||
|
||||
|
||||
namespace rclcpp
|
||||
{
|
||||
namespace dynamic_typesupport
|
||||
{
|
||||
|
||||
|
||||
class DynamicMessageType;
|
||||
class DynamicMessageTypeBuilder;
|
||||
|
||||
/// Utility wrapper class for rosidl_dynamic_typesupport_dynamic_data_t *
|
||||
/// Utility wrapper class for rosidl_dynamic_typesupport_dynamic_data_t
|
||||
/**
|
||||
* This class:
|
||||
* - Manages the lifetime of the raw pointer.
|
||||
* - Exposes getter methods to get the raw pointer and shared pointers
|
||||
* - Exposes getter methods for the struct
|
||||
* - Exposes the underlying serialization support API
|
||||
*
|
||||
* Ownership:
|
||||
@@ -67,50 +65,48 @@ public:
|
||||
// the data should be the exact same object managed by the DynamicSerializationSupport,
|
||||
// otherwise the lifetime management will not work properly.
|
||||
|
||||
/// Construct a new DynamicMessage with the provided dynamic type builder
|
||||
/// Construct a new DynamicMessage with the provided dynamic type builder, using its allocator
|
||||
RCLCPP_PUBLIC
|
||||
explicit DynamicMessage(std::shared_ptr<DynamicMessageTypeBuilder> dynamic_type_builder);
|
||||
|
||||
/// Construct a new DynamicMessage with the provided dynamic type
|
||||
/// Construct a new DynamicMessage with the provided dynamic type builder and allocator
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage(
|
||||
std::shared_ptr<DynamicMessageTypeBuilder> dynamic_type_builder,
|
||||
rcl_allocator_t allocator);
|
||||
|
||||
/// Construct a new DynamicMessage with the provided dynamic type, using its allocator
|
||||
RCLCPP_PUBLIC
|
||||
explicit DynamicMessage(std::shared_ptr<DynamicMessageType> dynamic_type);
|
||||
|
||||
/// Assume ownership of raw pointer
|
||||
/// Construct a new DynamicMessage with the provided dynamic type and allocator
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
rosidl_dynamic_typesupport_dynamic_data_t * rosidl_dynamic_data);
|
||||
std::shared_ptr<DynamicMessageType> dynamic_type,
|
||||
rcl_allocator_t allocator);
|
||||
|
||||
/// Copy shared pointer
|
||||
/// Assume ownership of struct
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_dynamic_data_t> rosidl_dynamic_data);
|
||||
rosidl_dynamic_typesupport_dynamic_data_t && rosidl_dynamic_data);
|
||||
|
||||
/// Loaning constructor
|
||||
/// Must only be called with raw ptr obtained from loaning!
|
||||
/// Must only be called with a rosidl dynaimc data object obtained from loaning!
|
||||
// NOTE(methylDragon): I'd put this in protected, but I need this exposed to
|
||||
// enable_shared_from_this...
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage(
|
||||
DynamicMessage::SharedPtr parent_data,
|
||||
rosidl_dynamic_typesupport_dynamic_data_t * rosidl_loaned_data);
|
||||
rosidl_dynamic_typesupport_dynamic_data_t && rosidl_loaned_data);
|
||||
|
||||
// NOTE(methylDragon): Deliberately no constructor from description to nudge users towards using
|
||||
// construction from dynamic type/builder, which is more efficient
|
||||
|
||||
/// Copy constructor
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage(const DynamicMessage & other);
|
||||
|
||||
/// Move constructor
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage(DynamicMessage && other) noexcept;
|
||||
|
||||
/// Copy assignment
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage & operator=(const DynamicMessage & other);
|
||||
|
||||
/// Move assignment
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage & operator=(DynamicMessage && other) noexcept;
|
||||
@@ -122,28 +118,20 @@ public:
|
||||
// GETTERS =======================================================================================
|
||||
RCLCPP_PUBLIC
|
||||
const std::string
|
||||
get_library_identifier() const;
|
||||
get_serialization_library_identifier() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
const std::string
|
||||
get_name() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
rosidl_dynamic_typesupport_dynamic_data_t *
|
||||
rosidl_dynamic_typesupport_dynamic_data_t &
|
||||
get_rosidl_dynamic_data();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
const rosidl_dynamic_typesupport_dynamic_data_t *
|
||||
const rosidl_dynamic_typesupport_dynamic_data_t &
|
||||
get_rosidl_dynamic_data() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_dynamic_data_t>
|
||||
get_shared_rosidl_dynamic_data();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::shared_ptr<const rosidl_dynamic_typesupport_dynamic_data_t>
|
||||
get_shared_rosidl_dynamic_data() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicSerializationSupport::SharedPtr
|
||||
get_shared_dynamic_serialization_support();
|
||||
@@ -176,19 +164,21 @@ public:
|
||||
// METHODS =======================================================================================
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage
|
||||
clone() const;
|
||||
clone(rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage::SharedPtr
|
||||
clone_shared() const;
|
||||
clone_shared(rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage
|
||||
init_from_type(DynamicMessageType & type) const;
|
||||
init_from_type(
|
||||
DynamicMessageType & type, rcl_allocator_t allocator = rcl_get_default_allocator()) const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage::SharedPtr
|
||||
init_from_type_shared(DynamicMessageType & type) const;
|
||||
init_from_type_shared(
|
||||
DynamicMessageType & type, rcl_allocator_t allocator = rcl_get_default_allocator()) const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
@@ -196,11 +186,15 @@ public:
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage::SharedPtr
|
||||
loan_value(rosidl_dynamic_typesupport_member_id_t id);
|
||||
loan_value(
|
||||
rosidl_dynamic_typesupport_member_id_t id,
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage::SharedPtr
|
||||
loan_value(const std::string & name);
|
||||
loan_value(
|
||||
const std::string & name,
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
@@ -232,11 +226,11 @@ public:
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
serialize(rcl_serialized_message_t * buffer);
|
||||
serialize(rcl_serialized_message_t & buffer);
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
deserialize(rcl_serialized_message_t * buffer);
|
||||
deserialize(rcl_serialized_message_t & buffer);
|
||||
|
||||
|
||||
// MEMBER ACCESS TEMPLATES =======================================================================
|
||||
@@ -366,19 +360,27 @@ public:
|
||||
// NESTED MEMBER ACCESS ==========================================================================
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage
|
||||
get_complex_value(rosidl_dynamic_typesupport_member_id_t id);
|
||||
get_complex_value(
|
||||
rosidl_dynamic_typesupport_member_id_t id,
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage
|
||||
get_complex_value(const std::string & name);
|
||||
get_complex_value(
|
||||
const std::string & name,
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage::SharedPtr
|
||||
get_complex_value_shared(rosidl_dynamic_typesupport_member_id_t id);
|
||||
get_complex_value_shared(
|
||||
rosidl_dynamic_typesupport_member_id_t id,
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage::SharedPtr
|
||||
get_complex_value_shared(const std::string & name);
|
||||
get_complex_value_shared(
|
||||
const std::string & name,
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
@@ -405,14 +407,15 @@ protected:
|
||||
// DynamicSerializationSupport
|
||||
DynamicSerializationSupport::SharedPtr serialization_support_;
|
||||
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_dynamic_data_t> rosidl_dynamic_data_;
|
||||
|
||||
rosidl_dynamic_typesupport_dynamic_data_t rosidl_dynamic_data_;
|
||||
bool is_loaned_;
|
||||
|
||||
// Used for returning the loaned value, and lifetime management
|
||||
DynamicMessage::SharedPtr parent_data_;
|
||||
|
||||
private:
|
||||
RCLCPP_DISABLE_COPY(DynamicMessage)
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage();
|
||||
|
||||
@@ -423,7 +426,6 @@ private:
|
||||
const rosidl_dynamic_typesupport_dynamic_data_t & dynamic_data);
|
||||
};
|
||||
|
||||
|
||||
} // namespace dynamic_typesupport
|
||||
} // namespace rclcpp
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#ifndef RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_TYPE_HPP_
|
||||
#define RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_TYPE_HPP_
|
||||
|
||||
#include <rcl/allocator.h>
|
||||
#include <rosidl_dynamic_typesupport/types.h>
|
||||
|
||||
#include <memory>
|
||||
@@ -24,21 +25,18 @@
|
||||
#include "rclcpp/macros.hpp"
|
||||
#include "rclcpp/visibility_control.hpp"
|
||||
|
||||
|
||||
namespace rclcpp
|
||||
{
|
||||
namespace dynamic_typesupport
|
||||
{
|
||||
|
||||
|
||||
class DynamicMessage;
|
||||
class DynamicMessageTypeBuilder;
|
||||
|
||||
/// Utility wrapper class for `rosidl_dynamic_typesupport_dynamic_type_t *`
|
||||
/// Utility wrapper class for `rosidl_dynamic_typesupport_dynamic_type_t`
|
||||
/**
|
||||
* This class:
|
||||
* - Manages the lifetime of the raw pointer.
|
||||
* - Exposes getter methods to get the raw pointer and shared pointers
|
||||
* - Exposes getter methods for the struct
|
||||
* - Exposes the underlying serialization support API
|
||||
*
|
||||
* Ownership:
|
||||
@@ -71,40 +69,34 @@ public:
|
||||
// the type should be the exact same object managed by the `DynamicSerializationSupport`,
|
||||
// otherwise the lifetime management will not work properly.
|
||||
|
||||
/// Construct a new `DynamicMessageType` with the provided dynamic type builder
|
||||
/// Construct a new `DynamicMessageType` with the provided dynamic type builder,
|
||||
/// using its allocator
|
||||
RCLCPP_PUBLIC
|
||||
explicit DynamicMessageType(std::shared_ptr<DynamicMessageTypeBuilder> dynamic_type_builder);
|
||||
|
||||
/// Assume ownership of raw pointer
|
||||
/// Construct a new `DynamicMessageType` with the provided dynamic type builder and allocator
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageType(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
rosidl_dynamic_typesupport_dynamic_type_t * rosidl_dynamic_type);
|
||||
std::shared_ptr<DynamicMessageTypeBuilder> dynamic_type_builder,
|
||||
rcl_allocator_t allocator);
|
||||
|
||||
/// Copy shared pointer
|
||||
/// Assume ownership of struct
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageType(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_dynamic_type_t> rosidl_dynamic_type);
|
||||
rosidl_dynamic_typesupport_dynamic_type_t && rosidl_dynamic_type);
|
||||
|
||||
/// From description
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageType(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description);
|
||||
|
||||
/// Copy constructor
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageType(const DynamicMessageType & other);
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description,
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
/// Move constructor
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageType(DynamicMessageType && other) noexcept;
|
||||
|
||||
/// Copy assignment
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageType & operator=(const DynamicMessageType & other);
|
||||
|
||||
/// Move assignment
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageType & operator=(DynamicMessageType && other) noexcept;
|
||||
@@ -113,16 +105,21 @@ public:
|
||||
virtual ~DynamicMessageType();
|
||||
|
||||
/// Swaps the serialization support if `serialization_support` is populated
|
||||
/**
|
||||
* The user can call this with another description to reconfigure the type without changing the
|
||||
* serialization support
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
init_from_description(
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description,
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator(),
|
||||
DynamicSerializationSupport::SharedPtr serialization_support = nullptr);
|
||||
|
||||
// GETTERS =======================================================================================
|
||||
RCLCPP_PUBLIC
|
||||
const std::string
|
||||
get_library_identifier() const;
|
||||
get_serialization_library_identifier() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
const std::string
|
||||
@@ -133,21 +130,13 @@ public:
|
||||
get_member_count() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
rosidl_dynamic_typesupport_dynamic_type_t *
|
||||
rosidl_dynamic_typesupport_dynamic_type_t &
|
||||
get_rosidl_dynamic_type();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
const rosidl_dynamic_typesupport_dynamic_type_t *
|
||||
const rosidl_dynamic_typesupport_dynamic_type_t &
|
||||
get_rosidl_dynamic_type() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_dynamic_type_t>
|
||||
get_shared_rosidl_dynamic_type();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::shared_ptr<const rosidl_dynamic_typesupport_dynamic_type_t>
|
||||
get_shared_rosidl_dynamic_type() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicSerializationSupport::SharedPtr
|
||||
get_shared_dynamic_serialization_support();
|
||||
@@ -160,11 +149,11 @@ public:
|
||||
// METHODS =======================================================================================
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageType
|
||||
clone() const;
|
||||
clone(rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageType::SharedPtr
|
||||
clone_shared() const;
|
||||
clone_shared(rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
@@ -172,11 +161,11 @@ public:
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage
|
||||
build_dynamic_message();
|
||||
build_dynamic_message(rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::shared_ptr<DynamicMessage>
|
||||
build_dynamic_message_shared();
|
||||
build_dynamic_message_shared(rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
protected:
|
||||
// NOTE(methylDragon):
|
||||
@@ -187,9 +176,11 @@ protected:
|
||||
// `DynamicSerializationSupport`
|
||||
DynamicSerializationSupport::SharedPtr serialization_support_;
|
||||
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_dynamic_type_t> rosidl_dynamic_type_;
|
||||
rosidl_dynamic_typesupport_dynamic_type_t rosidl_dynamic_type_;
|
||||
|
||||
private:
|
||||
RCLCPP_DISABLE_COPY(DynamicMessageType)
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageType();
|
||||
|
||||
@@ -200,7 +191,6 @@ private:
|
||||
const rosidl_dynamic_typesupport_dynamic_type_t & rosidl_dynamic_type);
|
||||
};
|
||||
|
||||
|
||||
} // namespace dynamic_typesupport
|
||||
} // namespace rclcpp
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#ifndef RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_TYPE_BUILDER_HPP_
|
||||
#define RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_TYPE_BUILDER_HPP_
|
||||
|
||||
#include <rcl/allocator.h>
|
||||
#include <rosidl_dynamic_typesupport/types.h>
|
||||
|
||||
#include <memory>
|
||||
@@ -24,7 +25,6 @@
|
||||
#include "rclcpp/macros.hpp"
|
||||
#include "rclcpp/visibility_control.hpp"
|
||||
|
||||
|
||||
namespace rclcpp
|
||||
{
|
||||
namespace dynamic_typesupport
|
||||
@@ -69,82 +69,75 @@ public:
|
||||
// the builder should be the exact same object managed by the `DynamicSerializationSupport`,
|
||||
// otherwise the lifetime management will not work properly.
|
||||
|
||||
/// Construct a new `DynamicMessageTypeBuilder` with the provided serialization support
|
||||
/// Construct a new `DynamicMessageTypeBuilder` with the provided serialization support using its
|
||||
/// allocator
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageTypeBuilder(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
const std::string & name);
|
||||
|
||||
/// Assume ownership of raw pointer
|
||||
/// Construct a new `DynamicMessageTypeBuilder` with the provided serialization support and
|
||||
/// allocator
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageTypeBuilder(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t * dynamic_type_builder);
|
||||
const std::string & name,
|
||||
rcl_allocator_t allocator);
|
||||
|
||||
/// Copy shared pointer
|
||||
/// Assume ownership of struct
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageTypeBuilder(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_dynamic_type_builder_t> dynamic_type_builder);
|
||||
|
||||
/// Copy constructor
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageTypeBuilder(const DynamicMessageTypeBuilder & other);
|
||||
|
||||
/// Move constructor
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageTypeBuilder(DynamicMessageTypeBuilder && other) noexcept;
|
||||
|
||||
/// Copy assignment
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageTypeBuilder & operator=(const DynamicMessageTypeBuilder & other);
|
||||
|
||||
/// Move assignment
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageTypeBuilder & operator=(DynamicMessageTypeBuilder && other) noexcept;
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t && dynamic_type_builder);
|
||||
|
||||
/// From description
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageTypeBuilder(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description);
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description,
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
/// Move constructor
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageTypeBuilder(DynamicMessageTypeBuilder && other) noexcept;
|
||||
|
||||
/// Move assignment
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageTypeBuilder & operator=(DynamicMessageTypeBuilder && other) noexcept;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
virtual ~DynamicMessageTypeBuilder();
|
||||
|
||||
/// Swaps the serialization support if serialization_support is populated
|
||||
/**
|
||||
* The user can call this with another description to reconfigure the type without changing the
|
||||
* serialization support
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
init_from_description(
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description,
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator(),
|
||||
DynamicSerializationSupport::SharedPtr serialization_support = nullptr);
|
||||
|
||||
|
||||
// GETTERS =======================================================================================
|
||||
RCLCPP_PUBLIC
|
||||
const std::string
|
||||
get_library_identifier() const;
|
||||
get_serialization_library_identifier() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
const std::string
|
||||
get_name() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t *
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t &
|
||||
get_rosidl_dynamic_type_builder();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
const rosidl_dynamic_typesupport_dynamic_type_builder_t *
|
||||
const rosidl_dynamic_typesupport_dynamic_type_builder_t &
|
||||
get_rosidl_dynamic_type_builder() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_dynamic_type_builder_t>
|
||||
get_shared_rosidl_dynamic_type_builder();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::shared_ptr<const rosidl_dynamic_typesupport_dynamic_type_builder_t>
|
||||
get_shared_rosidl_dynamic_type_builder() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicSerializationSupport::SharedPtr
|
||||
get_shared_dynamic_serialization_support();
|
||||
@@ -161,31 +154,31 @@ public:
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageTypeBuilder
|
||||
clone() const;
|
||||
clone(rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageTypeBuilder::SharedPtr
|
||||
clone_shared() const;
|
||||
clone_shared(rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
clear();
|
||||
clear(rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage
|
||||
build_dynamic_message();
|
||||
build_dynamic_message(rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessage::SharedPtr
|
||||
build_dynamic_message_shared();
|
||||
build_dynamic_message_shared(rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageType
|
||||
build_dynamic_message_type();
|
||||
build_dynamic_message_type(rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageType::SharedPtr
|
||||
build_dynamic_message_type_shared();
|
||||
build_dynamic_message_type_shared(rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
|
||||
// ADD MEMBERS TEMPLATES =========================================================================
|
||||
@@ -387,9 +380,11 @@ protected:
|
||||
// `DynamicSerializationSupport`
|
||||
DynamicSerializationSupport::SharedPtr serialization_support_;
|
||||
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_dynamic_type_builder_t> rosidl_dynamic_type_builder_;
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t rosidl_dynamic_type_builder_;
|
||||
|
||||
private:
|
||||
RCLCPP_DISABLE_COPY(DynamicMessageTypeBuilder)
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageTypeBuilder();
|
||||
|
||||
@@ -397,7 +392,8 @@ private:
|
||||
void
|
||||
init_from_serialization_support_(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
const std::string & name);
|
||||
const std::string & name,
|
||||
rcl_allocator_t allocator);
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
@@ -406,7 +402,6 @@ private:
|
||||
const rosidl_dynamic_typesupport_dynamic_type_builder_t & dynamic_type_builder);
|
||||
};
|
||||
|
||||
|
||||
} // namespace dynamic_typesupport
|
||||
} // namespace rclcpp
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#ifndef RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_TYPE_SUPPORT_HPP_
|
||||
#define RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_TYPE_SUPPORT_HPP_
|
||||
|
||||
#include <rcl/allocator.h>
|
||||
|
||||
#include <rosidl_dynamic_typesupport/dynamic_message_type_support_struct.h>
|
||||
#include <rosidl_dynamic_typesupport/types.h>
|
||||
#include <rosidl_runtime_c/message_type_support_struct.h>
|
||||
@@ -30,25 +32,23 @@
|
||||
#include "rclcpp/macros.hpp"
|
||||
#include "rclcpp/visibility_control.hpp"
|
||||
|
||||
|
||||
namespace rclcpp
|
||||
{
|
||||
namespace dynamic_typesupport
|
||||
{
|
||||
|
||||
/// Utility wrapper class for `rosidl_message_type_support_t *` containing managed
|
||||
/// Utility wrapper class for `rosidl_message_type_support_t` containing managed
|
||||
/// instances of the typesupport handle impl.
|
||||
/**
|
||||
*
|
||||
* NOTE: This class is the recommended way to obtain the dynamic message type
|
||||
* support struct, instead of `rcl_dynamic_message_type_support_handle_create()`,
|
||||
* support struct, instead of `rcl_dynamic_message_type_support_handle_init()`,
|
||||
* because this class will manage the lifetimes for you.
|
||||
*
|
||||
* Do NOT call rcl_dynamic_message_type_support_handle_destroy!!
|
||||
* Do NOT call rcl_dynamic_message_type_support_handle_fini
|
||||
*
|
||||
* This class:
|
||||
* - Manages the lifetime of the raw pointer.
|
||||
* - Exposes getter methods to get the raw pointer and shared pointers
|
||||
* - Exposes getter methods for the struct
|
||||
* - Stores shared pointers to wrapper classes that expose the underlying
|
||||
* serialization support API
|
||||
*
|
||||
@@ -68,16 +68,17 @@ public:
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageTypeSupport(
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description,
|
||||
const std::string & serialization_library_name = "");
|
||||
const std::string & serialization_library_name = "",
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
/// From description, for provided serialization support
|
||||
/// Does NOT take ownership of the description (copies instead.)
|
||||
/// Constructs type support top-down (calling
|
||||
/// `rosidl_dynamic_message_type_support_handle_create()`)
|
||||
/// Constructs type support top-down (calling `rosidl_dynamic_message_type_support_handle_init()`)
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageTypeSupport(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description);
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description,
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
/// Assume ownership of managed types
|
||||
/// Does NOT take ownership of the description (copies instead.)
|
||||
@@ -93,7 +94,8 @@ public:
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
DynamicMessageType::SharedPtr dynamic_message_type,
|
||||
DynamicMessage::SharedPtr dynamic_message,
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description);
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description,
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
virtual ~DynamicMessageTypeSupport();
|
||||
@@ -102,40 +104,20 @@ public:
|
||||
// GETTERS =======================================================================================
|
||||
RCLCPP_PUBLIC
|
||||
const std::string
|
||||
get_library_identifier() const;
|
||||
get_serialization_library_identifier() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
rosidl_message_type_support_t *
|
||||
get_rosidl_message_type_support();
|
||||
const rosidl_message_type_support_t &
|
||||
get_const_rosidl_message_type_support();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
const rosidl_message_type_support_t *
|
||||
get_rosidl_message_type_support() const;
|
||||
const rosidl_message_type_support_t &
|
||||
get_const_rosidl_message_type_support() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::shared_ptr<rosidl_message_type_support_t>
|
||||
get_shared_rosidl_message_type_support();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::shared_ptr<const rosidl_message_type_support_t>
|
||||
get_shared_rosidl_message_type_support() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
rosidl_runtime_c__type_description__TypeDescription *
|
||||
get_rosidl_runtime_c_type_description();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
const rosidl_runtime_c__type_description__TypeDescription *
|
||||
const rosidl_runtime_c__type_description__TypeDescription &
|
||||
get_rosidl_runtime_c_type_description() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::shared_ptr<rosidl_runtime_c__type_description__TypeDescription>
|
||||
get_shared_rosidl_runtime_c_type_description();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::shared_ptr<const rosidl_runtime_c__type_description__TypeDescription>
|
||||
get_shared_rosidl_runtime_c_type_description() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
DynamicSerializationSupport::SharedPtr
|
||||
get_shared_dynamic_serialization_support();
|
||||
@@ -163,42 +145,21 @@ public:
|
||||
protected:
|
||||
RCLCPP_DISABLE_COPY(DynamicMessageTypeSupport)
|
||||
|
||||
DynamicSerializationSupport::SharedPtr serialization_support_;
|
||||
DynamicMessageType::SharedPtr dynamic_message_type_;
|
||||
DynamicMessage::SharedPtr dynamic_message_;
|
||||
std::shared_ptr<rosidl_runtime_c__type_description__TypeDescription> description_;
|
||||
|
||||
std::shared_ptr<rosidl_message_type_support_t> rosidl_message_type_support_;
|
||||
RCLCPP_PUBLIC
|
||||
rosidl_message_type_support_t &
|
||||
get_rosidl_message_type_support();
|
||||
|
||||
private:
|
||||
RCLCPP_PUBLIC
|
||||
DynamicMessageTypeSupport();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
manage_description_(rosidl_runtime_c__type_description__TypeDescription * description);
|
||||
DynamicSerializationSupport::SharedPtr serialization_support_;
|
||||
DynamicMessageType::SharedPtr dynamic_message_type_;
|
||||
DynamicMessage::SharedPtr dynamic_message_;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
init_dynamic_message_type_(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
const rosidl_runtime_c__type_description__TypeDescription * description);
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
init_dynamic_message_(DynamicMessageType::SharedPtr dynamic_type);
|
||||
|
||||
// By aggregation
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
init_rosidl_message_type_support_(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
DynamicMessageType::SharedPtr dynamic_message_type,
|
||||
DynamicMessage::SharedPtr dynamic_message,
|
||||
rosidl_runtime_c__type_description__TypeDescription * description);
|
||||
rosidl_message_type_support_t rosidl_message_type_support_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace dynamic_typesupport
|
||||
} // namespace rclcpp
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#ifndef RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_SERIALIZATION_SUPPORT_HPP_
|
||||
#define RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_SERIALIZATION_SUPPORT_HPP_
|
||||
|
||||
#include <rcl/allocator.h>
|
||||
#include <rosidl_dynamic_typesupport/api/serialization_support.h>
|
||||
#include <rosidl_dynamic_typesupport/types.h>
|
||||
|
||||
#include <memory>
|
||||
@@ -23,17 +25,15 @@
|
||||
#include "rclcpp/macros.hpp"
|
||||
#include "rclcpp/visibility_control.hpp"
|
||||
|
||||
|
||||
namespace rclcpp
|
||||
{
|
||||
namespace dynamic_typesupport
|
||||
{
|
||||
|
||||
/// Utility wrapper class for rosidl_dynamic_typesupport_serialization_support_t *
|
||||
/// Utility wrapper class for rosidl_dynamic_typesupport_serialization_support_t
|
||||
/**
|
||||
* This class:
|
||||
* - Manages the lifetime of the raw pointer.
|
||||
* - Exposes getter methods to get the raw pointer and shared pointers
|
||||
* - Exposes getter methods for the struct
|
||||
* - Exposes the underlying serialization support API
|
||||
*
|
||||
* Ownership:
|
||||
@@ -47,21 +47,18 @@ public:
|
||||
|
||||
// CONSTRUCTION ==================================================================================
|
||||
RCLCPP_PUBLIC
|
||||
DynamicSerializationSupport();
|
||||
explicit DynamicSerializationSupport(rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
/// Get the rmw middleware implementation specific serialization support (configured by name)
|
||||
RCLCPP_PUBLIC
|
||||
explicit DynamicSerializationSupport(const std::string & serialization_library_name);
|
||||
DynamicSerializationSupport(
|
||||
const std::string & serialization_library_name,
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator());
|
||||
|
||||
/// Assume ownership of raw pointer
|
||||
/// Assume ownership of struct
|
||||
RCLCPP_PUBLIC
|
||||
explicit DynamicSerializationSupport(
|
||||
rosidl_dynamic_typesupport_serialization_support_t * rosidl_serialization_support);
|
||||
|
||||
/// Copy shared pointer
|
||||
RCLCPP_PUBLIC
|
||||
DynamicSerializationSupport(
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_serialization_support_t> serialization_support);
|
||||
rosidl_dynamic_typesupport_serialization_support_t && rosidl_serialization_support);
|
||||
|
||||
/// Move constructor
|
||||
RCLCPP_PUBLIC
|
||||
@@ -78,31 +75,23 @@ public:
|
||||
// GETTERS =======================================================================================
|
||||
RCLCPP_PUBLIC
|
||||
const std::string
|
||||
get_library_identifier() const;
|
||||
get_serialization_library_identifier() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
rosidl_dynamic_typesupport_serialization_support_t *
|
||||
rosidl_dynamic_typesupport_serialization_support_t &
|
||||
get_rosidl_serialization_support();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
const rosidl_dynamic_typesupport_serialization_support_t *
|
||||
const rosidl_dynamic_typesupport_serialization_support_t &
|
||||
get_rosidl_serialization_support() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_serialization_support_t>
|
||||
get_shared_rosidl_serialization_support();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::shared_ptr<const rosidl_dynamic_typesupport_serialization_support_t>
|
||||
get_shared_rosidl_serialization_support() const;
|
||||
|
||||
protected:
|
||||
RCLCPP_DISABLE_COPY(DynamicSerializationSupport)
|
||||
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_serialization_support_t> rosidl_serialization_support_;
|
||||
private:
|
||||
rosidl_dynamic_typesupport_serialization_support_t rosidl_serialization_support_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace dynamic_typesupport
|
||||
} // namespace rclcpp
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ void DynamicSubscription::handle_dynamic_message(
|
||||
const rclcpp::MessageInfo & message_info)
|
||||
{
|
||||
(void) message_info;
|
||||
callback_(message, ts_->get_shared_rosidl_runtime_c_type_description());
|
||||
callback_(message, ts_->get_rosidl_runtime_c_type_description());
|
||||
}
|
||||
|
||||
} // namespace rclcpp
|
||||
|
||||
@@ -14,11 +14,13 @@
|
||||
|
||||
#include <rosidl_dynamic_typesupport/api/dynamic_type.h>
|
||||
#include <rosidl_dynamic_typesupport/api/dynamic_data.h>
|
||||
#include <rosidl_dynamic_typesupport/api/serialization_support.h>
|
||||
#include <rosidl_dynamic_typesupport/types.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "rcl/allocator.h"
|
||||
#include "rcl/types.h"
|
||||
#include "rcutils/logging_macros.h"
|
||||
|
||||
@@ -42,111 +44,81 @@ using rclcpp::dynamic_typesupport::DynamicSerializationSupport;
|
||||
|
||||
// CONSTRUCTION ==================================================================================
|
||||
DynamicMessage::DynamicMessage(const DynamicMessageTypeBuilder::SharedPtr dynamic_type_builder)
|
||||
: DynamicMessage::DynamicMessage(
|
||||
dynamic_type_builder, dynamic_type_builder->get_rosidl_dynamic_type_builder().allocator) {}
|
||||
|
||||
|
||||
DynamicMessage::DynamicMessage(
|
||||
const DynamicMessageTypeBuilder::SharedPtr dynamic_type_builder,
|
||||
rcl_allocator_t allocator)
|
||||
: serialization_support_(dynamic_type_builder->get_shared_dynamic_serialization_support()),
|
||||
rosidl_dynamic_data_(nullptr),
|
||||
rosidl_dynamic_data_(rosidl_dynamic_typesupport_get_zero_initialized_dynamic_data()),
|
||||
is_loaned_(false),
|
||||
parent_data_(nullptr)
|
||||
{
|
||||
if (!serialization_support_) {
|
||||
throw std::runtime_error("dynamic type could not bind serialization support!");
|
||||
throw std::runtime_error("dynamic message could not bind serialization support!");
|
||||
}
|
||||
if (!dynamic_type_builder) {
|
||||
throw std::runtime_error("dynamic message type builder cannot be nullptr!");
|
||||
}
|
||||
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t * rosidl_dynamic_type_builder =
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t rosidl_dynamic_type_builder =
|
||||
dynamic_type_builder->get_rosidl_dynamic_type_builder();
|
||||
if (!rosidl_dynamic_type_builder) {
|
||||
throw std::runtime_error("dynamic type builder cannot be nullptr!");
|
||||
}
|
||||
|
||||
rosidl_dynamic_typesupport_dynamic_data_t * rosidl_dynamic_data = nullptr;
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_create_from_dynamic_type_builder(
|
||||
rosidl_dynamic_type_builder, &rosidl_dynamic_data);
|
||||
if (ret != RCUTILS_RET_OK || !rosidl_dynamic_data) {
|
||||
throw std::runtime_error("could not create new dynamic data object from dynamic type builder");
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_init_from_dynamic_type_builder(
|
||||
&rosidl_dynamic_type_builder, &allocator, &get_rosidl_dynamic_data());
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error("could not init new dynamic data object from dynamic type builder");
|
||||
}
|
||||
|
||||
rosidl_dynamic_data_.reset(
|
||||
rosidl_dynamic_data,
|
||||
// Custom deleter
|
||||
[](rosidl_dynamic_typesupport_dynamic_data_t * rosidl_dynamic_data)->void {
|
||||
rosidl_dynamic_typesupport_dynamic_data_destroy(rosidl_dynamic_data);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage::DynamicMessage(const DynamicMessageType::SharedPtr dynamic_type)
|
||||
: DynamicMessage::DynamicMessage(
|
||||
dynamic_type, dynamic_type->get_rosidl_dynamic_type().allocator) {}
|
||||
|
||||
|
||||
DynamicMessage::DynamicMessage(
|
||||
const DynamicMessageType::SharedPtr dynamic_type,
|
||||
rcl_allocator_t allocator)
|
||||
: serialization_support_(dynamic_type->get_shared_dynamic_serialization_support()),
|
||||
rosidl_dynamic_data_(nullptr),
|
||||
rosidl_dynamic_data_(rosidl_dynamic_typesupport_get_zero_initialized_dynamic_data()),
|
||||
is_loaned_(false),
|
||||
parent_data_(nullptr)
|
||||
{
|
||||
if (!serialization_support_) {
|
||||
throw std::runtime_error("dynamic type could not bind serialization support!");
|
||||
}
|
||||
|
||||
rosidl_dynamic_typesupport_dynamic_type_t * rosidl_dynamic_type =
|
||||
dynamic_type->get_rosidl_dynamic_type();
|
||||
if (!rosidl_dynamic_type) {
|
||||
throw std::runtime_error("dynamic type cannot be nullptr!");
|
||||
if (!dynamic_type) {
|
||||
throw std::runtime_error("dynamic message type cannot be nullptr!");
|
||||
}
|
||||
|
||||
rosidl_dynamic_typesupport_dynamic_data_t * rosidl_dynamic_data = nullptr;
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_create_from_dynamic_type(
|
||||
rosidl_dynamic_type, &rosidl_dynamic_data);
|
||||
if (ret != RCUTILS_RET_OK || !rosidl_dynamic_data) {
|
||||
rosidl_dynamic_typesupport_dynamic_type_t rosidl_dynamic_type =
|
||||
dynamic_type->get_rosidl_dynamic_type();
|
||||
|
||||
rosidl_dynamic_typesupport_dynamic_data_t rosidl_dynamic_data =
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_data();
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_init_from_dynamic_type(
|
||||
&rosidl_dynamic_type, &allocator, &rosidl_dynamic_data);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error(
|
||||
std::string("could not create new dynamic data object from dynamic type") +
|
||||
std::string("could not init new dynamic data object from dynamic type") +
|
||||
rcl_get_error_string().str);
|
||||
}
|
||||
|
||||
rosidl_dynamic_data_.reset(
|
||||
rosidl_dynamic_data,
|
||||
// Custom deleter
|
||||
[](rosidl_dynamic_typesupport_dynamic_data_t * rosidl_dynamic_data)->void {
|
||||
rosidl_dynamic_typesupport_dynamic_data_destroy(rosidl_dynamic_data);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage::DynamicMessage(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
rosidl_dynamic_typesupport_dynamic_data_t * rosidl_dynamic_data)
|
||||
rosidl_dynamic_typesupport_dynamic_data_t && rosidl_dynamic_data)
|
||||
: serialization_support_(serialization_support),
|
||||
rosidl_dynamic_data_(nullptr),
|
||||
rosidl_dynamic_data_(std::move(rosidl_dynamic_data)),
|
||||
is_loaned_(false),
|
||||
parent_data_(nullptr)
|
||||
{
|
||||
if (!rosidl_dynamic_data) {
|
||||
throw std::runtime_error("rosidl dynamic data cannot be nullptr!");
|
||||
}
|
||||
if (serialization_support) {
|
||||
if (!match_serialization_support_(*serialization_support, *rosidl_dynamic_data)) {
|
||||
throw std::runtime_error(
|
||||
"serialization support library identifier does not match dynamic data's!");
|
||||
}
|
||||
}
|
||||
|
||||
rosidl_dynamic_data_.reset(
|
||||
rosidl_dynamic_data,
|
||||
// Custom deleter
|
||||
[](rosidl_dynamic_typesupport_dynamic_data_t * rosidl_dynamic_data)->void {
|
||||
rosidl_dynamic_typesupport_dynamic_data_destroy(rosidl_dynamic_data);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage::DynamicMessage(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_dynamic_data_t> rosidl_dynamic_data)
|
||||
: serialization_support_(serialization_support),
|
||||
rosidl_dynamic_data_(rosidl_dynamic_data),
|
||||
is_loaned_(false),
|
||||
parent_data_(nullptr)
|
||||
{
|
||||
if (!rosidl_dynamic_data) {
|
||||
throw std::runtime_error("rosidl dynamic data cannot be nullptr!");
|
||||
}
|
||||
if (serialization_support) {
|
||||
if (!match_serialization_support_(*serialization_support, *rosidl_dynamic_data)) {
|
||||
if (!match_serialization_support_(*serialization_support, rosidl_dynamic_data)) {
|
||||
throw std::runtime_error(
|
||||
"serialization support library identifier does not match dynamic data's!");
|
||||
}
|
||||
@@ -156,66 +128,35 @@ DynamicMessage::DynamicMessage(
|
||||
|
||||
DynamicMessage::DynamicMessage(
|
||||
DynamicMessage::SharedPtr parent_data,
|
||||
rosidl_dynamic_typesupport_dynamic_data_t * rosidl_loaned_data)
|
||||
rosidl_dynamic_typesupport_dynamic_data_t && rosidl_loaned_data)
|
||||
: serialization_support_(parent_data->get_shared_dynamic_serialization_support()),
|
||||
rosidl_dynamic_data_(nullptr),
|
||||
rosidl_dynamic_data_(std::move(rosidl_loaned_data)),
|
||||
is_loaned_(true),
|
||||
parent_data_(nullptr)
|
||||
{
|
||||
if (!parent_data) {
|
||||
throw std::runtime_error("parent dynamic data cannot be nullptr!");
|
||||
}
|
||||
if (!rosidl_loaned_data) {
|
||||
throw std::runtime_error("loaned rosidl dynamic data cannot be nullptr!");
|
||||
}
|
||||
|
||||
if (serialization_support_) {
|
||||
if (!match_serialization_support_(*serialization_support_, *rosidl_loaned_data)) {
|
||||
if (!match_serialization_support_(*serialization_support_, rosidl_loaned_data)) {
|
||||
throw std::runtime_error(
|
||||
"serialization support library identifier does not match loaned dynamic data's!");
|
||||
}
|
||||
}
|
||||
|
||||
rosidl_dynamic_data_.reset(
|
||||
rosidl_loaned_data,
|
||||
// Custom no-op deleter
|
||||
[](rosidl_dynamic_typesupport_dynamic_data_t * rosidl_dynamic_data)->void {
|
||||
// Data fini and destruction is deferred to return_loaned_value()
|
||||
(void) rosidl_dynamic_data;
|
||||
});
|
||||
parent_data_ = parent_data;
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage::DynamicMessage(const DynamicMessage & other)
|
||||
: enable_shared_from_this(),
|
||||
serialization_support_(nullptr),
|
||||
rosidl_dynamic_data_(nullptr),
|
||||
is_loaned_(false),
|
||||
parent_data_(nullptr)
|
||||
{
|
||||
DynamicMessage out = other.clone();
|
||||
// We don't copy is_loaned_ or parent_data_ because it's a fresh copy now
|
||||
std::swap(serialization_support_, out.serialization_support_);
|
||||
std::swap(rosidl_dynamic_data_, out.rosidl_dynamic_data_);
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage::DynamicMessage(DynamicMessage && other) noexcept
|
||||
: serialization_support_(std::exchange(other.serialization_support_, nullptr)),
|
||||
rosidl_dynamic_data_(std::exchange(other.rosidl_dynamic_data_, nullptr)),
|
||||
rosidl_dynamic_data_(std::exchange(
|
||||
other.rosidl_dynamic_data_,
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_data())),
|
||||
is_loaned_(other.is_loaned_),
|
||||
parent_data_(std::exchange(other.parent_data_, nullptr))
|
||||
{}
|
||||
|
||||
|
||||
DynamicMessage &
|
||||
DynamicMessage::operator=(const DynamicMessage & other)
|
||||
{
|
||||
return *this = DynamicMessage(other);
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage &
|
||||
DynamicMessage::operator=(DynamicMessage && other) noexcept
|
||||
{
|
||||
@@ -229,13 +170,21 @@ DynamicMessage::operator=(DynamicMessage && other) noexcept
|
||||
|
||||
DynamicMessage::~DynamicMessage()
|
||||
{
|
||||
if (is_loaned_) {
|
||||
if (!parent_data_) {
|
||||
RCUTILS_LOG_ERROR("dynamic data is loaned, but parent is missing!!");
|
||||
} else {
|
||||
rosidl_dynamic_typesupport_dynamic_data_return_loaned_value(
|
||||
parent_data_->get_rosidl_dynamic_data(), get_rosidl_dynamic_data());
|
||||
if (!is_loaned_) {
|
||||
if (rosidl_dynamic_typesupport_dynamic_data_fini(&get_rosidl_dynamic_data()) !=
|
||||
RCUTILS_RET_OK)
|
||||
{
|
||||
RCUTILS_LOG_ERROR("could not fini rosidl dynamic data");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Loaned case
|
||||
if (!parent_data_) {
|
||||
RCUTILS_LOG_ERROR("dynamic data is loaned, but parent is missing!!");
|
||||
} else {
|
||||
rosidl_dynamic_typesupport_dynamic_data_return_loaned_value(
|
||||
&parent_data_->get_rosidl_dynamic_data(), &get_rosidl_dynamic_data());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,32 +194,22 @@ DynamicMessage::match_serialization_support_(
|
||||
const DynamicSerializationSupport & serialization_support,
|
||||
const rosidl_dynamic_typesupport_dynamic_data_t & rosidl_dynamic_type_data)
|
||||
{
|
||||
bool out = true;
|
||||
|
||||
if (serialization_support.get_library_identifier() != std::string(
|
||||
rosidl_dynamic_type_data.serialization_support->library_identifier))
|
||||
if (serialization_support.get_serialization_library_identifier() != std::string(
|
||||
rosidl_dynamic_type_data.serialization_support->serialization_library_identifier))
|
||||
{
|
||||
RCUTILS_LOG_ERROR("serialization support library identifier does not match dynamic data's");
|
||||
out = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO(methylDragon): Can I do this?? Is it portable?
|
||||
if (serialization_support.get_rosidl_serialization_support() !=
|
||||
rosidl_dynamic_type_data.serialization_support)
|
||||
{
|
||||
RCUTILS_LOG_ERROR("serialization support pointer does not match dynamic data's");
|
||||
out = false;
|
||||
}
|
||||
|
||||
return out;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// GETTERS =======================================================================================
|
||||
const std::string
|
||||
DynamicMessage::get_library_identifier() const
|
||||
DynamicMessage::get_serialization_library_identifier() const
|
||||
{
|
||||
return std::string(rosidl_dynamic_data_->serialization_support->library_identifier);
|
||||
return std::string(
|
||||
get_rosidl_dynamic_data().serialization_support->serialization_library_identifier);
|
||||
}
|
||||
|
||||
|
||||
@@ -281,7 +220,7 @@ DynamicMessage::get_name() const
|
||||
const char * buf;
|
||||
if (
|
||||
rosidl_dynamic_typesupport_dynamic_data_get_name(
|
||||
get_rosidl_dynamic_data(), &buf,
|
||||
&get_rosidl_dynamic_data(), &buf,
|
||||
&buf_length) !=
|
||||
RCUTILS_RET_OK)
|
||||
{
|
||||
@@ -292,33 +231,17 @@ DynamicMessage::get_name() const
|
||||
}
|
||||
|
||||
|
||||
rosidl_dynamic_typesupport_dynamic_data_t *
|
||||
rosidl_dynamic_typesupport_dynamic_data_t &
|
||||
DynamicMessage::get_rosidl_dynamic_data()
|
||||
{
|
||||
return rosidl_dynamic_data_.get();
|
||||
return rosidl_dynamic_data_;
|
||||
}
|
||||
|
||||
|
||||
const rosidl_dynamic_typesupport_dynamic_data_t *
|
||||
const rosidl_dynamic_typesupport_dynamic_data_t &
|
||||
DynamicMessage::get_rosidl_dynamic_data() const
|
||||
{
|
||||
return rosidl_dynamic_data_.get();
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_dynamic_data_t>
|
||||
DynamicMessage::get_shared_rosidl_dynamic_data()
|
||||
{
|
||||
return std::shared_ptr<rosidl_dynamic_typesupport_dynamic_data_t>(
|
||||
shared_from_this(), rosidl_dynamic_data_.get());
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<const rosidl_dynamic_typesupport_dynamic_data_t>
|
||||
DynamicMessage::get_shared_rosidl_dynamic_data() const
|
||||
{
|
||||
return std::shared_ptr<rosidl_dynamic_typesupport_dynamic_data_t>(
|
||||
shared_from_this(), rosidl_dynamic_data_.get());
|
||||
return rosidl_dynamic_data_;
|
||||
}
|
||||
|
||||
|
||||
@@ -341,7 +264,7 @@ DynamicMessage::get_item_count() const
|
||||
{
|
||||
size_t item_count;
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_get_item_count(
|
||||
get_rosidl_dynamic_data(), &item_count);
|
||||
&get_rosidl_dynamic_data(), &item_count);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error("could not get item count of dynamic data");
|
||||
}
|
||||
@@ -354,7 +277,7 @@ DynamicMessage::get_member_id(size_t index) const
|
||||
{
|
||||
rosidl_dynamic_typesupport_member_id_t member_id;
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_get_member_id_at_index(
|
||||
get_rosidl_dynamic_data(), index, &member_id);
|
||||
&get_rosidl_dynamic_data(), index, &member_id);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error("could not member id of dynamic data element by index");
|
||||
}
|
||||
@@ -367,7 +290,7 @@ DynamicMessage::get_member_id(const std::string & name) const
|
||||
{
|
||||
rosidl_dynamic_typesupport_member_id_t member_id;
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_get_member_id_by_name(
|
||||
get_rosidl_dynamic_data(), name.c_str(), name.size(), &member_id);
|
||||
&get_rosidl_dynamic_data(), name.c_str(), name.size(), &member_id);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error("could not member id of dynamic data element by name");
|
||||
}
|
||||
@@ -380,7 +303,7 @@ DynamicMessage::get_array_index(size_t index) const
|
||||
{
|
||||
rosidl_dynamic_typesupport_member_id_t array_index;
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_get_array_index(
|
||||
get_rosidl_dynamic_data(), index, &array_index);
|
||||
&get_rosidl_dynamic_data(), index, &array_index);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error("could not array index of dynamic data element by index");
|
||||
}
|
||||
@@ -397,68 +320,73 @@ DynamicMessage::get_array_index(const std::string & name) const
|
||||
|
||||
// METHODS =======================================================================================
|
||||
DynamicMessage
|
||||
DynamicMessage::clone() const
|
||||
DynamicMessage::clone(rcl_allocator_t allocator)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_t * rosidl_dynamic_data = nullptr;
|
||||
rosidl_dynamic_typesupport_dynamic_data_t rosidl_dynamic_data =
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_data();
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_clone(
|
||||
get_rosidl_dynamic_data(), &rosidl_dynamic_data);
|
||||
if (ret != RCUTILS_RET_OK || !rosidl_dynamic_data) {
|
||||
&get_rosidl_dynamic_data(), &allocator, &rosidl_dynamic_data);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error(
|
||||
std::string("could not clone dynamic data: ") + rcl_get_error_string().str);
|
||||
}
|
||||
return DynamicMessage(serialization_support_, rosidl_dynamic_data);
|
||||
return DynamicMessage(get_shared_dynamic_serialization_support(), std::move(rosidl_dynamic_data));
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage::SharedPtr
|
||||
DynamicMessage::clone_shared() const
|
||||
DynamicMessage::clone_shared(rcl_allocator_t allocator)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_t * rosidl_dynamic_data = nullptr;
|
||||
rosidl_dynamic_typesupport_dynamic_data_t rosidl_dynamic_data =
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_data();
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_clone(
|
||||
get_rosidl_dynamic_data(), &rosidl_dynamic_data);
|
||||
if (ret != RCUTILS_RET_OK || !rosidl_dynamic_data) {
|
||||
&get_rosidl_dynamic_data(), &allocator, &rosidl_dynamic_data);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error(
|
||||
std::string("could not clone dynamic data: ") + rcl_get_error_string().str);
|
||||
}
|
||||
return DynamicMessage::make_shared(serialization_support_, rosidl_dynamic_data);
|
||||
return DynamicMessage::make_shared(
|
||||
get_shared_dynamic_serialization_support(), std::move(rosidl_dynamic_data));
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage
|
||||
DynamicMessage::init_from_type(DynamicMessageType & type) const
|
||||
DynamicMessage::init_from_type(DynamicMessageType & type, rcl_allocator_t allocator) const
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_t * rosidl_dynamic_data = nullptr;
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_create_from_dynamic_type(
|
||||
type.get_rosidl_dynamic_type(), &rosidl_dynamic_data);
|
||||
if (ret != RCUTILS_RET_OK || !rosidl_dynamic_data) {
|
||||
throw std::runtime_error("could not create new dynamic data object from dynamic type");
|
||||
rosidl_dynamic_typesupport_dynamic_data_t rosidl_dynamic_data =
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_data();
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_init_from_dynamic_type(
|
||||
&type.get_rosidl_dynamic_type(), &allocator, &rosidl_dynamic_data);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error("could not init new dynamic data object from dynamic type");
|
||||
}
|
||||
return DynamicMessage(serialization_support_, rosidl_dynamic_data);
|
||||
return DynamicMessage(serialization_support_, std::move(rosidl_dynamic_data));
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage::SharedPtr
|
||||
DynamicMessage::init_from_type_shared(DynamicMessageType & type) const
|
||||
DynamicMessage::init_from_type_shared(DynamicMessageType & type, rcl_allocator_t allocator) const
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_t * rosidl_dynamic_data = nullptr;
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_create_from_dynamic_type(
|
||||
type.get_rosidl_dynamic_type(), &rosidl_dynamic_data);
|
||||
if (ret != RCUTILS_RET_OK || !rosidl_dynamic_data) {
|
||||
throw std::runtime_error("could not create new dynamic data object from dynamic type");
|
||||
rosidl_dynamic_typesupport_dynamic_data_t rosidl_dynamic_data =
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_data();
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_init_from_dynamic_type(
|
||||
&type.get_rosidl_dynamic_type(), &allocator, &rosidl_dynamic_data);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error("could not init new dynamic data object from dynamic type");
|
||||
}
|
||||
return DynamicMessage::make_shared(serialization_support_, rosidl_dynamic_data);
|
||||
return DynamicMessage::make_shared(serialization_support_, std::move(rosidl_dynamic_data));
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DynamicMessage::equals(const DynamicMessage & other) const
|
||||
{
|
||||
if (get_library_identifier() != other.get_library_identifier()) {
|
||||
if (get_serialization_library_identifier() != other.get_serialization_library_identifier()) {
|
||||
throw std::runtime_error("library identifiers don't match");
|
||||
}
|
||||
bool equals;
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_equals(
|
||||
get_rosidl_dynamic_data(), other.get_rosidl_dynamic_data(), &equals);
|
||||
&get_rosidl_dynamic_data(), &other.get_rosidl_dynamic_data(), &equals);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error("could not equate dynamic messages");
|
||||
}
|
||||
@@ -467,44 +395,47 @@ DynamicMessage::equals(const DynamicMessage & other) const
|
||||
|
||||
|
||||
DynamicMessage::SharedPtr
|
||||
DynamicMessage::loan_value(rosidl_dynamic_typesupport_member_id_t id)
|
||||
DynamicMessage::loan_value(
|
||||
rosidl_dynamic_typesupport_member_id_t id,
|
||||
rcl_allocator_t allocator)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_t * rosidl_dynamic_data = nullptr;
|
||||
rosidl_dynamic_typesupport_dynamic_data_t rosidl_dynamic_data =
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_data();
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_loan_value(
|
||||
get_rosidl_dynamic_data(), id, &rosidl_dynamic_data);
|
||||
if (ret != RCUTILS_RET_OK || !rosidl_dynamic_data) {
|
||||
&get_rosidl_dynamic_data(), id, &allocator, &rosidl_dynamic_data);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error(
|
||||
std::string("could not loan dynamic data: ") + rcl_get_error_string().str);
|
||||
}
|
||||
return DynamicMessage::make_shared(shared_from_this(), rosidl_dynamic_data);
|
||||
return DynamicMessage::make_shared(shared_from_this(), std::move(rosidl_dynamic_data));
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage::SharedPtr
|
||||
DynamicMessage::loan_value(const std::string & name)
|
||||
DynamicMessage::loan_value(const std::string & name, rcl_allocator_t allocator)
|
||||
{
|
||||
return loan_value(get_member_id(name));
|
||||
return loan_value(get_member_id(name), allocator);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DynamicMessage::clear_all_values()
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_clear_all_values(get_rosidl_dynamic_data());
|
||||
rosidl_dynamic_typesupport_dynamic_data_clear_all_values(&get_rosidl_dynamic_data());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DynamicMessage::clear_nonkey_values()
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_clear_nonkey_values(get_rosidl_dynamic_data());
|
||||
rosidl_dynamic_typesupport_dynamic_data_clear_nonkey_values(&get_rosidl_dynamic_data());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DynamicMessage::clear_value(rosidl_dynamic_typesupport_member_id_t id)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_clear_value(get_rosidl_dynamic_data(), id);
|
||||
rosidl_dynamic_typesupport_dynamic_data_clear_value(&get_rosidl_dynamic_data(), id);
|
||||
}
|
||||
|
||||
|
||||
@@ -518,7 +449,7 @@ DynamicMessage::clear_value(const std::string & name)
|
||||
void
|
||||
DynamicMessage::clear_sequence()
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_clear_sequence_data(get_rosidl_dynamic_data());
|
||||
rosidl_dynamic_typesupport_dynamic_data_clear_sequence_data(&get_rosidl_dynamic_data());
|
||||
}
|
||||
|
||||
|
||||
@@ -526,7 +457,7 @@ rosidl_dynamic_typesupport_member_id_t
|
||||
DynamicMessage::insert_sequence_data()
|
||||
{
|
||||
rosidl_dynamic_typesupport_member_id_t out;
|
||||
rosidl_dynamic_typesupport_dynamic_data_insert_sequence_data(get_rosidl_dynamic_data(), &out);
|
||||
rosidl_dynamic_typesupport_dynamic_data_insert_sequence_data(&get_rosidl_dynamic_data(), &out);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -535,37 +466,33 @@ void
|
||||
DynamicMessage::remove_sequence_data(rosidl_dynamic_typesupport_member_id_t index)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_remove_sequence_data(
|
||||
get_rosidl_dynamic_data(), index);
|
||||
&get_rosidl_dynamic_data(), index);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DynamicMessage::serialize(rcl_serialized_message_t * buffer)
|
||||
DynamicMessage::serialize(rcl_serialized_message_t & buffer)
|
||||
{
|
||||
bool success;
|
||||
rcutils_ret_t ret =
|
||||
rosidl_dynamic_typesupport_dynamic_data_serialize(get_rosidl_dynamic_data(), buffer, &success);
|
||||
if (ret != RCUTILS_RET_OK || !success) {
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_serialize(
|
||||
&get_rosidl_dynamic_data(), &buffer);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error(
|
||||
std::string("could serialize loan dynamic data: ") + rcl_get_error_string().str);
|
||||
}
|
||||
return success;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DynamicMessage::deserialize(rcl_serialized_message_t * buffer)
|
||||
DynamicMessage::deserialize(rcl_serialized_message_t & buffer)
|
||||
{
|
||||
bool success;
|
||||
rcutils_ret_t ret =
|
||||
rosidl_dynamic_typesupport_dynamic_data_deserialize(
|
||||
get_rosidl_dynamic_data(), buffer,
|
||||
&success);
|
||||
if (ret != RCUTILS_RET_OK || !success) {
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_data_deserialize(
|
||||
&get_rosidl_dynamic_data(), &buffer);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error(
|
||||
std::string("could deserialize loan dynamic data: ") + rcl_get_error_string().str);
|
||||
}
|
||||
return success;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -581,7 +508,7 @@ DynamicMessage::get_fixed_string_value(
|
||||
size_t buf_length;
|
||||
char * buf = nullptr;
|
||||
rosidl_dynamic_typesupport_dynamic_data_get_fixed_string_value(
|
||||
get_rosidl_dynamic_data(), id, &buf, &buf_length, string_length);
|
||||
&get_rosidl_dynamic_data(), id, &buf, &buf_length, string_length);
|
||||
auto out = std::string(buf, buf_length);
|
||||
delete buf;
|
||||
return out;
|
||||
@@ -602,7 +529,7 @@ DynamicMessage::get_fixed_wstring_value(
|
||||
size_t buf_length;
|
||||
char16_t * buf = nullptr;
|
||||
rosidl_dynamic_typesupport_dynamic_data_get_fixed_wstring_value(
|
||||
get_rosidl_dynamic_data(), id, &buf, &buf_length, wstring_length);
|
||||
&get_rosidl_dynamic_data(), id, &buf, &buf_length, wstring_length);
|
||||
auto out = std::u16string(buf, buf_length);
|
||||
delete buf;
|
||||
return out;
|
||||
@@ -621,7 +548,7 @@ DynamicMessage::set_fixed_string_value(
|
||||
rosidl_dynamic_typesupport_member_id_t id, const std::string value, size_t string_length)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_set_fixed_string_value(
|
||||
get_rosidl_dynamic_data(), id, value.c_str(), value.size(), string_length);
|
||||
&get_rosidl_dynamic_data(), id, value.c_str(), value.size(), string_length);
|
||||
}
|
||||
|
||||
|
||||
@@ -638,7 +565,7 @@ DynamicMessage::set_fixed_wstring_value(
|
||||
rosidl_dynamic_typesupport_member_id_t id, const std::u16string value, size_t wstring_length)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_set_fixed_wstring_value(
|
||||
get_rosidl_dynamic_data(), id, value.c_str(), value.size(), wstring_length);
|
||||
&get_rosidl_dynamic_data(), id, value.c_str(), value.size(), wstring_length);
|
||||
}
|
||||
|
||||
|
||||
@@ -655,7 +582,7 @@ DynamicMessage::insert_fixed_string_value(const std::string value, size_t string
|
||||
{
|
||||
rosidl_dynamic_typesupport_member_id_t out;
|
||||
rosidl_dynamic_typesupport_dynamic_data_insert_fixed_string_value(
|
||||
get_rosidl_dynamic_data(), value.c_str(), value.size(), string_length, &out);
|
||||
&get_rosidl_dynamic_data(), value.c_str(), value.size(), string_length, &out);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -665,7 +592,7 @@ DynamicMessage::insert_fixed_wstring_value(const std::u16string value, size_t ws
|
||||
{
|
||||
rosidl_dynamic_typesupport_member_id_t out;
|
||||
rosidl_dynamic_typesupport_dynamic_data_insert_fixed_wstring_value(
|
||||
get_rosidl_dynamic_data(), value.c_str(), value.size(), wstring_length, &out);
|
||||
&get_rosidl_dynamic_data(), value.c_str(), value.size(), wstring_length, &out);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -678,7 +605,7 @@ DynamicMessage::get_bounded_string_value(
|
||||
size_t buf_length;
|
||||
char * buf = nullptr;
|
||||
rosidl_dynamic_typesupport_dynamic_data_get_bounded_string_value(
|
||||
get_rosidl_dynamic_data(), id, &buf, &buf_length, string_bound);
|
||||
&get_rosidl_dynamic_data(), id, &buf, &buf_length, string_bound);
|
||||
auto out = std::string(buf, buf_length);
|
||||
delete buf;
|
||||
return out;
|
||||
@@ -699,7 +626,7 @@ DynamicMessage::get_bounded_wstring_value(
|
||||
size_t buf_length;
|
||||
char16_t * buf = nullptr;
|
||||
rosidl_dynamic_typesupport_dynamic_data_get_bounded_wstring_value(
|
||||
get_rosidl_dynamic_data(), id, &buf, &buf_length, wstring_bound);
|
||||
&get_rosidl_dynamic_data(), id, &buf, &buf_length, wstring_bound);
|
||||
auto out = std::u16string(buf, buf_length);
|
||||
delete buf;
|
||||
return out;
|
||||
@@ -718,7 +645,7 @@ DynamicMessage::set_bounded_string_value(
|
||||
rosidl_dynamic_typesupport_member_id_t id, const std::string value, size_t string_bound)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_set_bounded_string_value(
|
||||
get_rosidl_dynamic_data(), id, value.c_str(), value.size(), string_bound);
|
||||
&get_rosidl_dynamic_data(), id, value.c_str(), value.size(), string_bound);
|
||||
}
|
||||
|
||||
|
||||
@@ -735,7 +662,7 @@ DynamicMessage::set_bounded_wstring_value(
|
||||
rosidl_dynamic_typesupport_member_id_t id, const std::u16string value, size_t wstring_bound)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_set_bounded_wstring_value(
|
||||
get_rosidl_dynamic_data(), id, value.c_str(), value.size(), wstring_bound);
|
||||
&get_rosidl_dynamic_data(), id, value.c_str(), value.size(), wstring_bound);
|
||||
}
|
||||
|
||||
|
||||
@@ -752,7 +679,7 @@ DynamicMessage::insert_bounded_string_value(const std::string value, size_t stri
|
||||
{
|
||||
rosidl_dynamic_typesupport_member_id_t out;
|
||||
rosidl_dynamic_typesupport_dynamic_data_insert_bounded_string_value(
|
||||
get_rosidl_dynamic_data(), value.c_str(), value.size(), string_bound, &out);
|
||||
&get_rosidl_dynamic_data(), value.c_str(), value.size(), string_bound, &out);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -762,43 +689,47 @@ DynamicMessage::insert_bounded_wstring_value(const std::u16string value, size_t
|
||||
{
|
||||
rosidl_dynamic_typesupport_member_id_t out;
|
||||
rosidl_dynamic_typesupport_dynamic_data_insert_bounded_wstring_value(
|
||||
get_rosidl_dynamic_data(), value.c_str(), value.size(), wstring_bound, &out);
|
||||
&get_rosidl_dynamic_data(), value.c_str(), value.size(), wstring_bound, &out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
// NESTED MEMBER ACCESS ============================================================================
|
||||
DynamicMessage
|
||||
DynamicMessage::get_complex_value(rosidl_dynamic_typesupport_member_id_t id)
|
||||
DynamicMessage::get_complex_value(
|
||||
rosidl_dynamic_typesupport_member_id_t id, rcl_allocator_t allocator)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_t * out_ptr = nullptr;
|
||||
rosidl_dynamic_typesupport_dynamic_data_t out =
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_data();
|
||||
rosidl_dynamic_typesupport_dynamic_data_get_complex_value(
|
||||
get_rosidl_dynamic_data(), id, &out_ptr);
|
||||
return DynamicMessage(get_shared_dynamic_serialization_support(), out_ptr);
|
||||
&get_rosidl_dynamic_data(), id, &allocator, &out);
|
||||
return DynamicMessage(get_shared_dynamic_serialization_support(), std::move(out));
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage
|
||||
DynamicMessage::get_complex_value(const std::string & name)
|
||||
DynamicMessage::get_complex_value(const std::string & name, rcl_allocator_t allocator)
|
||||
{
|
||||
return get_complex_value(get_member_id(name));
|
||||
return get_complex_value(get_member_id(name), allocator);
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage::SharedPtr
|
||||
DynamicMessage::get_complex_value_shared(rosidl_dynamic_typesupport_member_id_t id)
|
||||
DynamicMessage::get_complex_value_shared(
|
||||
rosidl_dynamic_typesupport_member_id_t id, rcl_allocator_t allocator)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_t * out_ptr = nullptr;
|
||||
rosidl_dynamic_typesupport_dynamic_data_t out =
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_data();
|
||||
rosidl_dynamic_typesupport_dynamic_data_get_complex_value(
|
||||
get_rosidl_dynamic_data(), id, &out_ptr);
|
||||
return DynamicMessage::make_shared(get_shared_dynamic_serialization_support(), out_ptr);
|
||||
&get_rosidl_dynamic_data(), id, &allocator, &out);
|
||||
return DynamicMessage::make_shared(get_shared_dynamic_serialization_support(), std::move(out));
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage::SharedPtr
|
||||
DynamicMessage::get_complex_value_shared(const std::string & name)
|
||||
DynamicMessage::get_complex_value_shared(const std::string & name, rcl_allocator_t allocator)
|
||||
{
|
||||
return get_complex_value_shared(get_member_id(name));
|
||||
return get_complex_value_shared(get_member_id(name), allocator);
|
||||
}
|
||||
|
||||
|
||||
@@ -807,7 +738,7 @@ DynamicMessage::set_complex_value(
|
||||
rosidl_dynamic_typesupport_member_id_t id, DynamicMessage & value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_data_set_complex_value(
|
||||
get_rosidl_dynamic_data(), id, value.get_rosidl_dynamic_data());
|
||||
&get_rosidl_dynamic_data(), id, &value.get_rosidl_dynamic_data());
|
||||
}
|
||||
|
||||
|
||||
@@ -823,7 +754,7 @@ DynamicMessage::insert_complex_value_copy(const DynamicMessage & value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_member_id_t out;
|
||||
rosidl_dynamic_typesupport_dynamic_data_insert_complex_value_copy(
|
||||
get_rosidl_dynamic_data(), value.get_rosidl_dynamic_data(), &out);
|
||||
&get_rosidl_dynamic_data(), &value.get_rosidl_dynamic_data(), &out);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -833,6 +764,6 @@ DynamicMessage::insert_complex_value(DynamicMessage & value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_member_id_t out;
|
||||
rosidl_dynamic_typesupport_dynamic_data_insert_complex_value(
|
||||
get_rosidl_dynamic_data(), value.get_rosidl_dynamic_data(), &out);
|
||||
&get_rosidl_dynamic_data(), &value.get_rosidl_dynamic_data(), &out);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <rosidl_dynamic_typesupport/api/dynamic_data.h>
|
||||
#include <rosidl_dynamic_typesupport/api/dynamic_type.h>
|
||||
#include <rosidl_dynamic_typesupport/api/serialization_support.h>
|
||||
#include <rosidl_dynamic_typesupport/types.h>
|
||||
|
||||
#include <memory>
|
||||
@@ -36,69 +37,39 @@ using rclcpp::dynamic_typesupport::DynamicSerializationSupport;
|
||||
|
||||
// CONSTRUCTION ====================================================================================
|
||||
DynamicMessageType::DynamicMessageType(DynamicMessageTypeBuilder::SharedPtr dynamic_type_builder)
|
||||
: DynamicMessageType::DynamicMessageType(
|
||||
dynamic_type_builder, dynamic_type_builder->get_rosidl_dynamic_type_builder().allocator) {}
|
||||
|
||||
|
||||
DynamicMessageType::DynamicMessageType(
|
||||
DynamicMessageTypeBuilder::SharedPtr dynamic_type_builder,
|
||||
rcl_allocator_t allocator)
|
||||
: serialization_support_(dynamic_type_builder->get_shared_dynamic_serialization_support()),
|
||||
rosidl_dynamic_type_(nullptr)
|
||||
rosidl_dynamic_type_(rosidl_dynamic_typesupport_get_zero_initialized_dynamic_type())
|
||||
{
|
||||
if (!serialization_support_) {
|
||||
throw std::runtime_error("dynamic type could not bind serialization support!");
|
||||
}
|
||||
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t * rosidl_dynamic_type_builder =
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t rosidl_dynamic_type_builder =
|
||||
dynamic_type_builder->get_rosidl_dynamic_type_builder();
|
||||
if (!rosidl_dynamic_type_builder) {
|
||||
throw std::runtime_error("dynamic type builder cannot be nullptr!");
|
||||
}
|
||||
|
||||
rosidl_dynamic_typesupport_dynamic_type_t * rosidl_dynamic_type = nullptr;
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_type_create_from_dynamic_type_builder(
|
||||
rosidl_dynamic_type_builder, &rosidl_dynamic_type);
|
||||
if (ret != RCUTILS_RET_OK || !rosidl_dynamic_type) {
|
||||
throw std::runtime_error("could not create new dynamic type object");
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_type_init_from_dynamic_type_builder(
|
||||
&rosidl_dynamic_type_builder, &allocator, &get_rosidl_dynamic_type());
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error("could not init new dynamic type object");
|
||||
}
|
||||
|
||||
rosidl_dynamic_type_.reset(
|
||||
rosidl_dynamic_type,
|
||||
// Custom deleter
|
||||
[](rosidl_dynamic_typesupport_dynamic_type_t * rosidl_dynamic_type)->void {
|
||||
rosidl_dynamic_typesupport_dynamic_type_destroy(rosidl_dynamic_type);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageType::DynamicMessageType(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
rosidl_dynamic_typesupport_dynamic_type_t * rosidl_dynamic_type)
|
||||
: serialization_support_(serialization_support), rosidl_dynamic_type_(nullptr)
|
||||
rosidl_dynamic_typesupport_dynamic_type_t && rosidl_dynamic_type)
|
||||
: serialization_support_(serialization_support),
|
||||
rosidl_dynamic_type_(std::move(rosidl_dynamic_type))
|
||||
{
|
||||
if (!rosidl_dynamic_type) {
|
||||
throw std::runtime_error("rosidl dynamic type cannot be nullptr!");
|
||||
}
|
||||
if (serialization_support) {
|
||||
if (!match_serialization_support_(*serialization_support, *rosidl_dynamic_type)) {
|
||||
throw std::runtime_error(
|
||||
"serialization support library identifier does not match dynamic type's!");
|
||||
}
|
||||
}
|
||||
|
||||
rosidl_dynamic_type_.reset(
|
||||
rosidl_dynamic_type,
|
||||
// Custom deleter
|
||||
[](rosidl_dynamic_typesupport_dynamic_type_t * rosidl_dynamic_type)->void {
|
||||
rosidl_dynamic_typesupport_dynamic_type_destroy(rosidl_dynamic_type);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageType::DynamicMessageType(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_dynamic_type_t> rosidl_dynamic_type)
|
||||
: serialization_support_(serialization_support), rosidl_dynamic_type_(rosidl_dynamic_type)
|
||||
{
|
||||
if (!rosidl_dynamic_type) {
|
||||
throw std::runtime_error("rosidl dynamic type cannot be nullptr!");
|
||||
}
|
||||
if (serialization_support) {
|
||||
if (!match_serialization_support_(*serialization_support, *rosidl_dynamic_type)) {
|
||||
if (!match_serialization_support_(*serialization_support, rosidl_dynamic_type)) {
|
||||
throw std::runtime_error(
|
||||
"serialization support library identifier does not match dynamic type's!");
|
||||
}
|
||||
@@ -108,32 +79,20 @@ DynamicMessageType::DynamicMessageType(
|
||||
|
||||
DynamicMessageType::DynamicMessageType(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description)
|
||||
: serialization_support_(serialization_support), rosidl_dynamic_type_(nullptr)
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description,
|
||||
rcl_allocator_t allocator)
|
||||
: serialization_support_(serialization_support),
|
||||
rosidl_dynamic_type_(rosidl_dynamic_typesupport_get_zero_initialized_dynamic_type())
|
||||
{
|
||||
init_from_description(description, serialization_support);
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageType::DynamicMessageType(const DynamicMessageType & other)
|
||||
: enable_shared_from_this(), serialization_support_(nullptr), rosidl_dynamic_type_(nullptr)
|
||||
{
|
||||
DynamicMessageType out = other.clone();
|
||||
std::swap(serialization_support_, out.serialization_support_);
|
||||
std::swap(rosidl_dynamic_type_, out.rosidl_dynamic_type_);
|
||||
init_from_description(description, allocator, serialization_support);
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageType::DynamicMessageType(DynamicMessageType && other) noexcept
|
||||
: serialization_support_(std::exchange(other.serialization_support_, nullptr)),
|
||||
rosidl_dynamic_type_(std::exchange(other.rosidl_dynamic_type_, nullptr)) {}
|
||||
|
||||
|
||||
DynamicMessageType &
|
||||
DynamicMessageType::operator=(const DynamicMessageType & other)
|
||||
{
|
||||
return *this = DynamicMessageType(other);
|
||||
}
|
||||
rosidl_dynamic_type_(std::exchange(
|
||||
other.rosidl_dynamic_type_, rosidl_dynamic_typesupport_get_zero_initialized_dynamic_type()))
|
||||
{}
|
||||
|
||||
|
||||
DynamicMessageType &
|
||||
@@ -145,12 +104,18 @@ DynamicMessageType::operator=(DynamicMessageType && other) noexcept
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageType::~DynamicMessageType() {}
|
||||
DynamicMessageType::~DynamicMessageType()
|
||||
{
|
||||
if (rosidl_dynamic_typesupport_dynamic_type_fini(&get_rosidl_dynamic_type()) != RCUTILS_RET_OK) {
|
||||
RCUTILS_LOG_ERROR("could not fini rosidl dynamic type");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DynamicMessageType::init_from_description(
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description,
|
||||
rcl_allocator_t allocator,
|
||||
DynamicSerializationSupport::SharedPtr serialization_support)
|
||||
{
|
||||
if (serialization_support) {
|
||||
@@ -158,19 +123,18 @@ DynamicMessageType::init_from_description(
|
||||
serialization_support_ = serialization_support;
|
||||
}
|
||||
|
||||
rosidl_dynamic_typesupport_dynamic_type_t * rosidl_dynamic_type = nullptr;
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_type_create_from_description(
|
||||
serialization_support_->get_rosidl_serialization_support(), &description, &rosidl_dynamic_type);
|
||||
if (ret != RCUTILS_RET_OK || !rosidl_dynamic_type) {
|
||||
throw std::runtime_error("could not create new dynamic type object");
|
||||
rosidl_dynamic_typesupport_dynamic_type_t rosidl_dynamic_type =
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_type();
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_type_init_from_description(
|
||||
&serialization_support_->get_rosidl_serialization_support(),
|
||||
&description,
|
||||
&allocator,
|
||||
&rosidl_dynamic_type);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error("could not init new dynamic type object");
|
||||
}
|
||||
|
||||
rosidl_dynamic_type_.reset(
|
||||
rosidl_dynamic_type,
|
||||
// Custom deleter
|
||||
[](rosidl_dynamic_typesupport_dynamic_type_t * rosidl_dynamic_type)->void {
|
||||
rosidl_dynamic_typesupport_dynamic_type_destroy(rosidl_dynamic_type);
|
||||
});
|
||||
rosidl_dynamic_type_ = std::move(rosidl_dynamic_type);
|
||||
}
|
||||
|
||||
|
||||
@@ -179,34 +143,25 @@ DynamicMessageType::match_serialization_support_(
|
||||
const DynamicSerializationSupport & serialization_support,
|
||||
const rosidl_dynamic_typesupport_dynamic_type_t & rosidl_dynamic_type)
|
||||
{
|
||||
bool out = true;
|
||||
|
||||
if (serialization_support.get_library_identifier() != std::string(
|
||||
rosidl_dynamic_type.serialization_support->library_identifier))
|
||||
if (serialization_support.get_serialization_library_identifier() != std::string(
|
||||
rosidl_dynamic_type.serialization_support->serialization_library_identifier))
|
||||
{
|
||||
RCUTILS_LOG_ERROR(
|
||||
"serialization support library identifier does not match dynamic type's");
|
||||
out = false;
|
||||
"serialization support library identifier does not match dynamic type's (%s vs %s)",
|
||||
serialization_support.get_serialization_library_identifier().c_str(),
|
||||
rosidl_dynamic_type.serialization_support->serialization_library_identifier);
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO(methylDragon): Can I do this?? Is it portable?
|
||||
if (serialization_support.get_rosidl_serialization_support() !=
|
||||
rosidl_dynamic_type.serialization_support)
|
||||
{
|
||||
RCUTILS_LOG_ERROR(
|
||||
"serialization support pointer does not match dynamic type's");
|
||||
out = false;
|
||||
}
|
||||
|
||||
return out;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// GETTERS =========================================================================================
|
||||
const std::string
|
||||
DynamicMessageType::get_library_identifier() const
|
||||
DynamicMessageType::get_serialization_library_identifier() const
|
||||
{
|
||||
return std::string(rosidl_dynamic_type_->serialization_support->library_identifier);
|
||||
return std::string(
|
||||
get_rosidl_dynamic_type().serialization_support->serialization_library_identifier);
|
||||
}
|
||||
|
||||
|
||||
@@ -215,7 +170,7 @@ DynamicMessageType::get_name() const
|
||||
{
|
||||
size_t buf_length;
|
||||
const char * buf;
|
||||
rosidl_dynamic_typesupport_dynamic_type_get_name(get_rosidl_dynamic_type(), &buf, &buf_length);
|
||||
rosidl_dynamic_typesupport_dynamic_type_get_name(&get_rosidl_dynamic_type(), &buf, &buf_length);
|
||||
return std::string(buf, buf_length);
|
||||
}
|
||||
|
||||
@@ -225,7 +180,7 @@ DynamicMessageType::get_member_count() const
|
||||
{
|
||||
size_t out;
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_type_get_member_count(
|
||||
rosidl_dynamic_type_.get(), &out);
|
||||
&get_rosidl_dynamic_type(), &out);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error(
|
||||
std::string("could not get member count: ") + rcl_get_error_string().str);
|
||||
@@ -234,33 +189,17 @@ DynamicMessageType::get_member_count() const
|
||||
}
|
||||
|
||||
|
||||
rosidl_dynamic_typesupport_dynamic_type_t *
|
||||
rosidl_dynamic_typesupport_dynamic_type_t &
|
||||
DynamicMessageType::get_rosidl_dynamic_type()
|
||||
{
|
||||
return rosidl_dynamic_type_.get();
|
||||
return rosidl_dynamic_type_;
|
||||
}
|
||||
|
||||
|
||||
const rosidl_dynamic_typesupport_dynamic_type_t *
|
||||
const rosidl_dynamic_typesupport_dynamic_type_t &
|
||||
DynamicMessageType::get_rosidl_dynamic_type() const
|
||||
{
|
||||
return rosidl_dynamic_type_.get();
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_dynamic_type_t>
|
||||
DynamicMessageType::get_shared_rosidl_dynamic_type()
|
||||
{
|
||||
return std::shared_ptr<rosidl_dynamic_typesupport_dynamic_type_t>(
|
||||
shared_from_this(), rosidl_dynamic_type_.get());
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<const rosidl_dynamic_typesupport_dynamic_type_t>
|
||||
DynamicMessageType::get_shared_rosidl_dynamic_type() const
|
||||
{
|
||||
return std::shared_ptr<rosidl_dynamic_typesupport_dynamic_type_t>(
|
||||
shared_from_this(), rosidl_dynamic_type_.get());
|
||||
return rosidl_dynamic_type_;
|
||||
}
|
||||
|
||||
|
||||
@@ -280,42 +219,46 @@ DynamicMessageType::get_shared_dynamic_serialization_support() const
|
||||
|
||||
// METHODS =========================================================================================
|
||||
DynamicMessageType
|
||||
DynamicMessageType::clone() const
|
||||
DynamicMessageType::clone(rcl_allocator_t allocator)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_t * rosidl_dynamic_type = nullptr;
|
||||
rosidl_dynamic_typesupport_dynamic_type_t rosidl_dynamic_type =
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_type();
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_type_clone(
|
||||
get_rosidl_dynamic_type(), &rosidl_dynamic_type);
|
||||
if (ret != RCUTILS_RET_OK || !rosidl_dynamic_type) {
|
||||
&get_rosidl_dynamic_type(), &allocator, &rosidl_dynamic_type);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error(
|
||||
std::string("could not clone dynamic type: ") + rcl_get_error_string().str);
|
||||
}
|
||||
return DynamicMessageType(serialization_support_, rosidl_dynamic_type);
|
||||
return DynamicMessageType(
|
||||
get_shared_dynamic_serialization_support(), std::move(rosidl_dynamic_type));
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageType::SharedPtr
|
||||
DynamicMessageType::clone_shared() const
|
||||
DynamicMessageType::clone_shared(rcl_allocator_t allocator)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_t * rosidl_dynamic_type = nullptr;
|
||||
rosidl_dynamic_typesupport_dynamic_type_t rosidl_dynamic_type =
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_type();
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_type_clone(
|
||||
get_rosidl_dynamic_type(), &rosidl_dynamic_type);
|
||||
if (ret != RCUTILS_RET_OK || !rosidl_dynamic_type) {
|
||||
&get_rosidl_dynamic_type(), &allocator, &rosidl_dynamic_type);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error(
|
||||
std::string("could not clone dynamic type: ") + rcl_get_error_string().str);
|
||||
}
|
||||
return DynamicMessageType::make_shared(serialization_support_, rosidl_dynamic_type);
|
||||
return DynamicMessageType::make_shared(
|
||||
get_shared_dynamic_serialization_support(), std::move(rosidl_dynamic_type));
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DynamicMessageType::equals(const DynamicMessageType & other) const
|
||||
{
|
||||
if (get_library_identifier() != other.get_library_identifier()) {
|
||||
if (get_serialization_library_identifier() != other.get_serialization_library_identifier()) {
|
||||
throw std::runtime_error("library identifiers don't match");
|
||||
}
|
||||
bool out;
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_type_equals(
|
||||
get_rosidl_dynamic_type(), other.get_rosidl_dynamic_type(), &out);
|
||||
&get_rosidl_dynamic_type(), &other.get_rosidl_dynamic_type(), &out);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error(
|
||||
std::string("could not equate dynamic message types: ") + rcl_get_error_string().str);
|
||||
@@ -325,14 +268,14 @@ DynamicMessageType::equals(const DynamicMessageType & other) const
|
||||
|
||||
|
||||
DynamicMessage
|
||||
DynamicMessageType::build_dynamic_message()
|
||||
DynamicMessageType::build_dynamic_message(rcl_allocator_t allocator)
|
||||
{
|
||||
return DynamicMessage(shared_from_this());
|
||||
return DynamicMessage(shared_from_this(), allocator);
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage::SharedPtr
|
||||
DynamicMessageType::build_dynamic_message_shared()
|
||||
DynamicMessageType::build_dynamic_message_shared(rcl_allocator_t allocator)
|
||||
{
|
||||
return DynamicMessage::make_shared(shared_from_this());
|
||||
return DynamicMessage::make_shared(shared_from_this(), allocator);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <rosidl_dynamic_typesupport/api/dynamic_data.h>
|
||||
#include <rosidl_dynamic_typesupport/api/dynamic_type.h>
|
||||
#include <rosidl_dynamic_typesupport/api/serialization_support.h>
|
||||
#include <rosidl_dynamic_typesupport/types.h>
|
||||
|
||||
#include <memory>
|
||||
@@ -27,69 +28,48 @@
|
||||
#include "rclcpp/dynamic_typesupport/dynamic_serialization_support.hpp"
|
||||
#include "rclcpp/exceptions.hpp"
|
||||
|
||||
|
||||
using rclcpp::dynamic_typesupport::DynamicMessage;
|
||||
using rclcpp::dynamic_typesupport::DynamicMessageType;
|
||||
using rclcpp::dynamic_typesupport::DynamicMessageTypeBuilder;
|
||||
using rclcpp::dynamic_typesupport::DynamicSerializationSupport;
|
||||
|
||||
|
||||
#ifndef RCLCPP__DYNAMIC_TYPESUPPORT__DETAIL__DYNAMIC_MESSAGE_TYPE_BUILDER_IMPL_HPP_
|
||||
// Template specialization implementations
|
||||
#include "rclcpp/dynamic_typesupport/detail/dynamic_message_type_builder_impl.hpp"
|
||||
#endif
|
||||
|
||||
|
||||
// CONSTRUCTION ====================================================================================
|
||||
DynamicMessageTypeBuilder::DynamicMessageTypeBuilder(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support, const std::string & name)
|
||||
: serialization_support_(serialization_support), rosidl_dynamic_type_builder_(nullptr)
|
||||
{
|
||||
init_from_serialization_support_(serialization_support, name);
|
||||
if (!rosidl_dynamic_type_builder_) {
|
||||
throw std::runtime_error("could not create new dynamic type builder object");
|
||||
}
|
||||
}
|
||||
: DynamicMessageTypeBuilder::DynamicMessageTypeBuilder(
|
||||
serialization_support,
|
||||
name,
|
||||
serialization_support->get_rosidl_serialization_support().allocator) {}
|
||||
|
||||
|
||||
DynamicMessageTypeBuilder::DynamicMessageTypeBuilder(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t * rosidl_dynamic_type_builder)
|
||||
: serialization_support_(serialization_support), rosidl_dynamic_type_builder_(nullptr)
|
||||
{
|
||||
if (!serialization_support) {
|
||||
throw std::runtime_error("serialization support cannot be nullptr!");
|
||||
}
|
||||
if (!rosidl_dynamic_type_builder) {
|
||||
throw std::runtime_error("rosidl dynamic type builder cannot be nullptr!");
|
||||
}
|
||||
if (!match_serialization_support_(*serialization_support, *rosidl_dynamic_type_builder)) {
|
||||
throw std::runtime_error(
|
||||
"serialization support library does not match dynamic type builder's!");
|
||||
}
|
||||
|
||||
rosidl_dynamic_type_builder_.reset(
|
||||
rosidl_dynamic_type_builder,
|
||||
// Custom deleter
|
||||
[](rosidl_dynamic_typesupport_dynamic_type_builder_t * rosidl_dynamic_type_builder)->void {
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_destroy(rosidl_dynamic_type_builder);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageTypeBuilder::DynamicMessageTypeBuilder(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_dynamic_type_builder_t> rosidl_dynamic_type_builder)
|
||||
const std::string & name,
|
||||
rcl_allocator_t allocator)
|
||||
: serialization_support_(serialization_support),
|
||||
rosidl_dynamic_type_builder_(rosidl_dynamic_type_builder)
|
||||
rosidl_dynamic_type_builder_(
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_type_builder())
|
||||
{
|
||||
init_from_serialization_support_(serialization_support, name, allocator);
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageTypeBuilder::DynamicMessageTypeBuilder(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t && rosidl_dynamic_type_builder)
|
||||
: serialization_support_(serialization_support),
|
||||
rosidl_dynamic_type_builder_(
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_type_builder())
|
||||
{
|
||||
if (!serialization_support) {
|
||||
throw std::runtime_error("serialization support cannot be nullptr!");
|
||||
}
|
||||
if (!rosidl_dynamic_type_builder) {
|
||||
throw std::runtime_error("rosidl dynamic type builder cannot be nullptr!");
|
||||
}
|
||||
if (!match_serialization_support_(*serialization_support, *rosidl_dynamic_type_builder.get())) {
|
||||
if (!match_serialization_support_(*serialization_support, rosidl_dynamic_type_builder)) {
|
||||
throw std::runtime_error(
|
||||
"serialization support library does not match dynamic type builder's!");
|
||||
}
|
||||
@@ -98,36 +78,24 @@ DynamicMessageTypeBuilder::DynamicMessageTypeBuilder(
|
||||
|
||||
DynamicMessageTypeBuilder::DynamicMessageTypeBuilder(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description)
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description,
|
||||
rcl_allocator_t allocator)
|
||||
: serialization_support_(serialization_support),
|
||||
rosidl_dynamic_type_builder_(nullptr)
|
||||
rosidl_dynamic_type_builder_(
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_type_builder())
|
||||
{
|
||||
if (!serialization_support) {
|
||||
throw std::runtime_error("serialization support cannot be nullptr!");
|
||||
}
|
||||
init_from_description(description, serialization_support);
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageTypeBuilder::DynamicMessageTypeBuilder(const DynamicMessageTypeBuilder & other)
|
||||
: enable_shared_from_this(), serialization_support_(nullptr), rosidl_dynamic_type_builder_(nullptr)
|
||||
{
|
||||
DynamicMessageTypeBuilder out = other.clone();
|
||||
std::swap(serialization_support_, out.serialization_support_);
|
||||
std::swap(rosidl_dynamic_type_builder_, out.rosidl_dynamic_type_builder_);
|
||||
init_from_description(description, allocator, serialization_support);
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageTypeBuilder::DynamicMessageTypeBuilder(DynamicMessageTypeBuilder && other) noexcept
|
||||
: serialization_support_(std::exchange(other.serialization_support_, nullptr)),
|
||||
rosidl_dynamic_type_builder_(std::exchange(other.rosidl_dynamic_type_builder_, nullptr)) {}
|
||||
|
||||
|
||||
DynamicMessageTypeBuilder &
|
||||
DynamicMessageTypeBuilder::operator=(const DynamicMessageTypeBuilder & other)
|
||||
{
|
||||
return *this = DynamicMessageTypeBuilder(other);
|
||||
}
|
||||
rosidl_dynamic_type_builder_(std::exchange(
|
||||
other.rosidl_dynamic_type_builder_,
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_type_builder())) {}
|
||||
|
||||
|
||||
DynamicMessageTypeBuilder &
|
||||
@@ -139,12 +107,20 @@ DynamicMessageTypeBuilder::operator=(DynamicMessageTypeBuilder && other) noexcep
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageTypeBuilder::~DynamicMessageTypeBuilder() {}
|
||||
DynamicMessageTypeBuilder::~DynamicMessageTypeBuilder()
|
||||
{
|
||||
if (rosidl_dynamic_typesupport_dynamic_type_builder_fini(&get_rosidl_dynamic_type_builder()) !=
|
||||
RCUTILS_RET_OK)
|
||||
{
|
||||
RCUTILS_LOG_ERROR("could not fini rosidl dynamic type builder");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DynamicMessageTypeBuilder::init_from_description(
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description,
|
||||
rcl_allocator_t allocator,
|
||||
DynamicSerializationSupport::SharedPtr serialization_support)
|
||||
{
|
||||
if (serialization_support) {
|
||||
@@ -152,55 +128,45 @@ DynamicMessageTypeBuilder::init_from_description(
|
||||
serialization_support_ = serialization_support;
|
||||
}
|
||||
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t * rosidl_dynamic_type_builder = nullptr;
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_type_builder_create_from_description(
|
||||
serialization_support_->get_rosidl_serialization_support(), &description,
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t rosidl_dynamic_type_builder =
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_type_builder();
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_type_builder_init_from_description(
|
||||
&serialization_support_->get_rosidl_serialization_support(),
|
||||
&description,
|
||||
&allocator,
|
||||
&rosidl_dynamic_type_builder);
|
||||
if (ret != RCUTILS_RET_OK || !rosidl_dynamic_type_builder) {
|
||||
throw std::runtime_error("could not create new dynamic type builder object");
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error("could not init new dynamic type builder object");
|
||||
}
|
||||
|
||||
rosidl_dynamic_type_builder_.reset(
|
||||
rosidl_dynamic_type_builder,
|
||||
// Custom deleter
|
||||
[](rosidl_dynamic_typesupport_dynamic_type_builder_t * rosidl_dynamic_type_builder)->void {
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_destroy(rosidl_dynamic_type_builder);
|
||||
});
|
||||
rosidl_dynamic_type_builder_ = std::move(rosidl_dynamic_type_builder);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DynamicMessageTypeBuilder::init_from_serialization_support_(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
const std::string & name)
|
||||
const std::string & name,
|
||||
rcl_allocator_t allocator)
|
||||
{
|
||||
if (!serialization_support) {
|
||||
throw std::runtime_error("serialization support cannot be nullptr!");
|
||||
}
|
||||
if (!serialization_support->get_rosidl_serialization_support()) {
|
||||
if (!&serialization_support->get_rosidl_serialization_support()) {
|
||||
throw std::runtime_error("serialization support raw pointer cannot be nullptr!");
|
||||
}
|
||||
|
||||
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t * rosidl_dynamic_type_builder = nullptr;
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_type_builder_create(
|
||||
serialization_support->get_rosidl_serialization_support(),
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t rosidl_dynamic_type_builder =
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_type_builder();
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_type_builder_init(
|
||||
&serialization_support->get_rosidl_serialization_support(),
|
||||
name.c_str(), name.size(),
|
||||
&allocator,
|
||||
&rosidl_dynamic_type_builder);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error(
|
||||
std::string("could not init dynamic type builder: ") + rcl_get_error_string().str);
|
||||
}
|
||||
if (!rosidl_dynamic_type_builder) {
|
||||
throw std::runtime_error("could not init dynamic type builder object");
|
||||
}
|
||||
|
||||
rosidl_dynamic_type_builder_.reset(
|
||||
rosidl_dynamic_type_builder,
|
||||
// Custom deleter
|
||||
[](rosidl_dynamic_typesupport_dynamic_type_builder_t * rosidl_dynamic_type_builder)->void {
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_destroy(rosidl_dynamic_type_builder);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -209,34 +175,23 @@ DynamicMessageTypeBuilder::match_serialization_support_(
|
||||
const DynamicSerializationSupport & serialization_support,
|
||||
const rosidl_dynamic_typesupport_dynamic_type_builder_t & rosidl_dynamic_type_builder)
|
||||
{
|
||||
bool out = true;
|
||||
|
||||
if (serialization_support.get_library_identifier() != std::string(
|
||||
rosidl_dynamic_type_builder.serialization_support->library_identifier))
|
||||
if (serialization_support.get_serialization_library_identifier() != std::string(
|
||||
rosidl_dynamic_type_builder.serialization_support->serialization_library_identifier))
|
||||
{
|
||||
RCUTILS_LOG_ERROR(
|
||||
"serialization support library identifier does not match dynamic type builder's");
|
||||
out = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO(methylDragon): Can I do this?? Is it portable?
|
||||
if (serialization_support.get_rosidl_serialization_support() !=
|
||||
rosidl_dynamic_type_builder.serialization_support)
|
||||
{
|
||||
RCUTILS_LOG_ERROR(
|
||||
"serialization support pointer does not match dynamic type builder's");
|
||||
out = false;
|
||||
}
|
||||
|
||||
return out;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// GETTERS =======================================================================================
|
||||
const std::string
|
||||
DynamicMessageTypeBuilder::get_library_identifier() const
|
||||
DynamicMessageTypeBuilder::get_serialization_library_identifier() const
|
||||
{
|
||||
return std::string(rosidl_dynamic_type_builder_->serialization_support->library_identifier);
|
||||
return std::string(
|
||||
get_rosidl_dynamic_type_builder().serialization_support->serialization_library_identifier);
|
||||
}
|
||||
|
||||
|
||||
@@ -246,38 +201,22 @@ DynamicMessageTypeBuilder::get_name() const
|
||||
size_t buf_length;
|
||||
const char * buf;
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_get_name(
|
||||
get_rosidl_dynamic_type_builder(), &buf, &buf_length);
|
||||
&get_rosidl_dynamic_type_builder(), &buf, &buf_length);
|
||||
return std::string(buf, buf_length);
|
||||
}
|
||||
|
||||
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t *
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t &
|
||||
DynamicMessageTypeBuilder::get_rosidl_dynamic_type_builder()
|
||||
{
|
||||
return rosidl_dynamic_type_builder_.get();
|
||||
return rosidl_dynamic_type_builder_;
|
||||
}
|
||||
|
||||
|
||||
const rosidl_dynamic_typesupport_dynamic_type_builder_t *
|
||||
const rosidl_dynamic_typesupport_dynamic_type_builder_t &
|
||||
DynamicMessageTypeBuilder::get_rosidl_dynamic_type_builder() const
|
||||
{
|
||||
return rosidl_dynamic_type_builder_.get();
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_dynamic_type_builder_t>
|
||||
DynamicMessageTypeBuilder::get_shared_rosidl_dynamic_type_builder()
|
||||
{
|
||||
return std::shared_ptr<rosidl_dynamic_typesupport_dynamic_type_builder_t>(
|
||||
shared_from_this(), rosidl_dynamic_type_builder_.get());
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<const rosidl_dynamic_typesupport_dynamic_type_builder_t>
|
||||
DynamicMessageTypeBuilder::get_shared_rosidl_dynamic_type_builder() const
|
||||
{
|
||||
return std::shared_ptr<rosidl_dynamic_typesupport_dynamic_type_builder_t>(
|
||||
shared_from_this(), rosidl_dynamic_type_builder_.get());
|
||||
return rosidl_dynamic_type_builder_;
|
||||
}
|
||||
|
||||
|
||||
@@ -300,41 +239,44 @@ void
|
||||
DynamicMessageTypeBuilder::set_name(const std::string & name)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_set_name(
|
||||
get_rosidl_dynamic_type_builder(), name.c_str(), name.size());
|
||||
&get_rosidl_dynamic_type_builder(), name.c_str(), name.size());
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageTypeBuilder
|
||||
DynamicMessageTypeBuilder::clone() const
|
||||
DynamicMessageTypeBuilder::clone(rcl_allocator_t allocator)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t * rosidl_dynamic_type_builder = nullptr;
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t rosidl_dynamic_type_builder =
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_type_builder();
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_type_builder_clone(
|
||||
get_rosidl_dynamic_type_builder(), &rosidl_dynamic_type_builder);
|
||||
if (ret != RCUTILS_RET_OK || !rosidl_dynamic_type_builder) {
|
||||
&get_rosidl_dynamic_type_builder(), &allocator, &rosidl_dynamic_type_builder);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error(
|
||||
std::string("could not clone dynamic type builder: ") + rcl_get_error_string().str);
|
||||
}
|
||||
return DynamicMessageTypeBuilder(serialization_support_, rosidl_dynamic_type_builder);
|
||||
return DynamicMessageTypeBuilder(
|
||||
get_shared_dynamic_serialization_support(), std::move(rosidl_dynamic_type_builder));
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageTypeBuilder::SharedPtr
|
||||
DynamicMessageTypeBuilder::clone_shared() const
|
||||
DynamicMessageTypeBuilder::clone_shared(rcl_allocator_t allocator)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t * rosidl_dynamic_type_builder = nullptr;
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_t rosidl_dynamic_type_builder =
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_type_builder();
|
||||
rcutils_ret_t ret = rosidl_dynamic_typesupport_dynamic_type_builder_clone(
|
||||
get_rosidl_dynamic_type_builder(), &rosidl_dynamic_type_builder);
|
||||
if (ret != RCUTILS_RET_OK || !rosidl_dynamic_type_builder) {
|
||||
&get_rosidl_dynamic_type_builder(), &allocator, &rosidl_dynamic_type_builder);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error(
|
||||
std::string("could not clone dynamic type builder: ") + rcl_get_error_string().str);
|
||||
}
|
||||
return DynamicMessageTypeBuilder::make_shared(
|
||||
serialization_support_, rosidl_dynamic_type_builder);
|
||||
get_shared_dynamic_serialization_support(), std::move(rosidl_dynamic_type_builder));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DynamicMessageTypeBuilder::clear()
|
||||
DynamicMessageTypeBuilder::clear(rcl_allocator_t allocator)
|
||||
{
|
||||
if (!serialization_support_) {
|
||||
throw std::runtime_error(
|
||||
@@ -343,38 +285,35 @@ DynamicMessageTypeBuilder::clear()
|
||||
}
|
||||
|
||||
const std::string & name = get_name();
|
||||
init_from_serialization_support_(serialization_support_, name);
|
||||
if (!rosidl_dynamic_type_builder_) {
|
||||
throw std::runtime_error("could not create new dynamic type builder object");
|
||||
}
|
||||
init_from_serialization_support_(serialization_support_, name, allocator);
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage
|
||||
DynamicMessageTypeBuilder::build_dynamic_message()
|
||||
DynamicMessageTypeBuilder::build_dynamic_message(rcl_allocator_t allocator)
|
||||
{
|
||||
return DynamicMessage(shared_from_this());
|
||||
return DynamicMessage(shared_from_this(), allocator);
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage::SharedPtr
|
||||
DynamicMessageTypeBuilder::build_dynamic_message_shared()
|
||||
DynamicMessageTypeBuilder::build_dynamic_message_shared(rcl_allocator_t allocator)
|
||||
{
|
||||
return DynamicMessage::make_shared(shared_from_this());
|
||||
return DynamicMessage::make_shared(shared_from_this(), allocator);
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageType
|
||||
DynamicMessageTypeBuilder::build_dynamic_message_type()
|
||||
DynamicMessageTypeBuilder::build_dynamic_message_type(rcl_allocator_t allocator)
|
||||
{
|
||||
return DynamicMessageType(shared_from_this());
|
||||
return DynamicMessageType(shared_from_this(), allocator);
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageType::SharedPtr
|
||||
DynamicMessageTypeBuilder::build_dynamic_message_type_shared()
|
||||
DynamicMessageTypeBuilder::build_dynamic_message_type_shared(rcl_allocator_t allocator)
|
||||
{
|
||||
return DynamicMessageType::make_shared(shared_from_this());
|
||||
return DynamicMessageType::make_shared(shared_from_this(), allocator);
|
||||
}
|
||||
|
||||
|
||||
@@ -389,7 +328,7 @@ DynamicMessageTypeBuilder::add_fixed_string_member(
|
||||
const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_fixed_string_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
string_length);
|
||||
}
|
||||
@@ -401,7 +340,7 @@ DynamicMessageTypeBuilder::add_fixed_wstring_member(
|
||||
const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_fixed_wstring_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
wstring_length);
|
||||
}
|
||||
@@ -413,7 +352,7 @@ DynamicMessageTypeBuilder::add_fixed_string_array_member(
|
||||
size_t string_length, size_t array_length, const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_fixed_string_array_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
string_length, array_length);
|
||||
}
|
||||
@@ -425,7 +364,7 @@ DynamicMessageTypeBuilder::add_fixed_wstring_array_member(
|
||||
size_t wstring_length, size_t array_length, const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_fixed_wstring_array_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
wstring_length, array_length);
|
||||
}
|
||||
@@ -437,7 +376,7 @@ DynamicMessageTypeBuilder::add_fixed_string_unbounded_sequence_member(
|
||||
const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_fixed_string_unbounded_sequence_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
string_length);
|
||||
}
|
||||
@@ -449,7 +388,7 @@ DynamicMessageTypeBuilder::add_fixed_wstring_unbounded_sequence_member(
|
||||
const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_fixed_wstring_unbounded_sequence_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
wstring_length);
|
||||
}
|
||||
@@ -461,7 +400,7 @@ DynamicMessageTypeBuilder::add_fixed_string_bounded_sequence_member(
|
||||
size_t string_length, size_t sequence_bound, const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_fixed_string_bounded_sequence_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
string_length, sequence_bound);
|
||||
}
|
||||
@@ -473,7 +412,7 @@ DynamicMessageTypeBuilder::add_fixed_wstring_bounded_sequence_member(
|
||||
size_t wstring_length, size_t sequence_bound, const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_fixed_wstring_bounded_sequence_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
wstring_length, sequence_bound);
|
||||
}
|
||||
@@ -486,7 +425,7 @@ DynamicMessageTypeBuilder::add_bounded_string_member(
|
||||
const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_bounded_string_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
string_bound);
|
||||
}
|
||||
@@ -498,7 +437,7 @@ DynamicMessageTypeBuilder::add_bounded_wstring_member(
|
||||
const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_bounded_wstring_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
wstring_bound);
|
||||
}
|
||||
@@ -510,7 +449,7 @@ DynamicMessageTypeBuilder::add_bounded_string_array_member(
|
||||
size_t string_bound, size_t array_length, const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_bounded_string_array_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
string_bound, array_length);
|
||||
}
|
||||
@@ -522,7 +461,7 @@ DynamicMessageTypeBuilder::add_bounded_wstring_array_member(
|
||||
size_t wstring_bound, size_t array_length, const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_bounded_wstring_array_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
wstring_bound, array_length);
|
||||
}
|
||||
@@ -534,7 +473,7 @@ DynamicMessageTypeBuilder::add_bounded_string_unbounded_sequence_member(
|
||||
const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_bounded_string_unbounded_sequence_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
string_bound);
|
||||
}
|
||||
@@ -546,7 +485,7 @@ DynamicMessageTypeBuilder::add_bounded_wstring_unbounded_sequence_member(
|
||||
const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_bounded_wstring_unbounded_sequence_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
wstring_bound);
|
||||
}
|
||||
@@ -558,7 +497,7 @@ DynamicMessageTypeBuilder::add_bounded_string_bounded_sequence_member(
|
||||
size_t string_bound, size_t sequence_bound, const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_bounded_string_bounded_sequence_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
string_bound, sequence_bound);
|
||||
}
|
||||
@@ -570,7 +509,7 @@ DynamicMessageTypeBuilder::add_bounded_wstring_bounded_sequence_member(
|
||||
size_t wstring_bound, size_t sequence_bound, const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_bounded_wstring_bounded_sequence_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
wstring_bound, sequence_bound);
|
||||
}
|
||||
@@ -583,9 +522,9 @@ DynamicMessageTypeBuilder::add_complex_member(
|
||||
DynamicMessageType & nested_type, const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_complex_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
nested_type.get_rosidl_dynamic_type());
|
||||
&nested_type.get_rosidl_dynamic_type());
|
||||
}
|
||||
|
||||
|
||||
@@ -595,9 +534,9 @@ DynamicMessageTypeBuilder::add_complex_array_member(
|
||||
DynamicMessageType & nested_type, size_t array_length, const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_complex_array_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
nested_type.get_rosidl_dynamic_type(), array_length);
|
||||
&nested_type.get_rosidl_dynamic_type(), array_length);
|
||||
}
|
||||
|
||||
|
||||
@@ -607,9 +546,9 @@ DynamicMessageTypeBuilder::add_complex_unbounded_sequence_member(
|
||||
DynamicMessageType & nested_type, const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_complex_unbounded_sequence_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
nested_type.get_rosidl_dynamic_type());
|
||||
&nested_type.get_rosidl_dynamic_type());
|
||||
}
|
||||
|
||||
|
||||
@@ -619,9 +558,9 @@ DynamicMessageTypeBuilder::add_complex_bounded_sequence_member(
|
||||
DynamicMessageType & nested_type, size_t sequence_bound, const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_complex_bounded_sequence_member(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
nested_type.get_rosidl_dynamic_type(), sequence_bound);
|
||||
&nested_type.get_rosidl_dynamic_type(), sequence_bound);
|
||||
}
|
||||
|
||||
|
||||
@@ -631,9 +570,9 @@ DynamicMessageTypeBuilder::add_complex_member_builder(
|
||||
DynamicMessageTypeBuilder & nested_type_builder, const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_complex_member_builder(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
nested_type_builder.get_rosidl_dynamic_type_builder());
|
||||
&nested_type_builder.get_rosidl_dynamic_type_builder());
|
||||
}
|
||||
|
||||
|
||||
@@ -644,9 +583,9 @@ DynamicMessageTypeBuilder::add_complex_array_member_builder(
|
||||
const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_complex_array_member_builder(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
nested_type_builder.get_rosidl_dynamic_type_builder(), array_length);
|
||||
&nested_type_builder.get_rosidl_dynamic_type_builder(), array_length);
|
||||
}
|
||||
|
||||
|
||||
@@ -656,9 +595,9 @@ DynamicMessageTypeBuilder::add_complex_unbounded_sequence_member_builder(
|
||||
DynamicMessageTypeBuilder & nested_type_builder, const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_complex_unbounded_sequence_member_builder(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
nested_type_builder.get_rosidl_dynamic_type_builder());
|
||||
&nested_type_builder.get_rosidl_dynamic_type_builder());
|
||||
}
|
||||
|
||||
|
||||
@@ -669,7 +608,7 @@ DynamicMessageTypeBuilder::add_complex_bounded_sequence_member_builder(
|
||||
const std::string & default_value)
|
||||
{
|
||||
rosidl_dynamic_typesupport_dynamic_type_builder_add_complex_bounded_sequence_member_builder(
|
||||
get_rosidl_dynamic_type_builder(),
|
||||
&get_rosidl_dynamic_type_builder(),
|
||||
id, name.c_str(), name.size(), default_value.c_str(), default_value.size(),
|
||||
nested_type_builder.get_rosidl_dynamic_type_builder(), sequence_bound);
|
||||
&nested_type_builder.get_rosidl_dynamic_type_builder(), sequence_bound);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include <rosidl_runtime_c/type_description_utils.h>
|
||||
#include <rosidl_runtime_c/type_description/type_description__functions.h>
|
||||
#include <rosidl_runtime_c/type_description/type_description__struct.h>
|
||||
#include <rosidl_runtime_c/type_description/type_source__functions.h>
|
||||
#include <rosidl_runtime_c/type_description/type_source__struct.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -38,162 +40,113 @@
|
||||
#include "rclcpp/macros.hpp"
|
||||
#include "rclcpp/visibility_control.hpp"
|
||||
|
||||
|
||||
using rclcpp::dynamic_typesupport::DynamicMessage;
|
||||
using rclcpp::dynamic_typesupport::DynamicMessageType;
|
||||
using rclcpp::dynamic_typesupport::DynamicMessageTypeSupport;
|
||||
using rclcpp::dynamic_typesupport::DynamicSerializationSupport;
|
||||
|
||||
|
||||
// CONSTRUCTION ====================================================================================
|
||||
DynamicMessageTypeSupport::DynamicMessageTypeSupport(
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description,
|
||||
const std::string & serialization_library_name)
|
||||
const std::string & serialization_library_name,
|
||||
rcl_allocator_t allocator)
|
||||
: serialization_support_(nullptr),
|
||||
dynamic_message_type_(nullptr),
|
||||
dynamic_message_(nullptr),
|
||||
description_(nullptr),
|
||||
rosidl_message_type_support_(nullptr)
|
||||
rosidl_message_type_support_(rosidl_get_zero_initialized_message_type_support_handle())
|
||||
{
|
||||
rosidl_message_type_support_t * ts = nullptr;
|
||||
rcl_ret_t ret;
|
||||
|
||||
if (serialization_library_name.empty()) {
|
||||
ret = rcl_dynamic_message_type_support_handle_create(nullptr, &description, &ts);
|
||||
ret = rcl_dynamic_message_type_support_handle_init(
|
||||
nullptr, &description, &allocator, &rosidl_message_type_support_);
|
||||
} else {
|
||||
ret = rcl_dynamic_message_type_support_handle_create(
|
||||
serialization_library_name.c_str(), &description, &ts);
|
||||
ret = rcl_dynamic_message_type_support_handle_init(
|
||||
serialization_library_name.c_str(), &description, &allocator, &rosidl_message_type_support_);
|
||||
}
|
||||
if (ret != RCL_RET_OK) {
|
||||
throw std::runtime_error("error initializing rosidl message type support");
|
||||
std::string error_msg =
|
||||
std::string("error initializing rosidl message type support: ") + rcl_get_error_string().str;
|
||||
rcl_reset_error();
|
||||
throw std::runtime_error(error_msg);
|
||||
}
|
||||
if (!ts) {
|
||||
throw std::runtime_error("could not init rosidl message type support");
|
||||
}
|
||||
if (!ts->data) {
|
||||
throw std::runtime_error("could not init rosidl message type support impl");
|
||||
}
|
||||
if (ts->typesupport_identifier != rosidl_get_dynamic_typesupport_identifier()) {
|
||||
if (rosidl_message_type_support_.typesupport_identifier !=
|
||||
rosidl_get_dynamic_typesupport_identifier())
|
||||
{
|
||||
throw std::runtime_error("rosidl message type support is of the wrong type");
|
||||
}
|
||||
|
||||
// NOTE(methylDragon): Not technically const correct, but since it's a const void *,
|
||||
// we do it anyway...
|
||||
auto ts_impl = static_cast<const rosidl_dynamic_message_type_support_impl_t *>(ts->data);
|
||||
auto ts_impl = static_cast<rosidl_dynamic_message_type_support_impl_t *>(const_cast<void *>(
|
||||
rosidl_message_type_support_.data));
|
||||
|
||||
// NOTE(methylDragon): We don't destroy the rosidl_message_type_support->data since its members
|
||||
// are managed by the passed in SharedPtr wrapper classes. We just delete it.
|
||||
rosidl_message_type_support_.reset(
|
||||
ts,
|
||||
[](rosidl_message_type_support_t * ts) -> void {
|
||||
auto ts_impl = static_cast<const rosidl_dynamic_message_type_support_impl_t *>(ts->data);
|
||||
auto allocator = rcl_get_default_allocator();
|
||||
|
||||
// These are all C allocated
|
||||
allocator.deallocate(ts_impl->type_hash, &allocator.state);
|
||||
allocator.deallocate(
|
||||
const_cast<rosidl_dynamic_message_type_support_impl_t *>(ts_impl), &allocator.state);
|
||||
allocator.deallocate(ts, &allocator.state);
|
||||
}
|
||||
);
|
||||
|
||||
manage_description_(ts_impl->type_description);
|
||||
serialization_support_ = DynamicSerializationSupport::make_shared(ts_impl->serialization_support);
|
||||
serialization_support_ = DynamicSerializationSupport::make_shared(
|
||||
std::move(ts_impl->serialization_support));
|
||||
|
||||
dynamic_message_type_ = DynamicMessageType::make_shared(
|
||||
get_shared_dynamic_serialization_support(), ts_impl->dynamic_message_type);
|
||||
get_shared_dynamic_serialization_support(), std::move(*ts_impl->dynamic_message_type));
|
||||
|
||||
dynamic_message_ = DynamicMessage::make_shared(
|
||||
get_shared_dynamic_serialization_support(), ts_impl->dynamic_message);
|
||||
|
||||
if (!rosidl_message_type_support_) {
|
||||
throw std::runtime_error("could not init rosidl message type support.");
|
||||
}
|
||||
get_shared_dynamic_serialization_support(), std::move(*ts_impl->dynamic_message));
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageTypeSupport::DynamicMessageTypeSupport(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description)
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description,
|
||||
rcl_allocator_t allocator)
|
||||
: serialization_support_(serialization_support),
|
||||
dynamic_message_type_(nullptr),
|
||||
dynamic_message_(nullptr),
|
||||
description_(nullptr),
|
||||
rosidl_message_type_support_(nullptr)
|
||||
rosidl_message_type_support_(rosidl_get_zero_initialized_message_type_support_handle())
|
||||
{
|
||||
// Check null
|
||||
if (!serialization_support) {
|
||||
throw std::runtime_error("serialization_support cannot be nullptr.");
|
||||
}
|
||||
|
||||
rosidl_message_type_support_t * ts = nullptr;
|
||||
|
||||
auto type_hash = std::make_unique<rosidl_type_hash_t>();
|
||||
rosidl_type_hash_t type_hash;
|
||||
rcutils_ret_t hash_ret = rcl_calculate_type_hash(
|
||||
// TODO(methylDragon): Swap this out with the conversion function when it is ready
|
||||
reinterpret_cast<const type_description_interfaces__msg__TypeDescription *>(&description),
|
||||
type_hash.get());
|
||||
if (hash_ret != RCL_RET_OK || !type_hash) {
|
||||
&type_hash);
|
||||
if (hash_ret != RCL_RET_OK) {
|
||||
throw std::runtime_error("failed to get type hash");
|
||||
}
|
||||
|
||||
rcutils_ret_t ret = rosidl_dynamic_message_type_support_handle_create(
|
||||
serialization_support->get_rosidl_serialization_support(),
|
||||
type_hash.get(), // type_hash
|
||||
rcutils_ret_t ret = rosidl_dynamic_message_type_support_handle_init(
|
||||
&serialization_support->get_rosidl_serialization_support(),
|
||||
&type_hash, // type_hash
|
||||
&description, // type_description
|
||||
nullptr, // type_description_sources (not implemented for dynamic types)
|
||||
&ts);
|
||||
if (ret != RCUTILS_RET_OK || !ts) {
|
||||
&allocator,
|
||||
&rosidl_message_type_support_);
|
||||
if (ret != RCUTILS_RET_OK) {
|
||||
throw std::runtime_error("could not init rosidl message type support");
|
||||
}
|
||||
if (!ts->data) {
|
||||
throw std::runtime_error("could not init rosidl message type support impl");
|
||||
}
|
||||
if (ts->typesupport_identifier != rosidl_get_dynamic_typesupport_identifier()) {
|
||||
if (rosidl_message_type_support_.typesupport_identifier !=
|
||||
rosidl_get_dynamic_typesupport_identifier())
|
||||
{
|
||||
throw std::runtime_error("rosidl message type support is of the wrong type");
|
||||
}
|
||||
|
||||
auto ts_impl = static_cast<const rosidl_dynamic_message_type_support_impl_t *>(ts->data);
|
||||
|
||||
// NOTE(methylDragon): We don't finalize the rosidl_message_type_support->data since its members
|
||||
// are managed by the passed in SharedPtr wrapper classes. We just delete it.
|
||||
rosidl_message_type_support_.reset(
|
||||
ts,
|
||||
[](rosidl_message_type_support_t * ts) -> void {
|
||||
auto ts_impl = static_cast<const rosidl_dynamic_message_type_support_impl_t *>(ts->data);
|
||||
|
||||
// These are allocated with new
|
||||
delete ts_impl->type_hash; // Only because we should've allocated it here
|
||||
delete ts_impl;
|
||||
delete ts;
|
||||
}
|
||||
);
|
||||
manage_description_(ts_impl->type_description);
|
||||
auto ts_impl = static_cast<const rosidl_dynamic_message_type_support_impl_t *>(
|
||||
rosidl_message_type_support_.data);
|
||||
|
||||
dynamic_message_type_ = DynamicMessageType::make_shared(
|
||||
get_shared_dynamic_serialization_support(), ts_impl->dynamic_message_type);
|
||||
get_shared_dynamic_serialization_support(), std::move(*ts_impl->dynamic_message_type));
|
||||
|
||||
dynamic_message_ = DynamicMessage::make_shared(
|
||||
get_shared_dynamic_serialization_support(), ts_impl->dynamic_message);
|
||||
|
||||
if (!rosidl_message_type_support_) {
|
||||
throw std::runtime_error("could not init rosidl message type support.");
|
||||
}
|
||||
|
||||
type_hash.release();
|
||||
get_shared_dynamic_serialization_support(), std::move(*ts_impl->dynamic_message));
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageTypeSupport::DynamicMessageTypeSupport(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
DynamicMessageType::SharedPtr dynamic_message_type,
|
||||
DynamicMessage::SharedPtr dynamic_message,
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description)
|
||||
const rosidl_runtime_c__type_description__TypeDescription & description,
|
||||
rcl_allocator_t allocator)
|
||||
: serialization_support_(serialization_support),
|
||||
dynamic_message_type_(dynamic_message_type),
|
||||
dynamic_message_(dynamic_message),
|
||||
description_(nullptr),
|
||||
rosidl_message_type_support_(nullptr)
|
||||
rosidl_message_type_support_(rosidl_get_zero_initialized_message_type_support_handle())
|
||||
{
|
||||
// Check null
|
||||
if (!serialization_support) {
|
||||
@@ -206,258 +159,157 @@ DynamicMessageTypeSupport::DynamicMessageTypeSupport(
|
||||
throw std::runtime_error("dynamic_message cannot be nullptr.");
|
||||
}
|
||||
|
||||
description_.reset(
|
||||
new rosidl_runtime_c__type_description__TypeDescription(),
|
||||
[](rosidl_runtime_c__type_description__TypeDescription * description) -> void {
|
||||
rosidl_runtime_c__type_description__TypeDescription__destroy(description);
|
||||
});
|
||||
if (!description_) {
|
||||
throw std::runtime_error("could not init type description.");
|
||||
}
|
||||
if (!rosidl_runtime_c__type_description__TypeDescription__copy(
|
||||
&description,
|
||||
description_.get()))
|
||||
{
|
||||
throw std::runtime_error("could not copy type description.");
|
||||
}
|
||||
|
||||
// Check identifiers
|
||||
if (serialization_support->get_library_identifier() !=
|
||||
dynamic_message_type->get_library_identifier())
|
||||
if (serialization_support->get_serialization_library_identifier() !=
|
||||
dynamic_message_type->get_serialization_library_identifier())
|
||||
{
|
||||
throw std::runtime_error(
|
||||
"serialization support library identifier does not match "
|
||||
"dynamic message type library identifier.");
|
||||
}
|
||||
if (dynamic_message_type->get_library_identifier() != dynamic_message->get_library_identifier()) {
|
||||
if (dynamic_message_type->get_serialization_library_identifier() !=
|
||||
dynamic_message->get_serialization_library_identifier())
|
||||
{
|
||||
throw std::runtime_error(
|
||||
"dynamic message type library identifier does not match "
|
||||
"dynamic message library identifier.");
|
||||
}
|
||||
|
||||
// Check pointers
|
||||
/* *INDENT-OFF* */
|
||||
if (serialization_support->get_rosidl_serialization_support() !=
|
||||
dynamic_message_type
|
||||
->get_shared_dynamic_serialization_support()
|
||||
->get_rosidl_serialization_support())
|
||||
{
|
||||
throw std::runtime_error("serialization support pointer does not match dynamic message type's");
|
||||
}
|
||||
if (dynamic_message_type
|
||||
->get_shared_dynamic_serialization_support()
|
||||
->get_rosidl_serialization_support() !=
|
||||
dynamic_message_type
|
||||
->get_shared_dynamic_serialization_support()
|
||||
->get_rosidl_serialization_support())
|
||||
{
|
||||
throw std::runtime_error("serialization support does not match pointer dynamic message type's");
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
|
||||
init_rosidl_message_type_support_(
|
||||
serialization_support_, dynamic_message_type_, dynamic_message_, description_.get());
|
||||
if (!rosidl_message_type_support_) {
|
||||
throw std::runtime_error("could not init rosidl message type support.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageTypeSupport::~DynamicMessageTypeSupport() {}
|
||||
|
||||
|
||||
void
|
||||
DynamicMessageTypeSupport::manage_description_(
|
||||
rosidl_runtime_c__type_description__TypeDescription * description)
|
||||
{
|
||||
if (!description) {
|
||||
throw std::runtime_error("description cannot be nullptr");
|
||||
}
|
||||
description_.reset(
|
||||
description,
|
||||
[](rosidl_runtime_c__type_description__TypeDescription * description) -> void {
|
||||
rosidl_runtime_c__type_description__TypeDescription__destroy(description);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// This looks like rmw_`dynamic_message_type_support_handle_create()`, but instead just aggregates
|
||||
// already initialized objects
|
||||
void
|
||||
DynamicMessageTypeSupport::init_rosidl_message_type_support_(
|
||||
DynamicSerializationSupport::SharedPtr serialization_support,
|
||||
DynamicMessageType::SharedPtr dynamic_message_type,
|
||||
DynamicMessage::SharedPtr dynamic_message,
|
||||
rosidl_runtime_c__type_description__TypeDescription * description)
|
||||
{
|
||||
bool middleware_supports_type_discovery = rmw_feature_supported(
|
||||
RMW_MIDDLEWARE_SUPPORTS_TYPE_DISCOVERY);
|
||||
|
||||
if (!middleware_supports_type_discovery && !description) {
|
||||
throw std::runtime_error(
|
||||
"Middleware does not support type discovery! Deferred dynamic type"
|
||||
"message type support will never be populated! You must provide a type "
|
||||
"description.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto type_hash = std::make_unique<rosidl_type_hash_t>();
|
||||
rosidl_type_hash_t type_hash;
|
||||
rcutils_ret_t hash_ret = rcl_calculate_type_hash(
|
||||
// TODO(methylDragon): Swap this out with the conversion function when it is ready
|
||||
// from https://github.com/ros2/rcl/pull/1052
|
||||
reinterpret_cast<type_description_interfaces__msg__TypeDescription *>(description),
|
||||
type_hash.get());
|
||||
if (hash_ret != RCL_RET_OK || !type_hash) {
|
||||
throw std::runtime_error("failed to get type hash");
|
||||
reinterpret_cast<const type_description_interfaces__msg__TypeDescription *>(&description),
|
||||
&type_hash);
|
||||
if (hash_ret != RCL_RET_OK) {
|
||||
std::string error_msg = std::string("failed to get type hash: ") + rcl_get_error_string().str;
|
||||
rcl_reset_error();
|
||||
throw std::runtime_error(error_msg);
|
||||
}
|
||||
|
||||
rosidl_dynamic_message_type_support_impl_t * ts_impl =
|
||||
new rosidl_dynamic_message_type_support_impl_t {
|
||||
type_hash.get(), // type_hash
|
||||
description, // type_description
|
||||
nullptr, // NOTE(methylDragon): Not supported for now // type_description_sources
|
||||
serialization_support->get_rosidl_serialization_support(), // serialization_support
|
||||
dynamic_message_type->get_rosidl_dynamic_type(), // dynamic_message_type
|
||||
dynamic_message->get_rosidl_dynamic_data() // dynamic_message
|
||||
};
|
||||
auto ts_impl = static_cast<rosidl_dynamic_message_type_support_impl_t *>(
|
||||
allocator.zero_allocate(1, sizeof(rosidl_dynamic_message_type_support_impl_t), allocator.state)
|
||||
);
|
||||
if (!ts_impl) {
|
||||
throw std::runtime_error(
|
||||
"Could not allocate rosidl_dynamic_message_type_support_impl_t struct");
|
||||
return;
|
||||
throw std::runtime_error("could not allocate rosidl_message_type_support_t");
|
||||
}
|
||||
|
||||
// NOTE(methylDragon): We don't finalize the rosidl_message_type_support->data since its members
|
||||
// are managed by the passed in SharedPtr wrapper classes. We just delete it.
|
||||
rosidl_message_type_support_.reset(
|
||||
new rosidl_message_type_support_t{
|
||||
rosidl_get_dynamic_typesupport_identifier(), // typesupport_identifier
|
||||
ts_impl, // data
|
||||
get_message_typesupport_handle_function, // func
|
||||
ts_impl->allocator = allocator;
|
||||
ts_impl->type_hash = type_hash;
|
||||
if (!rosidl_runtime_c__type_description__TypeDescription__copy(
|
||||
&description, &ts_impl->type_description))
|
||||
{
|
||||
throw std::runtime_error("could not copy type description");
|
||||
}
|
||||
// ts_impl->type_description_sources = // Not used
|
||||
|
||||
ts_impl->serialization_support = serialization_support->get_rosidl_serialization_support();
|
||||
ts_impl->dynamic_message_type = &dynamic_message_type->get_rosidl_dynamic_type();
|
||||
ts_impl->dynamic_message = &dynamic_message->get_rosidl_dynamic_data();
|
||||
|
||||
rosidl_message_type_support_ = {
|
||||
rosidl_get_dynamic_typesupport_identifier(), // typesupport_identifier
|
||||
ts_impl, // data
|
||||
get_message_typesupport_handle_function, // func
|
||||
// get_type_hash_func
|
||||
rosidl_get_dynamic_message_type_support_type_hash_function,
|
||||
// get_type_description_func
|
||||
rosidl_get_dynamic_message_type_support_type_description_function,
|
||||
// get_type_description_sources_func
|
||||
rosidl_get_dynamic_message_type_support_type_description_sources_function
|
||||
},
|
||||
[](rosidl_message_type_support_t * ts) -> void {
|
||||
auto ts_impl = static_cast<const rosidl_dynamic_message_type_support_impl_t *>(ts->data);
|
||||
auto allocator = rcl_get_default_allocator();
|
||||
// Only because we should've allocated it here (also it's C allocated)
|
||||
allocator.deallocate(ts_impl->type_hash, &allocator.state);
|
||||
delete ts_impl;
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
if (!rosidl_message_type_support_) {
|
||||
throw std::runtime_error("Could not allocate rosidl_message_type_support_t struct");
|
||||
delete ts_impl;
|
||||
DynamicMessageTypeSupport::~DynamicMessageTypeSupport()
|
||||
{
|
||||
// These must go first
|
||||
serialization_support_.reset();
|
||||
dynamic_message_type_.reset();
|
||||
dynamic_message_.reset();
|
||||
|
||||
// Early return if type support isn't populated to avoid segfaults
|
||||
if (!rosidl_message_type_support_.data) {
|
||||
return;
|
||||
}
|
||||
|
||||
type_hash.release();
|
||||
// We only partially finalize the rosidl_message_type_support->data since its pointer members are
|
||||
// managed by their respective SharedPtr wrapper classes.
|
||||
auto ts_impl = static_cast<rosidl_dynamic_message_type_support_impl_t *>(
|
||||
const_cast<void *>(rosidl_message_type_support_.data)
|
||||
);
|
||||
rcutils_allocator_t allocator = ts_impl->allocator;
|
||||
|
||||
rosidl_runtime_c__type_description__TypeDescription__fini(&ts_impl->type_description);
|
||||
rosidl_runtime_c__type_description__TypeSource__Sequence__fini(
|
||||
&ts_impl->type_description_sources);
|
||||
allocator.deallocate(static_cast<void *>(ts_impl), allocator.state); // Always C allocated
|
||||
}
|
||||
|
||||
|
||||
// GETTERS =========================================================================================
|
||||
const std::string
|
||||
DynamicMessageTypeSupport::get_library_identifier() const
|
||||
DynamicMessageTypeSupport::get_serialization_library_identifier() const
|
||||
{
|
||||
return serialization_support_->get_library_identifier();
|
||||
return serialization_support_->get_serialization_library_identifier();
|
||||
}
|
||||
|
||||
|
||||
rosidl_message_type_support_t *
|
||||
rosidl_message_type_support_t &
|
||||
DynamicMessageTypeSupport::get_rosidl_message_type_support()
|
||||
{
|
||||
return rosidl_message_type_support_.get();
|
||||
return rosidl_message_type_support_;
|
||||
}
|
||||
|
||||
|
||||
const rosidl_message_type_support_t *
|
||||
DynamicMessageTypeSupport::get_rosidl_message_type_support() const
|
||||
{
|
||||
return rosidl_message_type_support_.get();
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<rosidl_message_type_support_t>
|
||||
DynamicMessageTypeSupport::get_shared_rosidl_message_type_support()
|
||||
const rosidl_message_type_support_t &
|
||||
DynamicMessageTypeSupport::get_const_rosidl_message_type_support()
|
||||
{
|
||||
return rosidl_message_type_support_;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<const rosidl_message_type_support_t>
|
||||
DynamicMessageTypeSupport::get_shared_rosidl_message_type_support() const
|
||||
const rosidl_message_type_support_t &
|
||||
DynamicMessageTypeSupport::get_const_rosidl_message_type_support() const
|
||||
{
|
||||
return rosidl_message_type_support_;
|
||||
}
|
||||
|
||||
|
||||
rosidl_runtime_c__type_description__TypeDescription *
|
||||
DynamicMessageTypeSupport::get_rosidl_runtime_c_type_description()
|
||||
{
|
||||
return description_.get();
|
||||
}
|
||||
|
||||
|
||||
const rosidl_runtime_c__type_description__TypeDescription *
|
||||
const rosidl_runtime_c__type_description__TypeDescription &
|
||||
DynamicMessageTypeSupport::get_rosidl_runtime_c_type_description() const
|
||||
{
|
||||
return description_.get();
|
||||
auto ts_impl = static_cast<const rosidl_dynamic_message_type_support_impl_t *>(
|
||||
get_const_rosidl_message_type_support().data
|
||||
);
|
||||
return ts_impl->type_description;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<rosidl_runtime_c__type_description__TypeDescription>
|
||||
DynamicMessageTypeSupport::get_shared_rosidl_runtime_c_type_description()
|
||||
{
|
||||
return description_;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<const rosidl_runtime_c__type_description__TypeDescription>
|
||||
DynamicMessageTypeSupport::get_shared_rosidl_runtime_c_type_description() const
|
||||
{
|
||||
return description_;
|
||||
}
|
||||
|
||||
|
||||
DynamicSerializationSupport::SharedPtr
|
||||
DynamicMessageTypeSupport::get_shared_dynamic_serialization_support()
|
||||
{
|
||||
return serialization_support_;
|
||||
}
|
||||
|
||||
|
||||
DynamicSerializationSupport::ConstSharedPtr
|
||||
DynamicMessageTypeSupport::get_shared_dynamic_serialization_support() const
|
||||
{
|
||||
return serialization_support_;
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageType::SharedPtr
|
||||
DynamicMessageTypeSupport::get_shared_dynamic_message_type()
|
||||
{
|
||||
return dynamic_message_type_;
|
||||
}
|
||||
|
||||
|
||||
DynamicMessageType::ConstSharedPtr
|
||||
DynamicMessageTypeSupport::get_shared_dynamic_message_type() const
|
||||
{
|
||||
return dynamic_message_type_;
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage::SharedPtr
|
||||
DynamicMessageTypeSupport::get_shared_dynamic_message()
|
||||
{
|
||||
return dynamic_message_;
|
||||
}
|
||||
|
||||
|
||||
DynamicMessage::ConstSharedPtr
|
||||
DynamicMessageTypeSupport::get_shared_dynamic_message() const
|
||||
{
|
||||
|
||||
@@ -12,78 +12,56 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <rcl/allocator.h>
|
||||
#include <rcutils/logging_macros.h>
|
||||
#include <rmw/dynamic_message_type_support.h>
|
||||
#include <rmw/ret_types.h>
|
||||
#include <rosidl_dynamic_typesupport/api/serialization_support.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "rcutils/logging_macros.h"
|
||||
#include "rmw/dynamic_message_type_support.h"
|
||||
#include "rmw/ret_types.h"
|
||||
|
||||
#include "rclcpp/dynamic_typesupport/dynamic_serialization_support.hpp"
|
||||
#include "rclcpp/exceptions.hpp"
|
||||
|
||||
|
||||
using rclcpp::dynamic_typesupport::DynamicSerializationSupport;
|
||||
|
||||
// CONSTRUCTION ====================================================================================
|
||||
DynamicSerializationSupport::DynamicSerializationSupport()
|
||||
: DynamicSerializationSupport::DynamicSerializationSupport("") {}
|
||||
DynamicSerializationSupport::DynamicSerializationSupport(rcl_allocator_t allocator)
|
||||
: DynamicSerializationSupport::DynamicSerializationSupport("", allocator) {}
|
||||
|
||||
DynamicSerializationSupport::DynamicSerializationSupport(
|
||||
const std::string & serialization_library_name)
|
||||
: rosidl_serialization_support_(nullptr)
|
||||
const std::string & serialization_library_name,
|
||||
rcl_allocator_t allocator)
|
||||
: rosidl_serialization_support_(
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_serialization_support())
|
||||
{
|
||||
rosidl_dynamic_typesupport_serialization_support_t * rosidl_serialization_support = nullptr;
|
||||
rmw_ret_t ret = RMW_RET_ERROR;
|
||||
|
||||
if (serialization_library_name.empty()) {
|
||||
ret = rmw_get_serialization_support(NULL, &rosidl_serialization_support);
|
||||
ret = rmw_serialization_support_init(NULL, &allocator, &rosidl_serialization_support_);
|
||||
} else {
|
||||
ret = rmw_get_serialization_support(
|
||||
serialization_library_name.c_str(), &rosidl_serialization_support);
|
||||
ret = rmw_serialization_support_init(
|
||||
serialization_library_name.c_str(), &allocator, &rosidl_serialization_support_);
|
||||
}
|
||||
|
||||
if (ret != RMW_RET_OK || !rosidl_serialization_support) {
|
||||
throw std::runtime_error("could not create new serialization support object");
|
||||
if (ret != RCL_RET_OK) {
|
||||
std::string error_msg =
|
||||
std::string("could not initialize new serialization support object: ") +
|
||||
rcl_get_error_string().str;
|
||||
rcl_reset_error();
|
||||
throw std::runtime_error(error_msg);
|
||||
}
|
||||
|
||||
rosidl_serialization_support_.reset(
|
||||
rosidl_serialization_support,
|
||||
// Custom deleter
|
||||
[](rosidl_dynamic_typesupport_serialization_support_t * rosidl_serialization_support) -> void {
|
||||
rosidl_dynamic_typesupport_serialization_support_destroy(rosidl_serialization_support);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
DynamicSerializationSupport::DynamicSerializationSupport(
|
||||
rosidl_dynamic_typesupport_serialization_support_t * rosidl_serialization_support)
|
||||
: rosidl_serialization_support_(nullptr)
|
||||
{
|
||||
if (!rosidl_serialization_support) {
|
||||
throw std::runtime_error("serialization support cannot be nullptr!");
|
||||
}
|
||||
|
||||
// Custom deleter
|
||||
rosidl_serialization_support_.reset(
|
||||
rosidl_serialization_support,
|
||||
[](rosidl_dynamic_typesupport_serialization_support_t * rosidl_serialization_support) -> void {
|
||||
rosidl_dynamic_typesupport_serialization_support_destroy(rosidl_serialization_support);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
DynamicSerializationSupport::DynamicSerializationSupport(
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_serialization_support_t> rosidl_serialization_support)
|
||||
: rosidl_serialization_support_(rosidl_serialization_support) {}
|
||||
|
||||
rosidl_dynamic_typesupport_serialization_support_t && rosidl_serialization_support)
|
||||
: rosidl_serialization_support_(std::move(rosidl_serialization_support)) {}
|
||||
|
||||
DynamicSerializationSupport::DynamicSerializationSupport(
|
||||
DynamicSerializationSupport && other) noexcept
|
||||
: rosidl_serialization_support_(std::exchange(other.rosidl_serialization_support_, nullptr)) {}
|
||||
|
||||
: rosidl_serialization_support_(std::exchange(
|
||||
other.rosidl_serialization_support_,
|
||||
rosidl_dynamic_typesupport_get_zero_initialized_serialization_support())) {}
|
||||
|
||||
DynamicSerializationSupport &
|
||||
DynamicSerializationSupport::operator=(DynamicSerializationSupport && other) noexcept
|
||||
@@ -92,45 +70,29 @@ DynamicSerializationSupport::operator=(DynamicSerializationSupport && other) noe
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
DynamicSerializationSupport::~DynamicSerializationSupport() {}
|
||||
DynamicSerializationSupport::~DynamicSerializationSupport()
|
||||
{
|
||||
rosidl_dynamic_typesupport_serialization_support_fini(&rosidl_serialization_support_);
|
||||
}
|
||||
|
||||
|
||||
// GETTERS =========================================================================================
|
||||
const std::string
|
||||
DynamicSerializationSupport::get_library_identifier() const
|
||||
DynamicSerializationSupport::get_serialization_library_identifier() const
|
||||
{
|
||||
return std::string(
|
||||
rosidl_dynamic_typesupport_serialization_support_get_library_identifier(
|
||||
rosidl_serialization_support_.get()));
|
||||
&rosidl_serialization_support_));
|
||||
}
|
||||
|
||||
|
||||
rosidl_dynamic_typesupport_serialization_support_t *
|
||||
rosidl_dynamic_typesupport_serialization_support_t &
|
||||
DynamicSerializationSupport::get_rosidl_serialization_support()
|
||||
{
|
||||
return rosidl_serialization_support_.get();
|
||||
return rosidl_serialization_support_;
|
||||
}
|
||||
|
||||
|
||||
const rosidl_dynamic_typesupport_serialization_support_t *
|
||||
const rosidl_dynamic_typesupport_serialization_support_t &
|
||||
DynamicSerializationSupport::get_rosidl_serialization_support() const
|
||||
{
|
||||
return rosidl_serialization_support_.get();
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<rosidl_dynamic_typesupport_serialization_support_t>
|
||||
DynamicSerializationSupport::get_shared_rosidl_serialization_support()
|
||||
{
|
||||
return std::shared_ptr<rosidl_dynamic_typesupport_serialization_support_t>(
|
||||
shared_from_this(), rosidl_serialization_support_.get());
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<const rosidl_dynamic_typesupport_serialization_support_t>
|
||||
DynamicSerializationSupport::get_shared_rosidl_serialization_support() const
|
||||
{
|
||||
return std::shared_ptr<const rosidl_dynamic_typesupport_serialization_support_t>(
|
||||
shared_from_this(), rosidl_serialization_support_.get());
|
||||
return rosidl_serialization_support_;
|
||||
}
|
||||
|
||||
@@ -716,7 +716,7 @@ Executor::execute_subscription(rclcpp::SubscriptionBase::SharedPtr subscription)
|
||||
[&]() {return subscription->take_serialized(*serialized_msg.get(), message_info);},
|
||||
[&]()
|
||||
{
|
||||
bool ret = dynamic_message->deserialize(&serialized_msg->get_rcl_serialized_message());
|
||||
bool ret = dynamic_message->deserialize(serialized_msg->get_rcl_serialized_message());
|
||||
if (!ret) {
|
||||
throw_from_rcl_error(ret, "Couldn't convert serialized message to dynamic data!");
|
||||
}
|
||||
|
||||
@@ -536,7 +536,7 @@ SubscriptionBase::take_dynamic_message(
|
||||
{
|
||||
rcl_ret_t ret = rcl_take_dynamic_message(
|
||||
this->get_subscription_handle().get(),
|
||||
message_out.get_rosidl_dynamic_data(),
|
||||
&message_out.get_rosidl_dynamic_data(),
|
||||
&message_info_out.get_rmw_message_info(),
|
||||
nullptr);
|
||||
if (RCL_RET_SUBSCRIPTION_TAKE_FAILED == ret) {
|
||||
|
||||
Reference in New Issue
Block a user