mirror of
https://github.com/micro-ROS/micro-ROS-Agent.git
synced 2026-09-06 09:55:15 +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
|
||||
Reference in New Issue
Block a user