Skip to content

Commit 85f50f2

Browse files
committed
Merge branch 'release/1.0.0'
2 parents cff5e7e + e3289d5 commit 85f50f2

24 files changed

Lines changed: 603 additions & 420 deletions

FastRTPSBridge.xcodeproj/project.pbxproj

Lines changed: 91 additions & 104 deletions
Large diffs are not rendered by default.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>FILEHEADER</key>
6+
<string><![CDATA[///
7+
//// ___FILENAME___
8+
/// Copyright © ___YEAR___ ___ORGANIZATIONNAME___. All rights reserved.
9+
//
10+
]]></string>
11+
</dict>
12+
</plist>
Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
//
2-
// RovParticipant.h
3-
// TridentVideoViewer
4-
//
5-
// Created by Dmitriy Borovikov on 06/09/2019.
6-
// Copyright © 2019 Dmitriy Borovikov. All rights reserved.
1+
/////
2+
//// BridgedParticipant.h
3+
/// Copyright © 2019 Dmitriy Borovikov. All rights reserved.
74
//
85

96
#pragma once
@@ -12,21 +9,21 @@
129
#include <fastrtps/rtps/common/Types.h>
1310
#include <fastrtps/rtps/attributes/WriterAttributes.h>
1411
#include <fastrtps/rtps/reader/RTPSReader.h>
15-
#include "fastrtps/rtps/writer/RTPSWriter.h"
12+
#include <fastrtps/rtps/writer/RTPSWriter.h>
1613
#include <fastrtps/rtps/history/ReaderHistory.h>
17-
#include "fastrtps/rtps/history/WriterHistory.h"
14+
#include <fastrtps/rtps/history/WriterHistory.h>
1815
#include <string>
1916
#include <map>
20-
#import "RovTopicListener.h"
21-
#import "RovWriterListener.h"
17+
#import "BridgedReaderListener.h"
18+
#import "BridgedWriterListener.h"
2219

