Skip to content

Commit

Permalink
Refs 17138. API update fixes ... part 2
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Barro <[email protected]>
  • Loading branch information
Miguel Barro committed Jun 19, 2023
1 parent 16c1501 commit b21a6c6
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 95 deletions.
2 changes: 1 addition & 1 deletion include/fastrtps/types/TypesBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ namespace fastrtps {
namespace types {
namespace v1_3 {

using DynamicType_ptr = std::shared_ptr<DynamicType>;
using DynamicType_ptr = std::shared_ptr<const DynamicType>;
using DynamicTypeBuilder_ptr = std::shared_ptr<DynamicTypeBuilder>;
using DynamicTypeBuilder_cptr = std::shared_ptr<const DynamicTypeBuilder>;

Expand Down
4 changes: 2 additions & 2 deletions include/fastrtps/types/v1_3/DynamicPubSubType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DynamicPubSubType : public virtual eprosima::fastdds::dds::TopicDataType
RTPS_DllAPI DynamicPubSubType() = default;

RTPS_DllAPI DynamicPubSubType(
v1_3::DynamicType& type);
const v1_3::DynamicType& type);

RTPS_DllAPI virtual ~DynamicPubSubType();

Expand Down Expand Up @@ -74,7 +74,7 @@ class DynamicPubSubType : public virtual eprosima::fastdds::dds::TopicDataType
const v1_3::DynamicData& data);

RTPS_DllAPI ReturnCode_t SetDynamicType(
v1_3::DynamicType& type);
const v1_3::DynamicType& type);
};

} // namespace v1_3
Expand Down
5 changes: 4 additions & 1 deletion include/fastrtps/types/v1_3/DynamicTypeBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class DynamicTypeBuilder final
static void before_destruction(
DynamicType* b);

static ReturnCode_t delete_type(
const DynamicType* type) noexcept;

