Skip to content

Commit e372abd

Browse files
authored
Merge pull request #1 from embedded-software-laboratory/feature/check_for_exisiting_endpoints
Feature/check for exisiting endpoints * adding flag to indicate that writer/reader has been initialized * appyling clang-format and adding script for future use
2 parents 00a8e6b + 26072bf commit e372abd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+4465
-4125
lines changed

ci/clang-check-format.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
4+
5+
cd $DIR/../
6+
7+
# DIR dos2unix to clean-up line endings
8+
echo "Applying dos2unix"
9+
find . -iname *.hpp -o -iname *.cpp -o -iname *.tpp -o -iname *.h | grep -vi config.h | grep -vi thirdparty | xargs dos2unix
10+
11+
# Apply clang-format
12+
echo "Applying clang-format"
13+
find . -iname *.hpp -o -iname *.cpp -o -iname *.tpp -o -iname *.h | grep -vi config.h | grep -vi thirdparty | xargs clang-format -i --verbose style=Google

include/rtps/ThreadPool.h

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,57 +25,58 @@ Author: i11 - Embedded Software, RWTH Aachen University
2525
#ifndef RTPS_THREADPOOL_H
2626
#define RTPS_THREADPOOL_H
2727

28-
#include "rtps/config.h"
2928
#include "lwip/sys.h"
30-
#include "rtps/communication/UdpDriver.h"
3129
#include "rtps/communication/PacketInfo.h"
30+
#include "rtps/communication/UdpDriver.h"
31+
#include "rtps/config.h"
3232
#include "rtps/storages/PBufWrapper.h"
3333
#include "rtps/storages/ThreadSafeCircularBuffer.h"
3434

3535
#include <array>
3636

3737
namespace rtps {
3838

39-
class Writer;
40-
41-
42-
class ThreadPool {
43-
public:
44-
using receiveJumppad_fp = void(*)(void* callee, const PacketInfo& packet);
45-
46-
ThreadPool(receiveJumppad_fp receiveCallback, void* callee);
39+
class Writer;
4740

48-
~ThreadPool();
41+
class ThreadPool {
42+
public:
43+
using receiveJumppad_fp = void (*)(void *callee, const PacketInfo &packet);
4944

50-
bool startThreads();
51-
void stopThreads();
45+
ThreadPool(receiveJumppad_fp receiveCallback, void *callee);
5246

53-
void clearQueues();
54-
bool addWorkload(Writer* workload);
55-
bool addNewPacket(PacketInfo&& packet);
47+
~ThreadPool();
5648

57-
static void readCallback(void* arg, udp_pcb* pcb, pbuf* p, const ip_addr_t* addr, Ip4Port_t port);
49+
bool startThreads();
50+
void stopThreads();
5851

52+
void clearQueues();
53+
bool addWorkload(Writer *workload);
54+
bool addNewPacket(PacketInfo &&packet);
5955

60-
private:
61-
receiveJumppad_fp m_receiveJumppad;
62-
void* m_callee;
63-
bool m_running = false;
64-
std::array<sys_thread_t, Config::THREAD_POOL_NUM_WRITERS> m_writers;
65-
std::array<sys_thread_t, Config::THREAD_POOL_NUM_READERS> m_readers;
56+
static void readCallback(void *arg, udp_pcb *pcb, pbuf *p,
57+
const ip_addr_t *addr, Ip4Port_t port);
6658

67-
sys_sem_t m_readerNotificationSem;
68-
sys_sem_t m_writerNotificationSem;
59+
private:
60+
receiveJumppad_fp m_receiveJumppad;
61+
void *m_callee;
62+
bool m_running = false;
63+
std::array<sys_thread_t, Config::THREAD_POOL_NUM_WRITERS> m_writers;
64+
std::array<sys_thread_t, Config::THREAD_POOL_NUM_READERS> m_readers;
6965

70-
ThreadSafeCircularBuffer<Writer*, Config::THREAD_POOL_WORKLOAD_QUEUE_LENGTH> m_queueOutgoing;
71-
ThreadSafeCircularBuffer<PacketInfo, Config::THREAD_POOL_WORKLOAD_QUEUE_LENGTH> m_queueIncoming;
66+
sys_sem_t m_readerNotificationSem;
67+
sys_sem_t m_writerNotificationSem;
7268

73-
static void writerThreadFunction(void* arg);
74-
static void readerThreadFunction(void* arg);
75-
void doWriterWork();
76-
void doReaderWork();
69+
ThreadSafeCircularBuffer<Writer *, Config::THREAD_POOL_WORKLOAD_QUEUE_LENGTH>
70+
m_queueOutgoing;
71+
ThreadSafeCircularBuffer<PacketInfo,
72+
Config::THREAD_POOL_WORKLOAD_QUEUE_LENGTH>
73+
m_queueIncoming;
7774

78-
};
79-
}
75+
static void writerThreadFunction(void *arg);
76+
static void readerThreadFunction(void *arg);
77+
void doWriterWork();
78+
void doReaderWork();
79+
};
80+
} // namespace rtps
8081

