mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-21 01:12:11 +00:00
microRTPS: by default, when FastDDS >= 2.0, enable Shared Memory transport for the agent participants when the localhost network is enabled
This commit is contained in:
@@ -62,16 +62,20 @@ except AttributeError:
|
|||||||
* This file was adapted from the fastcdrgen tool.
|
* This file was adapted from the fastcdrgen tool.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "@(topic)_Publisher.h"
|
||||||
|
|
||||||
|
#include <fastrtps/Domain.h>
|
||||||
#include <fastrtps/participant/Participant.h>
|
#include <fastrtps/participant/Participant.h>
|
||||||
#include <fastrtps/attributes/ParticipantAttributes.h>
|
#include <fastrtps/attributes/ParticipantAttributes.h>
|
||||||
#include <fastrtps/publisher/Publisher.h>
|
#include <fastrtps/publisher/Publisher.h>
|
||||||
#include <fastrtps/attributes/PublisherAttributes.h>
|
#include <fastrtps/attributes/PublisherAttributes.h>
|
||||||
#include <fastrtps/transport/UDPv4TransportDescriptor.h>
|
#include <fastrtps/transport/UDPv4TransportDescriptor.h>
|
||||||
|
@[if version.parse(fastrtps_version) >= version.parse('2.0')]@
|
||||||
|
#include <fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h>
|
||||||
|
|
||||||
#include <fastrtps/Domain.h>
|
using SharedMemTransportDescriptor = eprosima::fastdds::rtps::SharedMemTransportDescriptor;
|
||||||
|
@[end if]@
|
||||||
|
|
||||||
#include "@(topic)_Publisher.h"
|
|
||||||
|
|
||||||
@(topic)_Publisher::@(topic)_Publisher()
|
@(topic)_Publisher::@(topic)_Publisher()
|
||||||
: mp_participant(nullptr),
|
: mp_participant(nullptr),
|
||||||
@@ -102,19 +106,26 @@ bool @(topic)_Publisher::init(const std::string &ns)
|
|||||||
PParam.rtps.setName(nodeName.c_str());
|
PParam.rtps.setName(nodeName.c_str());
|
||||||
|
|
||||||
// Check if ROS_LOCALHOST_ONLY is set. This means that one wants to use
|
// Check if ROS_LOCALHOST_ONLY is set. This means that one wants to use
|
||||||
// only the localhost network for data sharing
|
// only the localhost network for data sharing. If FastRTPS/DDS >= 2.0
|
||||||
const char *localhost_only = std::getenv("ROS_LOCALHOST_ONLY");
|
// then the Shared Memory transport is used
|
||||||
|
const char* localhost_only = std::getenv("ROS_LOCALHOST_ONLY");
|
||||||
if (localhost_only && strcmp(localhost_only, "1") == 0) {
|
if (localhost_only && strcmp(localhost_only, "1") == 0) {
|
||||||
// Create a custom network transport descriptor to whitelist the localhost
|
// Create a custom network UDPv4 transport descriptor
|
||||||
auto localhostDescriptor = std::make_shared<UDPv4TransportDescriptor>();
|
// to whitelist the localhost
|
||||||
localhostDescriptor->interfaceWhiteList.emplace_back("127.0.0.1");
|
auto localhostUdpTransport = std::make_shared<UDPv4TransportDescriptor>();
|
||||||
|
localhostUdpTransport->interfaceWhiteList.emplace_back("127.0.0.1");
|
||||||
|
|
||||||
// Disable the built-in Transport Layer
|
// Disable the built-in Transport Layer
|
||||||
PParam.rtps.useBuiltinTransports = false;
|
PParam.rtps.useBuiltinTransports = false;
|
||||||
|
|
||||||
// Add the descriptor as a custom user transport
|
// Add the descriptor as a custom user transport
|
||||||
PParam.rtps.userTransports.push_back(localhostDescriptor);
|
PParam.rtps.userTransports.push_back(localhostUdpTransport);
|
||||||
|
|
||||||
|
@[if version.parse(fastrtps_version) >= version.parse('2.0')]@
|
||||||
|
// Add shared memory transport when available
|
||||||
|
auto shmTransport = std::make_shared<SharedMemTransportDescriptor>();
|
||||||
|
PParam.rtps.userTransports.push_back(shmTransport);
|
||||||
|
@[end if]@
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_participant = Domain::createParticipant(PParam);
|
mp_participant = Domain::createParticipant(PParam);
|
||||||
|
|||||||
@@ -62,15 +62,20 @@ except AttributeError:
|
|||||||
* This file was adapted from the fastcdrgen tool.
|
* This file was adapted from the fastcdrgen tool.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "@(topic)_Subscriber.h"
|
||||||
|
|
||||||
|
#include <fastrtps/Domain.h>
|
||||||
#include <fastrtps/participant/Participant.h>
|
#include <fastrtps/participant/Participant.h>
|
||||||
#include <fastrtps/attributes/ParticipantAttributes.h>
|
#include <fastrtps/attributes/ParticipantAttributes.h>
|
||||||
#include <fastrtps/subscriber/Subscriber.h>
|
#include <fastrtps/subscriber/Subscriber.h>
|
||||||
#include <fastrtps/attributes/SubscriberAttributes.h>
|
#include <fastrtps/attributes/SubscriberAttributes.h>
|
||||||
#include <fastrtps/transport/UDPv4TransportDescriptor.h>
|
#include <fastrtps/transport/UDPv4TransportDescriptor.h>
|
||||||
|
@[if version.parse(fastrtps_version) >= version.parse('2.0')]@
|
||||||
|
#include <fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h>
|
||||||
|
|
||||||
#include <fastrtps/Domain.h>
|
using SharedMemTransportDescriptor = eprosima::fastdds::rtps::SharedMemTransportDescriptor;
|
||||||
|
@[end if]@
|
||||||
|
|
||||||
#include "@(topic)_Subscriber.h"
|
|
||||||
|
|
||||||
@(topic)_Subscriber::@(topic)_Subscriber()
|
@(topic)_Subscriber::@(topic)_Subscriber()
|
||||||
: mp_participant(nullptr),
|
: mp_participant(nullptr),
|
||||||
@@ -107,19 +112,26 @@ bool @(topic)_Subscriber::init(uint8_t topic_ID, std::condition_variable *t_send
|
|||||||
PParam.rtps.setName(nodeName.c_str());
|
PParam.rtps.setName(nodeName.c_str());
|
||||||
|
|
||||||
// Check if ROS_LOCALHOST_ONLY is set. This means that one wants to use
|
// Check if ROS_LOCALHOST_ONLY is set. This means that one wants to use
|
||||||
// only the localhost network for data sharing
|
// only the localhost network for data sharing. If FastRTPS/DDS >= 2.0
|
||||||
const char *localhost_only = std::getenv("ROS_LOCALHOST_ONLY");
|
// then the Shared Memory transport is used
|
||||||
|
const char* localhost_only = std::getenv("ROS_LOCALHOST_ONLY");
|
||||||
if (localhost_only && strcmp(localhost_only, "1") == 0) {
|
if (localhost_only && strcmp(localhost_only, "1") == 0) {
|
||||||
// Create a custom network transport descriptor to whitelist the localhost
|
// Create a custom network UDPv4 transport descriptor
|
||||||
auto localhostDescriptor = std::make_shared<UDPv4TransportDescriptor>();
|
// to whitelist the localhost
|
||||||
localhostDescriptor->interfaceWhiteList.emplace_back("127.0.0.1");
|
auto localhostUdpTransport = std::make_shared<UDPv4TransportDescriptor>();
|
||||||
|
localhostUdpTransport->interfaceWhiteList.emplace_back("127.0.0.1");
|
||||||
|
|
||||||
// Disable the built-in Transport Layer
|
// Disable the built-in Transport Layer
|
||||||
PParam.rtps.useBuiltinTransports = false;
|
PParam.rtps.useBuiltinTransports = false;
|
||||||
|
|
||||||
// Add the descriptor as a custom user transport
|
// Add the descriptor as a custom user transport
|
||||||
PParam.rtps.userTransports.push_back(localhostDescriptor);
|
PParam.rtps.userTransports.push_back(localhostUdpTransport);
|
||||||
|
|
||||||
|
@[if version.parse(fastrtps_version) >= version.parse('2.0')]@
|
||||||
|
// Add shared memory transport when available
|
||||||
|
auto shmTransport = std::make_shared<SharedMemTransportDescriptor>();
|
||||||
|
PParam.rtps.userTransports.push_back(shmTransport);
|
||||||
|
@[end if]@
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_participant = Domain::createParticipant(PParam);
|
mp_participant = Domain::createParticipant(PParam);
|
||||||
|
|||||||
@@ -237,10 +237,10 @@ int main(int argc, char **argv)
|
|||||||
printf("\033[0;37m--- MicroRTPS Agent ---\033[0m\n");
|
printf("\033[0;37m--- MicroRTPS Agent ---\033[0m\n");
|
||||||
printf("[ micrortps_agent ]\tStarting link...\n");
|
printf("[ micrortps_agent ]\tStarting link...\n");
|
||||||
|
|
||||||
const char *localhost_only = std::getenv("ROS_LOCALHOST_ONLY");
|
const char* localhost_only = std::getenv("ROS_LOCALHOST_ONLY");
|
||||||
|
|
||||||
if (localhost_only && strcmp(localhost_only, "1") == 0) {
|
if (localhost_only && strcmp(localhost_only, "1") == 0) {
|
||||||
printf("[ micrortps_agent ]\tUsing only the localhost network for data sharing...\n");
|
printf("[ micrortps_agent ]\tUsing only the localhost network...\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (_options.transport) {
|
switch (_options.transport) {
|
||||||
|
|||||||
Reference in New Issue
Block a user