Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaRU committed Dec 7, 2019
2 parents cff5e7e + e3289d5 commit 85f50f2
Show file tree
Hide file tree
Showing 24 changed files with 603 additions and 420 deletions.
195 changes: 91 additions & 104 deletions FastRTPSBridge.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions FastRTPSBridge.xcodeproj/xcshareddata/IDETemplateMacros.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>FILEHEADER</key>
<string><![CDATA[///
//// ___FILENAME___
/// Copyright © ___YEAR___ ___ORGANIZATIONNAME___. All rights reserved.
//
]]></string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//
// RovParticipant.h
// TridentVideoViewer
//
// Created by Dmitriy Borovikov on 06/09/2019.
// Copyright © 2019 Dmitriy Borovikov. All rights reserved.
/////
//// BridgedParticipant.h
/// Copyright © 2019 Dmitriy Borovikov. All rights reserved.
//

#pragma once
Expand All @@ -12,21 +9,21 @@
#include <fastrtps/rtps/common/Types.h>
#include <fastrtps/rtps/attributes/WriterAttributes.h>
#include <fastrtps/rtps/reader/RTPSReader.h>
#include "fastrtps/rtps/writer/RTPSWriter.h"
#include <fastrtps/rtps/writer/RTPSWriter.h>
#include <fastrtps/rtps/history/ReaderHistory.h>
#include "fastrtps/rtps/history/WriterHistory.h"
#include <fastrtps/rtps/history/WriterHistory.h>
#include <string>
#include <map>
#import "RovTopicListener.h"
#import "RovWriterListener.h"
#import "BridgedReaderListener.h"
#import "BridgedWriterListener.h"