81-
#endif //RTPS_THREADPOOL_H
82+
#endif // RTPS_THREADPOOL_H

include/rtps/common/Locator.h

Lines changed: 85 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -25,97 +25,99 @@ Author: i11 - Embedded Software, RWTH Aachen University
2525
#ifndef RTPS_LOCATOR_T_H
2626
#define RTPS_LOCATOR_T_H
2727

28-
#include "ucdr/microcdr.h"
29-
#include "rtps/utils/udpUtils.h"
3028
#include "rtps/communication/UdpDriver.h"
29+
#include "rtps/utils/udpUtils.h"
30+
#include "ucdr/microcdr.h"
3131

3232
#include <array>
3333

34-
namespace rtps{
35-
enum class LocatorKind_t : int32_t{
36-
LOCATOR_KIND_INVALID = -1,
37-
LOCATOR_KIND_RESERVED = 0,
38-
LOCATOR_KIND_UDPv4 = 1,
39-
LOCATOR_KIND_UDPv6 = 2
40-
};
41-
42-
const uint32_t LOCATOR_PORT_INVALID = 0;
43-
const std::array<uint8_t, 16> LOCATOR_ADDRESS_INVALID = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
44-
45-
struct Locator{
46-
LocatorKind_t kind = LocatorKind_t::LOCATOR_KIND_INVALID;
47-
uint32_t port = LOCATOR_PORT_INVALID;
48-
std::array<uint8_t,16> address = LOCATOR_ADDRESS_INVALID; // TODO make private such that kind and address always match?
49-
50-
static Locator createUDPv4Locator(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint32_t port){
51-
Locator locator;
52-
locator.kind = LocatorKind_t::LOCATOR_KIND_UDPv4;
53-
locator.address = {0,0,0,0,0,0,0,0,0,0,0,0,a,b,c,d};
54-
locator.port = port;
55-
return locator;
56-
}
57-
58-
void setInvalid(){
59-
kind = LocatorKind_t::LOCATOR_KIND_INVALID;
60-
}
61-
62-
bool isValid() const{
63-
return kind != LocatorKind_t::LOCATOR_KIND_INVALID;
64-
}
65-
66-
bool readFromUcdrBuffer(ucdrBuffer& buffer){
67-
if(ucdr_buffer_remaining(&buffer) < sizeof(Locator)){
68-
return false;
69-
}else{
70-
ucdr_deserialize_array_uint8_t(&buffer, reinterpret_cast<uint8_t*>(this), sizeof(Locator));
71-
return true;
72-
}
73-
}
74-
75-
bool serializeIntoUdcrBuffer(ucdrBuffer& buffer){
76-
if(ucdr_buffer_remaining(&buffer) < sizeof(Locator)){
77-
return false;
78-
}else{
79-
ucdr_serialize_array_uint8_t(&buffer, reinterpret_cast<uint8_t*>(this), sizeof(Locator));
80-
}
81-
}
82-
83-
ip4_addr_t getIp4Address() const{
84-
return transformIP4ToU32(address[12], address[13], address[14], address[15]);
85-
}
86-
87-
inline bool isSameSubnet() const{
88-
return UdpDriver::isSameSubnet(getIp4Address());
89-
}
90-
91-
} __attribute__((packed));
92-
93-
inline Locator getBuiltInUnicastLocator(ParticipantId_t participantId) {
94-
return Locator::createUDPv4Locator(Config::IP_ADDRESS[0], Config::IP_ADDRESS[1],
95-
Config::IP_ADDRESS[2], Config::IP_ADDRESS[3],
96-
getBuiltInUnicastPort(participantId));
34+
namespace rtps {
35+
enum class LocatorKind_t : int32_t {
36+
LOCATOR_KIND_INVALID = -1,
37+
LOCATOR_KIND_RESERVED = 0,
38+
LOCATOR_KIND_UDPv4 = 1,
39+
LOCATOR_KIND_UDPv6 = 2
40+
};
41+
42+
const uint32_t LOCATOR_PORT_INVALID = 0;
43+
const std::array<uint8_t, 16> LOCATOR_ADDRESS_INVALID = {
44+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
45+
46+
struct Locator {
47+
LocatorKind_t kind = LocatorKind_t::LOCATOR_KIND_INVALID;
48+
uint32_t port = LOCATOR_PORT_INVALID;
49+
std::array<uint8_t, 16> address =
50+
LOCATOR_ADDRESS_INVALID; // TODO make private such that kind and address
51+
// always match?
52+
53+
static Locator createUDPv4Locator(uint8_t a, uint8_t b, uint8_t c, uint8_t d,
54+
uint32_t port) {
55+
Locator locator;
56+
locator.kind = LocatorKind_t::LOCATOR_KIND_UDPv4;
57+
locator.address = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, a, b, c, d};
58+
locator.port = port;
59+
return locator;
60+
}
61+
62+
void setInvalid() { kind = LocatorKind_t::LOCATOR_KIND_INVALID; }
63+
64+
bool isValid() const { return kind != LocatorKind_t::LOCATOR_KIND_INVALID; }
65+
66+
bool readFromUcdrBuffer(ucdrBuffer &buffer) {
67+
if (ucdr_buffer_remaining(&buffer) < sizeof(Locator)) {
68+
return false;
69+
} else {
70+
ucdr_deserialize_array_uint8_t(&buffer, reinterpret_cast<uint8_t *>(this),
71+
sizeof(Locator));
72+
return true;
9773
}
98-
99-
inline Locator getBuiltInMulticastLocator() {
100-
return Locator::createUDPv4Locator(239, 255, 0, 1, getBuiltInMulticastPort());
74+
}
75+
76+
bool serializeIntoUdcrBuffer(ucdrBuffer &buffer) {
77+
if (ucdr_buffer_remaining(&buffer) < sizeof(Locator)) {
78+
return false;
79+
} else {
80+
ucdr_serialize_array_uint8_t(&buffer, reinterpret_cast<uint8_t *>(this),
81+
sizeof(Locator));
10182
}
83+
}
10284

103-
inline Locator getUserUnicastLocator(ParticipantId_t participantId) {
104-
return Locator::createUDPv4Locator(Config::IP_ADDRESS[0], Config::IP_ADDRESS[1],
105-
Config::IP_ADDRESS[2], Config::IP_ADDRESS[3],
106-
getUserUnicastPort(participantId));
107-
}
85+
ip4_addr_t getIp4Address() const {
86+
return transformIP4ToU32(address[12], address[13], address[14],
87+
address[15]);
88+
}
10889

109-
inline Locator getUserMulticastLocator() {
110-
return Locator::createUDPv4Locator(Config::IP_ADDRESS[0], Config::IP_ADDRESS[1],
111-
Config::IP_ADDRESS[2], Config::IP_ADDRESS[3],
112-
getUserMulticastPort());
113-
}
90+
inline bool isSameSubnet() const {
91+
return UdpDriver::isSameSubnet(getIp4Address());
92+
}
11493

115-
inline Locator getDefaultSendMulticastLocator() {
116-
return Locator::createUDPv4Locator(239, 255, 0, 1,
117-
getBuiltInMulticastPort());
118-
}
94+
} __attribute__((packed));
95+
96+
inline Locator getBuiltInUnicastLocator(ParticipantId_t participantId) {
97+
return Locator::createUDPv4Locator(
98+
Config::IP_ADDRESS[0], Config::IP_ADDRESS[1], Config::IP_ADDRESS[2],
99+
Config::IP_ADDRESS[3], getBuiltInUnicastPort(participantId));
100+
}
101+
102+
inline Locator getBuiltInMulticastLocator() {
103+
return Locator::createUDPv4Locator(239, 255, 0, 1, getBuiltInMulticastPort());
104+
}
105+
106+
inline Locator getUserUnicastLocator(ParticipantId_t participantId) {
107+
return Locator::createUDPv4Locator(
108+
Config::IP_ADDRESS[0], Config::IP_ADDRESS[1], Config::IP_ADDRESS[2],
109+
Config::IP_ADDRESS[3], getUserUnicastPort(participantId));
110+
}
111+
112+
inline Locator getUserMulticastLocator() {
113+
return Locator::createUDPv4Locator(
114+
Config::IP_ADDRESS[0], Config::IP_ADDRESS[1], Config::IP_ADDRESS[2],
115+
Config::IP_ADDRESS[3], getUserMulticastPort());
116+
}
117+
118+
inline Locator getDefaultSendMulticastLocator() {
119+
return Locator::createUDPv4Locator(239, 255, 0, 1, getBuiltInMulticastPort());
119120
}
121+
} // namespace rtps
120122

121-
#endif //RTPS_LOCATOR_T_H
123+
#endif // RTPS_LOCATOR_T_H

0 commit comments

Comments
 (0)