Skip to content

Commit

Permalink
Binary DomainParticipant
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
pablogs9 committed Apr 8, 2021
1 parent c9b43d9 commit 28654ec
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 20 deletions.
5 changes: 5 additions & 0 deletions include/uxr/agent/middleware/Middleware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define UXR_AGENT_MIDDLEWARE_MIDDLEWARE_HPP_

#include <uxr/agent/config.hpp>
#include <uxr/agent/types/XRCETypes.hpp>

#include <string>
#include <cstdint>
Expand Down Expand Up @@ -64,6 +65,10 @@ class Middleware
int16_t domain_id,
const std::string& xml) = 0;

virtual bool create_participant_by_bin(
uint16_t participant_id,
const dds::xrce::OBJK_DomainParticipant_Binary participant_xrce) = 0;

virtual bool create_topic_by_ref(
uint16_t topic_id,
uint16_t participant_id,
Expand Down
4 changes: 4 additions & 0 deletions include/uxr/agent/middleware/ced/CedMiddleware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class CedMiddleware : public Middleware
int16_t domain_id,
const std::string&) override;

bool create_participant_by_bin(
uint16_t participant_id,
const dds::xrce::OBJK_DomainParticipant_Binary participant_xrce) override;

/**
* @startuml
* !include agent/middleware/ced/create_topic.puml!0
Expand Down
4 changes: 4 additions & 0 deletions include/uxr/agent/middleware/fast/FastMiddleware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class FastMiddleware : public Middleware
int16_t domain_id,
const std::string& xml) override;

bool create_participant_by_bin(
uint16_t participant_id,
const dds::xrce::OBJK_DomainParticipant_Binary participant_xrce) override;

bool create_topic_by_ref(
uint16_t topic_id,
uint16_t participant_id,
Expand Down
1 change: 1 addition & 0 deletions include/uxr/agent/middleware/fastdds/FastDDSEntities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class FastDDSParticipant

bool create_by_ref(const std::string& ref);
bool create_by_xml(const std::string& xml);
bool create_by_bin(const dds::xrce::OBJK_DomainParticipant_Binary participant_xrce);
bool match_from_ref(const std::string& ref) const;
bool match_from_xml(const std::string& xml) const;

Expand Down
4 changes: 4 additions & 0 deletions include/uxr/agent/middleware/fastdds/FastDDSMiddleware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class FastDDSMiddleware : public Middleware
int16_t domain_id,
const std::string& xml) override;

bool create_participant_by_bin(
uint16_t participant_id,
const dds::xrce::OBJK_DomainParticipant_Binary participant_xrce);

bool create_topic_by_ref(
uint16_t topic_id,
uint16_t participant_id,
Expand Down
12 changes: 6 additions & 6 deletions include/uxr/agent/types/XRCETypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3743,7 +3743,7 @@ class OBJK_DomainParticipant_Binary
*/
inline const std::string& domain_referente() const
{
return m_domain_referente;
return *m_domain_referente;
}

/*!
Expand All @@ -3752,7 +3752,7 @@ class OBJK_DomainParticipant_Binary
*/
inline std::string& domain_referente()
{
return m_domain_referente;
return *m_domain_referente;
}
/*!
* @brief This function copies the value in member qos_profile
Expand All @@ -3778,7 +3778,7 @@ class OBJK_DomainParticipant_Binary
*/
inline const std::string& qos_profile() const
{
return m_qos_profile;
return *m_qos_profile;
}

/*!
Expand All @@ -3787,7 +3787,7 @@ class OBJK_DomainParticipant_Binary
*/
inline std::string& qos_profile()
{
return m_qos_profile;
return *m_qos_profile;
}

/*!
Expand Down Expand Up @@ -3820,8 +3820,8 @@ class OBJK_DomainParticipant_Binary

private:
int32_t m_domain_id;
std::string m_domain_referente;
std::string m_qos_profile;
eprosima::Optional<std::string> m_domain_referente;
eprosima::Optional<std::string> m_qos_profile;
};
/*!
* @brief This class represents the structure OBJK_Topic_Binary defined by the user in the IDL file.
Expand Down
7 changes: 7 additions & 0 deletions src/cpp/middleware/ced/CedMiddleware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ bool CedMiddleware::create_participant_by_xml(
return create_participant_by_ref(participant_id, domain_id, xml);
}

bool CedMiddleware::create_participant_by_bin(
uint16_t /*participant_id*/,
dds::xrce::OBJK_DomainParticipant_Binary /*participant*/)
{
return false;
}