class CustomParticipantListener;
class RovParticipant
class BridgedParticipantListener;
class BridgedParticipant
{
struct ReaderInfo {
eprosima::fastrtps::rtps::RTPSReader* reader;
eprosima::fastrtps::rtps::ReaderHistory* history;
RovTopicListener* listener;
BridgedReaderListener* listener;
~ReaderInfo() {
delete history;
delete listener;
Expand All @@ -36,22 +33,24 @@ class RovParticipant
struct WriterInfo {
eprosima::fastrtps::rtps::RTPSWriter* writer;
eprosima::fastrtps::rtps::WriterHistory* history;
RovWriterListener* listener;
BridgedWriterListener* listener;
~WriterInfo() {
delete history;
delete listener;
}
};
public:
RovParticipant();
virtual ~RovParticipant();
BridgedParticipant();
virtual ~BridgedParticipant();
eprosima::fastrtps::rtps::RTPSParticipant* mp_participant;
CustomParticipantListener* mp_listener;
BridgedParticipantListener* mp_listener;
std::string partitionName;

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

bool startRTPS(); //Initialization
bool createParticipant(const char* name, const char *interfaceIPv4, const char* networkAddress);
void setPartition(const char* name) { partitionName = std::string(name); }
bool addReader(const char* name,
const char* dataType,
const bool keyed,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
//
// RovParticipant.mm
// TridentVideoViewer
//
// Created by Dmitriy Borovikov on 06/09/2019.
// Copyright © 2019 Dmitriy Borovikov. All rights reserved.
/////
//// BridgedParticipant.mm
/// Copyright © 2019 Dmitriy Borovikov. All rights reserved.
//

#include "RovParticipant.h"
#include "RovTopicListener.h"
#include "RovWriterListener.h"
#include "CustomParticipantListener.h"
#include "BridgedParticipant.h"
#include "BridgedReaderListener.h"
#include "BridgedWriterListener.h"
#include "BridgedParticipantListener.h"

#include <fastrtps/rtps/RTPSDomain.h>
#include <fastrtps/rtps/participant/RTPSParticipant.h>
Expand All @@ -23,27 +20,31 @@
#include <fastrtps/qos/ReaderQos.h>
#include <fastrtps/qos/WriterQos.h>
#include <fastrtps/log/Log.h>
#include <fastrtps/transport/UDPv4TransportDescriptor.h>
#include <memory>
#include <arpa/inet.h>

using namespace eprosima::fastrtps;
using namespace eprosima::fastrtps::rtps;

RovParticipant::RovParticipant():
BridgedParticipant::BridgedParticipant():
mp_participant(nullptr),
mp_listener(nullptr)
mp_listener(nullptr),
partitionName("*")
{
}

RovParticipant::~RovParticipant()
BridgedParticipant::~BridgedParticipant()
{
mp_participant->stopRTPSParticipantAnnouncement();
logInfo(ROV_PARTICIPANT, "Delete participant")
mp_participant->stopRTPSParticipantAnnouncement();
resignAll();
RTPSDomain::removeRTPSParticipant(mp_participant);
delete mp_listener;
// RTPSDomain::stopAll();
}

void RovParticipant::resignAll() {
void BridgedParticipant::resignAll() {
for(auto it = readerList.begin(); it != readerList.end(); it++)
{
logInfo(ROV_PARTICIPANT, "Remove reader: " << it->first)
Expand All @@ -63,28 +64,40 @@
writerList.clear();
}

bool RovParticipant::startRTPS()
bool BridgedParticipant::createParticipant(const char* name, const char *interfaceIPv4, const char* networkAddress)
{
//CREATE PARTICIPANT
RTPSParticipantAttributes PParam;
PParam.builtin.use_WriterLivelinessProtocol = true;
PParam.builtin.discovery_config.discoveryProtocol = eprosima::fastrtps::rtps::DiscoveryProtocol::SIMPLE;
PParam.builtin.discovery_config.leaseDuration_announcementperiod.seconds = 1;
PParam.builtin.discovery_config.leaseDuration.seconds = 20;
PParam.builtin.readerHistoryMemoryPolicy = PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
PParam.builtin.writerHistoryMemoryPolicy = PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
PParam.builtin.domainId = 0;
PParam.setName("TridentVideoViewer");
RTPSParticipantAttributes pattr;
pattr.builtin.use_WriterLivelinessProtocol = true;
pattr.builtin.discovery_config.discoveryProtocol = eprosima::fastrtps::rtps::DiscoveryProtocol::SIMPLE;
pattr.builtin.discovery_config.leaseDuration_announcementperiod.seconds = 1;
pattr.builtin.discovery_config.leaseDuration.seconds = 10;
pattr.builtin.discovery_config.ignoreParticipantFlags = FILTER_SAME_PROCESS;
pattr.builtin.readerHistoryMemoryPolicy = PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
pattr.builtin.writerHistoryMemoryPolicy = PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
pattr.builtin.domainId = 0;
pattr.setName(name);

mp_listener = new CustomParticipantListener();
mp_participant = RTPSDomain::createParticipant(PParam, mp_listener);
auto customTransport = std::make_shared<UDPv4TransportDescriptor>();
customTransport->sendBufferSize = 65536;
customTransport->receiveBufferSize = 65536;
if (interfaceIPv4 != nullptr) {
customTransport->interfaceWhiteList.emplace_back(interfaceIPv4);
}
if (networkAddress != nullptr) {
customTransport->remoteWhiteList.emplace_back(networkAddress);
}
pattr.userTransports.push_back(customTransport);
pattr.useBuiltinTransports = false;

mp_listener = new BridgedParticipantListener();
mp_participant = RTPSDomain::createParticipant(pattr, mp_listener);
if (mp_participant == nullptr)
return false;

return true;
}

bool RovParticipant::addReader(const char* name,
bool BridgedParticipant::addReader(const char* name,
const char* dataType,
const bool keyed,
NSObject<PayloadDecoderInterface>* payloadDecoder)
Expand All @@ -95,14 +108,14 @@
// aready registered
return false;
}
//CREATE READER
ReaderAttributes readerAttributes;
readerAttributes.endpoint.topicKind = tKind;
auto listener = new RovTopicListener(name, payloadDecoder);
//CREATE READERHISTORY
auto listener = new BridgedReaderListener(name, payloadDecoder);

HistoryAttributes hatt;
hatt.payloadMaxSize = 10000;
hatt.memoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
hatt.payloadMaxSize = 1000;
hatt.initialReservedCaches = 5;
hatt.maximumReservedCaches = 0;
auto history = new ReaderHistory(hatt);
auto reader = RTPSDomain::createRTPSReader(mp_participant, readerAttributes, history, listener);
Expand All @@ -111,16 +124,16 @@
delete history;
return false;
}

auto readerInfo = new ReaderInfo;
readerInfo->reader = reader;
readerInfo->history = history;
readerInfo->listener = listener;
readerList[topicName] = readerInfo;

TopicAttributes Tatt(name, dataType, tKind);
ReaderQos Rqos;
Rqos.m_partition.push_back("*");
Rqos.m_partition.push_back(partitionName.c_str());
auto rezult = mp_participant->registerReader(reader, Tatt, Rqos);
if (!rezult) {
RTPSDomain::removeRTPSReader(reader);
Expand All @@ -132,7 +145,7 @@
return true;
}

bool RovParticipant::removeReader(const char* name)
bool BridgedParticipant::removeReader(const char* name)
{
logInfo(ROV_PARTICIPANT, "Remove reader: " << name)
auto topicName = std::string(name);
Expand All @@ -147,7 +160,7 @@
return true;
}

bool RovParticipant::addWriter(const char* name,
bool BridgedParticipant::addWriter(const char* name,
const char* dataType,
const bool keyed)
{
Expand All @@ -161,11 +174,11 @@
WriterAttributes watt;
watt.endpoint.reliabilityKind = BEST_EFFORT;
watt.endpoint.topicKind = tKind;
auto listener = new RovWriterListener(name);
//CREATE WRITERHISTORY
auto listener = new BridgedWriterListener(name);
HistoryAttributes hatt;
// hatt.payloadMaxSize = 10000;
hatt.memoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
hatt.payloadMaxSize = 1000;
hatt.initialReservedCaches = 5;
hatt.maximumReservedCaches = 0;
auto history = new WriterHistory(hatt);
auto writer = RTPSDomain::createRTPSWriter(mp_participant, watt, history, listener);
Expand All @@ -183,7 +196,7 @@

TopicAttributes Tatt(name, dataType, tKind);
WriterQos Wqos;
Wqos.m_partition.push_back("*");
Wqos.m_partition.push_back(partitionName.c_str());
Wqos.m_disablePositiveACKs.enabled = true;
auto rezult = mp_participant->registerWriter(writer, Tatt, Wqos);
if (!rezult) {
Expand All @@ -196,7 +209,7 @@
return true;
}

bool RovParticipant::removeWriter(const char* name)
bool BridgedParticipant::removeWriter(const char* name)
{
logInfo(ROV_PARTICIPANT, "Remove writer: " << name)
auto topicName = std::string(name);
Expand All @@ -211,7 +224,7 @@
return true;
}

bool RovParticipant::send(const char* name, const uint8_t* data, uint32_t length, const void* key, uint32_t keyLength)
bool BridgedParticipant::send(const char* name, const uint8_t* data, uint32_t length, const void* key, uint32_t keyLength)
{
static const octet header[] = {0, 1, 0, 0};
auto topicName = std::string(name);
Expand All @@ -231,14 +244,14 @@
memcpy(instanceHandle.value, key, len);
change = writer->new_change([length]() -> uint32_t { return length+sizeof(header);}, ALIVE, instanceHandle);
if (!change) { // In the case history is full, remove some old changes
logWarning(ROV_PARTICIPANT, "cleaning history...")
logInfo(ROV_PARTICIPANT, "cleaning history...")
writer->remove_older_changes(2);
change = writer->new_change([length]() -> uint32_t { return length+sizeof(header);}, ALIVE, instanceHandle);
}
} else {
change = writer->new_change([length]() -> uint32_t { return length+sizeof(header);}, ALIVE);
if (!change) { // In the case history is full, remove some old changes
logWarning(ROV_PARTICIPANT, "cleaning history...")
logInfo(ROV_PARTICIPANT, "cleaning history...")
writer->remove_older_changes(2);
change = writer->new_change([length]() -> uint32_t { return length+sizeof(header);}, ALIVE);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
//
// CustomParticipantListener.h
// TestFastRTPS
//
// Created by Dmitriy Borovikov on 29/07/2019.
// Copyright © 2019 Dmitriy Borovikov. All rights reserved.
/////
//// BridgedParticipantListener.h
/// Copyright © 2019 Dmitriy Borovikov. All rights reserved.
//

#ifndef CustomParticipantListener_h
#define CustomParticipantListener_h
#pragma once

#include <fastrtps/fastrtps_fwd.h>
#include <fastrtps/subscriber/SampleInfo.h>
#include <fastrtps/rtps/participant/RTPSParticipantListener.h>
#import "FastRTPSBridge.h"

using namespace eprosima::fastrtps;
using namespace eprosima::fastrtps::rtps;

class CustomParticipantListener: public eprosima::fastrtps::rtps::RTPSParticipantListener
class BridgedParticipantListener: public eprosima::fastrtps::rtps::RTPSParticipantListener
{
void onParticipantDiscovery(RTPSParticipant *participant, ParticipantDiscoveryInfo &&info) override;
void onReaderDiscovery(RTPSParticipant *participant, ReaderDiscoveryInfo &&info) override;
void onWriterDiscovery(RTPSParticipant *participant, WriterDiscoveryInfo &&info) override;
NSSet* dumpLocators(ResourceLimitedVector<eprosima::fastrtps::rtps::Locator_t> locators);
};

#endif /* CustomParticipantListener_h */
Loading

0 comments on commit 85f50f2

Please sign in to comment.