mirror of
https://github.com/micro-ROS/micro-ROS-Agent.git
synced 2026-09-06 18:05:17 +02:00
Add multi domain graph manager (#69)
* Add multi domain graph manager * Update * Fix * Fix * Update micro_ros_agent/include/agent/graph_manager/graph_manager.hpp Co-authored-by: Antonio Cuadros <49162117+Acuadros95@users.noreply.github.com> Co-authored-by: Antonio Cuadros <49162117+Acuadros95@users.noreply.github.com>
This commit is contained in:
co-authored by
Antonio Cuadros
parent
003cb38ef2
commit
a3fe4aa376
@@ -22,7 +22,6 @@ namespace agent {
|
||||
|
||||
Agent::Agent()
|
||||
: xrce_dds_agent_instance_(xrce_dds_agent_instance_.getInstance())
|
||||
, graph_manager_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -33,8 +32,6 @@ bool Agent::create(
|
||||
bool result = xrce_dds_agent_instance_.create(argc, argv);
|
||||
if (result)
|
||||
{
|
||||
graph_manager_.reset(new graph_manager::GraphManager());
|
||||
|
||||
/**
|
||||
* Add CREATE_PARTICIPANT callback.
|
||||
*/
|
||||
@@ -43,6 +40,12 @@ bool Agent::create(
|
||||
([&](
|
||||
const eprosima::fastdds::dds::DomainParticipant* participant) -> void
|
||||
{
|
||||
auto graph_manager_ =
|
||||
find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t(
|
||||
participant->get_domain_id()
|
||||
)
|
||||
);
|
||||
|
||||
graph_manager_->add_participant(participant);
|
||||
});
|
||||
xrce_dds_agent_instance_.add_middleware_callback(
|
||||
@@ -58,6 +61,12 @@ bool Agent::create(
|
||||
([&](
|
||||
const eprosima::fastdds::dds::DomainParticipant* participant) -> void
|
||||
{
|
||||
auto graph_manager_ =
|
||||
find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t(
|
||||
participant->get_domain_id()
|
||||
)
|
||||
);
|
||||
|
||||
graph_manager_->remove_participant(participant->guid());
|
||||
});
|
||||
xrce_dds_agent_instance_.add_middleware_callback(
|
||||
@@ -75,6 +84,12 @@ bool Agent::create(
|
||||
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||
const eprosima::fastdds::dds::DataWriter* datawriter) -> void
|
||||
{
|
||||
auto graph_manager_ =
|
||||
find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t(
|
||||
participant->get_domain_id()
|
||||
)
|
||||
);
|
||||
|
||||
// TODO(jamoralp): Workaround for Fast-DDS bug #9977. Remove when fixed
|
||||
const eprosima::fastrtps::rtps::InstanceHandle_t instance_handle =
|
||||
datawriter->get_instance_handle();
|
||||
@@ -96,9 +111,16 @@ bool Agent::create(
|
||||
const eprosima::fastdds::dds::DomainParticipant *,
|
||||
const eprosima::fastdds::dds::DataWriter *)> on_delete_datawriter
|
||||
([&](
|
||||
const eprosima::fastdds::dds::DomainParticipant* /*participant*/,
|
||||
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||
const eprosima::fastdds::dds::DataWriter* datawriter) -> void
|
||||
{
|
||||
|
||||
auto graph_manager_ =
|
||||
find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t(
|
||||
participant->get_domain_id()
|
||||
)
|
||||
);
|
||||
|
||||
// TODO(jamoralp): Workaround for Fast-DDS bug #9977. Remove when fixed
|
||||
const eprosima::fastrtps::rtps::InstanceHandle_t instance_handle =
|
||||
datawriter->get_instance_handle();
|
||||
@@ -122,6 +144,12 @@ bool Agent::create(
|
||||
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||
const eprosima::fastdds::dds::DataReader* datareader) -> void
|
||||
{
|
||||
auto graph_manager_ =
|
||||
find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t(
|
||||
participant->get_domain_id()
|
||||
)
|
||||
);
|
||||
|
||||
// TODO(jamoralp): Workaround for Fast-DDS bug #9977. Remove when fixed
|
||||
const eprosima::fastrtps::rtps::InstanceHandle_t instance_handle =
|
||||
datareader->get_instance_handle();
|
||||
@@ -143,9 +171,15 @@ bool Agent::create(
|
||||
const eprosima::fastdds::dds::DomainParticipant *,
|
||||
const eprosima::fastdds::dds::DataReader *)> on_delete_datareader
|
||||
([&](
|
||||
const eprosima::fastdds::dds::DomainParticipant* /*participant*/,
|
||||
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||
const eprosima::fastdds::dds::DataReader* datareader) -> void
|
||||
{
|
||||
auto graph_manager_ =
|
||||
find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t(
|
||||
participant->get_domain_id()
|
||||
)
|
||||
);
|
||||
|
||||
// TODO(jamoralp): Workaround for Fast-DDS bug #9977. Remove when fixed
|
||||
const eprosima::fastrtps::rtps::InstanceHandle_t instance_handle =
|
||||
datareader->get_instance_handle();
|
||||
@@ -168,6 +202,25 @@ void Agent::run()
|
||||
return xrce_dds_agent_instance_.run();
|
||||
}
|
||||
|
||||
std::shared_ptr<graph_manager::GraphManager> Agent::find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t domain_id)
|
||||
{
|
||||
auto it = graph_manager_map_.find(domain_id);
|
||||
|
||||
if (it != graph_manager_map_.end()) {
|
||||
return it->second;
|
||||
}else{
|
||||
return graph_manager_map_.insert(
|
||||
std::pair<
|
||||
eprosima::fastdds::dds::DomainId_t,
|
||||
std::shared_ptr<graph_manager::GraphManager>
|
||||
>(
|
||||
domain_id,
|
||||
std::make_shared<graph_manager::GraphManager>(domain_id)
|
||||
)
|
||||
).first->second;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace agent
|
||||
} // namespace uros
|
||||
#endif // _UROS_AGENT_AGENT_CPP
|
||||
@@ -21,9 +21,10 @@ namespace uros {
|
||||
namespace agent {
|
||||
namespace graph_manager {
|
||||
|
||||
GraphManager::GraphManager()
|
||||
GraphManager::GraphManager(eprosima::fastdds::dds::DomainId_t domain_id)
|
||||
// : eprosima::fastrtps::ParticipantListener()
|
||||
: graph_changed_(false)
|
||||
: domain_id_(domain_id)
|
||||
, graph_changed_(false)
|
||||
, display_on_change_(false)
|
||||
, enclave_("/")
|
||||
, mtx_()
|
||||
@@ -37,8 +38,6 @@ GraphManager::GraphManager()
|
||||
eprosima::fastdds::dds::TypeSupport>(new graph_manager::MicrorosGraphInfoTypeSupport()))
|
||||
{
|
||||
// Create DomainParticipant
|
||||
eprosima::fastdds::dds::DomainId_t domain_id(0);
|
||||
|
||||
eprosima::fastdds::dds::DomainParticipantQos participant_qos =
|
||||
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->get_default_participant_qos();
|
||||
|
||||
@@ -54,7 +53,7 @@ GraphManager::GraphManager()
|
||||
eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
|
||||
|
||||
participant_.reset(eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->
|
||||
create_participant(domain_id, participant_qos, participant_listener_.get()));
|
||||
create_participant(domain_id_, participant_qos, participant_listener_.get()));
|
||||
|
||||
// Register participant within typesupport
|
||||
participant_->register_type(*participant_info_typesupport_);
|
||||
|
||||
Reference in New Issue
Block a user