Skip to content

Commit dd9e88d

Browse files
Servers as external
Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com>
1 parent f0adba6 commit dd9e88d

2 files changed

Lines changed: 49 additions & 4 deletions

File tree

ddsenabler_participants/include/ddsenabler_participants/rpc/RpcStructs.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ struct ServiceDiscovered
358358

359359
std::optional<ddspipe::core::types::Endpoint> endpoint_request;
360360
bool enabler_as_server{false};
361+
bool external_server{false};
361362

362363
bool add_topic(
363364
const ddspipe::core::types::DdsTopic& topic,
@@ -481,6 +482,7 @@ struct ActionDiscovered
481482
bool status_discovered{false};
482483
bool fully_discovered{false};
483484
bool enabler_as_server{false};
485+
bool external_server{false};
484486

485487
bool check_fully_discovered()
486488
{

ddsenabler_participants/src/cpp/EnablerParticipant.cpp

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ bool EnablerParticipant::service_discovered_nts_(
5353
{
5454
auto [it, inserted] = services_.try_emplace(rpc_info->service_name,
5555
std::make_shared<ServiceDiscovered>(rpc_info->service_name, rpc_info->rpc_protocol));
56-
return it->second->add_topic(topic, rpc_info->service_type);
56+
if (it->second->add_topic(topic, rpc_info->service_type))
57+
{
58+
it->second->external_server = true;
59+
return true;
60+
}
61+
return false;
5762
}
5863

5964
bool EnablerParticipant::action_discovered_nts_(
@@ -80,7 +85,12 @@ bool EnablerParticipant::action_discovered_nts_(
8085
it->second->add_topic(topic, rpc_info->action_type);
8186
}
8287

83-
return it->second->check_fully_discovered();
88+
if (it->second->check_fully_discovered())
89+
{
90+
it->second->external_server = true;
91+
return true;
92+
}
93+
return false;
8494
}
8595

8696
std::shared_ptr<IReader> EnablerParticipant::create_reader(
@@ -124,8 +134,17 @@ std::shared_ptr<IReader> EnablerParticipant::create_reader(
124134
{
125135
if (service_discovered_nts_(rpc_info, dds_topic))
126136
{
127-
RpcTopic service = services_.find(rpc_info->service_name)->second->get_service();
128-
handler_->add_service(service);
137+
try
138+
{
139+
RpcTopic service = services_.find(rpc_info->service_name)->second->get_service();
140+
handler_->add_service(service);
141+
}
142+
catch (const std::exception& e)
143+
{
144+
EPROSIMA_LOG_ERROR(DDSENABLER_ENABLER_PARTICIPANT,
145+
"Failed to add service " << rpc_info->service_name << ": " << e.what());
146+
return std::make_shared<BlankReader>();
147+
}
129148
}
130149
}
131150
else if (RpcType::ACTION == rpc_info->rpc_type)
@@ -146,6 +165,10 @@ std::shared_ptr<IReader> EnablerParticipant::create_reader(
146165
}
147166
}
148167
}
168+
else
169+
{
170+
std::cout << "Topic " << dds_topic.m_topic_name << " discovered from topic query callback. Not adding RPC." << std::endl;
171+
}
149172
}
150173
else
151174
{
@@ -295,6 +318,13 @@ bool EnablerParticipant::publish_rpc(
295318
return false;
296319
}
297320

321+
if (!it->second->external_server && rpc_info->service_type == ServiceType::REQUEST)
322+
{
323+
EPROSIMA_LOG_ERROR(DDSENABLER_ENABLER_PARTICIPANT,
324+
"Failed to publish data in service " << rpc_info->service_name << " : service is only announced on the enabler side.");
325+
return false;
326+
}
327+
298328
std::string type_name;
299329
auto reader = std::dynamic_pointer_cast<InternalRpcReader>(lookup_reader_nts_(topic_name, type_name));
300330

@@ -442,6 +472,12 @@ bool EnablerParticipant::revoke_service_nts_(
442472
return false;
443473
}
444474

475+
if (it->second->external_server)
476+
{
477+
it->second->enabler_as_server = false;
478+
return true;
479+
}
480+
445481
std::string request_name = it->second->topic_request.m_topic_name;
446482

447483
this->discovery_database_->erase_endpoint(it->second->endpoint_request.value());
@@ -599,13 +635,20 @@ bool EnablerParticipant::revoke_action(
599635
"Failed to stop action " << action_name << " : action not found.");
600636
return false;
601637
}
638+
602639
if (!it->second->enabler_as_server)
603640
{
604641
EPROSIMA_LOG_ERROR(DDSENABLER_ENABLER_PARTICIPANT,
605642
"Failed to stop action " << action_name << " : action not announced as server.");
606643
return false;
607644
}
608645

646+
if (it->second->external_server)
647+
{
648+
it->second->enabler_as_server = false;
649+
return true;
650+
}
651+
609652
auto action = it->second;
610653

611654
auto goal = action->goal.lock();

0 commit comments

Comments
 (0)