23-
class CustomParticipantListener;
24-
class RovParticipant
20+
class BridgedParticipantListener;
21+
class BridgedParticipant
2522
{
2623
struct ReaderInfo {
2724
eprosima::fastrtps::rtps::RTPSReader* reader;
2825
eprosima::fastrtps::rtps::ReaderHistory* history;
29-
RovTopicListener* listener;
26+
BridgedReaderListener* listener;
3027
~ReaderInfo() {
3128
delete history;
3229
delete listener;
@@ -36,22 +33,24 @@ class RovParticipant
3633
struct WriterInfo {
3734
eprosima::fastrtps::rtps::RTPSWriter* writer;
3835
eprosima::fastrtps::rtps::WriterHistory* history;
39-
RovWriterListener* listener;
36+
BridgedWriterListener* listener;
4037
~WriterInfo() {
4138
delete history;
4239
delete listener;
4340
}
4441
};
4542
public:
46-
RovParticipant();
47-
virtual ~RovParticipant();
43+
BridgedParticipant();
44+
virtual ~BridgedParticipant();
4845
eprosima::fastrtps::rtps::RTPSParticipant* mp_participant;
49-
CustomParticipantListener* mp_listener;
46+
BridgedParticipantListener* mp_listener;
47+
std::string partitionName;
5048

5149
std::map<std::string, ReaderInfo*> readerList;
5250
std::map<std::string, WriterInfo*> writerList;
5351

54-
bool startRTPS(); //Initialization
52+
bool createParticipant(const char* name, const char *interfaceIPv4, const char* networkAddress);
53+
void setPartition(const char* name) { partitionName = std::string(name); }
5554
bool addReader(const char* name,
5655
const char* dataType,
5756
const bool keyed,
Lines changed: 59 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
//
2-
// RovParticipant.mm
3-
// TridentVideoViewer
4-
//
5-
// Created by Dmitriy Borovikov on 06/09/2019.
6-
// Copyright © 2019 Dmitriy Borovikov. All rights reserved.
1+
/////
2+
//// BridgedParticipant.mm
3+
/// Copyright © 2019 Dmitriy Borovikov. All rights reserved.
74
//
85

9-
#include "RovParticipant.h"
10-
#include "RovTopicListener.h"
11-
#include "RovWriterListener.h"
12-
#include "CustomParticipantListener.h"
6+
#include "BridgedParticipant.h"
7+
#include "BridgedReaderListener.h"
8+
#include "BridgedWriterListener.h"
9+
#include "BridgedParticipantListener.h"
1310

1411
#include <fastrtps/rtps/RTPSDomain.h>
1512
#include <fastrtps/rtps/participant/RTPSParticipant.h>
@@ -23,27 +20,31 @@
2320
#include <fastrtps/qos/ReaderQos.h>
2421
#include <fastrtps/qos/WriterQos.h>
2522
#include <fastrtps/log/Log.h>
23+
#include <fastrtps/transport/UDPv4TransportDescriptor.h>
24+
#include <memory>
25+
#include <arpa/inet.h>
2626

2727
using namespace eprosima::fastrtps;
2828
using namespace eprosima::fastrtps::rtps;
2929

30-
RovParticipant::RovParticipant():
30+
BridgedParticipant::BridgedParticipant():
3131
mp_participant(nullptr),
32-
mp_listener(nullptr)
32+
mp_listener(nullptr),
33+
partitionName("*")
3334
{
3435
}
3536

36-
RovParticipant::~RovParticipant()
37+
BridgedParticipant::~BridgedParticipant()
3738
{
38-
mp_participant->stopRTPSParticipantAnnouncement();
3939
logInfo(ROV_PARTICIPANT, "Delete participant")
40+
mp_participant->stopRTPSParticipantAnnouncement();
4041
resignAll();
4142
RTPSDomain::removeRTPSParticipant(mp_participant);
4243
delete mp_listener;
4344
// RTPSDomain::stopAll();
4445
}
4546

46-
void RovParticipant::resignAll() {
47+
void BridgedParticipant::resignAll() {
4748
for(auto it = readerList.begin(); it != readerList.end(); it++)
4849
{
4950
logInfo(ROV_PARTICIPANT, "Remove reader: " << it->first)
@@ -63,28 +64,40 @@
6364
writerList.clear();
6465
}
6566

66-
bool RovParticipant::startRTPS()
67+
bool BridgedParticipant::createParticipant(const char* name, const char *interfaceIPv4, const char* networkAddress)
6768
{
68-
//CREATE PARTICIPANT
69-
RTPSParticipantAttributes PParam;
70-
PParam.builtin.use_WriterLivelinessProtocol = true;
71-
PParam.builtin.discovery_config.discoveryProtocol = eprosima::fastrtps::rtps::DiscoveryProtocol::SIMPLE;
72-
PParam.builtin.discovery_config.leaseDuration_announcementperiod.seconds = 1;
73-
PParam.builtin.discovery_config.leaseDuration.seconds = 20;
74-
PParam.builtin.readerHistoryMemoryPolicy = PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
75-
PParam.builtin.writerHistoryMemoryPolicy = PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
76-
PParam.builtin.domainId = 0;
77-
PParam.setName("TridentVideoViewer");
69+
RTPSParticipantAttributes pattr;
70+
pattr.builtin.use_WriterLivelinessProtocol = true;
71+
pattr.builtin.discovery_config.discoveryProtocol = eprosima::fastrtps::rtps::DiscoveryProtocol::SIMPLE;
72+
pattr.builtin.discovery_config.leaseDuration_announcementperiod.seconds = 1;
73+
pattr.builtin.discovery_config.leaseDuration.seconds = 10;
74+
pattr.builtin.discovery_config.ignoreParticipantFlags = FILTER_SAME_PROCESS;
75+
pattr.builtin.readerHistoryMemoryPolicy = PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
76+
pattr.builtin.writerHistoryMemoryPolicy = PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
77+
pattr.builtin.domainId = 0;
78+
pattr.setName(name);
7879

79-
mp_listener = new CustomParticipantListener();
80-
mp_participant = RTPSDomain::createParticipant(PParam, mp_listener);
80+
auto customTransport = std::make_shared<UDPv4TransportDescriptor>();
81+
customTransport->sendBufferSize = 65536;
82+
customTransport->receiveBufferSize = 65536;
83+
if (interfaceIPv4 != nullptr) {
84+
customTransport->interfaceWhiteList.emplace_back(interfaceIPv4);
85+
}
86+
if (networkAddress != nullptr) {
87+
customTransport->remoteWhiteList.emplace_back(networkAddress);
88+
}
89+
pattr.userTransports.push_back(customTransport);
90+
pattr.useBuiltinTransports = false;
91+
92+
mp_listener = new BridgedParticipantListener();
93+
mp_participant = RTPSDomain::createParticipant(pattr, mp_listener);
8194
if (mp_participant == nullptr)
8295
return false;
8396

8497
return true;
8598
}
8699

87-
bool RovParticipant::addReader(const char* name,
100+
bool BridgedParticipant::addReader(const char* name,
88101
const char* dataType,
89102
const bool keyed,
90103
NSObject<PayloadDecoderInterface>* payloadDecoder)
@@ -95,14 +108,14 @@
95108
// aready registered
96109
return false;
97110
}
98-
//CREATE READER
99111
ReaderAttributes readerAttributes;
100112
readerAttributes.endpoint.topicKind = tKind;
101-
auto listener = new RovTopicListener(name, payloadDecoder);
102-
//CREATE READERHISTORY
113+
auto listener = new BridgedReaderListener(name, payloadDecoder);
114+
103115
HistoryAttributes hatt;
104-
hatt.payloadMaxSize = 10000;
105116
hatt.memoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
117+
hatt.payloadMaxSize = 1000;
118+
hatt.initialReservedCaches = 5;
106119
hatt.maximumReservedCaches = 0;
107120
auto history = new ReaderHistory(hatt);
108121
auto reader = RTPSDomain::createRTPSReader(mp_participant, readerAttributes, history, listener);
@@ -111,16 +124,16 @@
111124
delete history;
112125
return false;
113126
}
114-
127+
115128
auto readerInfo = new ReaderInfo;
116129
readerInfo->reader = reader;
117130
readerInfo->history = history;
118131
readerInfo->listener = listener;
119132
readerList[topicName] = readerInfo;
120-
133+
121134
TopicAttributes Tatt(name, dataType, tKind);
122135
ReaderQos Rqos;
123-
Rqos.m_partition.push_back("*");
136+
Rqos.m_partition.push_back(partitionName.c_str());
124137
auto rezult = mp_participant->registerReader(reader, Tatt, Rqos);
125138
if (!rezult) {
126139
RTPSDomain::removeRTPSReader(reader);
@@ -132,7 +145,7 @@
132145
return true;
133146
}
134147

135-
bool RovParticipant::removeReader(const char* name)
148+
bool BridgedParticipant::removeReader(const char* name)
136149
{
137150
logInfo(ROV_PARTICIPANT, "Remove reader: " << name)
138151
auto topicName = std::string(name);
@@ -147,7 +160,7 @@
147160
return true;
148161
}
149162

150-
bool RovParticipant::addWriter(const char* name,
163+
bool BridgedParticipant::addWriter(const char* name,
151164
const char* dataType,
152165
const bool keyed)
153166
{
@@ -161,11 +174,11 @@
161174
WriterAttributes watt;
162175
watt.endpoint.reliabilityKind = BEST_EFFORT;
163176
watt.endpoint.topicKind = tKind;
164-
auto listener = new RovWriterListener(name);
165-
//CREATE WRITERHISTORY
177+
auto listener = new BridgedWriterListener(name);
166178
HistoryAttributes hatt;
167-
// hatt.payloadMaxSize = 10000;
168179
hatt.memoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
180+
hatt.payloadMaxSize = 1000;
181+
hatt.initialReservedCaches = 5;
169182
hatt.maximumReservedCaches = 0;
170183
auto history = new WriterHistory(hatt);
171184
auto writer = RTPSDomain::createRTPSWriter(mp_participant, watt, history, listener);
@@ -183,7 +196,7 @@
183196

184197
TopicAttributes Tatt(name, dataType, tKind);
185198
WriterQos Wqos;
186-
Wqos.m_partition.push_back("*");
199+
Wqos.m_partition.push_back(partitionName.c_str());
187200
Wqos.m_disablePositiveACKs.enabled = true;
188201
auto rezult = mp_participant->registerWriter(writer, Tatt, Wqos);
189202
if (!rezult) {
@@ -196,7 +209,7 @@
196209
return true;
197210
}
198211

199-
bool RovParticipant::removeWriter(const char* name)
212+
bool BridgedParticipant::removeWriter(const char* name)
200213
{
201214
logInfo(ROV_PARTICIPANT, "Remove writer: " << name)
202215
auto topicName = std::string(name);
@@ -211,7 +224,7 @@
211224
return true;
212225
}
213226

214-
bool RovParticipant::send(const char* name, const uint8_t* data, uint32_t length, const void* key, uint32_t keyLength)
227+
bool BridgedParticipant::send(const char* name, const uint8_t* data, uint32_t length, const void* key, uint32_t keyLength)
215228
{
216229
static const octet header[] = {0, 1, 0, 0};
217230
auto topicName = std::string(name);
@@ -231,14 +244,14 @@
231244
memcpy(instanceHandle.value, key, len);
232245
change = writer->new_change([length]() -> uint32_t { return length+sizeof(header);}, ALIVE, instanceHandle);
233246
if (!change) { // In the case history is full, remove some old changes
234-
logWarning(ROV_PARTICIPANT, "cleaning history...")
247+
logInfo(ROV_PARTICIPANT, "cleaning history...")
235248
writer->remove_older_changes(2);
236249
change = writer->new_change([length]() -> uint32_t { return length+sizeof(header);}, ALIVE, instanceHandle);
237250
}
238251
} else {
239252
change = writer->new_change([length]() -> uint32_t { return length+sizeof(header);}, ALIVE);
240253
if (!change) { // In the case history is full, remove some old changes
241-
logWarning(ROV_PARTICIPANT, "cleaning history...")
254+
logInfo(ROV_PARTICIPANT, "cleaning history...")
242255
writer->remove_older_changes(2);
243256
change = writer->new_change([length]() -> uint32_t { return length+sizeof(header);}, ALIVE);
244257
}
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
1-
//
2-
// CustomParticipantListener.h
3-
// TestFastRTPS
4-
//
5-
// Created by Dmitriy Borovikov on 29/07/2019.
6-
// Copyright © 2019 Dmitriy Borovikov. All rights reserved.
1+
/////
2+
//// BridgedParticipantListener.h
3+
/// Copyright © 2019 Dmitriy Borovikov. All rights reserved.
74
//
85

9-
#ifndef CustomParticipantListener_h
10-
#define CustomParticipantListener_h
6+
#pragma once
117

128
#include <fastrtps/fastrtps_fwd.h>
139
#include <fastrtps/subscriber/SampleInfo.h>
1410
#include <fastrtps/rtps/participant/RTPSParticipantListener.h>
11+
#import "FastRTPSBridge.h"
1512

1613
using namespace eprosima::fastrtps;
1714
using namespace eprosima::fastrtps::rtps;
1815

19-
class CustomParticipantListener: public eprosima::fastrtps::rtps::RTPSParticipantListener
16+
class BridgedParticipantListener: public eprosima::fastrtps::rtps::RTPSParticipantListener
2017
{
2118
void onParticipantDiscovery(RTPSParticipant *participant, ParticipantDiscoveryInfo &&info) override;
2219
void onReaderDiscovery(RTPSParticipant *participant, ReaderDiscoveryInfo &&info) override;
2320
void onWriterDiscovery(RTPSParticipant *participant, WriterDiscoveryInfo &&info) override;
21+
NSSet* dumpLocators(ResourceLimitedVector<eprosima::fastrtps::rtps::Locator_t> locators);
2422
};
25-
26-
#endif /* CustomParticipantListener_h */

0 commit comments

Comments
 (0)