Skip to content

Commit

Permalink
override domain_id with agent_domain_id from env
Browse files Browse the repository at this point in the history
  • Loading branch information
delihus committed Jun 30, 2023
1 parent caf8876 commit 514de9c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion include/uxr/agent/middleware/Middleware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <chrono>

#define UXR_CLIENT_DOMAIN_ID_TO_USE_FROM_REF (255)
#define UXR_CLIENT_DOMAIN_ID_TO_OVERRIDE_WITH_ENV (255)

namespace eprosima {
namespace uxr {
Expand Down Expand Up @@ -298,7 +299,7 @@ class Middleware
/**********************************************************************************************************************
* Members.
**********************************************************************************************************************/
protected:
protected:
bool intraprocess_enabled_;
};

Expand Down
3 changes: 3 additions & 0 deletions include/uxr/agent/middleware/fastdds/FastDDSMiddleware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ class FastDDSMiddleware : public Middleware
std::shared_ptr<FastDDSParticipant>& participant,
const fastrtps::ReplierAttributes& attrs);

uint8_t get_domain_id_from_env();

uint8_t agent_domain_id_ = 0;
std::unordered_map<uint16_t, std::shared_ptr<FastDDSParticipant>> participants_;
std::unordered_map<uint16_t, std::shared_ptr<FastDDSTopic>> topics_;
std::unordered_map<uint16_t, std::shared_ptr<FastDDSPublisher>> publishers_;
Expand Down
29 changes: 28 additions & 1 deletion src/cpp/middleware/fastdds/FastDDSMiddleware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <uxr/agent/middleware/fastdds/FastDDSMiddleware.hpp>
#include <uxr/agent/utils/Conversion.hpp>
#include <uxr/agent/logger/Logger.hpp>

#include <fastrtps/xmlparser/XMLProfileManager.h>
#include <fastdds/dds/subscriber/SampleInfo.hpp>
Expand Down Expand Up @@ -51,6 +52,14 @@ FastDDSMiddleware::FastDDSMiddleware(bool intraprocess_enabled)
, repliers_()
, callback_factory_(callback_factory_.getInstance())
{
agent_domain_id_ = get_domain_id_from_env();
if (agent_domain_id_)
{
UXR_AGENT_LOG_INFO(
UXR_DECORATE_GREEN("Micro XRCE-DDS Agent DOMAIN_ID read from env"),
"domain_id: {}", agent_domain_id_);
}

}

/**********************************************************************************************************************
Expand Down Expand Up @@ -108,8 +117,16 @@ bool FastDDSMiddleware::create_participant_by_bin(
uint16_t participant_id,
const dds::xrce::OBJK_DomainParticipant_Binary& participant_xrce)
{
auto participant_domain_id = static_cast<int16_t>(participant_xrce.domain_id());
if(participant_domain_id == UXR_CLIENT_DOMAIN_ID_TO_OVERRIDE_WITH_ENV){
participant_domain_id = static_cast<int16_t>(agent_domain_id_);
UXR_AGENT_LOG_WARN(
UXR_DECORATE_YELLOW("Overriding Micro XRCE-DDS Client DOMAIN_ID"),
"domain_id: {}", participant_domain_id);
}

bool rv = false;
std::shared_ptr<FastDDSParticipant> participant(new FastDDSParticipant((int16_t) participant_xrce.domain_id()));
std::shared_ptr<FastDDSParticipant> participant(new FastDDSParticipant(participant_domain_id));
if (participant->create_by_bin(participant_xrce))
{
auto emplace_res = participants_.emplace(participant_id, std::move(participant));
Expand Down Expand Up @@ -1242,5 +1259,15 @@ bool FastDDSMiddleware::matched_replier_from_bin(
return rv;
}

uint8_t FastDDSMiddleware::get_domain_id_from_env(){
uint8_t agent_domain_id = 0;
const char * agent_domain_id_env = std::getenv( "ROS_DOMAIN_ID" );
if (nullptr != agent_domain_id_env)
{
agent_domain_id = std::atoi(agent_domain_id_env);
}
return agent_domain_id;
}

} // namespace uxr
} // namespace eprosima

0 comments on commit 514de9c

Please sign in to comment.