// Only create objects from the associated factory
struct use_the_create_method
{
Expand Down Expand Up @@ -171,7 +174,7 @@ class DynamicTypeBuilder final
* non-const method usage.
* @return new @ref DynamicType object reference
*/
RTPS_DllAPI DynamicType* build() const;
RTPS_DllAPI const DynamicType* build() const;

RTPS_DllAPI ReturnCode_t copy_from(
const DynamicTypeBuilder* other);
Expand Down
40 changes: 20 additions & 20 deletions include/fastrtps/types/v1_3/DynamicTypeBuilderFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class DynamicTypeBuilderFactory final
* @param[in] kind type identifying the primitive type to retrieve
* @return @ref DynamicType object
*/
RTPS_DllAPI DynamicType* get_primitive_type(
RTPS_DllAPI const DynamicType* get_primitive_type(
TypeKind kind) noexcept;

/**
Expand Down Expand Up @@ -470,7 +470,7 @@ class DynamicTypeBuilderFactory final
* Creates a new @ref DynamicTypeBuilder object representing an enum
* @return new @ref DynamicTypeBuilder object
*/
RTPS_DllAPI DynamicTypeBuilder* create_enum_type();
RTPS_DllAPI const DynamicTypeBuilder* create_enum_type();

/**
* Returns a @ref DynamicTypeBuilder associated with a `TypeKind::TK_STRUCTURE`
Expand Down Expand Up @@ -499,67 +499,67 @@ class DynamicTypeBuilderFactory final
* @param[in] name string annotation identifier
* @return new @ref DynamicTypeBuilder object
*/
RTPS_DllAPI DynamicType* create_annotation_primitive(
RTPS_DllAPI const DynamicType* create_annotation_primitive(
const std::string& name);

//! returns type instantiation of the @ref DynamicTypeBuilderFactory::create_alias_type builder
RTPS_DllAPI DynamicType* get_alias_type(
RTPS_DllAPI const DynamicType* get_alias_type(
const DynamicType& base_type,
const std::string& sName);

//! returns the cache type associated to create_int16_type()
RTPS_DllAPI DynamicType* get_int16_type();
RTPS_DllAPI const DynamicType* get_int16_type();

//! returns the cache type associated to create_uint16_type()
RTPS_DllAPI DynamicType* get_uint16_type();
RTPS_DllAPI const DynamicType* get_uint16_type();

//! returns the cache type associated to create_int32_type()
RTPS_DllAPI DynamicType* get_int32_type();
RTPS_DllAPI const DynamicType* get_int32_type();

//! returns the cache type associated to create_uint32_type()
RTPS_DllAPI DynamicType* get_uint32_type();
RTPS_DllAPI const DynamicType* get_uint32_type();

//! returns the cache type associated to create_int64_type()
RTPS_DllAPI DynamicType* get_int64_type();
RTPS_DllAPI const DynamicType* get_int64_type();

//! returns the cache type associated to create_uint64_type()
RTPS_DllAPI DynamicType* get_uint64_type();
RTPS_DllAPI const DynamicType* get_uint64_type();

//! returns the cache type associated to create_float32_type()
RTPS_DllAPI DynamicType* get_float32_type();
RTPS_DllAPI const DynamicType* get_float32_type();

//! returns the cache type associated to create_float64_type()
RTPS_DllAPI DynamicType* get_float64_type();
RTPS_DllAPI const DynamicType* get_float64_type();

//! returns the cache type associated to create_float128_type()
RTPS_DllAPI DynamicType* get_float128_type();
RTPS_DllAPI const DynamicType* get_float128_type();

//! returns the cache type associated to create_char8_type()
RTPS_DllAPI DynamicType* get_char8_type();
RTPS_DllAPI const DynamicType* get_char8_type();

//! returns the cache type associated to create_char16_type()
RTPS_DllAPI DynamicType* get_char16_type();
RTPS_DllAPI const DynamicType* get_char16_type();

//! returns the cache type associated to create_bool_type()
RTPS_DllAPI DynamicType* get_bool_type();
RTPS_DllAPI const DynamicType* get_bool_type();

//! returns the cache type associated to get_byte_type()
RTPS_DllAPI DynamicType* get_byte_type();
RTPS_DllAPI const DynamicType* get_byte_type();

//! returns the cache type associated to create_string_type()
RTPS_DllAPI DynamicType* get_string_type(
RTPS_DllAPI const DynamicType* get_string_type(
uint32_t bound = LENGTH_UNLIMITED) noexcept;

//! returns the cache type associated to create_wstring_type()
RTPS_DllAPI DynamicType* get_wstring_type(
RTPS_DllAPI const DynamicType* get_wstring_type(
uint32_t bound = LENGTH_UNLIMITED) noexcept;

/**
* Creates a new @ref DynamicTypeBuilder object representing a bitset
* @param[in] bound `uint32_t` representing the maximum number of elements that may be stored.
* @return new @ref DynamicTypeBuilder object
*/
RTPS_DllAPI DynamicType* get_bitset_type(
RTPS_DllAPI const DynamicType* get_bitset_type(
uint32_t bound);

RTPS_DllAPI void build_type_identifier(
Expand Down
18 changes: 9 additions & 9 deletions include/fastrtps/utils/custom_allocators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ namespace detail {

template<class T>
class external_reference_counting
: public std::enable_shared_from_this<T>
: public std::enable_shared_from_this<const T>
{
//! Keeps the object alive is external references are held
std::shared_ptr<T> external_lock_;
mutable std::shared_ptr<const T> external_lock_;
//! External references tracker
std::atomic_long counter_ = {0l};
mutable std::atomic_long counter_ = {0l};

protected:

Expand All @@ -231,7 +231,7 @@ class external_reference_counting
return counter_;
}

long add_ref()
long add_ref() const
{
long former = counter_;

Expand All @@ -248,8 +248,8 @@ class external_reference_counting
}

// sync with other threads release() operations
std::shared_ptr<T> empty;
std::shared_ptr<T> inner = this->shared_from_this();
std::shared_ptr<const T> empty;
std::shared_ptr<const T> inner = this->shared_from_this();

while (!std::atomic_compare_exchange_strong(
&external_lock_,
Expand Down Expand Up @@ -281,7 +281,7 @@ class external_reference_counting
}
}

long release()
long release() const
{
long former = counter_;

Expand All @@ -301,13 +301,13 @@ class external_reference_counting
}

// sync with other threads add_ref() operations
std::shared_ptr<T> inner = this->shared_from_this(),
std::shared_ptr<const T> inner = this->shared_from_this(),
cmp = inner;

while (!std::atomic_compare_exchange_strong(
&external_lock_,
&cmp,
std::shared_ptr<T>{}))
std::shared_ptr<const T>{}))
{
if (!cmp)
{
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/dynamic-types/v1_3/DynamicDataFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ DynamicData* DynamicDataFactory::create_data(
{
if (pBuilder != nullptr && pBuilder->is_consistent())
{
DynamicType_ptr pType = pBuilder->build();
DynamicType_ptr pType{pBuilder->build()};
return create_data(pType);
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/dynamic-types/v1_3/DynamicPubSubType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
using namespace eprosima::fastrtps::types::v1_3;

DynamicPubSubType::DynamicPubSubType(
DynamicType& type)
const DynamicType& type)
: dynamic_type_(&type)
{
UpdateDynamicTypeInfo();
Expand Down Expand Up @@ -66,7 +66,7 @@ ReturnCode_t DynamicPubSubType::SetDynamicType(
}

ReturnCode_t DynamicPubSubType::SetDynamicType(
DynamicType& type)
const DynamicType& type)
{
if (!dynamic_type_)
{
Expand Down
14 changes: 13 additions & 1 deletion src/cpp/dynamic-types/v1_3/DynamicTypeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ ReturnCode_t DynamicTypeBuilder::add_member(
return ReturnCode_t::RETCODE_OK;
}

DynamicType* DynamicTypeBuilder::build() const
const DynamicType* DynamicTypeBuilder::build() const
{
// check if an instance is already available
// and is still valid
Expand Down Expand Up @@ -334,3 +334,15 @@ std::function<void(const DynamicTypeBuilder*)> eprosima::fastrtps::types::v1_3::

return nullptr;
}

ReturnCode_t DynamicTypeBuilder::delete_type(
const DynamicType* type) noexcept
{
if (type != nullptr)
{
type->release();
return ReturnCode_t::RETCODE_OK;
}

return ReturnCode_t::RETCODE_PRECONDITION_NOT_MET;
}
Loading

0 comments on commit b21a6c6

Please sign in to comment.