static
std::shared_ptr<CedTopic> create_topic(
std::shared_ptr<CedParticipant>& participant,
Expand Down
7 changes: 7 additions & 0 deletions src/cpp/middleware/fast/FastMiddleware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ bool FastMiddleware::create_participant_by_xml(
return rv;
}

bool FastMiddleware::create_participant_by_bin(
uint16_t /*participant_id*/,
dds::xrce::OBJK_DomainParticipant_Binary /*participant*/)
{
return false;
}

static
std::shared_ptr<FastTopic> create_topic(
std::shared_ptr<FastParticipant>& participant,
Expand Down
13 changes: 13 additions & 0 deletions src/cpp/middleware/fastdds/FastDDSEntities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,19 @@ bool FastDDSParticipant::create_by_xml(
return rv;
}

bool FastDDSParticipant::create_by_bin(
const dds::xrce::OBJK_DomainParticipant_Binary /*participant_xrce*/)
{
bool rv = false;
if (nullptr == ptr_)
{
fastdds::dds::DomainParticipantQos qos;
ptr_ = factory_->create_participant(domain_id_, qos);
rv = (nullptr != ptr_);
}
return rv;
}

bool FastDDSParticipant::match_from_ref(
const std::string& ref) const
{
Expand Down
20 changes: 20 additions & 0 deletions src/cpp/middleware/fastdds/FastDDSMiddleware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,26 @@ bool FastDDSMiddleware::create_participant_by_xml(
return rv;
}

bool FastDDSMiddleware::create_participant_by_bin(
uint16_t participant_id,
dds::xrce::OBJK_DomainParticipant_Binary participant_xrce)
{
bool rv = false;
std::shared_ptr<FastDDSParticipant> participant(new FastDDSParticipant(participant_xrce.domain_id()));
if (participant->create_by_bin(participant_xrce))
{
auto emplace_res = participants_.emplace(participant_id, std::move(participant));
rv = emplace_res.second;
if (rv)
{
callback_factory_.execute_callbacks(Middleware::Kind::FASTDDS,
middleware::CallbackKind::CREATE_PARTICIPANT,
**(emplace_res.first->second));
}
}
return rv;
}

static
std::shared_ptr<FastDDSTopic> create_topic(
std::shared_ptr<FastDDSParticipant>& participant,
Expand Down
14 changes: 14 additions & 0 deletions src/cpp/participant/Participant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <uxr/agent/participant/Participant.hpp>
#include <uxr/agent/client/ProxyClient.hpp>
#include <uxr/agent/types/XRCETypes.hpp>

namespace eprosima {
namespace uxr {
Expand All @@ -40,6 +41,19 @@ std::unique_ptr<Participant> Participant::create(
created_entity = proxy_client->get_middleware().create_participant_by_xml(raw_object_id, representation.domain_id(), xml_rep);
break;
}
case dds::xrce::REPRESENTATION_IN_BINARY:
{
auto rep = representation.representation();
dds::xrce::OBJK_DomainParticipant_Binary participant_xrce;
participant_xrce.domain_id(representation.domain_id());

fastcdr::FastBuffer fastbuffer{reinterpret_cast<char*>(const_cast<uint8_t*>(rep.binary_representation().data())), rep.binary_representation().size()};
eprosima::fastcdr::Cdr cdr(fastbuffer);
participant_xrce.deserialize(cdr);

created_entity = proxy_client->get_middleware().create_participant_by_bin(raw_object_id, participant_xrce);
break;
}
default:
break;
}
Expand Down
41 changes: 27 additions & 14 deletions src/cpp/types/XRCETypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3114,8 +3114,6 @@ void dds::xrce::REPLIER_Representation::deserialize(eprosima::fastcdr::Cdr &dcdr
dds::xrce::OBJK_DomainParticipant_Binary::OBJK_DomainParticipant_Binary()
{
m_domain_id = 0;


}

dds::xrce::OBJK_DomainParticipant_Binary::~OBJK_DomainParticipant_Binary()
Expand Down Expand Up @@ -3158,8 +3156,6 @@ size_t dds::xrce::OBJK_DomainParticipant_Binary::getMaxCdrSerializedSize(size_t
{
size_t initial_alignment = current_alignment;

current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);

current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 128 + 1;

current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 128 + 1;
Expand All @@ -3172,28 +3168,45 @@ size_t dds::xrce::OBJK_DomainParticipant_Binary::getCdrSerializedSize(size_t cur
{
size_t initial_alignment = current_alignment;

current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);

current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + m_domain_referente.size() + 1;
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + (*m_domain_referente).size() + 1;

current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + m_qos_profile.size() + 1;
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + (*m_qos_profile).size() + 1;


return current_alignment - initial_alignment;
}

void dds::xrce::OBJK_DomainParticipant_Binary::serialize(eprosima::fastcdr::Cdr &scdr) const
{
scdr << m_domain_id;
scdr << m_domain_referente;
scdr << m_qos_profile;
scdr << bool(m_domain_referente);
if (m_domain_referente)
{
scdr << *m_domain_referente;
}
scdr << bool(m_qos_profile);
if (m_qos_profile)
{
scdr << *m_qos_profile;
}
}

void dds::xrce::OBJK_DomainParticipant_Binary::deserialize(eprosima::fastcdr::Cdr &dcdr)
{
dcdr >> m_domain_id;
dcdr >> m_domain_referente;
dcdr >> m_qos_profile;
bool temp;
dcdr >> temp;
if (temp)
{
std::string temp_domain_referente;
dcdr >> temp_domain_referente;
m_domain_referente = temp_domain_referente;
}
dcdr >> temp;
if (temp)
{
std::string temp_qos_profile;
dcdr >> temp_qos_profile;
m_qos_profile = temp_qos_profile;
}
}

dds::xrce::OBJK_Topic_Binary::OBJK_Topic_Binary()
Expand Down

0 comments on commit 28654ec

Please sign in to comment.