@@ -118,7 +118,7 @@ RTPSParticipant* RTPSDomain::createParticipant(
118
118
const RTPSParticipantAttributes& attrs,
119
119
RTPSParticipantListener* listen)
120
120
{
121
- return RTPSDomainImpl:: createParticipant (domain_id, true , attrs, listen);
121
+ return createParticipant (domain_id, true , attrs, listen);
122
122
}
123
123
124
124
RTPSParticipant* RTPSDomain::createParticipant (
@@ -127,7 +127,20 @@ RTPSParticipant* RTPSDomain::createParticipant(
127
127
const RTPSParticipantAttributes& attrs,
128
128
RTPSParticipantListener* listen)
129
129
{
130
- return RTPSDomainImpl::createParticipant (domain_id, enabled, attrs, listen);
130
+ RTPSParticipant* part = nullptr ;
131
+ RTPSParticipantAttributes env_attrs = attrs;
132
+
133
+ if (RTPSDomainImpl::client_server_environment_attributes_override (domain_id, env_attrs))
134
+ {
135
+ part = RTPSDomainImpl::createParticipant (domain_id, enabled, env_attrs, listen);
136
+ }
137
+
138
+ if (nullptr == part)
139
+ {
140
+ part = RTPSDomainImpl::createParticipant (domain_id, enabled, attrs, listen);
141
+ }
142
+
143
+ return part;
131
144
}
132
145
133
146
bool RTPSDomain::removeRTPSParticipant (
@@ -518,18 +531,188 @@ bool RTPSDomainImpl::removeRTPSReader(
518
531
return false ;
519
532
}
520
533
521
- RTPSParticipant* RTPSDomainImpl::clientServerEnvironmentCreationOverride (
534
+ // RTPSParticipant* RTPSDomainImpl::clientServerEnvironmentCreationOverride(
535
+ // uint32_t domain_id,
536
+ // bool enabled,
537
+ // const RTPSParticipantAttributes& att,
538
+ // RTPSParticipantListener* listen)
539
+ // {
540
+ // // Check the specified discovery protocol: if other than simple it has priority over ros environment variable
541
+ // if (att.builtin.discovery_config.discoveryProtocol != DiscoveryProtocol::SIMPLE)
542
+ // {
543
+ // EPROSIMA_LOG_INFO(RTPS_DOMAIN, "Detected non simple discovery protocol attributes."
544
+ // << " Ignoring auto default client-server setup.");
545
+ // return nullptr;
546
+ // }
547
+
548
+ // // We only make the attributes copy when we are sure is worth
549
+ // // Is up to the caller guarantee the att argument is not modified during the call
550
+ // RTPSParticipantAttributes client_att(att);
551
+
552
+ // // Check whether we need to initialize in easy mode
553
+ // const std::string& easy_mode_env_value = easy_mode_env();
554
+
555
+ // if (easy_mode_env_value.empty())
556
+ // {
557
+ // // Retrieve the info from the environment variable
558
+ // LocatorList_t& server_list = client_att.builtin.discovery_config.m_DiscoveryServers;
559
+ // if (load_environment_server_info(server_list) && server_list.empty())
560
+ // {
561
+ // // It's not an error, the environment variable may not be set. Any issue with environment
562
+ // // variable syntax is EPROSIMA_LOG_ERROR already
563
+ // return nullptr;
564
+ // }
565
+
566
+ // // Check if some address requires the UDPv6, TCPv4 or TCPv6 transport
567
+ // if (server_list.has_kind<LOCATOR_KIND_UDPv6>() &&
568
+ // !has_user_transport<fastdds::rtps::UDPv6TransportDescriptor>(client_att))
569
+ // {
570
+ // // Extend builtin transports with the UDPv6 transport
571
+ // auto descriptor = std::make_shared<fastdds::rtps::UDPv6TransportDescriptor>();
572
+ // descriptor->sendBufferSize = client_att.sendSocketBufferSize;
573
+ // descriptor->receiveBufferSize = client_att.listenSocketBufferSize;
574
+ // client_att.userTransports.push_back(std::move(descriptor));
575
+ // }
576
+ // if (server_list.has_kind<LOCATOR_KIND_TCPv4>() &&
577
+ // !has_user_transport<fastdds::rtps::TCPv4TransportDescriptor>(client_att))
578
+ // {
579
+ // // Extend builtin transports with the TCPv4 transport
580
+ // auto descriptor = std::make_shared<fastdds::rtps::TCPv4TransportDescriptor>();
581
+ // // Add automatic port
582
+ // descriptor->add_listener_port(0);
583
+ // descriptor->sendBufferSize = client_att.sendSocketBufferSize;
584
+ // descriptor->receiveBufferSize = client_att.listenSocketBufferSize;
585
+ // client_att.userTransports.push_back(std::move(descriptor));
586
+ // }
587
+ // if (server_list.has_kind<LOCATOR_KIND_TCPv6>() &&
588
+ // !has_user_transport<fastdds::rtps::TCPv6TransportDescriptor>(client_att))
589
+ // {
590
+ // // Extend builtin transports with the TCPv6 transport
591
+ // auto descriptor = std::make_shared<fastdds::rtps::TCPv6TransportDescriptor>();
592
+ // // Add automatic port
593
+ // descriptor->add_listener_port(0);
594
+ // descriptor->sendBufferSize = client_att.sendSocketBufferSize;
595
+ // descriptor->receiveBufferSize = client_att.listenSocketBufferSize;
596
+ // client_att.userTransports.push_back(std::move(descriptor));
597
+ // }
598
+
599
+ // EPROSIMA_LOG_INFO(RTPS_DOMAIN, "Detected auto client-server environment variable."
600
+ // << "Trying to create client with the default server setup: "
601
+ // << client_att.builtin.discovery_config.m_DiscoveryServers);
602
+
603
+ // client_att.builtin.discovery_config.discoveryProtocol = DiscoveryProtocol::CLIENT;
604
+ // // RemoteServerAttributes already fill in above
605
+
606
+ // // Check if the client must become a super client
607
+ // if (ros_super_client_env())
608
+ // {
609
+ // client_att.builtin.discovery_config.discoveryProtocol = DiscoveryProtocol::SUPER_CLIENT;
610
+ // }
611
+ // }
612
+ // else
613
+ // {
614
+ // // SUPER_CLIENT
615
+ // client_att.builtin.discovery_config.discoveryProtocol = DiscoveryProtocol::SUPER_CLIENT;
616
+
617
+ // // P2P transport. Similar to LARGE_DATA, but with UDPv4 unicast
618
+ // client_att.useBuiltinTransports = false;
619
+ // client_att.setup_transports(BuiltinTransports::P2P);
620
+
621
+ // // Ignore initialpeers
622
+ // client_att.builtin.initialPeersList = LocatorList();
623
+
624
+ // eprosima::fastdds::rtps::PortParameters port_params;
625
+
626
+ // auto domain_port = port_params.get_discovery_server_port(domain_id);
627
+
628
+ // // Add user traffic TCP
629
+ // eprosima::fastdds::rtps::Locator_t locator_tcp;
630
+ // locator_tcp.kind = LOCATOR_KIND_TCPv4;
631
+
632
+ // IPLocator::setPhysicalPort(locator_tcp, 0);
633
+ // IPLocator::setLogicalPort(locator_tcp, 0);
634
+ // // Initialize to the wan interface
635
+ // IPLocator::setIPv4(locator_tcp, "0.0.0.0");
636
+
637
+ // client_att.defaultUnicastLocatorList.push_back(locator_tcp);
638
+
639
+ // // Add remote DS based on port
640
+ // eprosima::fastdds::rtps::Locator_t locator_udp;
641
+ // locator_udp.kind = LOCATOR_KIND_UDPv4;
642
+
643
+ // locator_udp.port = domain_port;
644
+ // IPLocator::setIPv4(locator_udp, 127, 0, 0, 1);
645
+
646
+ // // Point to the well known DS port in the corresponding domain
647
+ // client_att.builtin.discovery_config.m_DiscoveryServers.push_back(locator_udp);
648
+
649
+ // // Load the 'service' profile for ROS2_EASY_MODE services if there is no existing profile yet
650
+ // xmlparser::PublisherAttributes attr;
651
+ // auto ret_if = xmlparser::XMLProfileManager::fillPublisherAttributes("service", attr, false);
652
+ // if (ret_if == xmlparser::XMLP_ret::XML_ERROR)
653
+ // {
654
+ // // An XML_ERROR is returned if there is no existing profile for the given name
655
+ // xmlparser::XMLProfileManager::loadXMLString(EASY_MODE_SERVICE_PROFILE, strlen(EASY_MODE_SERVICE_PROFILE));
656
+ // EPROSIMA_LOG_INFO(RTPS_DOMAIN, "Loaded service profile for ROS2_EASY_MODE servers");
657
+ // }
658
+ // else
659
+ // {
660
+ // // There is already a profile with the given name. Do not overwrite it
661
+ // EPROSIMA_LOG_WARNING(RTPS_DOMAIN, "An XML profile for 'service' was found. When using ROS2_EASY_MODE, please ensure"
662
+ // " the max_blocking_time is configured with a value higher than the default.");
663
+ // }
664
+
665
+ // SystemCommandBuilder sys_command;
666
+ // int res = sys_command.executable(FAST_DDS_DEFAULT_CLI_SCRIPT_NAME)
667
+ // .verb(FAST_DDS_DEFAULT_CLI_DISCOVERY_VERB)
668
+ // .verb(FAST_DDS_DEFAULT_CLI_AUTO_VERB)
669
+ // .arg("-d")
670
+ // .value(std::to_string(domain_id))
671
+ // .value(easy_mode_env_value + ":" + std::to_string(domain_id))
672
+ // .build_and_call();
673
+ // #ifndef _WIN32
674
+ // // Adecuate Python subprocess return
675
+ // res = WEXITSTATUS(res);
676
+ // #endif // _WIN32
677
+
678
+ // if (res != SystemCommandBuilder::SystemCommandResult::SUCCESS)
679
+ // {
680
+ // if (res == SystemCommandBuilder::SystemCommandResult::BAD_PARAM)
681
+ // {
682
+ // EPROSIMA_LOG_ERROR("DOMAIN", "ROS2_EASY_MODE IP connection conflicts with a previous one.");
683
+ // }
684
+ // else
685
+ // {
686
+ // EPROSIMA_LOG_ERROR(DOMAIN, "Auto discovery server client setup. Unable to spawn daemon.");
687
+ // }
688
+ // return nullptr;
689
+ // }
690
+ // }
691
+
692
+ // RTPSParticipant* part = createParticipant(domain_id, enabled, client_att, listen);
693
+ // if (nullptr != part)
694
+ // {
695
+ // // Client successfully created
696
+ // EPROSIMA_LOG_INFO(RTPS_DOMAIN, "Auto default server-client setup. Default client created.");
697
+ // part->mp_impl->client_override(true);
698
+ // return part;
699
+ // }
700
+
701
+ // // Unable to create auto server-client default participants
702
+ // EPROSIMA_LOG_ERROR(RTPS_DOMAIN, "Auto default server-client setup. Unable to create the client.");
703
+ // return nullptr;
704
+ // }
705
+
706
+ bool RTPSDomainImpl::client_server_environment_attributes_override (
522
707
uint32_t domain_id,
523
- bool enabled,
524
- const RTPSParticipantAttributes& att,
525
- RTPSParticipantListener* listen)
708
+ RTPSParticipantAttributes& att)
526
709
{
527
710
// Check the specified discovery protocol: if other than simple it has priority over ros environment variable
528
711
if (att.builtin .discovery_config .discoveryProtocol != DiscoveryProtocol::SIMPLE)
529
712
{
530
713
EPROSIMA_LOG_INFO (RTPS_DOMAIN, " Detected non simple discovery protocol attributes."
531
714
<< " Ignoring auto default client-server setup." );
532
- return nullptr ;
715
+ return false ;
533
716
}
534
717
535
718
// We only make the attributes copy when we are sure is worth
@@ -547,7 +730,7 @@ RTPSParticipant* RTPSDomainImpl::clientServerEnvironmentCreationOverride(
547
730
{
548
731
// It's not an error, the environment variable may not be set. Any issue with environment
549
732
// variable syntax is EPROSIMA_LOG_ERROR already
550
- return nullptr ;
733
+ return false ;
551
734
}
552
735
553
736
// Check if some address requires the UDPv6, TCPv4 or TCPv6 transport
@@ -672,22 +855,21 @@ RTPSParticipant* RTPSDomainImpl::clientServerEnvironmentCreationOverride(
672
855
{
673
856
EPROSIMA_LOG_ERROR (DOMAIN, " Auto discovery server client setup. Unable to spawn daemon." );
674
857
}
675
- return nullptr ;
858
+ return false ;
676
859
}
677
860
}
678
861
679
- RTPSParticipant* part = createParticipant (domain_id, enabled, client_att, listen);
680
- if (nullptr != part)
681
- {
682
- // Client successfully created
683
- EPROSIMA_LOG_INFO (RTPS_DOMAIN, " Auto default server-client setup. Default client created." );
684
- part->mp_impl ->client_override (true );
685
- return part;
686
- }
687
-
688
- // Unable to create auto server-client default participants
689
- EPROSIMA_LOG_ERROR (RTPS_DOMAIN, " Auto default server-client setup. Unable to create the client." );
690
- return nullptr ;
862
+ // RTPSParticipant* part = createParticipant(domain_id, enabled, client_att, listen);
863
+ // if (nullptr != part)
864
+ // {
865
+ // // Client successfully created
866
+ // EPROSIMA_LOG_INFO(RTPS_DOMAIN, "Auto default server-client setup. Default client created.");
867
+ // part->mp_impl->client_override(true);
868
+ // return part;
869
+ // }
870
+ EPROSIMA_LOG_INFO (RTPS_DOMAIN, " TODO." );
871
+ att = client_att;
872
+ return true ;
691
873
}
692
874
693
875
uint32_t RTPSDomainImpl::getNewId ()
0 commit comments