diff --git a/include/rtps/ThreadPool.h b/include/rtps/ThreadPool.h index aafc59fa..14fd6249 100644 --- a/include/rtps/ThreadPool.h +++ b/include/rtps/ThreadPool.h @@ -34,11 +34,13 @@ Author: i11 - Embedded Software, RWTH Aachen University #include -namespace rtps { +namespace rtps +{ class Writer; -class ThreadPool { +class ThreadPool +{ public: using receiveJumppad_fp = void (*)(void *callee, const PacketInfo &packet); @@ -67,10 +69,10 @@ class ThreadPool { sys_sem_t m_writerNotificationSem; ThreadSafeCircularBuffer - m_queueOutgoing; + m_queueOutgoing; ThreadSafeCircularBuffer - m_queueIncoming; + m_queueIncoming; static void writerThreadFunction(void *arg); static void readerThreadFunction(void *arg); diff --git a/include/rtps/common/Locator.h b/include/rtps/common/Locator.h index 94f55c09..06a5e96d 100644 --- a/include/rtps/common/Locator.h +++ b/include/rtps/common/Locator.h @@ -31,7 +31,8 @@ Author: i11 - Embedded Software, RWTH Aachen University #include -namespace rtps { +namespace rtps +{ enum class LocatorKind_t : int32_t { LOCATOR_KIND_INVALID = -1, LOCATOR_KIND_RESERVED = 0, @@ -41,7 +42,8 @@ enum class LocatorKind_t : int32_t { const uint32_t LOCATOR_PORT_INVALID = 0; const std::array LOCATOR_ADDRESS_INVALID = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; /* * This representation corresponds to the RTPS wire format @@ -50,11 +52,12 @@ struct FullLengthLocator { LocatorKind_t kind = LocatorKind_t::LOCATOR_KIND_INVALID; uint32_t port = LOCATOR_PORT_INVALID; std::array address = - LOCATOR_ADDRESS_INVALID; // TODO make private such that kind and address - // always match? + LOCATOR_ADDRESS_INVALID; // TODO make private such that kind and address + // always match? static FullLengthLocator createUDPv4Locator(uint8_t a, uint8_t b, uint8_t c, - uint8_t d, uint32_t port) { + uint8_t d, uint32_t port) + { FullLengthLocator locator; locator.kind = LocatorKind_t::LOCATOR_KIND_UDPv4; locator.address = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, a, b, c, d}; @@ -62,11 +65,18 @@ struct FullLengthLocator { return locator; } - void setInvalid() { kind = LocatorKind_t::LOCATOR_KIND_INVALID; } + void setInvalid() + { + kind = LocatorKind_t::LOCATOR_KIND_INVALID; + } - bool isValid() const { return kind != LocatorKind_t::LOCATOR_KIND_INVALID; } + bool isValid() const + { + return kind != LocatorKind_t::LOCATOR_KIND_INVALID; + } - bool readFromUcdrBuffer(ucdrBuffer &buffer) { + bool readFromUcdrBuffer(ucdrBuffer &buffer) + { if (ucdr_buffer_remaining(&buffer) < sizeof(FullLengthLocator)) { return false; } else { @@ -76,7 +86,8 @@ struct FullLengthLocator { } } - bool serializeIntoUdcrBuffer(ucdrBuffer &buffer) { + bool serializeIntoUdcrBuffer(ucdrBuffer &buffer) + { if (ucdr_buffer_remaining(&buffer) < sizeof(FullLengthLocator)) { return false; } else { @@ -85,57 +96,69 @@ struct FullLengthLocator { } } - ip4_addr_t getIp4Address() const { + ip4_addr_t getIp4Address() const + { return transformIP4ToU32(address[12], address[13], address[14], address[15]); } - bool isSameAddress(ip4_addr_t *address) { + bool isSameAddress(ip4_addr_t *address) + { ip4_addr_t ownaddress = getIp4Address(); return ip4_addr_cmp(&ownaddress, address); } - inline bool isSameSubnet() const { + inline bool isSameSubnet() const + { return UdpDriver::isSameSubnet(getIp4Address()); } - inline bool isMulticastAddress() const { + inline bool isMulticastAddress() const + { return UdpDriver::isMulticastAddress(getIp4Address()); } - inline uint32_t getLocatorPort() { return static_cast(port); } + inline uint32_t getLocatorPort() + { + return static_cast(port); + } } __attribute__((packed)); inline FullLengthLocator -getBuiltInUnicastLocator(ParticipantId_t participantId) { +getBuiltInUnicastLocator(ParticipantId_t participantId) +{ return FullLengthLocator::createUDPv4Locator( - Config::IP_ADDRESS[0], Config::IP_ADDRESS[1], Config::IP_ADDRESS[2], - Config::IP_ADDRESS[3], getBuiltInUnicastPort(participantId)); + Config::IP_ADDRESS[0], Config::IP_ADDRESS[1], Config::IP_ADDRESS[2], + Config::IP_ADDRESS[3], getBuiltInUnicastPort(participantId)); } -inline FullLengthLocator getBuiltInMulticastLocator() { +inline FullLengthLocator getBuiltInMulticastLocator() +{ return FullLengthLocator::createUDPv4Locator(239, 255, 0, 1, - getBuiltInMulticastPort()); + getBuiltInMulticastPort()); } -inline FullLengthLocator getUserUnicastLocator(ParticipantId_t participantId) { +inline FullLengthLocator getUserUnicastLocator(ParticipantId_t participantId) +{ return FullLengthLocator::createUDPv4Locator( - Config::IP_ADDRESS[0], Config::IP_ADDRESS[1], Config::IP_ADDRESS[2], - Config::IP_ADDRESS[3], getUserUnicastPort(participantId)); + Config::IP_ADDRESS[0], Config::IP_ADDRESS[1], Config::IP_ADDRESS[2], + Config::IP_ADDRESS[3], getUserUnicastPort(participantId)); } inline FullLengthLocator -getUserMulticastLocator() { // this would be a unicastaddress, as - // defined in config +getUserMulticastLocator() // this would be a unicastaddress, as +{ + // defined in config return FullLengthLocator::createUDPv4Locator( - Config::IP_ADDRESS[0], Config::IP_ADDRESS[1], Config::IP_ADDRESS[2], - Config::IP_ADDRESS[3], getUserMulticastPort()); + Config::IP_ADDRESS[0], Config::IP_ADDRESS[1], Config::IP_ADDRESS[2], + Config::IP_ADDRESS[3], getUserMulticastPort()); } -inline FullLengthLocator getDefaultSendMulticastLocator() { +inline FullLengthLocator getDefaultSendMulticastLocator() +{ return FullLengthLocator::createUDPv4Locator(239, 255, 0, 1, - getBuiltInMulticastPort()); + getBuiltInMulticastPort()); } /* @@ -147,7 +170,8 @@ struct LocatorIPv4 { uint32_t port = LOCATOR_PORT_INVALID; LocatorIPv4() = default; - LocatorIPv4(const FullLengthLocator &locator) { + LocatorIPv4(const FullLengthLocator &locator) + { address[0] = locator.address[12]; address[1] = locator.address[13]; address[2] = locator.address[14]; @@ -156,19 +180,28 @@ struct LocatorIPv4 { kind = locator.kind; } - ip4_addr_t getIp4Address() const { + ip4_addr_t getIp4Address() const + { return transformIP4ToU32(address[0], address[1], address[2], address[3]); } - void setInvalid() { kind = LocatorKind_t::LOCATOR_KIND_INVALID; } + void setInvalid() + { + kind = LocatorKind_t::LOCATOR_KIND_INVALID; + } - bool isValid() const { return kind != LocatorKind_t::LOCATOR_KIND_INVALID; } + bool isValid() const + { + return kind != LocatorKind_t::LOCATOR_KIND_INVALID; + } - inline bool isSameSubnet() const { + inline bool isSameSubnet() const + { return UdpDriver::isSameSubnet(getIp4Address()); } - inline bool isMulticastAddress() const { + inline bool isMulticastAddress() const + { return UdpDriver::isMulticastAddress(getIp4Address()); } }; diff --git a/include/rtps/common/types.h b/include/rtps/common/types.h index 781aba53..3fb97a2a 100644 --- a/include/rtps/common/types.h +++ b/include/rtps/common/types.h @@ -32,7 +32,8 @@ Author: i11 - Embedded Software, RWTH Aachen University #include // TODO subnamespaces -namespace rtps { +namespace rtps +{ // TODO move types to where they are needed! @@ -88,7 +89,8 @@ enum class DurabilityKind_t : uint32_t { struct GuidPrefix_t { std::array id; - bool operator==(const GuidPrefix_t &other) const { + bool operator==(const GuidPrefix_t &other) const + { return this->id == other.id; } }; @@ -97,23 +99,29 @@ struct EntityId_t { std::array entityKey; EntityKind_t entityKind; - bool operator==(const EntityId_t &other) const { + bool operator==(const EntityId_t &other) const + { return this->entityKey == other.entityKey && this->entityKind == other.entityKind; } - bool operator!=(const EntityId_t &other) const { return !(*this == other); } + bool operator!=(const EntityId_t &other) const + { + return !(*this == other); + } }; struct Guid_t { GuidPrefix_t prefix; EntityId_t entityId; - bool operator==(const Guid_t &other) const { + bool operator==(const Guid_t &other) const + { return this->prefix == other.prefix && this->entityId == other.entityId; } - static uint32_t sum(const Guid_t &other) { + static uint32_t sum(const Guid_t &other) + { uint32_t ret = 0; for (const auto &i : other.prefix.id) { ret += i; @@ -131,9 +139,10 @@ struct Time_t { int32_t seconds; // time in seconds uint32_t fraction; // time in sec/2^32 (?) - static Time_t create(int32_t s, uint32_t ns) { + static Time_t create(int32_t s, uint32_t ns) + { static constexpr double factor = - (static_cast(1) << 32) / 1000000000.; + (static_cast(1) << 32) / 1000000000.; auto fraction = static_cast(ns * factor); return Time_t{s, fraction}; } @@ -147,23 +156,28 @@ struct SequenceNumber_t { int32_t high; uint32_t low; - bool operator==(const SequenceNumber_t &other) const { + bool operator==(const SequenceNumber_t &other) const + { return high == other.high && low == other.low; } - bool operator!=(const SequenceNumber_t &other) const { + bool operator!=(const SequenceNumber_t &other) const + { return !(*this == other); } - bool operator<(const SequenceNumber_t &other) const { + bool operator<(const SequenceNumber_t &other) const + { return high < other.high || (high == other.high && low < other.low); } - bool operator<=(const SequenceNumber_t &other) const { + bool operator<=(const SequenceNumber_t &other) const + { return *this == other || *this < other; } - SequenceNumber_t &operator++() { + SequenceNumber_t &operator++() + { ++low; if (low == 0) { ++high; @@ -171,7 +185,8 @@ struct SequenceNumber_t { return *this; } - SequenceNumber_t operator++(int) { + SequenceNumber_t operator++(int) + { SequenceNumber_t tmp(*this); ++*this; return tmp; @@ -183,7 +198,7 @@ struct SequenceNumberSet { SequenceNumberSet() = default; explicit SequenceNumberSet(const SequenceNumber_t &firstMissing) - : base(firstMissing) {} + : base(firstMissing) {} SequenceNumber_t base = {0, 0}; // Cannot be static because of packed @@ -191,7 +206,8 @@ struct SequenceNumberSet { std::array bitMap{}; // We only need 1 byte because atm we don't store packets. - bool isSet(uint32_t bit) const { + bool isSet(uint32_t bit) const + { if (bit >= SNS_NUM_BITS) { return true; } @@ -236,27 +252,38 @@ struct ParticipantMessageData { // TODO /* Default Values */ const EntityId_t ENTITYID_UNKNOWN{}; const EntityId_t ENTITYID_BUILD_IN_PARTICIPANT = { - {00, 00, 01}, EntityKind_t::BUILD_IN_PARTICIPANT}; + {00, 00, 01}, EntityKind_t::BUILD_IN_PARTICIPANT +}; const EntityId_t ENTITYID_SEDP_BUILTIN_TOPIC_WRITER = { - {00, 00, 02}, EntityKind_t::BUILD_IN_WRITER_WITH_KEY}; + {00, 00, 02}, EntityKind_t::BUILD_IN_WRITER_WITH_KEY +}; const EntityId_t ENTITYID_SEDP_BUILTIN_TOPIC_READER = { - {00, 00, 02}, EntityKind_t::BUILD_IN_READER_WITH_KEY}; + {00, 00, 02}, EntityKind_t::BUILD_IN_READER_WITH_KEY +}; const EntityId_t ENTITYID_SEDP_BUILTIN_PUBLICATIONS_WRITER = { - {00, 00, 03}, EntityKind_t::BUILD_IN_WRITER_WITH_KEY}; + {00, 00, 03}, EntityKind_t::BUILD_IN_WRITER_WITH_KEY +}; const EntityId_t ENTITYID_SEDP_BUILTIN_PUBLICATIONS_READER = { - {00, 00, 03}, EntityKind_t::BUILD_IN_READER_WITH_KEY}; + {00, 00, 03}, EntityKind_t::BUILD_IN_READER_WITH_KEY +}; const EntityId_t ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_WRITER = { - {00, 00, 04}, EntityKind_t::BUILD_IN_WRITER_WITH_KEY}; + {00, 00, 04}, EntityKind_t::BUILD_IN_WRITER_WITH_KEY +}; const EntityId_t ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_READER = { - {00, 00, 04}, EntityKind_t::BUILD_IN_READER_WITH_KEY}; + {00, 00, 04}, EntityKind_t::BUILD_IN_READER_WITH_KEY +}; const EntityId_t ENTITYID_SPDP_BUILTIN_PARTICIPANT_WRITER = { - {00, 01, 00}, EntityKind_t::BUILD_IN_WRITER_WITH_KEY}; + {00, 01, 00}, EntityKind_t::BUILD_IN_WRITER_WITH_KEY +}; const EntityId_t ENTITYID_SPDP_BUILTIN_PARTICIPANT_READER = { - {00, 01, 00}, EntityKind_t::BUILD_IN_READER_WITH_KEY}; + {00, 01, 00}, EntityKind_t::BUILD_IN_READER_WITH_KEY +}; const EntityId_t ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_WRITER = { - {00, 02, 00}, EntityKind_t::BUILD_IN_WRITER_WITH_KEY}; + {00, 02, 00}, EntityKind_t::BUILD_IN_WRITER_WITH_KEY +}; const EntityId_t ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_READER = { - {00, 02, 00}, EntityKind_t::BUILD_IN_READER_WITH_KEY}; + {00, 02, 00}, EntityKind_t::BUILD_IN_READER_WITH_KEY +}; const GuidPrefix_t GUIDPREFIX_UNKNOWN{}; const Guid_t GUID_UNKNOWN{}; diff --git a/include/rtps/communication/PacketInfo.h b/include/rtps/communication/PacketInfo.h index 09cc50a0..b4211bdd 100644 --- a/include/rtps/communication/PacketInfo.h +++ b/include/rtps/communication/PacketInfo.h @@ -28,7 +28,8 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/common/types.h" #include "rtps/storages/PBufWrapper.h" -namespace rtps { +namespace rtps +{ struct PacketInfo { Ip4Port_t srcPort; // TODO Do we need that? @@ -36,7 +37,8 @@ struct PacketInfo { Ip4Port_t destPort; PBufWrapper buffer; - void copyTriviallyCopyable(const PacketInfo &other) { + void copyTriviallyCopyable(const PacketInfo &other) + { this->srcPort = other.srcPort; this->destPort = other.destPort; this->destAddr = other.destAddr; @@ -45,13 +47,15 @@ struct PacketInfo { PacketInfo() = default; ~PacketInfo() = default; - PacketInfo &operator=(const PacketInfo &other) { + PacketInfo &operator=(const PacketInfo &other) + { copyTriviallyCopyable(other); this->buffer = other.buffer; return *this; } - PacketInfo &operator=(PacketInfo &&other) noexcept { + PacketInfo &operator=(PacketInfo &&other) noexcept + { copyTriviallyCopyable(other); this->buffer = std::move(other.buffer); return *this; diff --git a/include/rtps/communication/TcpipCoreLock.h b/include/rtps/communication/TcpipCoreLock.h index fcd26bb0..023f5ca7 100644 --- a/include/rtps/communication/TcpipCoreLock.h +++ b/include/rtps/communication/TcpipCoreLock.h @@ -27,11 +27,19 @@ Author: i11 - Embedded Software, RWTH Aachen University #include -namespace rtps { -class TcpipCoreLock { +namespace rtps +{ +class TcpipCoreLock +{ public: - TcpipCoreLock() { LOCK_TCPIP_CORE(); } - ~TcpipCoreLock() { UNLOCK_TCPIP_CORE(); } + TcpipCoreLock() + { + LOCK_TCPIP_CORE(); + } + ~TcpipCoreLock() + { + UNLOCK_TCPIP_CORE(); + } }; } // namespace rtps diff --git a/include/rtps/communication/UdpConnection.h b/include/rtps/communication/UdpConnection.h index b95ac6fe..e1cbe75c 100644 --- a/include/rtps/communication/UdpConnection.h +++ b/include/rtps/communication/UdpConnection.h @@ -28,7 +28,8 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "TcpipCoreLock.h" #include "lwip/udp.h" -namespace rtps { +namespace rtps +{ struct UdpConnection { udp_pcb *pcb = nullptr; @@ -36,13 +37,15 @@ struct UdpConnection { UdpConnection() = default; // Required for static allocation - explicit UdpConnection(uint16_t port) : port(port) { + explicit UdpConnection(uint16_t port) : port(port) + { LOCK_TCPIP_CORE(); pcb = udp_new(); UNLOCK_TCPIP_CORE(); } - UdpConnection &operator=(UdpConnection &&other) noexcept { + UdpConnection &operator=(UdpConnection &&other) noexcept + { port = other.port; if (pcb != nullptr) { @@ -55,7 +58,8 @@ struct UdpConnection { return *this; } - ~UdpConnection() { + ~UdpConnection() + { if (pcb != nullptr) { LOCK_TCPIP_CORE(); udp_remove(pcb); diff --git a/include/rtps/communication/UdpDriver.h b/include/rtps/communication/UdpDriver.h index 80fcd399..bbe72783 100644 --- a/include/rtps/communication/UdpDriver.h +++ b/include/rtps/communication/UdpDriver.h @@ -34,9 +34,11 @@ Author: i11 - Embedded Software, RWTH Aachen University #include -namespace rtps { +namespace rtps +{ -class UdpDriver { +class UdpDriver +{ public: typedef void (*udpRxFunc_fp)(void *arg, udp_pcb *pcb, pbuf *p, diff --git a/include/rtps/config_aurix.h b/include/rtps/config_aurix.h index b801b38a..327be7ae 100644 --- a/include/rtps/config_aurix.h +++ b/include/rtps/config_aurix.h @@ -27,14 +27,16 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/common/types.h" -namespace rtps { +namespace rtps +{ #define IS_LITTLE_ENDIAN 1 // define only if using FreeRTOS #define OS_IS_FREERTOS -namespace Config { +namespace Config +{ const VendorId_t VENDOR_ID = {13, 37}; const std::array IP_ADDRESS = {192, 168, 0, 42}; const GuidPrefix_t BASE_GUID_PREFIX{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; @@ -66,7 +68,7 @@ const uint16_t SPDP_WRITER_STACKSIZE = 550; // byte const uint16_t SF_WRITER_HB_PERIOD_MS = 4000; const uint16_t SPDP_RESEND_PERIOD_MS = 10000; const uint8_t SPDP_CYCLECOUNT_HEARTBEAT = - 2; // skip x SPDP rounds before checking liveliness + 2; // skip x SPDP rounds before checking liveliness const uint8_t SPDP_WRITER_PRIO = 3; const uint8_t SPDP_MAX_NUMBER_FOUND_PARTICIPANTS = 5; const uint8_t SPDP_MAX_NUM_LOCATORS = 5; @@ -81,10 +83,10 @@ const int THREAD_POOL_READER_PRIO = 3; const int THREAD_POOL_WORKLOAD_QUEUE_LENGTH = 10; constexpr int OVERALL_HEAP_SIZE = - THREAD_POOL_NUM_WRITERS * THREAD_POOL_WRITER_STACKSIZE + - THREAD_POOL_NUM_READERS * THREAD_POOL_READER_STACKSIZE + - MAX_NUM_PARTICIPANTS * SPDP_WRITER_STACKSIZE + - NUM_STATEFUL_WRITERS * HEARTBEAT_STACKSIZE; + THREAD_POOL_NUM_WRITERS * THREAD_POOL_WRITER_STACKSIZE + + THREAD_POOL_NUM_READERS * THREAD_POOL_READER_STACKSIZE + + MAX_NUM_PARTICIPANTS * SPDP_WRITER_STACKSIZE + + NUM_STATEFUL_WRITERS * HEARTBEAT_STACKSIZE; } // namespace Config } // namespace rtps diff --git a/include/rtps/config_desktop.h b/include/rtps/config_desktop.h index 0d011e7e..c9dac230 100644 --- a/include/rtps/config_desktop.h +++ b/include/rtps/config_desktop.h @@ -27,28 +27,31 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/common/types.h" -namespace rtps { +namespace rtps +{ #define IS_LITTLE_ENDIAN 1 -namespace Config { +namespace Config +{ const VendorId_t VENDOR_ID = {13, 37}; const std::array IP_ADDRESS = { - 192, 168, 1, 2}; // Needs to be set in lwipcfg.h too. + 192, 168, 1, 2 +}; // Needs to be set in lwipcfg.h too. const GuidPrefix_t BASE_GUID_PREFIX{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9}; const uint8_t DOMAIN_ID = 0; // 230 possible with UDP const uint8_t MAX_NUM_PARTICIPANTS = 2; const uint8_t NUM_STATELESS_WRITERS = - MAX_NUM_PARTICIPANTS + 1; // Required + Additional + MAX_NUM_PARTICIPANTS + 1; // Required + Additional const uint8_t NUM_STATELESS_READERS = - MAX_NUM_PARTICIPANTS + 1; // Required + Additional + MAX_NUM_PARTICIPANTS + 1; // Required + Additional const uint8_t NUM_STATEFUL_READERS = - 4; // 1-4 required per participant depending on what they do and to whom - // they match + 4; // 1-4 required per participant depending on what they do and to whom +// they match const uint8_t NUM_STATEFUL_WRITERS = - 4; // 1-4 required per participant depending on what they do and to whom - // they match + 4; // 1-4 required per participant depending on what they do and to whom +// they match const uint8_t NUM_WRITERS_PER_PARTICIPANT = 4; const uint8_t NUM_READERS_PER_PARTICIPANT = 4; const uint8_t NUM_WRITER_PROXIES_PER_READER = 3; @@ -70,16 +73,18 @@ const uint16_t SPDP_WRITER_STACKSIZE = 550; // byte const uint16_t SF_WRITER_HB_PERIOD_MS = 500; const uint16_t SPDP_RESEND_PERIOD_MS = 10000; const uint8_t SPDP_CYCLECOUNT_HEARTBEAT = - 2; // skip x SPDP rounds before checking liveliness + 2; // skip x SPDP rounds before checking liveliness const uint8_t SPDP_WRITER_PRIO = 3; const uint8_t SPDP_MAX_NUMBER_FOUND_PARTICIPANTS = 5; const uint8_t SPDP_MAX_NUM_LOCATORS = 5; const Duration_t SPDP_DEFAULT_REMOTE_LEASE_DURATION = { - 100, 0}; // Default lease duration for remote participants, usually - // overwritten by remote info + 100, 0 +}; // Default lease duration for remote participants, usually +// overwritten by remote info const Duration_t SPDP_MAX_REMOTE_LEASE_DURATION = { - 180, - 0}; // Absolute maximum lease duration, ignoring remote participant info + 180, + 0 +}; // Absolute maximum lease duration, ignoring remote participant info const int MAX_NUM_UDP_CONNECTIONS = 10; @@ -90,10 +95,10 @@ const int THREAD_POOL_READER_PRIO = 3; const int THREAD_POOL_WORKLOAD_QUEUE_LENGTH = 10; constexpr int OVERALL_HEAP_SIZE = - THREAD_POOL_NUM_WRITERS * THREAD_POOL_WRITER_STACKSIZE + - THREAD_POOL_NUM_READERS * THREAD_POOL_READER_STACKSIZE + - MAX_NUM_PARTICIPANTS * SPDP_WRITER_STACKSIZE + - NUM_STATEFUL_WRITERS * HEARTBEAT_STACKSIZE; + THREAD_POOL_NUM_WRITERS * THREAD_POOL_WRITER_STACKSIZE + + THREAD_POOL_NUM_READERS * THREAD_POOL_READER_STACKSIZE + + MAX_NUM_PARTICIPANTS * SPDP_WRITER_STACKSIZE + + NUM_STATEFUL_WRITERS * HEARTBEAT_STACKSIZE; } // namespace Config } // namespace rtps diff --git a/include/rtps/config_r5.h b/include/rtps/config_r5.h index c87ba49c..510e8beb 100644 --- a/include/rtps/config_r5.h +++ b/include/rtps/config_r5.h @@ -3,14 +3,17 @@ #include "rtps/common/types.h" -namespace rtps { +namespace rtps +{ #define IS_LITTLE_ENDIAN 1 -namespace Config { +namespace Config +{ const VendorId_t VENDOR_ID = {13, 37}; const std::array IP_ADDRESS = { - 137, 226, 8, 70}; // Needs to be set in lwipcfg.h too. + 137, 226, 8, 70 +}; // Needs to be set in lwipcfg.h too. const GuidPrefix_t BASE_GUID_PREFIX{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12}; const uint8_t DOMAIN_ID = 0; // 230 possible with UDP @@ -20,9 +23,9 @@ const uint8_t NUM_STATEFUL_READERS = 4; const uint8_t NUM_STATEFUL_WRITERS = 4; const uint8_t MAX_NUM_PARTICIPANTS = 1; const uint8_t NUM_WRITERS_PER_PARTICIPANT = - 64; // 3 will be reserved for SPDP & SEDP + 64; // 3 will be reserved for SPDP & SEDP const uint8_t NUM_READERS_PER_PARTICIPANT = - 64; // 3 will be reserved for SPDP & SEDP + 64; // 3 will be reserved for SPDP & SEDP const uint8_t NUM_WRITER_PROXIES_PER_READER = 60; const uint8_t NUM_READER_PROXIES_PER_WRITER = 60; @@ -44,15 +47,17 @@ const uint16_t SF_WRITER_HB_PERIOD_MS = 4000; const uint16_t SPDP_RESEND_PERIOD_MS = 1000; const uint8_t SPDP_WRITER_PRIO = 3; const uint8_t SPDP_CYCLECOUNT_HEARTBEAT = - 2; // Every X*SPDP_RESEND_PERIOD_MS, check for missing heartbeats + 2; // Every X*SPDP_RESEND_PERIOD_MS, check for missing heartbeats const uint8_t SPDP_MAX_NUMBER_FOUND_PARTICIPANTS = 100; const uint8_t SPDP_MAX_NUM_LOCATORS = 1; const Duration_t SPDP_DEFAULT_REMOTE_LEASE_DURATION = { - 100, 0}; // Default lease duration for remote participants, usually - // overwritten by remote info + 100, 0 +}; // Default lease duration for remote participants, usually +// overwritten by remote info const Duration_t SPDP_MAX_REMOTE_LEASE_DURATION = { - 180, - 0}; // Absolute maximum lease duration, ignoring remote participant info + 180, + 0 +}; // Absolute maximum lease duration, ignoring remote participant info const int MAX_NUM_UDP_CONNECTIONS = 10; @@ -63,10 +68,10 @@ const int THREAD_POOL_READER_PRIO = 3; const int THREAD_POOL_WORKLOAD_QUEUE_LENGTH = 10; constexpr int OVERALL_HEAP_SIZE = - THREAD_POOL_NUM_WRITERS * THREAD_POOL_WRITER_STACKSIZE + - THREAD_POOL_NUM_READERS * THREAD_POOL_READER_STACKSIZE + - MAX_NUM_PARTICIPANTS * SPDP_WRITER_STACKSIZE + - NUM_STATEFUL_WRITERS * HEARTBEAT_STACKSIZE; + THREAD_POOL_NUM_WRITERS * THREAD_POOL_WRITER_STACKSIZE + + THREAD_POOL_NUM_READERS * THREAD_POOL_READER_STACKSIZE + + MAX_NUM_PARTICIPANTS * SPDP_WRITER_STACKSIZE + + NUM_STATEFUL_WRITERS * HEARTBEAT_STACKSIZE; } // namespace Config } // namespace rtps diff --git a/include/rtps/config_stm.h b/include/rtps/config_stm.h index 85e4c92d..9b8cef48 100644 --- a/include/rtps/config_stm.h +++ b/include/rtps/config_stm.h @@ -27,17 +27,20 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/common/types.h" -namespace rtps { +namespace rtps +{ #define IS_LITTLE_ENDIAN 1 // define only if using FreeRTOS #define OS_IS_FREERTOS -namespace Config { +namespace Config +{ const VendorId_t VENDOR_ID = {13, 37}; const std::array IP_ADDRESS = { - 192, 168, 0, 66}; // Needs to be set in lwipcfg.h too. + 192, 168, 0, 66 +}; // Needs to be set in lwipcfg.h too. const GuidPrefix_t BASE_GUID_PREFIX{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12}; const uint8_t DOMAIN_ID = 0; // 230 possible with UDP @@ -64,7 +67,7 @@ const uint16_t SPDP_WRITER_STACKSIZE = 550; // byte const uint16_t SF_WRITER_HB_PERIOD_MS = 4000; const uint16_t SPDP_RESEND_PERIOD_MS = 10000; const uint8_t SPDP_CYCLECOUNT_HEARTBEAT = - 2; // skip x SPDP rounds before checking liveliness + 2; // skip x SPDP rounds before checking liveliness const uint8_t SPDP_WRITER_PRIO = 3; const uint8_t SPDP_MAX_NUMBER_FOUND_PARTICIPANTS = 5; const uint8_t SPDP_MAX_NUM_LOCATORS = 5; @@ -79,10 +82,10 @@ const int THREAD_POOL_READER_PRIO = 3; const int THREAD_POOL_WORKLOAD_QUEUE_LENGTH = 10; constexpr int OVERALL_HEAP_SIZE = - THREAD_POOL_NUM_WRITERS * THREAD_POOL_WRITER_STACKSIZE + - THREAD_POOL_NUM_READERS * THREAD_POOL_READER_STACKSIZE + - MAX_NUM_PARTICIPANTS * SPDP_WRITER_STACKSIZE + - NUM_STATEFUL_WRITERS * HEARTBEAT_STACKSIZE; + THREAD_POOL_NUM_WRITERS * THREAD_POOL_WRITER_STACKSIZE + + THREAD_POOL_NUM_READERS * THREAD_POOL_READER_STACKSIZE + + MAX_NUM_PARTICIPANTS * SPDP_WRITER_STACKSIZE + + NUM_STATEFUL_WRITERS * HEARTBEAT_STACKSIZE; } // namespace Config } // namespace rtps diff --git a/include/rtps/discovery/BuiltInEndpoints.h b/include/rtps/discovery/BuiltInEndpoints.h index eb3a32c8..68ee060a 100644 --- a/include/rtps/discovery/BuiltInEndpoints.h +++ b/include/rtps/discovery/BuiltInEndpoints.h @@ -30,7 +30,8 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/entities/StatelessWriter.h" #include "rtps/entities/Writer.h" -namespace rtps { +namespace rtps +{ struct BuiltInEndpoints { Writer *spdpWriter = nullptr; diff --git a/include/rtps/discovery/ParticipantProxyData.h b/include/rtps/discovery/ParticipantProxyData.h index 6b251bd0..93a71b15 100644 --- a/include/rtps/discovery/ParticipantProxyData.h +++ b/include/rtps/discovery/ParticipantProxyData.h @@ -34,16 +34,21 @@ Author: i11 - Embedded Software, RWTH Aachen University #endif #include -namespace rtps { +namespace rtps +{ class Participant; using SMElement::ParameterId; typedef uint32_t BuiltinEndpointSet_t; -class ParticipantProxyData { +class ParticipantProxyData +{ public: - ParticipantProxyData() { onAliveSignal(); } + ParticipantProxyData() + { + onAliveSignal(); + } ParticipantProxyData(Guid_t guid); ProtocolVersion_t m_protocolVersion = PROTOCOLVERSION; @@ -52,18 +57,18 @@ class ParticipantProxyData { bool m_expectsInlineQos = false; BuiltinEndpointSet_t m_availableBuiltInEndpoints; std::array - m_metatrafficUnicastLocatorList; + m_metatrafficUnicastLocatorList; std::array - m_metatrafficMulticastLocatorList; + m_metatrafficMulticastLocatorList; std::array - m_defaultUnicastLocatorList; + m_defaultUnicastLocatorList; std::array - m_defaultMulticastLocatorList; + m_defaultMulticastLocatorList; Count_t m_manualLivelinessCount{1}; Duration_t m_leaseDuration = Config::SPDP_DEFAULT_REMOTE_LEASE_DURATION; #if defined(unix) || defined(__unix__) std::chrono::time_point - m_lastLivelinessReceivedTimestamp; + m_lastLivelinessReceivedTimestamp; #else TickType_t m_lastLivelinessReceivedTickCount = 0; #endif @@ -84,67 +89,74 @@ class ParticipantProxyData { private: bool readLocatorIntoList( - ucdrBuffer &buffer, - std::array &list); + ucdrBuffer &buffer, + std::array &list); static const BuiltinEndpointSet_t - DISC_BUILTIN_ENDPOINT_PARTICIPANT_ANNOUNCER = 1 << 0; + DISC_BUILTIN_ENDPOINT_PARTICIPANT_ANNOUNCER = 1 << 0; static const BuiltinEndpointSet_t DISC_BUILTIN_ENDPOINT_PARTICIPANT_DETECTOR = - 1 << 1; + 1 << 1; static const BuiltinEndpointSet_t - DISC_BUILTIN_ENDPOINT_PUBLICATION_ANNOUNCER = 1 << 2; + DISC_BUILTIN_ENDPOINT_PUBLICATION_ANNOUNCER = 1 << 2; static const BuiltinEndpointSet_t DISC_BUILTIN_ENDPOINT_PUBLICATION_DETECTOR = - 1 << 3; + 1 << 3; static const BuiltinEndpointSet_t - DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_ANNOUNCER = 1 << 4; + DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_ANNOUNCER = 1 << 4; static const BuiltinEndpointSet_t - DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_DETECTOR = 1 << 5; + DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_DETECTOR = 1 << 5; static const BuiltinEndpointSet_t - DISC_BUILTIN_ENDPOINT_PARTICIPANT_PROXY_ANNOUNCER = 1 << 6; + DISC_BUILTIN_ENDPOINT_PARTICIPANT_PROXY_ANNOUNCER = 1 << 6; static const BuiltinEndpointSet_t - DISC_BUILTIN_ENDPOINT_PARTICIPANT_PROXY_DETECTOR = 1 << 7; + DISC_BUILTIN_ENDPOINT_PARTICIPANT_PROXY_DETECTOR = 1 << 7; static const BuiltinEndpointSet_t - DISC_BUILTIN_ENDPOINT_PARTICIPANT_STATE_ANNOUNCER = 1 << 8; + DISC_BUILTIN_ENDPOINT_PARTICIPANT_STATE_ANNOUNCER = 1 << 8; static const BuiltinEndpointSet_t - DISC_BUILTIN_ENDPOINT_PARTICIPANT_STATE_DETECTOR = 1 << 9; + DISC_BUILTIN_ENDPOINT_PARTICIPANT_STATE_DETECTOR = 1 << 9; static const BuiltinEndpointSet_t - BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_DATA_WRITER = 1 << 10; + BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_DATA_WRITER = 1 << 10; static const BuiltinEndpointSet_t - BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_DATA_READER = 1 << 11; + BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_DATA_READER = 1 << 11; }; // Needs to be in header because they are marked with inline -bool ParticipantProxyData::hasParticipantWriter() { +bool ParticipantProxyData::hasParticipantWriter() +{ return (m_availableBuiltInEndpoints & DISC_BUILTIN_ENDPOINT_PARTICIPANT_ANNOUNCER) == 1; } -bool ParticipantProxyData::hasParticipantReader() { +bool ParticipantProxyData::hasParticipantReader() +{ return (m_availableBuiltInEndpoints & DISC_BUILTIN_ENDPOINT_PARTICIPANT_DETECTOR) != 0; } -bool ParticipantProxyData::hasPublicationWriter() { +bool ParticipantProxyData::hasPublicationWriter() +{ return (m_availableBuiltInEndpoints & DISC_BUILTIN_ENDPOINT_PUBLICATION_ANNOUNCER) != 0; } -bool ParticipantProxyData::hasPublicationReader() { +bool ParticipantProxyData::hasPublicationReader() +{ return (m_availableBuiltInEndpoints & DISC_BUILTIN_ENDPOINT_PUBLICATION_DETECTOR) != 0; } -bool ParticipantProxyData::hasSubscriptionWriter() { +bool ParticipantProxyData::hasSubscriptionWriter() +{ return (m_availableBuiltInEndpoints & DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_ANNOUNCER) != 0; } -bool ParticipantProxyData::hasSubscriptionReader() { +bool ParticipantProxyData::hasSubscriptionReader() +{ return (m_availableBuiltInEndpoints & DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_DETECTOR) != 0; } -void ParticipantProxyData::onAliveSignal() { +void ParticipantProxyData::onAliveSignal() +{ #if defined(unix) || defined(__unix__) m_lastLivelinessReceivedTimestamp = std::chrono::high_resolution_clock::now(); #else @@ -152,11 +164,12 @@ void ParticipantProxyData::onAliveSignal() { #endif } -uint32_t ParticipantProxyData::getAliveSignalAgeInMilliseconds() { +uint32_t ParticipantProxyData::getAliveSignalAgeInMilliseconds() +{ #if defined(unix) || defined(__unix__) auto now = std::chrono::high_resolution_clock::now(); std::chrono::duration duration = - now - m_lastLivelinessReceivedTimestamp; + now - m_lastLivelinessReceivedTimestamp; return duration.count(); #else return (xTaskGetTickCount() - m_lastLivelinessReceivedTickCount) * @@ -167,13 +180,14 @@ uint32_t ParticipantProxyData::getAliveSignalAgeInMilliseconds() { /* * Returns true if last heartbeat within lease duration, else false */ -bool ParticipantProxyData::isAlive() { +bool ParticipantProxyData::isAlive() +{ uint32_t lease_in_ms = - m_leaseDuration.seconds * 1000 + m_leaseDuration.fraction * 1e-6; + m_leaseDuration.seconds * 1000 + m_leaseDuration.fraction * 1e-6; uint32_t max_lease_in_ms = - Config::SPDP_MAX_REMOTE_LEASE_DURATION.seconds * 1000 + - Config::SPDP_MAX_REMOTE_LEASE_DURATION.fraction * 1e-6; + Config::SPDP_MAX_REMOTE_LEASE_DURATION.seconds * 1000 + + Config::SPDP_MAX_REMOTE_LEASE_DURATION.fraction * 1e-6; auto heatbeat_age_in_ms = getAliveSignalAgeInMilliseconds(); diff --git a/include/rtps/discovery/SEDPAgent.h b/include/rtps/discovery/SEDPAgent.h index 3b491502..9103462e 100644 --- a/include/rtps/discovery/SEDPAgent.h +++ b/include/rtps/discovery/SEDPAgent.h @@ -28,22 +28,24 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/discovery/BuiltInEndpoints.h" #include "rtps/discovery/TopicData.h" -namespace rtps { +namespace rtps +{ class Participant; class ReaderCacheChange; class Writer; class Reader; -class SEDPAgent { +class SEDPAgent +{ public: void init(Participant &part, const BuiltInEndpoints &endpoints); void addWriter(Writer &writer); void addReader(Reader &reader); void registerOnNewPublisherMatchedCallback(void (*callback)(void *arg), - void *args); + void *args); void registerOnNewSubscriberMatchedCallback(void (*callback)(void *arg), - void *args); + void *args); void removeUnmatchedEntitiesOfParticipant(const GuidPrefix_t &guidPrefix); uint32_t getNumRemoteUnmatchedReaders(); uint32_t getNumRemoteUnmatchedWriters(); @@ -56,7 +58,7 @@ class SEDPAgent { Participant *m_part; sys_mutex_t m_mutex; uint8_t m_buffer[600]; // TODO check size, currently changed from 300 to 600 - // (FastDDS gives too many options) + // (FastDDS gives too many options) BuiltInEndpoints m_endpoints; /* * If we add readers later on, remote participants will not send matching @@ -65,10 +67,10 @@ class SEDPAgent { * type are represented as hash values to save memory. */ MemoryPool - m_unmatchedRemoteWriters; + m_unmatchedRemoteWriters; size_t m_numUnmatchedRemoteWriters = 0; MemoryPool - m_unmatchedRemoteReaders; + m_unmatchedRemoteReaders; size_t m_numMatchedRemoteReaders = 0; void tryMatchUnmatchedEndpoints(); diff --git a/include/rtps/discovery/SPDPAgent.h b/include/rtps/discovery/SPDPAgent.h index 869861a6..33e5596e 100644 --- a/include/rtps/discovery/SPDPAgent.h +++ b/include/rtps/discovery/SPDPAgent.h @@ -44,13 +44,15 @@ Author: i11 - Embedded Software, RWTH Aachen University #define SPDP_LOG(...) // #endif -namespace rtps { +namespace rtps +{ class Participant; class Writer; class Reader; class ReaderCacheChange; -class SPDPAgent { +class SPDPAgent +{ public: ~SPDPAgent(); void init(Participant &participant, BuiltInEndpoints &endpoints); diff --git a/include/rtps/discovery/TopicData.h b/include/rtps/discovery/TopicData.h index 10a913a5..1f535add 100644 --- a/include/rtps/discovery/TopicData.h +++ b/include/rtps/discovery/TopicData.h @@ -33,7 +33,8 @@ Author: i11 - Embedded Software, RWTH Aachen University #include #include -namespace rtps { +namespace rtps +{ struct BuiltInTopicKey { std::array value; @@ -49,20 +50,22 @@ struct TopicData { FullLengthLocator multicastLocator; TopicData() - : endpointGuid(GUID_UNKNOWN), typeName{'\0'}, topicName{'\0'}, - reliabilityKind(ReliabilityKind_t::BEST_EFFORT), - durabilityKind(DurabilityKind_t::TRANSIENT_LOCAL) { + : endpointGuid(GUID_UNKNOWN), typeName{'\0'}, topicName{'\0'}, + reliabilityKind(ReliabilityKind_t::BEST_EFFORT), + durabilityKind(DurabilityKind_t::TRANSIENT_LOCAL) + { rtps::FullLengthLocator someLocator = - rtps::FullLengthLocator::createUDPv4Locator( - 192, 168, 0, 42, rtps::getUserUnicastPort(0)); + rtps::FullLengthLocator::createUDPv4Locator( + 192, 168, 0, 42, rtps::getUserUnicastPort(0)); unicastLocator = someLocator; multicastLocator = FullLengthLocator(); }; TopicData(Guid_t guid, ReliabilityKind_t reliability, FullLengthLocator loc) - : endpointGuid(guid), typeName{'\0'}, topicName{'\0'}, - reliabilityKind(reliability), - durabilityKind(DurabilityKind_t::TRANSIENT_LOCAL), unicastLocator(loc) { + : endpointGuid(guid), typeName{'\0'}, topicName{'\0'}, + reliabilityKind(reliability), + durabilityKind(DurabilityKind_t::TRANSIENT_LOCAL), unicastLocator(loc) + { } bool matchesTopicOf(const TopicData &other); @@ -81,10 +84,11 @@ struct TopicDataCompressed { LocatorIPv4 multicastLocator; TopicDataCompressed() = default; - TopicDataCompressed(const TopicData &topic_data) { + TopicDataCompressed(const TopicData &topic_data) + { endpointGuid = topic_data.endpointGuid; topicHash = - hashCharArray(topic_data.topicName, Config::MAX_TOPICNAME_LENGTH); + hashCharArray(topic_data.topicName, Config::MAX_TOPICNAME_LENGTH); typeHash = hashCharArray(topic_data.typeName, Config::MAX_TYPENAME_LENGTH); reliabilityKind = topic_data.reliabilityKind; durabilityKind = topic_data.durabilityKind; diff --git a/include/rtps/entities/Domain.h b/include/rtps/entities/Domain.h index 2b24ee8b..8d321df0 100644 --- a/include/rtps/entities/Domain.h +++ b/include/rtps/entities/Domain.h @@ -35,8 +35,10 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/storages/PBufWrapper.h" #include -namespace rtps { -class Domain { +namespace rtps +{ +class Domain +{ public: Domain(); ~Domain(); diff --git a/include/rtps/entities/Participant.h b/include/rtps/entities/Participant.h index 52271696..9bfaf75c 100644 --- a/include/rtps/entities/Participant.h +++ b/include/rtps/entities/Participant.h @@ -31,12 +31,14 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/discovery/SPDPAgent.h" #include "rtps/messages/MessageReceiver.h" -namespace rtps { +namespace rtps +{ class Writer; class Reader; -class Participant { +class Participant +{ public: GuidPrefix_t m_guidPrefix; ParticipantId_t m_participantId; @@ -61,9 +63,9 @@ class Participant { // Actually the only two function that should be used by the user bool registerOnNewPublisherMatchedCallback(void (*callback)(void *arg), - void *args); + void *args); bool registerOnNewSubscriberMatchedCallback(void (*callback)(void *arg), - void *args); + void *args); //! Not-thread-safe function to add a writer Writer *addWriter(Writer *writer); @@ -113,7 +115,7 @@ class Participant { sys_mutex_t m_mutex; MemoryPool - m_remoteParticipants; + m_remoteParticipants; SPDPAgent m_spdpAgent; SEDPAgent m_sedpAgent; diff --git a/include/rtps/entities/Reader.h b/include/rtps/entities/Reader.h index 0f8c7ed6..089e5200 100644 --- a/include/rtps/entities/Reader.h +++ b/include/rtps/entities/Reader.h @@ -33,11 +33,13 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/storages/PBufWrapper.h" #include -namespace rtps { +namespace rtps +{ struct SubmessageHeartbeat; -class ReaderCacheChange { +class ReaderCacheChange +{ private: const uint8_t *data; @@ -49,10 +51,10 @@ class ReaderCacheChange { ReaderCacheChange(ChangeKind_t kind, Guid_t &writerGuid, SequenceNumber_t sn, const uint8_t *data, DataSize_t size) - : data(data), kind(kind), size(size), writerGuid(writerGuid), sn(sn){}; + : data(data), kind(kind), size(size), writerGuid(writerGuid), sn(sn) {}; ~ReaderCacheChange() = - default; // No need to free data. It's not owned by this object + default; // No need to free data. It's not owned by this object // Not allowed because this class doesn't own the ptr and the user isn't // allowed to use it outside the Scope of the callback ReaderCacheChange(const ReaderCacheChange &other) = delete; @@ -60,7 +62,8 @@ class ReaderCacheChange { ReaderCacheChange &operator=(const ReaderCacheChange &other) = delete; ReaderCacheChange &operator=(ReaderCacheChange &&other) = delete; - bool copyInto(uint8_t *buffer, DataSize_t destSize) const { + bool copyInto(uint8_t *buffer, DataSize_t destSize) const + { if (destSize < size) { return false; } else { @@ -69,15 +72,22 @@ class ReaderCacheChange { } } - const uint8_t *getData() const { return data; } + const uint8_t *getData() const + { + return data; + } - const DataSize_t getDataSize() const { return size; } + const DataSize_t getDataSize() const + { + return size; + } }; typedef void (*ddsReaderCallback_fp)(void *callee, const ReaderCacheChange &cacheChange); -class Reader { +class Reader +{ public: TopicData m_attributes; virtual void newChange(const ReaderCacheChange &cacheChange) = 0; @@ -87,9 +97,13 @@ class Reader { virtual bool addNewMatchedWriter(const WriterProxy &newProxy) = 0; virtual void removeWriter(const Guid_t &guid) = 0; virtual void removeWriterOfParticipant(const GuidPrefix_t &guidPrefix) = 0; - bool isInitialized() { return m_is_initialized_; } + bool isInitialized() + { + return m_is_initialized_; + } - bool knowWriterId(const Guid_t &guid) { + bool knowWriterId(const Guid_t &guid) + { for (const auto &proxy : m_proxies) { if (proxy.remoteWriterGuid.operator==(guid)) { return true; @@ -98,7 +112,10 @@ class Reader { return false; } - uint32_t getNumMatchedWriters() { return m_proxies.getSize(); } + uint32_t getNumMatchedWriters() + { + return m_proxies.getSize(); + } protected: bool m_is_initialized_ = false; diff --git a/include/rtps/entities/ReaderProxy.h b/include/rtps/entities/ReaderProxy.h index a942870c..7e22b28d 100644 --- a/include/rtps/entities/ReaderProxy.h +++ b/include/rtps/entities/ReaderProxy.h @@ -28,7 +28,8 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/common/types.h" #include "rtps/discovery/ParticipantProxyData.h" -namespace rtps { +namespace rtps +{ struct ReaderProxy { Guid_t remoteReaderGuid; LocatorIPv4 remoteLocator; @@ -39,14 +40,14 @@ struct ReaderProxy { SequenceNumberSet ackNackSet; Count_t ackNackCount; - ReaderProxy() : remoteReaderGuid({GUIDPREFIX_UNKNOWN, ENTITYID_UNKNOWN}){}; + ReaderProxy() : remoteReaderGuid({GUIDPREFIX_UNKNOWN, ENTITYID_UNKNOWN}) {}; ReaderProxy(const Guid_t &guid, const LocatorIPv4 &loc) - : remoteReaderGuid(guid), remoteLocator(loc), - ackNackSet(), ackNackCount{0} {}; + : remoteReaderGuid(guid), remoteLocator(loc), + ackNackSet(), ackNackCount{0} {}; ReaderProxy(const Guid_t &guid, const LocatorIPv4 &loc, const LocatorIPv4 &mcastloc) - : remoteReaderGuid(guid), remoteLocator(loc), - remoteMulticastLocator(mcastloc), ackNackSet(), ackNackCount{0} {}; + : remoteReaderGuid(guid), remoteLocator(loc), + remoteMulticastLocator(mcastloc), ackNackSet(), ackNackCount{0} {}; }; } // namespace rtps diff --git a/include/rtps/entities/StatefulReader.h b/include/rtps/entities/StatefulReader.h index fc73892e..bae950af 100644 --- a/include/rtps/entities/StatefulReader.h +++ b/include/rtps/entities/StatefulReader.h @@ -32,10 +32,12 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/entities/WriterProxy.h" #include "rtps/storages/MemoryPool.h" -namespace rtps { +namespace rtps +{ struct SubmessageHeartbeat; -template class StatefulReaderT final : public Reader { +template class StatefulReaderT final : public Reader +{ public: ~StatefulReaderT() override; void init(const TopicData &attributes, NetworkDriver &driver); @@ -49,7 +51,7 @@ template class StatefulReaderT final : public Reader { private: PacketInfo - m_packetInfo; // TODO intended for reuse but buffer not used as such + m_packetInfo; // TODO intended for reuse but buffer not used as such NetworkDriver *m_transport; ddsReaderCallback_fp m_callback = nullptr; diff --git a/include/rtps/entities/StatefulWriter.h b/include/rtps/entities/StatefulWriter.h index 2b79d291..2c809b0a 100644 --- a/include/rtps/entities/StatefulWriter.h +++ b/include/rtps/entities/StatefulWriter.h @@ -30,9 +30,11 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/storages/MemoryPool.h" #include "rtps/storages/SimpleHistoryCache.h" -namespace rtps { +namespace rtps +{ -template class StatefulWriterT final : public Writer { +template class StatefulWriterT final : public Writer +{ public: ~StatefulWriterT() override; bool init(TopicData attributes, TopicKind_t topicKind, ThreadPool *threadPool, @@ -47,7 +49,7 @@ template class StatefulWriterT final : public Writer { const CacheChange *newChange(ChangeKind_t kind, const uint8_t *data, DataSize_t size) override; const CacheChange *newChangeCallback(ChangeKind_t kind, - CacheChange::SerializerCallback func, FragDataSize_t size) override; + CacheChange::SerializerCallback func, FragDataSize_t size) override; void setAllChangesToUnsent() override; void onNewAckNack(const SubmessageAckNack &msg, const GuidPrefix_t &sourceGuidPrefix) override; diff --git a/include/rtps/entities/StatelessReader.h b/include/rtps/entities/StatelessReader.h index e797a6a7..65d4471a 100644 --- a/include/rtps/entities/StatelessReader.h +++ b/include/rtps/entities/StatelessReader.h @@ -27,8 +27,10 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/entities/Reader.h" -namespace rtps { -class StatelessReader final : public Reader { +namespace rtps +{ +class StatelessReader final : public Reader +{ public: void init(const TopicData &attributes); void newChange(const ReaderCacheChange &cacheChange) override; diff --git a/include/rtps/entities/StatelessWriter.h b/include/rtps/entities/StatelessWriter.h index 7561e853..aebee6b4 100644 --- a/include/rtps/entities/StatelessWriter.h +++ b/include/rtps/entities/StatelessWriter.h @@ -32,11 +32,13 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/storages/MemoryPool.h" #include "rtps/storages/SimpleHistoryCache.h" -namespace rtps { +namespace rtps +{ struct PBufWrapper; -template class StatelessWriterT : public Writer { +template class StatelessWriterT : public Writer +{ public: ~StatelessWriterT() override; bool init(TopicData attributes, TopicKind_t topicKind, ThreadPool *threadPool, @@ -49,7 +51,7 @@ template class StatelessWriterT : public Writer { const CacheChange *newChange(ChangeKind_t kind, const uint8_t *data, DataSize_t size) override; const CacheChange *newChangeCallback(ChangeKind_t kind, - CacheChange::SerializerCallback func, FragDataSize_t size) override; + CacheChange::SerializerCallback func, FragDataSize_t size) override; void setAllChangesToUnsent() override; void onNewAckNack(const SubmessageAckNack &msg, const GuidPrefix_t &sourceGuidPrefix) override; diff --git a/include/rtps/entities/Writer.h b/include/rtps/entities/Writer.h index fbd6948e..216c2279 100644 --- a/include/rtps/entities/Writer.h +++ b/include/rtps/entities/Writer.h @@ -32,9 +32,11 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/storages/MemoryPool.h" #include "rtps/storages/PBufWrapper.h" -namespace rtps { +namespace rtps +{ -class Writer { +class Writer +{ public: TopicData m_attributes; virtual bool addNewMatchedReader(const ReaderProxy &newProxy) = 0; @@ -47,14 +49,20 @@ class Writer { virtual const CacheChange *newChange(ChangeKind_t kind, const uint8_t *data, DataSize_t size) = 0; virtual const CacheChange *newChangeCallback(ChangeKind_t kind, - CacheChange::SerializerCallback func, FragDataSize_t) = 0; + CacheChange::SerializerCallback func, FragDataSize_t) = 0; virtual void setAllChangesToUnsent() = 0; virtual void onNewAckNack(const SubmessageAckNack &msg, const GuidPrefix_t &sourceGuidPrefix) = 0; - bool isInitialized() { return m_is_initialized_; } + bool isInitialized() + { + return m_is_initialized_; + } - uint32_t getNumMatchedReader() { return m_proxies.getSize(); } + uint32_t getNumMatchedReader() + { + return m_proxies.getSize(); + } protected: friend class SizeInspector; diff --git a/include/rtps/entities/WriterProxy.h b/include/rtps/entities/WriterProxy.h index 3916088d..5ff4bcd6 100644 --- a/include/rtps/entities/WriterProxy.h +++ b/include/rtps/entities/WriterProxy.h @@ -28,7 +28,8 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/common/types.h" #include -namespace rtps { +namespace rtps +{ struct WriterProxy { Guid_t remoteWriterGuid; SequenceNumber_t expectedSN; @@ -39,14 +40,15 @@ struct WriterProxy { WriterProxy() = default; WriterProxy(const Guid_t &guid, const LocatorIPv4 &loc) - : remoteWriterGuid(guid), - expectedSN(SequenceNumber_t{0, 1}), ackNackCount{1}, hbCount{0}, - remoteLocator(loc) {} + : remoteWriterGuid(guid), + expectedSN(SequenceNumber_t{0, 1}), ackNackCount{1}, hbCount{0}, + remoteLocator(loc) {} // For now, we don't store any packets, so we just request all starting from // the next expected SequenceNumberSet getMissing(const SequenceNumber_t & /*firstAvail*/, - const SequenceNumber_t &lastAvail) { + const SequenceNumber_t &lastAvail) + { SequenceNumberSet set; if (lastAvail < expectedSN) { set.base = expectedSN; @@ -60,7 +62,8 @@ struct WriterProxy { return set; } - Count_t getNextAckNackCount() { + Count_t getNextAckNackCount() + { const Count_t tmp = ackNackCount; ++ackNackCount.value; return tmp; diff --git a/include/rtps/messages/MessageFactory.h b/include/rtps/messages/MessageFactory.h index 8ed6e008..dfaa7bf7 100644 --- a/include/rtps/messages/MessageFactory.h +++ b/include/rtps/messages/MessageFactory.h @@ -33,14 +33,17 @@ Author: i11 - Embedded Software, RWTH Aachen University #include #include -namespace rtps { -namespace MessageFactory { +namespace rtps +{ +namespace MessageFactory +{ const std::array PROTOCOL_TYPE{'R', 'T', 'P', 'S'}; const uint8_t numBytesUntilEndOfLength = - 4; // The first bytes incl. submessagelength don't count + 4; // The first bytes incl. submessagelength don't count template -void addHeader(Buffer &buffer, const GuidPrefix_t &guidPrefix) { +void addHeader(Buffer &buffer, const GuidPrefix_t &guidPrefix) +{ Header header; header.protocolName = PROTOCOL_TYPE; @@ -52,7 +55,8 @@ void addHeader(Buffer &buffer, const GuidPrefix_t &guidPrefix) { } template -bool addSubMessageInfoDST(Buffer &buffer, GuidPrefix_t &dst) { +bool addSubMessageInfoDST(Buffer &buffer, GuidPrefix_t &dst) +{ SubmessageInfoDST msg; msg.header.submessageId = SubmessageKind::INFO_DST; @@ -69,7 +73,8 @@ bool addSubMessageInfoDST(Buffer &buffer, GuidPrefix_t &dst) { } template -void addSubMessageTimeStamp(Buffer &buffer, bool setInvalid = false) { +void addSubMessageTimeStamp(Buffer &buffer, bool setInvalid = false) +{ SubmessageHeader header; header.submessageId = SubmessageKind::INFO_TS; @@ -100,11 +105,12 @@ void addSubMessageTimeStamp(Buffer &buffer, bool setInvalid = false) { template void addSubMessageDataFrag(Buffer &buffer, const Buffer &filledPayload, - bool containsInlineQos, const SequenceNumber_t &SN, - uint32_t fragStartingNumber, - uint16_t fragSize, - uint32_t sampleSize, - const EntityId_t &writerID, const EntityId_t &readerID) { + bool containsInlineQos, const SequenceNumber_t &SN, + uint32_t fragStartingNumber, + uint16_t fragSize, + uint32_t sampleSize, + const EntityId_t &writerID, const EntityId_t &readerID) +{ SubmessageDataFrag msg; msg.header.submessageId = SubmessageKind::DATA_FRAG; #if IS_LITTLE_ENDIAN @@ -129,8 +135,8 @@ void addSubMessageDataFrag(Buffer &buffer, const Buffer &filledPayload, msg.sampleSize = sampleSize; constexpr uint16_t octetsToInlineQoS = - 4 + 4 + 8 + 4 + 2 + 2 + 4; - // EntityIds + SequenceNumber + FragmentNumber + fragmentsInSubmessage + fragmentSize + sampleSize + 4 + 4 + 8 + 4 + 2 + 2 + 4; + // EntityIds + SequenceNumber + FragmentNumber + fragmentsInSubmessage + fragmentSize + sampleSize msg.octetsToInlineQos = octetsToInlineQoS; serializeMessage(buffer, msg); @@ -144,7 +150,8 @@ void addSubMessageDataFrag(Buffer &buffer, const Buffer &filledPayload, template void addSubMessageData(Buffer &buffer, const Buffer &filledPayload, bool containsInlineQos, const SequenceNumber_t &SN, - const EntityId_t &writerID, const EntityId_t &readerID) { + const EntityId_t &writerID, const EntityId_t &readerID) +{ SubmessageData msg; msg.header.submessageId = SubmessageKind::DATA; #if IS_LITTLE_ENDIAN @@ -170,7 +177,7 @@ void addSubMessageData(Buffer &buffer, const Buffer &filledPayload, msg.writerId = writerID; constexpr uint16_t octetsToInlineQoS = - 4 + 4 + 8; // EntityIds + SequenceNumber + 4 + 4 + 8; // EntityIds + SequenceNumber msg.octetsToInlineQos = octetsToInlineQoS; serializeMessage(buffer, msg); @@ -184,11 +191,12 @@ void addSubMessageData(Buffer &buffer, const Buffer &filledPayload, template void addHeartbeat(Buffer &buffer, EntityId_t writerId, EntityId_t readerId, SequenceNumber_t firstSN, SequenceNumber_t lastSN, - Count_t count) { + Count_t count) +{ SubmessageHeartbeat subMsg; subMsg.header.submessageId = SubmessageKind::HEARTBEAT; subMsg.header.octetsToNextHeader = - SubmessageHeartbeat::getRawSize() - numBytesUntilEndOfLength; + SubmessageHeartbeat::getRawSize() - numBytesUntilEndOfLength; #if IS_LITTLE_ENDIAN subMsg.header.flags = FLAG_LITTLE_ENDIAN; #else @@ -208,7 +216,8 @@ void addHeartbeat(Buffer &buffer, EntityId_t writerId, EntityId_t readerId, template void addAckNack(Buffer &buffer, EntityId_t writerId, EntityId_t readerId, SequenceNumberSet readerSNState, Count_t count, - bool final_flag) { + bool final_flag) +{ SubmessageAckNack subMsg; subMsg.header.submessageId = SubmessageKind::ACKNACK; #if IS_LITTLE_ENDIAN @@ -222,7 +231,7 @@ void addAckNack(Buffer &buffer, EntityId_t writerId, EntityId_t readerId, subMsg.header.flags &= ~FLAG_FINAL; // For now, we don't want any response } subMsg.header.octetsToNextHeader = - SubmessageAckNack::getRawSize(readerSNState) - numBytesUntilEndOfLength; + SubmessageAckNack::getRawSize(readerSNState) - numBytesUntilEndOfLength; subMsg.writerId = writerId; subMsg.readerId = readerId; diff --git a/include/rtps/messages/MessageReceiver.h b/include/rtps/messages/MessageReceiver.h index c7af7030..71b20006 100644 --- a/include/rtps/messages/MessageReceiver.h +++ b/include/rtps/messages/MessageReceiver.h @@ -30,13 +30,15 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/discovery/BuiltInEndpoints.h" #include -namespace rtps { +namespace rtps +{ class Reader; class Writer; class Participant; class MessageProcessingInfo; -class MessageReceiver { +class MessageReceiver +{ public: GuidPrefix_t sourceGuidPrefix = GUIDPREFIX_UNKNOWN; ProtocolVersion_t sourceVersion = PROTOCOLVERSION; diff --git a/include/rtps/messages/MessageTypes.h b/include/rtps/messages/MessageTypes.h index 97f38af9..0538b6d2 100644 --- a/include/rtps/messages/MessageTypes.h +++ b/include/rtps/messages/MessageTypes.h @@ -29,9 +29,11 @@ Author: i11 - Embedded Software, RWTH Aachen University #include -namespace rtps { +namespace rtps +{ -namespace SMElement { +namespace SMElement +{ // TODO endianess enum ParameterId : uint16_t { PID_PAD = 0x0000, @@ -153,7 +155,8 @@ struct Header { ProtocolVersion_t protocolVersion; VendorId_t vendorId; GuidPrefix_t guidPrefix; - static constexpr uint16_t getRawSize() { + static constexpr uint16_t getRawSize() + { return sizeof(std::array) + sizeof(ProtocolVersion_t) + sizeof(VendorId_t) + sizeof(GuidPrefix_t); } @@ -163,7 +166,8 @@ struct SubmessageHeader { SubmessageKind submessageId; uint8_t flags; uint16_t octetsToNextHeader; - static constexpr uint16_t getRawSize() { + static constexpr uint16_t getRawSize() + { return sizeof(SubmessageKind) + sizeof(uint8_t) + sizeof(uint16_t); } }; @@ -179,7 +183,8 @@ struct SubmessageDataFrag { uint16_t fragmentsInSubmessage; uint16_t fragmentSize; uint32_t sampleSize; - static constexpr uint16_t getRawSize() { + static constexpr uint16_t getRawSize() + { return SubmessageHeader::getRawSize() + sizeof(uint16_t) + sizeof(uint16_t) + (2 * 3 + 2 * 1) // EntityID @@ -198,7 +203,8 @@ struct SubmessageData { EntityId_t readerId; EntityId_t writerId; SequenceNumber_t writerSN; - static constexpr uint16_t getRawSize() { + static constexpr uint16_t getRawSize() + { return SubmessageHeader::getRawSize() + sizeof(uint16_t) + sizeof(uint16_t) + (2 * 3 + 2 * 1) // EntityID + sizeof(SequenceNumber_t); @@ -212,7 +218,8 @@ struct SubmessageHeartbeat { SequenceNumber_t firstSN; SequenceNumber_t lastSN; Count_t count; - static constexpr uint16_t getRawSize() { + static constexpr uint16_t getRawSize() + { return SubmessageHeader::getRawSize() + (2 * 3 + 2 * 1) // EntityID + 2 * sizeof(SequenceNumber_t) + sizeof(Count_t); } @@ -222,7 +229,8 @@ struct SubmessageInfoDST { SubmessageHeader header; GuidPrefix_t guidPrefix; - static constexpr uint16_t getRawSize() { + static constexpr uint16_t getRawSize() + { return SubmessageHeader::getRawSize() + (sizeof(guidPrefix)); } }; @@ -233,7 +241,8 @@ struct SubmessageAckNack { EntityId_t writerId; SequenceNumberSet readerSNState; Count_t count; - static uint16_t getRawSize(const SequenceNumberSet &set) { + static uint16_t getRawSize(const SequenceNumberSet &set) + { uint16_t bitMapSize = 0; if (set.numBits != 0) { bitMapSize = 4 * ((set.numBits / 32) + 1); @@ -241,14 +250,16 @@ struct SubmessageAckNack { return getRawSizeWithoutSNSet() + sizeof(SequenceNumber_t) + sizeof(uint32_t) + bitMapSize; // SequenceNumberSet } - static uint16_t getRawSizeWithoutSNSet() { + static uint16_t getRawSizeWithoutSNSet() + { return SubmessageHeader::getRawSize() + (2 * 3 + 2 * 1) // EntityID + sizeof(Count_t); } }; template -bool serializeMessage(Buffer &buffer, Header &header) { +bool serializeMessage(Buffer &buffer, Header &header) +{ if (!buffer.reserve(Header::getRawSize())) { return false; } @@ -262,7 +273,8 @@ bool serializeMessage(Buffer &buffer, Header &header) { } template -bool serializeMessage(Buffer &buffer, SubmessageHeader &header) { +bool serializeMessage(Buffer &buffer, SubmessageHeader &header) +{ if (!buffer.reserve(Header::getRawSize())) { return false; } @@ -277,7 +289,8 @@ bool serializeMessage(Buffer &buffer, SubmessageHeader &header) { } template -bool serializeMessage(Buffer &buffer, SubmessageInfoDST &msg) { +bool serializeMessage(Buffer &buffer, SubmessageInfoDST &msg) +{ if (!buffer.reserve(SubmessageInfoDST::getRawSize())) { return false; } @@ -291,7 +304,8 @@ bool serializeMessage(Buffer &buffer, SubmessageInfoDST &msg) { } template -bool serializeMessage(Buffer &buffer, SubmessageData &msg) { +bool serializeMessage(Buffer &buffer, SubmessageData &msg) +{ if (!buffer.reserve(SubmessageData::getRawSize())) { return false; } @@ -315,7 +329,8 @@ bool serializeMessage(Buffer &buffer, SubmessageData &msg) { } template -bool serializeMessage(Buffer &buffer, SubmessageDataFrag &msg) { +bool serializeMessage(Buffer &buffer, SubmessageDataFrag &msg) +{ if (!buffer.reserve(SubmessageDataFrag::getRawSize())) { return false; } @@ -348,7 +363,8 @@ bool serializeMessage(Buffer &buffer, SubmessageDataFrag &msg) { } template -bool serializeMessage(Buffer &buffer, SubmessageHeartbeat &msg) { +bool serializeMessage(Buffer &buffer, SubmessageHeartbeat &msg) +{ if (!buffer.reserve(SubmessageHeartbeat::getRawSize())) { return false; } @@ -375,7 +391,8 @@ bool serializeMessage(Buffer &buffer, SubmessageHeartbeat &msg) { } template -bool serializeMessage(Buffer &buffer, SubmessageAckNack &msg) { +bool serializeMessage(Buffer &buffer, SubmessageAckNack &msg) +{ if (!buffer.reserve(SubmessageAckNack::getRawSize(msg.readerSNState))) { return false; } @@ -405,19 +422,23 @@ bool serializeMessage(Buffer &buffer, SubmessageAckNack &msg) { struct MessageProcessingInfo { MessageProcessingInfo(const uint8_t *data, DataSize_t size) - : data(data), size(size) {} + : data(data), size(size) {} const uint8_t *data; const DataSize_t size; //! Offset to the next unprocessed byte DataSize_t nextPos = 0; - inline const uint8_t *getPointerToCurrentPos() const { + inline const uint8_t *getPointerToCurrentPos() const + { return &data[nextPos]; } //! Returns the size of data which isn't processed yet - inline DataSize_t getRemainingSize() const { return size - nextPos; } + inline DataSize_t getRemainingSize() const + { + return size - nextPos; + } }; bool deserializeMessage(const MessageProcessingInfo &info, Header &header); diff --git a/include/rtps/rtps.h b/include/rtps/rtps.h index 4995e016..a7396c47 100644 --- a/include/rtps/rtps.h +++ b/include/rtps/rtps.h @@ -27,7 +27,8 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/entities/Domain.h" -namespace rtps { +namespace rtps +{ #if defined(unix) || defined(__unix__) || defined(WIN32) || defined(_WIN32) || \ defined(__WIN32) && !defined(__CYGWIN__) diff --git a/include/rtps/storages/CacheChange.h b/include/rtps/storages/CacheChange.h index 5cadd5ef..ff921246 100644 --- a/include/rtps/storages/CacheChange.h +++ b/include/rtps/storages/CacheChange.h @@ -29,7 +29,8 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/common/types.h" #include "rtps/storages/PBufWrapper.h" -namespace rtps { +namespace rtps +{ struct CacheChange { ChangeKind_t kind = ChangeKind_t::INVALID; SequenceNumber_t sequenceNumber = SEQUENCENUMBER_UNKNOWN; @@ -41,7 +42,7 @@ struct CacheChange { CacheChange() = default; CacheChange(ChangeKind_t kind, SequenceNumber_t sequenceNumber) - : kind(kind), sequenceNumber(sequenceNumber){}; + : kind(kind), sequenceNumber(sequenceNumber) {}; }; } // namespace rtps diff --git a/include/rtps/storages/MemoryPool.h b/include/rtps/storages/MemoryPool.h index 323dc2ec..21c7f68b 100644 --- a/include/rtps/storages/MemoryPool.h +++ b/include/rtps/storages/MemoryPool.h @@ -29,11 +29,14 @@ Author: i11 - Embedded Software, RWTH Aachen University #include #include -namespace rtps { +namespace rtps +{ -template class MemoryPool { +template class MemoryPool +{ public: - template class MemoryPoolIterator { + template class MemoryPoolIterator + { public: using iterator_category = std::input_iterator_tag; using value_type = IT_TYPE; @@ -41,7 +44,8 @@ template class MemoryPool { using pointer = IT_TYPE *; using reference = IT_TYPE &; - explicit MemoryPoolIterator(MemoryPool &pool) : m_pool(pool) { + explicit MemoryPoolIterator(MemoryPool &pool) : m_pool(pool) + { memcpy(m_bitMap, m_pool.m_bitMap, sizeof(m_bitMap)); } @@ -49,16 +53,24 @@ template class MemoryPool { // return bit == other.bit; //} - bool operator!=(const MemoryPoolIterator &other) const { + bool operator!=(const MemoryPoolIterator &other) const + { return m_bit != other.m_bit; } - reference operator*() const { return m_pool.m_data[m_bit]; } + reference operator*() const + { + return m_pool.m_data[m_bit]; + } - reference operator->() const { return m_pool.m_data[m_bit]; } + reference operator->() const + { + return m_pool.m_data[m_bit]; + } // Pre-increment - MemoryPoolIterator &operator++() { + MemoryPoolIterator &operator++() + { if (m_pool.m_numElements == 0) { m_bit = SIZE; return *this; @@ -73,7 +85,8 @@ template class MemoryPool { } // Post-increment - MemoryPoolIterator operator++(int) { + MemoryPoolIterator operator++(int) + { MemoryPoolIterator tmp(*this); ++(*this); return tmp; @@ -91,15 +104,28 @@ template class MemoryPool { typedef bool (*condition_fp)(TYPE); - uint32_t getSize() { return SIZE; } + uint32_t getSize() + { + return SIZE; + } - bool isFull() { return m_numElements == SIZE; } + bool isFull() + { + return m_numElements == SIZE; + } - bool isEmpty() { return m_numElements == 0; } + bool isEmpty() + { + return m_numElements == 0; + } - uint32_t getNumElements() { return m_numElements; } + uint32_t getNumElements() + { + return m_numElements; + } - bool add(const TYPE &data) { + bool add(const TYPE &data) + { if (isFull()) { printf("[MemoryPool] RESSOURCE LIMIT EXCEEDED \n"); return false; @@ -133,15 +159,16 @@ template class MemoryPool { * NOTE: You have to make sure that the callback did not run out of scope. */ bool remove(bool (*jumppad)(void *, const TYPE &data), - void *isCorrectElement) { + void *isCorrectElement) + { bool retcode = false; for (auto it = begin(); it != end(); ++it) { if (jumppad(isCorrectElement, *it)) { const uint8_t bucket = it.m_bit / uint8_t{8}; const uint8_t pos = - it.m_bit & - uint8_t{ - 7}; // 7 sets all bits above and including the one for 8 to 0 + it.m_bit & + uint8_t{ + 7}; // 7 sets all bits above and including the one for 8 to 0 m_bitMap[bucket] &= ~(static_cast(1) << pos); --m_numElements; retcode = true; @@ -151,7 +178,8 @@ template class MemoryPool { } TYPE *find(bool (*jumppad)(void *, const TYPE &data), - void *isCorrectElement) { + void *isCorrectElement) + { for (auto it = begin(); it != end(); ++it) { if (jumppad(isCorrectElement, *it)) { return &(*it); @@ -160,7 +188,8 @@ template class MemoryPool { return nullptr; } - MemPoolIter begin() { + MemPoolIter begin() + { MemPoolIter it(*this); if (!(m_bitMap[0] & 1)) { ++it; @@ -168,14 +197,15 @@ template class MemoryPool { return it; } - MemPoolIter end() { + MemPoolIter end() + { MemPoolIter endIt(*this); endIt.m_bit = SIZE; return endIt; } private: - uint8_t m_bitMap[SIZE / 8 + 1]{}; + uint8_t m_bitMap[SIZE / 8 + 1] {}; uint32_t m_numElements = 0; TYPE m_data[SIZE]; }; diff --git a/include/rtps/storages/PBufWrapper.h b/include/rtps/storages/PBufWrapper.h index 6e8339e5..cf381128 100644 --- a/include/rtps/storages/PBufWrapper.h +++ b/include/rtps/storages/PBufWrapper.h @@ -28,7 +28,8 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "lwip/pbuf.h" #include "rtps/common/types.h" -namespace rtps { +namespace rtps +{ struct PBufWrapper { diff --git a/include/rtps/storages/SimpleHistoryCache.h b/include/rtps/storages/SimpleHistoryCache.h index d370b2f3..71b98e61 100644 --- a/include/rtps/storages/SimpleHistoryCache.h +++ b/include/rtps/storages/SimpleHistoryCache.h @@ -28,7 +28,8 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/config.h" #include "rtps/storages/CacheChange.h" -namespace rtps { +namespace rtps +{ /** * Simple version of a history cache. It sets consecutive sequence numbers @@ -37,18 +38,21 @@ namespace rtps { * However, this is in principle easy to add by changing the ChangeKind and * dropping it when passing it during deleting of other sequence numbers */ -template class SimpleHistoryCache { +template class SimpleHistoryCache +{ public: SimpleHistoryCache() = default; - bool isFull() const { + bool isFull() const + { uint16_t it = m_head; incrementIterator(it); return it == m_tail; } const CacheChange *addChange(CacheChange::SerializerCallback func, - FragDataSize_t size) { + FragDataSize_t size) + { CacheChange change; change.kind = ChangeKind_t::ALIVE; change.sizeToBeSerialized = size; @@ -62,7 +66,8 @@ template class SimpleHistoryCache { return place; } - const CacheChange *addChange(const uint8_t *data, DataSize_t size) { + const CacheChange *addChange(const uint8_t *data, DataSize_t size) + { CacheChange change; change.kind = ChangeKind_t::ALIVE; change.data.reserve(size); @@ -76,7 +81,8 @@ template class SimpleHistoryCache { return place; } - void removeUntilIncl(SequenceNumber_t sn) { + void removeUntilIncl(SequenceNumber_t sn) + { if (m_head == m_tail) { return; } @@ -91,9 +97,13 @@ template class SimpleHistoryCache { } } - void dropOldest() { removeUntilIncl(getSeqNumMin()); } + void dropOldest() + { + removeUntilIncl(getSeqNumMin()); + } - const CacheChange *getChangeBySN(SequenceNumber_t sn) const { + const CacheChange *getChangeBySN(SequenceNumber_t sn) const + { SequenceNumber_t minSN = getSeqNumMin(); if (sn < minSN || getSeqNumMax() < sn) { return nullptr; @@ -112,7 +122,8 @@ template class SimpleHistoryCache { return &m_buffer[pos]; } - const SequenceNumber_t &getSeqNumMin() const { + const SequenceNumber_t &getSeqNumMin() const + { if (m_head == m_tail) { return SEQUENCENUMBER_UNKNOWN; } else { @@ -120,7 +131,8 @@ template class SimpleHistoryCache { } } - const SequenceNumber_t &getSeqNumMax() const { + const SequenceNumber_t &getSeqNumMax() const + { if (m_head == m_tail) { return SEQUENCENUMBER_UNKNOWN; } else { @@ -137,7 +149,8 @@ template class SimpleHistoryCache { SequenceNumber_t m_lastUsedSequenceNumber{0, 0}; - inline void incrementHead() { + inline void incrementHead() + { incrementIterator(m_head); if (m_head == m_tail) { // Move without check @@ -145,14 +158,16 @@ template class SimpleHistoryCache { } } - inline void incrementIterator(uint16_t &iterator) const { + inline void incrementIterator(uint16_t &iterator) const + { ++iterator; if (iterator >= m_buffer.size()) { iterator = 0; } } - inline void incrementTail() { + inline void incrementTail() + { if (m_head != m_tail) { incrementIterator(m_tail); } @@ -161,7 +176,8 @@ template class SimpleHistoryCache { protected: // This constructor was created for unit testing explicit SimpleHistoryCache(SequenceNumber_t lastUsed) - : SimpleHistoryCache() { + : SimpleHistoryCache() + { m_lastUsedSequenceNumber = lastUsed; } }; diff --git a/include/rtps/storages/ThreadSafeCircularBuffer.h b/include/rtps/storages/ThreadSafeCircularBuffer.h index d0304ca7..00e05800 100644 --- a/include/rtps/storages/ThreadSafeCircularBuffer.h +++ b/include/rtps/storages/ThreadSafeCircularBuffer.h @@ -30,9 +30,11 @@ Author: i11 - Embedded Software, RWTH Aachen University #include #include -namespace rtps { +namespace rtps +{ -template class ThreadSafeCircularBuffer { +template class ThreadSafeCircularBuffer +{ public: bool init(); diff --git a/include/rtps/utils/Lock.h b/include/rtps/utils/Lock.h index 7de73c04..7460a7ef 100644 --- a/include/rtps/utils/Lock.h +++ b/include/rtps/utils/Lock.h @@ -27,15 +27,21 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "lwip/sys.h" -namespace rtps { +namespace rtps +{ -class Lock { +class Lock +{ public: - explicit Lock(sys_mutex_t &passedMutex) : m_mutex(passedMutex) { + explicit Lock(sys_mutex_t &passedMutex) : m_mutex(passedMutex) + { sys_mutex_lock(&m_mutex); }; - ~Lock() { sys_mutex_unlock(&m_mutex); }; + ~Lock() + { + sys_mutex_unlock(&m_mutex); + }; private: sys_mutex_t &m_mutex; diff --git a/include/rtps/utils/hash.h b/include/rtps/utils/hash.h index 3c868e52..655443ff 100644 --- a/include/rtps/utils/hash.h +++ b/include/rtps/utils/hash.h @@ -25,8 +25,10 @@ Author: i11 - Embedded Software, RWTH Aachen University #ifndef RTPS_HASH_H #define RTPS_HASH_H -namespace rtps { -inline size_t hashCharArray(const char *p, size_t s) { +namespace rtps +{ +inline size_t hashCharArray(const char *p, size_t s) +{ size_t result = 0; const size_t prime = 31; for (size_t i = 0; i < s; ++i) { diff --git a/include/rtps/utils/printutils.h b/include/rtps/utils/printutils.h index 4d4d1bfa..91d8123b 100644 --- a/include/rtps/utils/printutils.h +++ b/include/rtps/utils/printutils.h @@ -7,20 +7,23 @@ #include "rtps/common/types.h" -inline void printEntityId(rtps::EntityId_t id) { +inline void printEntityId(rtps::EntityId_t id) +{ for (const auto byte : id.entityKey) { printf("%x", (int)byte); } printf("%x", static_cast(id.entityKind)); } -inline void printGuidPrefix(rtps::GuidPrefix_t prefix) { +inline void printGuidPrefix(rtps::GuidPrefix_t prefix) +{ for (const auto byte : prefix.id) { printf("%x", (int)byte); } } -inline void printGuid(rtps::Guid_t guid) { +inline void printGuid(rtps::Guid_t guid) +{ printGuidPrefix(guid.prefix); printf(":"); printEntityId(guid.entityId); diff --git a/include/rtps/utils/sysFunctions.h b/include/rtps/utils/sysFunctions.h index df684126..9bb08617 100644 --- a/include/rtps/utils/sysFunctions.h +++ b/include/rtps/utils/sysFunctions.h @@ -28,8 +28,10 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "lwip/sys.h" #include "rtps/common/types.h" -namespace rtps { -inline Time_t getCurrentTimeStamp() { +namespace rtps +{ +inline Time_t getCurrentTimeStamp() +{ Time_t now; // TODO FIX uint32_t nowMs = sys_now(); diff --git a/include/rtps/utils/udpUtils.h b/include/rtps/utils/udpUtils.h index 356b096b..fb904706 100644 --- a/include/rtps/utils/udpUtils.h +++ b/include/rtps/utils/udpUtils.h @@ -27,8 +27,10 @@ Author: i11 - Embedded Software, RWTH Aachen University #include "rtps/config.h" -namespace rtps { -namespace { +namespace rtps +{ +namespace +{ const uint16_t PB = 7400; // Port Base Number const uint16_t DG = 250; // DomainId Gain const uint16_t PG = 2; // ParticipantId Gain @@ -40,52 +42,65 @@ const uint16_t D3 = 11; // User unicast } // namespace constexpr ip4_addr transformIP4ToU32(uint8_t MSB, uint8_t p2, uint8_t p1, - uint8_t LSB) { + uint8_t LSB) +{ return {((uint32_t)(LSB << 24)) | ((uint32_t)(p1 << 16)) | ((uint32_t)(p2 << 8)) | MSB}; } -constexpr Ip4Port_t getBuiltInUnicastPort(ParticipantId_t participantId) { +constexpr Ip4Port_t getBuiltInUnicastPort(ParticipantId_t participantId) +{ return PB + DG * Config::DOMAIN_ID + D1 + PG * participantId; } -constexpr Ip4Port_t getBuiltInMulticastPort() { +constexpr Ip4Port_t getBuiltInMulticastPort() +{ return PB + DG * Config::DOMAIN_ID + D0; } -constexpr Ip4Port_t getUserUnicastPort(ParticipantId_t participantId) { +constexpr Ip4Port_t getUserUnicastPort(ParticipantId_t participantId) +{ return PB + DG * Config::DOMAIN_ID + D3 + PG * participantId; } -constexpr Ip4Port_t getUserMulticastPort() { +constexpr Ip4Port_t getUserMulticastPort() +{ return PB + DG * Config::DOMAIN_ID + D2; } -constexpr bool isUserPort(Ip4Port_t port) { +constexpr bool isUserPort(Ip4Port_t port) +{ return (port & 1) == 1; } // really useful? There may be other user ports than just odd ones? -inline bool isMultiCastPort(Ip4Port_t port) { +inline bool isMultiCastPort(Ip4Port_t port) +{ const auto idWithoutBase = port - PB - DG * Config::DOMAIN_ID; return idWithoutBase == D0 || (idWithoutBase >= D2 && idWithoutBase < D3); // There are several UserMulticastPorts! } -inline bool isMetaMultiCastPort(Ip4Port_t port) { +inline bool isMetaMultiCastPort(Ip4Port_t port) +{ const auto idWithoutBase = port - PB - DG * Config::DOMAIN_ID; return idWithoutBase == D0; } -inline bool isUserMultiCastPort(Ip4Port_t port) { +inline bool isUserMultiCastPort(Ip4Port_t port) +{ const auto idWithoutBase = port - PB - DG * Config::DOMAIN_ID; return (idWithoutBase >= D2 && idWithoutBase < D1); } -inline bool isZeroAddress(ip4_addr_t address) { return address.addr == 0; } +inline bool isZeroAddress(ip4_addr_t address) +{ + return address.addr == 0; +} inline ParticipantId_t getParticipantIdFromUnicastPort(Ip4Port_t port, - bool isUserPort) { + bool isUserPort) +{ const auto basePart = PB + DG * Config::DOMAIN_ID; ParticipantId_t participantPart = port - basePart; diff --git a/src/ThreadPool.cpp b/src/ThreadPool.cpp index babc01d8..93be2a34 100644 --- a/src/ThreadPool.cpp +++ b/src/ThreadPool.cpp @@ -34,7 +34,8 @@ using rtps::ThreadPool; #define THREAD_POOL_VERBOSE 0 #if THREAD_POOL_VERBOSE && RTPS_GLOBAL_VERBOSE #define THREAD_POOL_LOG(...) -if (true) { +if (true) +{ printf("[ThreadPool] "); printf(__VA_ARGS__); printf("\n"); @@ -44,7 +45,8 @@ if (true) { #endif ThreadPool::ThreadPool(receiveJumppad_fp receiveCallback, void *callee) - : m_receiveJumppad(receiveCallback), m_callee(callee) { + : m_receiveJumppad(receiveCallback), m_callee(callee) +{ if (!m_queueOutgoing.init() || !m_queueIncoming.init()) { return; @@ -57,7 +59,8 @@ ThreadPool::ThreadPool(receiveJumppad_fp receiveCallback, void *callee) } } -ThreadPool::~ThreadPool() { +ThreadPool::~ThreadPool() +{ if (m_running) { stopThreads(); sys_msleep(500); @@ -71,7 +74,8 @@ ThreadPool::~ThreadPool() { } } -bool ThreadPool::startThreads() { +bool ThreadPool::startThreads() +{ if (m_running) { return true; } @@ -97,7 +101,8 @@ bool ThreadPool::startThreads() { return true; } -void ThreadPool::stopThreads() { +void ThreadPool::stopThreads() +{ m_running = false; // This should call all the semaphores for each thread once, so they don't // stuck before ended. @@ -114,12 +119,14 @@ void ThreadPool::stopThreads() { sys_msleep(10); } -void ThreadPool::clearQueues() { +void ThreadPool::clearQueues() +{ m_queueOutgoing.clear(); m_queueIncoming.clear(); } -bool ThreadPool::addWorkload(Writer *workload) { +bool ThreadPool::addWorkload(Writer *workload) +{ bool res = m_queueOutgoing.moveElementIntoBuffer(std::move(workload)); if (res) { sys_sem_signal(&m_writerNotificationSem); @@ -128,7 +135,8 @@ bool ThreadPool::addWorkload(Writer *workload) { return res; } -bool ThreadPool::addNewPacket(PacketInfo &&packet) { +bool ThreadPool::addNewPacket(PacketInfo &&packet) +{ bool res = m_queueIncoming.moveElementIntoBuffer(std::move(packet)); if (res) { sys_sem_signal(&m_readerNotificationSem); @@ -136,7 +144,8 @@ bool ThreadPool::addNewPacket(PacketInfo &&packet) { return res; } -void ThreadPool::writerThreadFunction(void *arg) { +void ThreadPool::writerThreadFunction(void *arg) +{ auto pool = static_cast(arg); if (pool == nullptr) { @@ -148,7 +157,8 @@ void ThreadPool::writerThreadFunction(void *arg) { pool->doWriterWork(); } -void ThreadPool::doWriterWork() { +void ThreadPool::doWriterWork() +{ while (m_running) { Writer *workload; auto isWorkToDo = m_queueOutgoing.moveFirstInto(workload); @@ -162,7 +172,8 @@ void ThreadPool::doWriterWork() { } void ThreadPool::readCallback(void *args, udp_pcb *target, pbuf *pbuf, - const ip_addr_t * /*addr*/, Ip4Port_t port) { + const ip_addr_t * /*addr*/, Ip4Port_t port) +{ auto &pool = *static_cast(args); PacketInfo packet; @@ -186,7 +197,8 @@ void ThreadPool::readCallback(void *args, udp_pcb *target, pbuf *pbuf, } } -void ThreadPool::readerThreadFunction(void *arg) { +void ThreadPool::readerThreadFunction(void *arg) +{ auto pool = static_cast(arg); if (pool == nullptr) { @@ -197,7 +209,8 @@ void ThreadPool::readerThreadFunction(void *arg) { pool->doReaderWork(); } -void ThreadPool::doReaderWork() { +void ThreadPool::doReaderWork() +{ while (m_running) { PacketInfo packet; diff --git a/src/communication/UdpDriver.cpp b/src/communication/UdpDriver.cpp index 4d65e538..17059a61 100644 --- a/src/communication/UdpDriver.cpp +++ b/src/communication/UdpDriver.cpp @@ -45,10 +45,11 @@ using rtps::UdpDriver; #endif UdpDriver::UdpDriver(rtps::UdpDriver::udpRxFunc_fp callback, void *args) - : m_rxCallback(callback), m_callbackArgs(args) {} + : m_rxCallback(callback), m_callbackArgs(args) {} const rtps::UdpConnection * -UdpDriver::createUdpConnection(Ip4Port_t receivePort) { +UdpDriver::createUdpConnection(Ip4Port_t receivePort) +{ for (uint8_t i = 0; i < m_numConns; ++i) { if (m_conns[i].port == receivePort) { return &m_conns[i]; @@ -82,16 +83,19 @@ UdpDriver::createUdpConnection(Ip4Port_t receivePort) { return &m_conns[m_numConns - 1]; } -bool UdpDriver::isSameSubnet(ip4_addr_t addr) { +bool UdpDriver::isSameSubnet(ip4_addr_t addr) +{ return (ip4_addr_netcmp(&addr, &(netif_default->ip_addr), &(netif_default->netmask)) != 0); } -bool UdpDriver::isMulticastAddress(ip4_addr_t addr) { +bool UdpDriver::isMulticastAddress(ip4_addr_t addr) +{ return ((addr.addr >> 28) == 14); } -bool UdpDriver::joinMultiCastGroup(ip4_addr_t addr) const { +bool UdpDriver::joinMultiCastGroup(ip4_addr_t addr) const +{ err_t iret; { @@ -114,7 +118,8 @@ bool UdpDriver::joinMultiCastGroup(ip4_addr_t addr) const { } bool UdpDriver::sendPacket(const UdpConnection &conn, ip4_addr_t &destAddr, - Ip4Port_t destPort, pbuf &buffer) { + Ip4Port_t destPort, pbuf &buffer) +{ err_t err; { TcpipCoreLock lock; @@ -132,7 +137,8 @@ bool UdpDriver::sendPacket(const UdpConnection &conn, ip4_addr_t &destAddr, return true; } -void UdpDriver::sendPacket(PacketInfo &packet) { +void UdpDriver::sendPacket(PacketInfo &packet) +{ auto p_conn = createUdpConnection(packet.srcPort); if (p_conn == nullptr) { ; diff --git a/src/discovery/ParticipantProxyData.cpp b/src/discovery/ParticipantProxyData.cpp index 24703fa1..d081cd7a 100644 --- a/src/discovery/ParticipantProxyData.cpp +++ b/src/discovery/ParticipantProxyData.cpp @@ -30,7 +30,8 @@ using rtps::ParticipantProxyData; ParticipantProxyData::ParticipantProxyData(Guid_t guid) : m_guid(guid) {} -void ParticipantProxyData::reset() { +void ParticipantProxyData::reset() +{ m_guid = Guid_t{GUIDPREFIX_UNKNOWN, ENTITYID_UNKNOWN}; m_manualLivelinessCount = Count_t{1}; m_expectsInlineQos = false; @@ -43,7 +44,8 @@ void ParticipantProxyData::reset() { } bool ParticipantProxyData::readFromUcdrBuffer(ucdrBuffer &buffer, - Participant *participant) { + Participant *participant) +{ reset(); SMElement::ParameterId pid; uint16_t length; @@ -86,7 +88,7 @@ bool ParticipantProxyData::readFromUcdrBuffer(ucdrBuffer &buffer, ucdr_deserialize_array_uint8_t(&buffer, m_guid.entityId.entityKey.data(), m_guid.entityId.entityKey.size()); ucdr_deserialize_uint8_t( - &buffer, reinterpret_cast(&m_guid.entityId.entityKind)); + &buffer, reinterpret_cast(&m_guid.entityId.entityKind)); if (participant->findRemoteParticipant(m_guid.prefix)) { SPDP_LOG("stopping deserialization early, participant is known\n"); return true; @@ -152,7 +154,9 @@ bool ParticipantProxyData::readFromUcdrBuffer(ucdrBuffer &buffer, case ParameterId::PID_SENTINEL: { return true; } - default: { return false; } + default: { + return false; + } } // Parameter lists are 4-byte aligned uint32_t alignment = ucdr_buffer_alignment(&buffer, 4); @@ -163,8 +167,9 @@ bool ParticipantProxyData::readFromUcdrBuffer(ucdrBuffer &buffer, } bool ParticipantProxyData::readLocatorIntoList( - ucdrBuffer &buffer, - std::array &list) { + ucdrBuffer &buffer, + std::array &list) +{ int valid_locators = 0; FullLengthLocator full_length_locator; for (auto &proxy_locator : list) { diff --git a/src/discovery/SEDPAgent.cpp b/src/discovery/SEDPAgent.cpp index fa67d781..da6e9e81 100644 --- a/src/discovery/SEDPAgent.cpp +++ b/src/discovery/SEDPAgent.cpp @@ -44,7 +44,8 @@ using rtps::SEDPAgent; #define SEDP_LOG(...) // #endif -void SEDPAgent::init(Participant &part, const BuiltInEndpoints &endpoints) { +void SEDPAgent::init(Participant &part, const BuiltInEndpoints &endpoints) +{ // TODO move if (sys_mutex_new(&m_mutex) != ERR_OK) { SEDP_LOG("SEDPAgent failed to create mutex\n"); @@ -58,35 +59,40 @@ void SEDPAgent::init(Participant &part, const BuiltInEndpoints &endpoints) { } if (m_endpoints.sedpSubReader != nullptr) { m_endpoints.sedpSubReader->registerCallback(receiveCallbackSubscriber, - this); + this); } } void SEDPAgent::registerOnNewPublisherMatchedCallback( - void (*callback)(void *arg), void *args) { + void (*callback)(void *arg), void *args) +{ mfp_onNewPublisherCallback = callback; m_onNewPublisherArgs = args; } void SEDPAgent::registerOnNewSubscriberMatchedCallback( - void (*callback)(void *arg), void *args) { + void (*callback)(void *arg), void *args) +{ mfp_onNewSubscriberCallback = callback; m_onNewSubscriberArgs = args; } void SEDPAgent::receiveCallbackPublisher(void *callee, - const ReaderCacheChange &cacheChange) { + const ReaderCacheChange &cacheChange) +{ auto agent = static_cast(callee); agent->onNewPublisher(cacheChange); } void SEDPAgent::receiveCallbackSubscriber( - void *callee, const ReaderCacheChange &cacheChange) { + void *callee, const ReaderCacheChange &cacheChange) +{ auto agent = static_cast(callee); agent->onNewSubscriber(cacheChange); } -void SEDPAgent::onNewPublisher(const ReaderCacheChange &change) { +void SEDPAgent::onNewPublisher(const ReaderCacheChange &change) +{ Lock lock{m_mutex}; #if SEDP_VERBOSE SEDP_LOG("New publisher\n"); @@ -107,7 +113,8 @@ void SEDPAgent::onNewPublisher(const ReaderCacheChange &change) { } } -void SEDPAgent::addUnmatchedRemoteWriter(const TopicData &writerData) { +void SEDPAgent::addUnmatchedRemoteWriter(const TopicData &writerData) +{ if (m_unmatchedRemoteWriters.isFull()) { #if SEDP_VERBOSE SEDP_LOG("List of unmatched remote writers is full.\n"); @@ -119,7 +126,8 @@ void SEDPAgent::addUnmatchedRemoteWriter(const TopicData &writerData) { m_unmatchedRemoteWriters.add(TopicDataCompressed(writerData)); } -void SEDPAgent::addUnmatchedRemoteReader(const TopicData &readerData) { +void SEDPAgent::addUnmatchedRemoteReader(const TopicData &readerData) +{ if (m_unmatchedRemoteReaders.isFull()) { #if SEDP_VERBOSE SEDP_LOG("List of unmatched remote readers is full.\n"); @@ -132,7 +140,8 @@ void SEDPAgent::addUnmatchedRemoteReader(const TopicData &readerData) { } void SEDPAgent::removeUnmatchedEntitiesOfParticipant( - const GuidPrefix_t &guidPrefix) { + const GuidPrefix_t &guidPrefix) +{ auto isElementToRemove = [&](const TopicDataCompressed &topicData) { return topicData.endpointGuid.prefix == guidPrefix; }; @@ -145,15 +154,18 @@ void SEDPAgent::removeUnmatchedEntitiesOfParticipant( m_unmatchedRemoteWriters.remove(thunk, &isElementToRemove); } -uint32_t SEDPAgent::getNumRemoteUnmatchedReaders() { +uint32_t SEDPAgent::getNumRemoteUnmatchedReaders() +{ return m_unmatchedRemoteReaders.getNumElements(); } -uint32_t SEDPAgent::getNumRemoteUnmatchedWriters() { +uint32_t SEDPAgent::getNumRemoteUnmatchedWriters() +{ return m_unmatchedRemoteWriters.getNumElements(); } -void SEDPAgent::onNewPublisher(const TopicData &writerData) { +void SEDPAgent::onNewPublisher(const TopicData &writerData) +{ // TODO Is it okay to add Endpoint if the respective participant is unknown // participant? if (!m_part->findRemoteParticipant(writerData.endpointGuid.prefix)) { @@ -182,13 +194,14 @@ void SEDPAgent::onNewPublisher(const TopicData &writerData) { SEDP_LOG("publisher\n"); #endif reader->addNewMatchedWriter( - WriterProxy{writerData.endpointGuid, writerData.unicastLocator}); + WriterProxy{writerData.endpointGuid, writerData.unicastLocator}); if (mfp_onNewPublisherCallback != nullptr) { mfp_onNewPublisherCallback(m_onNewPublisherArgs); } } -void SEDPAgent::onNewSubscriber(const ReaderCacheChange &change) { +void SEDPAgent::onNewSubscriber(const ReaderCacheChange &change) +{ Lock lock{m_mutex}; #if SEDP_VERBOSE SEDP_LOG("New subscriber\n"); @@ -209,7 +222,8 @@ void SEDPAgent::onNewSubscriber(const ReaderCacheChange &change) { } } -void SEDPAgent::onNewSubscriber(const TopicData &readerData) { +void SEDPAgent::onNewSubscriber(const TopicData &readerData) +{ if (!m_part->findRemoteParticipant(readerData.endpointGuid.prefix)) { return; } @@ -243,7 +257,7 @@ void SEDPAgent::onNewSubscriber(const TopicData &readerData) { readerData.multicastLocator}); } else { writer->addNewMatchedReader( - ReaderProxy{readerData.endpointGuid, readerData.unicastLocator}); + ReaderProxy{readerData.endpointGuid, readerData.unicastLocator}); } if (mfp_onNewSubscriberCallback != nullptr) { @@ -251,13 +265,14 @@ void SEDPAgent::onNewSubscriber(const TopicData &readerData) { } } -void SEDPAgent::tryMatchUnmatchedEndpoints() { +void SEDPAgent::tryMatchUnmatchedEndpoints() +{ // Try to match remote readers with local writers for (auto &proxy : m_unmatchedRemoteReaders) { auto writer = m_part->getMatchingWriter(proxy); if (writer != nullptr) { writer->addNewMatchedReader(ReaderProxy{ - proxy.endpointGuid, proxy.unicastLocator, proxy.multicastLocator}); + proxy.endpointGuid, proxy.unicastLocator, proxy.multicastLocator}); } } @@ -266,17 +281,18 @@ void SEDPAgent::tryMatchUnmatchedEndpoints() { auto reader = m_part->getMatchingReader(proxy); if (reader != nullptr) { reader->addNewMatchedWriter( - WriterProxy{proxy.endpointGuid, proxy.unicastLocator}); + WriterProxy{proxy.endpointGuid, proxy.unicastLocator}); } } } -void SEDPAgent::addWriter(Writer &writer) { +void SEDPAgent::addWriter(Writer &writer) +{ if (m_endpoints.sedpPubWriter == nullptr) { return; } EntityKind_t writerKind = - writer.m_attributes.endpointGuid.entityId.entityKind; + writer.m_attributes.endpointGuid.entityId.entityKind; if (writerKind == EntityKind_t::BUILD_IN_WRITER_WITH_KEY || writerKind == EntityKind_t::BUILD_IN_WRITER_WITHOUT_KEY) { return; // No need to announce builtin endpoints @@ -304,13 +320,14 @@ void SEDPAgent::addWriter(Writer &writer) { #endif } -void SEDPAgent::addReader(Reader &reader) { +void SEDPAgent::addReader(Reader &reader) +{ if (m_endpoints.sedpSubWriter == nullptr) { return; } EntityKind_t readerKind = - reader.m_attributes.endpointGuid.entityId.entityKind; + reader.m_attributes.endpointGuid.entityId.entityKind; if (readerKind == EntityKind_t::BUILD_IN_READER_WITH_KEY || readerKind == EntityKind_t::BUILD_IN_READER_WITHOUT_KEY) { return; // No need to announce builtin endpoints diff --git a/src/discovery/SPDPAgent.cpp b/src/discovery/SPDPAgent.cpp index 562d1b5f..637521e2 100644 --- a/src/discovery/SPDPAgent.cpp +++ b/src/discovery/SPDPAgent.cpp @@ -36,13 +36,15 @@ using rtps::SPDPAgent; using rtps::SMElement::BuildInEndpointSet; using rtps::SMElement::ParameterId; -SPDPAgent::~SPDPAgent() { +SPDPAgent::~SPDPAgent() +{ if (initialized) { sys_mutex_free(&m_mutex); } } -void SPDPAgent::init(Participant &participant, BuiltInEndpoints &endpoints) { +void SPDPAgent::init(Participant &participant, BuiltInEndpoints &endpoints) +{ if (sys_mutex_new(&m_mutex) != ERR_OK) { SPDP_LOG("Could not alloc mutex"); return; @@ -58,7 +60,8 @@ void SPDPAgent::init(Participant &participant, BuiltInEndpoints &endpoints) { initialized = true; } -void SPDPAgent::start() { +void SPDPAgent::start() +{ if (m_running) { return; } @@ -67,13 +70,17 @@ void SPDPAgent::start() { Config::SPDP_WRITER_STACKSIZE, Config::SPDP_WRITER_PRIO); } -void SPDPAgent::stop() { m_running = false; } +void SPDPAgent::stop() +{ + m_running = false; +} -void SPDPAgent::runBroadcast(void *args) { +void SPDPAgent::runBroadcast(void *args) +{ SPDPAgent &agent = *static_cast(args); const DataSize_t size = ucdr_buffer_length(&agent.m_microbuffer); agent.m_buildInEndpoints.spdpWriter->newChange( - ChangeKind_t::ALIVE, agent.m_microbuffer.init, size); + ChangeKind_t::ALIVE, agent.m_microbuffer.init, size); while (agent.m_running) { #ifdef OS_IS_FREERTOS vTaskDelay(pdMS_TO_TICKS(Config::SPDP_RESEND_PERIOD_MS)); @@ -91,12 +98,14 @@ void SPDPAgent::runBroadcast(void *args) { } void SPDPAgent::receiveCallback(void *callee, - const ReaderCacheChange &cacheChange) { + const ReaderCacheChange &cacheChange) +{ auto agent = static_cast(callee); agent->handleSPDPPackage(cacheChange); } -void SPDPAgent::handleSPDPPackage(const ReaderCacheChange &cacheChange) { +void SPDPAgent::handleSPDPPackage(const ReaderCacheChange &cacheChange) +{ if (!initialized) { SPDP_LOG("Callback called without initialization\n"); return; @@ -119,7 +128,7 @@ void SPDPAgent::handleSPDPPackage(const ReaderCacheChange &cacheChange) { if (cacheChange.kind == ChangeKind_t::ALIVE) { configureEndianessAndOptions(buffer); volatile bool success = - m_proxyDataBuffer.readFromUcdrBuffer(buffer, mp_participant); + m_proxyDataBuffer.readFromUcdrBuffer(buffer, mp_participant); if (success) { // TODO In case we store the history we can free the history mutex here processProxyData(); @@ -131,7 +140,8 @@ void SPDPAgent::handleSPDPPackage(const ReaderCacheChange &cacheChange) { } } -void SPDPAgent::configureEndianessAndOptions(ucdrBuffer &buffer) { +void SPDPAgent::configureEndianessAndOptions(ucdrBuffer &buffer) +{ std::array encapsulation{}; // Endianess doesn't matter for this since those are single bytes ucdr_deserialize_array_uint8_t(&buffer, encapsulation.data(), @@ -146,19 +156,20 @@ void SPDPAgent::configureEndianessAndOptions(ucdrBuffer &buffer) { encapsulation.size()); } -void SPDPAgent::processProxyData() { +void SPDPAgent::processProxyData() +{ if (m_proxyDataBuffer.m_guid.prefix.id == mp_participant->m_guidPrefix.id) { return; // Our own packet } const rtps::ParticipantProxyData *remote_part; remote_part = - mp_participant->findRemoteParticipant(m_proxyDataBuffer.m_guid.prefix); + mp_participant->findRemoteParticipant(m_proxyDataBuffer.m_guid.prefix); if (remote_part != nullptr) { SPDP_LOG("Not adding remote participant guid.prefix = %u \n", (unsigned int)Guid_t::sum(remote_part->m_guid)); mp_participant->refreshRemoteParticipantLiveliness( - m_proxyDataBuffer.m_guid.prefix); + m_proxyDataBuffer.m_guid.prefix); return; // Already in our list } @@ -172,7 +183,8 @@ void SPDPAgent::processProxyData() { SPDP_LOG("Failed to add new participant"); } #else - } else { + } else + { while (1) { SPDP_LOG("failed to add remote participant"); } @@ -180,7 +192,8 @@ void SPDPAgent::processProxyData() { #endif } -bool SPDPAgent::addProxiesForBuiltInEndpoints() { +bool SPDPAgent::addProxiesForBuiltInEndpoints() +{ LocatorIPv4 *locator = nullptr; @@ -203,37 +216,46 @@ bool SPDPAgent::addProxiesForBuiltInEndpoints() { SPDP_LOG("Adding IPv4 Locator %s\n", addr); if (m_proxyDataBuffer.hasPublicationWriter()) { - const WriterProxy proxy{{m_proxyDataBuffer.m_guid.prefix, - ENTITYID_SEDP_BUILTIN_PUBLICATIONS_WRITER}, - *locator}; + const WriterProxy proxy{{ + m_proxyDataBuffer.m_guid.prefix, + ENTITYID_SEDP_BUILTIN_PUBLICATIONS_WRITER + }, + *locator}; m_buildInEndpoints.sedpPubReader->addNewMatchedWriter(proxy); } if (m_proxyDataBuffer.hasSubscriptionWriter()) { - const WriterProxy proxy{{m_proxyDataBuffer.m_guid.prefix, - ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_WRITER}, - *locator}; + const WriterProxy proxy{{ + m_proxyDataBuffer.m_guid.prefix, + ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_WRITER + }, + *locator}; m_buildInEndpoints.sedpSubReader->addNewMatchedWriter(proxy); } if (m_proxyDataBuffer.hasPublicationReader()) { - const ReaderProxy proxy{{m_proxyDataBuffer.m_guid.prefix, - ENTITYID_SEDP_BUILTIN_PUBLICATIONS_READER}, - *locator}; + const ReaderProxy proxy{{ + m_proxyDataBuffer.m_guid.prefix, + ENTITYID_SEDP_BUILTIN_PUBLICATIONS_READER + }, + *locator}; m_buildInEndpoints.sedpPubWriter->addNewMatchedReader(proxy); } if (m_proxyDataBuffer.hasSubscriptionReader()) { - const ReaderProxy proxy{{m_proxyDataBuffer.m_guid.prefix, - ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_READER}, - *locator}; + const ReaderProxy proxy{{ + m_proxyDataBuffer.m_guid.prefix, + ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_READER + }, + *locator}; m_buildInEndpoints.sedpSubWriter->addNewMatchedReader(proxy); } return true; } -void SPDPAgent::addInlineQos() { +void SPDPAgent::addInlineQos() +{ ucdr_serialize_uint16_t(&m_microbuffer, ParameterId::PID_KEY_HASH); ucdr_serialize_uint16_t(&m_microbuffer, 16); ucdr_serialize_array_uint8_t(&m_microbuffer, @@ -243,36 +265,38 @@ void SPDPAgent::addInlineQos() { ENTITYID_BUILD_IN_PARTICIPANT.entityKey.data(), sizeof(EntityId_t::entityKey)); ucdr_serialize_uint8_t( - &m_microbuffer, - static_cast(ENTITYID_BUILD_IN_PARTICIPANT.entityKind)); + &m_microbuffer, + static_cast(ENTITYID_BUILD_IN_PARTICIPANT.entityKind)); endCurrentList(); } -void SPDPAgent::endCurrentList() { +void SPDPAgent::endCurrentList() +{ ucdr_serialize_uint16_t(&m_microbuffer, ParameterId::PID_SENTINEL); ucdr_serialize_uint16_t(&m_microbuffer, 0); } -void SPDPAgent::addParticipantParameters() { +void SPDPAgent::addParticipantParameters() +{ const uint16_t zero_options = 0; const uint16_t protocolVersionSize = - sizeof(PROTOCOLVERSION.major) + sizeof(PROTOCOLVERSION.minor); + sizeof(PROTOCOLVERSION.major) + sizeof(PROTOCOLVERSION.minor); const uint16_t vendorIdSize = Config::VENDOR_ID.vendorId.size(); const uint16_t locatorSize = sizeof(FullLengthLocator); const uint16_t durationSize = - sizeof(Duration_t::seconds) + sizeof(Duration_t::fraction); + sizeof(Duration_t::seconds) + sizeof(Duration_t::fraction); const uint16_t entityKeySize = 3; const uint16_t entityKindSize = 1; const uint16_t entityIdSize = entityKeySize + entityKindSize; const uint16_t guidSize = sizeof(GuidPrefix_t::id) + entityIdSize; const FullLengthLocator userUniCastLocator = - getUserUnicastLocator(mp_participant->m_participantId); + getUserUnicastLocator(mp_participant->m_participantId); const FullLengthLocator builtInUniCastLocator = - getBuiltInUnicastLocator(mp_participant->m_participantId); + getBuiltInUnicastLocator(mp_participant->m_participantId); const FullLengthLocator builtInMultiCastLocator = - getBuiltInMulticastLocator(); + getBuiltInMulticastLocator(); ucdr_serialize_array_uint8_t(&m_microbuffer, rtps::SMElement::SCHEME_PL_CDR_LE.data(), @@ -297,22 +321,22 @@ void SPDPAgent::addParticipantParameters() { ParameterId::PID_DEFAULT_UNICAST_LOCATOR); ucdr_serialize_uint16_t(&m_microbuffer, locatorSize); ucdr_serialize_array_uint8_t( - &m_microbuffer, reinterpret_cast(&userUniCastLocator), - locatorSize); + &m_microbuffer, reinterpret_cast(&userUniCastLocator), + locatorSize); ucdr_serialize_uint16_t(&m_microbuffer, ParameterId::PID_METATRAFFIC_UNICAST_LOCATOR); ucdr_serialize_uint16_t(&m_microbuffer, locatorSize); ucdr_serialize_array_uint8_t( - &m_microbuffer, reinterpret_cast(&builtInUniCastLocator), - locatorSize); + &m_microbuffer, reinterpret_cast(&builtInUniCastLocator), + locatorSize); ucdr_serialize_uint16_t(&m_microbuffer, ParameterId::PID_METATRAFFIC_MULTICAST_LOCATOR); ucdr_serialize_uint16_t(&m_microbuffer, locatorSize); ucdr_serialize_array_uint8_t( - &m_microbuffer, - reinterpret_cast(&builtInMultiCastLocator), locatorSize); + &m_microbuffer, + reinterpret_cast(&builtInMultiCastLocator), locatorSize); ucdr_serialize_uint16_t(&m_microbuffer, ParameterId::PID_PARTICIPANT_LEASE_DURATION); @@ -331,19 +355,19 @@ void SPDPAgent::addParticipantParameters() { ENTITYID_BUILD_IN_PARTICIPANT.entityKey.data(), entityKeySize); ucdr_serialize_uint8_t( - &m_microbuffer, - static_cast(ENTITYID_BUILD_IN_PARTICIPANT.entityKind)); + &m_microbuffer, + static_cast(ENTITYID_BUILD_IN_PARTICIPANT.entityKind)); ucdr_serialize_uint16_t(&m_microbuffer, ParameterId::PID_BUILTIN_ENDPOINT_SET); ucdr_serialize_uint16_t(&m_microbuffer, sizeof(BuildInEndpointSet)); ucdr_serialize_uint32_t( - &m_microbuffer, BuildInEndpointSet::DISC_BIE_PARTICIPANT_ANNOUNCER | - BuildInEndpointSet::DISC_BIE_PARTICIPANT_DETECTOR | - BuildInEndpointSet::DISC_BIE_PUBLICATION_ANNOUNCER | - BuildInEndpointSet::DISC_BIE_PUBLICATION_DETECTOR | - BuildInEndpointSet::DISC_BIE_SUBSCRIPTION_ANNOUNCER | - BuildInEndpointSet::DISC_BIE_SUBSCRIPTION_DETECTOR); + &m_microbuffer, BuildInEndpointSet::DISC_BIE_PARTICIPANT_ANNOUNCER | + BuildInEndpointSet::DISC_BIE_PARTICIPANT_DETECTOR | + BuildInEndpointSet::DISC_BIE_PUBLICATION_ANNOUNCER | + BuildInEndpointSet::DISC_BIE_PUBLICATION_DETECTOR | + BuildInEndpointSet::DISC_BIE_SUBSCRIPTION_ANNOUNCER | + BuildInEndpointSet::DISC_BIE_SUBSCRIPTION_DETECTOR); endCurrentList(); } diff --git a/src/discovery/TopicData.cpp b/src/discovery/TopicData.cpp index 58eb8ff1..cd049d82 100644 --- a/src/discovery/TopicData.cpp +++ b/src/discovery/TopicData.cpp @@ -29,12 +29,14 @@ using rtps::TopicData; using rtps::TopicDataCompressed; using rtps::SMElement::ParameterId; -bool TopicData::matchesTopicOf(const TopicData &other) { +bool TopicData::matchesTopicOf(const TopicData &other) +{ return strcmp(this->topicName, other.topicName) == 0 && strcmp(this->typeName, other.typeName) == 0; } -bool TopicData::readFromUcdrBuffer(ucdrBuffer &buffer) { +bool TopicData::readFromUcdrBuffer(ucdrBuffer &buffer) +{ while (ucdr_buffer_remaining(&buffer) >= 4) { ParameterId pid; @@ -55,7 +57,7 @@ bool TopicData::readFromUcdrBuffer(ucdrBuffer &buffer) { endpointGuid.entityId.entityKey.data(), endpointGuid.entityId.entityKey.size()); ucdr_deserialize_uint8_t(&buffer, reinterpret_cast( - &endpointGuid.entityId.entityKind)); + &endpointGuid.entityId.entityKind)); break; case ParameterId::PID_RELIABILITY: ucdr_deserialize_uint32_t(&buffer, @@ -97,7 +99,8 @@ bool TopicData::readFromUcdrBuffer(ucdrBuffer &buffer) { return ucdr_buffer_remaining(&buffer) == 0; } -bool TopicData::serializeIntoUcdrBuffer(ucdrBuffer &buffer) const { +bool TopicData::serializeIntoUcdrBuffer(ucdrBuffer &buffer) const +{ // TODO Check if buffer length is sufficient const uint16_t guidSize = sizeof(GuidPrefix_t::id) + 4; @@ -107,8 +110,8 @@ bool TopicData::serializeIntoUcdrBuffer(ucdrBuffer &buffer) const { ucdr_serialize_uint16_t(&buffer, ParameterId::PID_UNICAST_LOCATOR); ucdr_serialize_uint16_t(&buffer, sizeof(FullLengthLocator)); ucdr_serialize_array_uint8_t( - &buffer, reinterpret_cast(&unicastLocator), - sizeof(FullLengthLocator)); + &buffer, reinterpret_cast(&unicastLocator), + sizeof(FullLengthLocator)); #if SUPPRESS_UNICAST } #endif @@ -117,13 +120,13 @@ bool TopicData::serializeIntoUcdrBuffer(ucdrBuffer &buffer) const { ucdr_serialize_uint16_t(&buffer, ParameterId::PID_MULTICAST_LOCATOR); ucdr_serialize_uint16_t(&buffer, sizeof(FullLengthLocator)); ucdr_serialize_array_uint8_t( - &buffer, reinterpret_cast(&multicastLocator), - sizeof(FullLengthLocator)); + &buffer, reinterpret_cast(&multicastLocator), + sizeof(FullLengthLocator)); } // It's a 32 bit instead of 16 because it seems like the field is padded. const auto lenTopicName = - static_cast(strlen(topicName) + 1); // + \0 + static_cast(strlen(topicName) + 1); // + \0 uint16_t topicAlignment = 0; if (lenTopicName % 4 != 0) { topicAlignment = static_cast(4 - (lenTopicName % 4)); @@ -143,7 +146,7 @@ bool TopicData::serializeIntoUcdrBuffer(ucdrBuffer &buffer) const { typeAlignment = static_cast(4 - (lenTypeName % 4)); } const auto totalLengthTypeNameField = - static_cast(sizeof(lenTypeName) + lenTypeName + typeAlignment); + static_cast(sizeof(lenTypeName) + lenTypeName + typeAlignment); ucdr_serialize_uint16_t(&buffer, ParameterId::PID_TYPE_NAME); ucdr_serialize_uint16_t(&buffer, totalLengthTypeNameField); @@ -158,7 +161,7 @@ bool TopicData::serializeIntoUcdrBuffer(ucdrBuffer &buffer) const { ucdr_serialize_array_uint8_t(&buffer, endpointGuid.entityId.entityKey.data(), endpointGuid.entityId.entityKey.size()); ucdr_serialize_uint8_t( - &buffer, static_cast(endpointGuid.entityId.entityKind)); + &buffer, static_cast(endpointGuid.entityId.entityKind)); ucdr_serialize_uint16_t(&buffer, ParameterId::PID_ENDPOINT_GUID); ucdr_serialize_uint16_t(&buffer, guidSize); @@ -167,7 +170,7 @@ bool TopicData::serializeIntoUcdrBuffer(ucdrBuffer &buffer) const { ucdr_serialize_array_uint8_t(&buffer, endpointGuid.entityId.entityKey.data(), endpointGuid.entityId.entityKey.size()); ucdr_serialize_uint8_t( - &buffer, static_cast(endpointGuid.entityId.entityKind)); + &buffer, static_cast(endpointGuid.entityId.entityKind)); const uint8_t unidentifiedOffset = 8; ucdr_serialize_uint16_t(&buffer, ParameterId::PID_RELIABILITY); @@ -187,8 +190,9 @@ bool TopicData::serializeIntoUcdrBuffer(ucdrBuffer &buffer) const { return true; } -bool TopicDataCompressed::matchesTopicOf(const TopicData &other) const { +bool TopicDataCompressed::matchesTopicOf(const TopicData &other) const +{ return (hashCharArray(other.topicName, sizeof(other.topicName)) == - topicHash && + topicHash && hashCharArray(other.typeName, sizeof(other.typeName)) == typeHash); } diff --git a/src/entities/Domain.cpp b/src/entities/Domain.cpp index bf545d09..4713ad23 100644 --- a/src/entities/Domain.cpp +++ b/src/entities/Domain.cpp @@ -40,16 +40,21 @@ Author: i11 - Embedded Software, RWTH Aachen University using rtps::Domain; Domain::Domain() - : m_threadPool(receiveJumppad, this), - m_transport(ThreadPool::readCallback, &m_threadPool) { + : m_threadPool(receiveJumppad, this), + m_transport(ThreadPool::readCallback, &m_threadPool) +{ m_transport.createUdpConnection(getUserMulticastPort()); m_transport.createUdpConnection(getBuiltInMulticastPort()); m_transport.joinMultiCastGroup(transformIP4ToU32(239, 255, 0, 1)); } -Domain::~Domain() { stop(); } +Domain::~Domain() +{ + stop(); +} -bool Domain::completeInit() { +bool Domain::completeInit() +{ m_initComplete = m_threadPool.startThreads(); if (!m_initComplete) { @@ -62,14 +67,19 @@ bool Domain::completeInit() { return m_initComplete; } -void Domain::stop() { m_threadPool.stopThreads(); } +void Domain::stop() +{ + m_threadPool.stopThreads(); +} -void Domain::receiveJumppad(void *callee, const PacketInfo &packet) { +void Domain::receiveJumppad(void *callee, const PacketInfo &packet) +{ auto domain = static_cast(callee); domain->receiveCallback(packet); } -void Domain::receiveCallback(const PacketInfo &packet) { +void Domain::receiveCallback(const PacketInfo &packet) +{ if (packet.buffer.firstElement->next != nullptr) { DOMAIN_LOG("Cannot handle multiple elements chained. You might " @@ -81,8 +91,8 @@ void Domain::receiveCallback(const PacketInfo &packet) { DOMAIN_LOG("Domain: Multicast to port %u\n", packet.destPort); for (auto i = 0; i < m_nextParticipantId - PARTICIPANT_START_ID; ++i) { m_participants[i].newMessage( - static_cast(packet.buffer.firstElement->payload), - packet.buffer.firstElement->len); + static_cast(packet.buffer.firstElement->payload), + packet.buffer.firstElement->len); } // First Check if UserTraffic Multicast } else if (isUserMultiCastPort(packet.destPort)) { @@ -94,22 +104,22 @@ void Domain::receiveCallback(const PacketInfo &packet) { if (m_participants[i].hasReaderWithMulticastLocator(packet.destAddr)) { DOMAIN_LOG("Domain: Forward Multicast only to Participant: %u\n", i); m_participants[i].newMessage( - static_cast(packet.buffer.firstElement->payload), - packet.buffer.firstElement->len); + static_cast(packet.buffer.firstElement->payload), + packet.buffer.firstElement->len); } } } else { // Pass to addressed one only (Unicast, by Port) ParticipantId_t id = getParticipantIdFromUnicastPort( - packet.destPort, isUserPort(packet.destPort)); + packet.destPort, isUserPort(packet.destPort)); if (id != PARTICIPANT_ID_INVALID) { DOMAIN_LOG("Domain: Got unicast message on port %u\n", packet.destPort); if (id < m_nextParticipantId && id >= PARTICIPANT_START_ID) { // added extra check to avoid segfault - // (id below START_ID) + // (id below START_ID) m_participants[id - PARTICIPANT_START_ID].newMessage( - static_cast(packet.buffer.firstElement->payload), - packet.buffer.firstElement->len); + static_cast(packet.buffer.firstElement->payload), + packet.buffer.firstElement->len); } else { DOMAIN_LOG("Domain: Participant id too high or unplausible.\n"); } @@ -120,12 +130,13 @@ void Domain::receiveCallback(const PacketInfo &packet) { } } -rtps::Participant *Domain::createParticipant() { +rtps::Participant *Domain::createParticipant() +{ DOMAIN_LOG("Domain: Creating new participant.\n"); auto nextSlot = - static_cast(m_nextParticipantId - PARTICIPANT_START_ID); + static_cast(m_nextParticipantId - PARTICIPANT_START_ID); if (m_initComplete || m_participants.size() <= nextSlot) { return nullptr; } @@ -138,7 +149,8 @@ rtps::Participant *Domain::createParticipant() { return &entry; } -void Domain::createBuiltinWritersAndReaders(Participant &part) { +void Domain::createBuiltinWritersAndReaders(Participant &part) +{ // SPDP StatelessWriter &spdpWriter = m_statelessWriters[m_numStatelessWriters++]; StatelessReader &spdpReader = m_statelessReaders[m_numStatelessReaders++]; @@ -150,18 +162,19 @@ void Domain::createBuiltinWritersAndReaders(Participant &part) { spdpWriterAttributes.durabilityKind = DurabilityKind_t::TRANSIENT_LOCAL; spdpWriterAttributes.endpointGuid.prefix = part.m_guidPrefix; spdpWriterAttributes.endpointGuid.entityId = - ENTITYID_SPDP_BUILTIN_PARTICIPANT_WRITER; + ENTITYID_SPDP_BUILTIN_PARTICIPANT_WRITER; spdpWriterAttributes.unicastLocator = getBuiltInMulticastLocator(); spdpWriter.init(spdpWriterAttributes, TopicKind_t::WITH_KEY, &m_threadPool, m_transport); spdpWriter.addNewMatchedReader( - ReaderProxy{{part.m_guidPrefix, ENTITYID_SPDP_BUILTIN_PARTICIPANT_READER}, - getBuiltInMulticastLocator()}); + ReaderProxy{{part.m_guidPrefix, ENTITYID_SPDP_BUILTIN_PARTICIPANT_READER}, + getBuiltInMulticastLocator()}); TopicData spdpReaderAttributes; spdpReaderAttributes.endpointGuid = { - part.m_guidPrefix, ENTITYID_SPDP_BUILTIN_PARTICIPANT_READER}; + part.m_guidPrefix, ENTITYID_SPDP_BUILTIN_PARTICIPANT_READER + }; spdpReader.init(spdpReaderAttributes); // SEDP @@ -178,24 +191,24 @@ void Domain::createBuiltinWritersAndReaders(Participant &part) { sedpAttributes.durabilityKind = DurabilityKind_t::TRANSIENT_LOCAL; sedpAttributes.endpointGuid.prefix = part.m_guidPrefix; sedpAttributes.unicastLocator = - getBuiltInUnicastLocator(part.m_participantId); + getBuiltInUnicastLocator(part.m_participantId); // READER sedpAttributes.endpointGuid.entityId = - ENTITYID_SEDP_BUILTIN_PUBLICATIONS_READER; + ENTITYID_SEDP_BUILTIN_PUBLICATIONS_READER; sedpPubReader.init(sedpAttributes, m_transport); sedpAttributes.endpointGuid.entityId = - ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_READER; + ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_READER; sedpSubReader.init(sedpAttributes, m_transport); // WRITER sedpAttributes.endpointGuid.entityId = - ENTITYID_SEDP_BUILTIN_PUBLICATIONS_WRITER; + ENTITYID_SEDP_BUILTIN_PUBLICATIONS_WRITER; sedpPubWriter.init(sedpAttributes, TopicKind_t::NO_KEY, &m_threadPool, m_transport); sedpAttributes.endpointGuid.entityId = - ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_WRITER; + ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_WRITER; sedpSubWriter.init(sedpAttributes, TopicKind_t::NO_KEY, &m_threadPool, m_transport); @@ -211,19 +224,22 @@ void Domain::createBuiltinWritersAndReaders(Participant &part) { part.addBuiltInEndpoints(endpoints); } -void Domain::registerPort(const Participant &part) { +void Domain::registerPort(const Participant &part) +{ m_transport.createUdpConnection(getUserUnicastPort(part.m_participantId)); m_transport.createUdpConnection(getBuiltInUnicastPort(part.m_participantId)); } -void Domain::registerMulticastPort(FullLengthLocator mcastLocator) { +void Domain::registerMulticastPort(FullLengthLocator mcastLocator) +{ if (mcastLocator.kind == LocatorKind_t::LOCATOR_KIND_UDPv4) { m_transport.createUdpConnection(mcastLocator.getLocatorPort()); } } rtps::Reader *Domain::readerExists(Participant &part, const char *topicName, - const char *typeName, bool reliable) { + const char *typeName, bool reliable) +{ if (reliable) { for (unsigned int i = 0; i < m_numStatefulReaders; i++) { if (m_statefulReaders[i].isInitialized()) { @@ -267,7 +283,8 @@ rtps::Reader *Domain::readerExists(Participant &part, const char *topicName, } rtps::Writer *Domain::writerExists(Participant &part, const char *topicName, - const char *typeName, bool reliable) { + const char *typeName, bool reliable) +{ if (reliable) { for (unsigned int i = 0; i < m_numStatefulWriters; i++) { if (m_statefulWriters[i].isInitialized()) { @@ -311,7 +328,8 @@ rtps::Writer *Domain::writerExists(Participant &part, const char *topicName, rtps::Writer *Domain::createWriter(Participant &part, const char *topicName, const char *typeName, bool reliable, - bool enforceUnicast) { + bool enforceUnicast) +{ // Check if there is enough capacity for more writers if ((reliable && m_statefulWriters.size() <= m_numStatefulWriters) || @@ -334,8 +352,9 @@ rtps::Writer *Domain::createWriter(Participant &part, const char *topicName, strcpy(attributes.typeName, typeName); attributes.endpointGuid.prefix = part.m_guidPrefix; attributes.endpointGuid.entityId = { - part.getNextUserEntityKey(), - EntityKind_t::USER_DEFINED_WRITER_WITHOUT_KEY}; + part.getNextUserEntityKey(), + EntityKind_t::USER_DEFINED_WRITER_WITHOUT_KEY + }; attributes.unicastLocator = getUserUnicastLocator(part.m_participantId); attributes.durabilityKind = DurabilityKind_t::TRANSIENT_LOCAL; @@ -364,7 +383,8 @@ rtps::Writer *Domain::createWriter(Participant &part, const char *topicName, rtps::Reader *Domain::createReader(Participant &part, const char *topicName, const char *typeName, bool reliable, - ip4_addr_t mcastaddress) { + ip4_addr_t mcastaddress) +{ if ((reliable && m_statefulReaders.size() <= m_numStatefulReaders) || (!reliable && m_statelessReaders.size() <= m_numStatelessReaders) || part.isReadersFull()) { @@ -385,17 +405,18 @@ rtps::Reader *Domain::createReader(Participant &part, const char *topicName, strcpy(attributes.typeName, typeName); attributes.endpointGuid.prefix = part.m_guidPrefix; attributes.endpointGuid.entityId = { - part.getNextUserEntityKey(), - EntityKind_t::USER_DEFINED_READER_WITHOUT_KEY}; + part.getNextUserEntityKey(), + EntityKind_t::USER_DEFINED_READER_WITHOUT_KEY + }; attributes.unicastLocator = getUserUnicastLocator(part.m_participantId); if (!isZeroAddress(mcastaddress)) { if (ip4_addr_ismulticast(&mcastaddress)) { attributes.multicastLocator = rtps::FullLengthLocator::createUDPv4Locator( - ip4_addr1(&mcastaddress), ip4_addr2(&mcastaddress), - ip4_addr3(&mcastaddress), ip4_addr4(&mcastaddress), - getUserMulticastPort()); + ip4_addr1(&mcastaddress), ip4_addr2(&mcastaddress), + ip4_addr3(&mcastaddress), ip4_addr4(&mcastaddress), + getUserMulticastPort()); m_transport.joinMultiCastGroup( - attributes.multicastLocator.getIp4Address()); + attributes.multicastLocator.getIp4Address()); registerMulticastPort(attributes.multicastLocator); DOMAIN_LOG("Multicast enabled!\n"); @@ -440,7 +461,8 @@ rtps::Reader *Domain::createReader(Participant &part, const char *topicName, } } -rtps::GuidPrefix_t Domain::generateGuidPrefix(ParticipantId_t id) const { +rtps::GuidPrefix_t Domain::generateGuidPrefix(ParticipantId_t id) const +{ GuidPrefix_t prefix = Config::BASE_GUID_PREFIX; #if defined(unix) || defined(__unix__) srand(time(nullptr)); diff --git a/src/entities/Participant.cpp b/src/entities/Participant.cpp index d9f60eca..59fb0212 100644 --- a/src/entities/Participant.cpp +++ b/src/entities/Participant.cpp @@ -43,8 +43,9 @@ Author: i11 - Embedded Software, RWTH Aachen University using rtps::Participant; Participant::Participant() - : m_guidPrefix(GUIDPREFIX_UNKNOWN), m_participantId(PARTICIPANT_ID_INVALID), - m_receiver(this) { + : m_guidPrefix(GUIDPREFIX_UNKNOWN), m_participantId(PARTICIPANT_ID_INVALID), + m_receiver(this) +{ if (sys_mutex_new(&m_mutex) != ERR_OK) { while (1) ; @@ -52,27 +53,34 @@ Participant::Participant() } Participant::Participant(const GuidPrefix_t &guidPrefix, ParticipantId_t participantId) - : m_guidPrefix(guidPrefix), m_participantId(participantId), - m_receiver(this) { + : m_guidPrefix(guidPrefix), m_participantId(participantId), + m_receiver(this) +{ if (sys_mutex_new(&m_mutex) != ERR_OK) { while (1) ; } } -Participant::~Participant() { m_spdpAgent.stop(); } +Participant::~Participant() +{ + m_spdpAgent.stop(); +} void Participant::reuse(const GuidPrefix_t &guidPrefix, - ParticipantId_t participantId) { + ParticipantId_t participantId) +{ m_guidPrefix = guidPrefix; m_participantId = participantId; } -bool Participant::isValid() { +bool Participant::isValid() +{ return m_participantId != PARTICIPANT_ID_INVALID; } -std::array Participant::getNextUserEntityKey() { +std::array Participant::getNextUserEntityKey() +{ const auto result = m_nextUserEntityId; ++m_nextUserEntityId[2]; @@ -86,7 +94,8 @@ std::array Participant::getNextUserEntityKey() { } bool Participant::registerOnNewPublisherMatchedCallback( - void (*callback)(void *arg), void *args) { + void (*callback)(void *arg), void *args) +{ if (!m_hasBuilInEndpoints) { return false; } @@ -96,7 +105,8 @@ bool Participant::registerOnNewPublisherMatchedCallback( } bool Participant::registerOnNewSubscriberMatchedCallback( - void (*callback)(void *arg), void *args) { + void (*callback)(void *arg), void *args) +{ if (!m_hasBuilInEndpoints) { return false; } @@ -105,7 +115,8 @@ bool Participant::registerOnNewSubscriberMatchedCallback( return true; } -rtps::Writer *Participant::addWriter(Writer *pWriter) { +rtps::Writer *Participant::addWriter(Writer *pWriter) +{ if (pWriter != nullptr && m_numWriters != m_writers.size()) { m_writers[m_numWriters++] = pWriter; if (m_hasBuilInEndpoints) { @@ -117,9 +128,13 @@ rtps::Writer *Participant::addWriter(Writer *pWriter) { } } -bool Participant::isWritersFull() { return m_numWriters == m_writers.size(); } +bool Participant::isWritersFull() +{ + return m_numWriters == m_writers.size(); +} -rtps::Reader *Participant::addReader(Reader *pReader) { +rtps::Reader *Participant::addReader(Reader *pReader) +{ if (pReader != nullptr && m_numReaders != m_readers.size()) { m_readers[m_numReaders++] = pReader; if (m_hasBuilInEndpoints) { @@ -131,9 +146,13 @@ rtps::Reader *Participant::addReader(Reader *pReader) { } } -bool Participant::isReadersFull() { return m_numReaders == m_readers.size(); } +bool Participant::isReadersFull() +{ + return m_numReaders == m_readers.size(); +} -rtps::Writer *Participant::getWriter(EntityId_t id) const { +rtps::Writer *Participant::getWriter(EntityId_t id) const +{ for (uint8_t i = 0; i < m_numWriters; ++i) { if (m_writers[i]->m_attributes.endpointGuid.entityId == id) { return m_writers[i]; @@ -142,7 +161,8 @@ rtps::Writer *Participant::getWriter(EntityId_t id) const { return nullptr; } -rtps::Reader *Participant::getReader(EntityId_t id) const { +rtps::Reader *Participant::getReader(EntityId_t id) const +{ for (uint8_t i = 0; i < m_numReaders; ++i) { if (m_readers[i]->m_attributes.endpointGuid.entityId == id) { return m_readers[i]; @@ -151,7 +171,8 @@ rtps::Reader *Participant::getReader(EntityId_t id) const { return nullptr; } -rtps::Reader *Participant::getReaderByWriterId(const Guid_t &guid) const { +rtps::Reader *Participant::getReaderByWriterId(const Guid_t &guid) const +{ for (uint8_t i = 0; i < m_numReaders; ++i) { if (m_readers[i]->knowWriterId(guid)) { return m_readers[i]; @@ -161,12 +182,13 @@ rtps::Reader *Participant::getReaderByWriterId(const Guid_t &guid) const { } rtps::Writer * -Participant::getMatchingWriter(const TopicData &readerTopicData) const { +Participant::getMatchingWriter(const TopicData &readerTopicData) const +{ for (uint8_t i = 0; i < m_numWriters; ++i) { if (m_writers[i]->m_attributes.matchesTopicOf(readerTopicData) && (readerTopicData.reliabilityKind == ReliabilityKind_t::BEST_EFFORT || m_writers[i]->m_attributes.reliabilityKind == - ReliabilityKind_t::RELIABLE)) { + ReliabilityKind_t::RELIABLE)) { return m_writers[i]; } } @@ -174,12 +196,13 @@ Participant::getMatchingWriter(const TopicData &readerTopicData) const { } rtps::Reader * -Participant::getMatchingReader(const TopicData &writerTopicData) const { +Participant::getMatchingReader(const TopicData &writerTopicData) const +{ for (uint8_t i = 0; i < m_numReaders; ++i) { if (m_readers[i]->m_attributes.matchesTopicOf(writerTopicData) && (writerTopicData.reliabilityKind == ReliabilityKind_t::RELIABLE || m_readers[i]->m_attributes.reliabilityKind == - ReliabilityKind_t::BEST_EFFORT)) { + ReliabilityKind_t::BEST_EFFORT)) { return m_readers[i]; } } @@ -187,12 +210,13 @@ Participant::getMatchingReader(const TopicData &writerTopicData) const { } rtps::Writer *Participant::getMatchingWriter( - const TopicDataCompressed &readerTopicData) const { + const TopicDataCompressed &readerTopicData) const +{ for (uint8_t i = 0; i < m_numWriters; ++i) { if (readerTopicData.matchesTopicOf(m_writers[i]->m_attributes) && (readerTopicData.reliabilityKind == ReliabilityKind_t::BEST_EFFORT || m_writers[i]->m_attributes.reliabilityKind == - ReliabilityKind_t::RELIABLE)) { + ReliabilityKind_t::RELIABLE)) { return m_writers[i]; } } @@ -200,12 +224,13 @@ rtps::Writer *Participant::getMatchingWriter( } rtps::Reader *Participant::getMatchingReader( - const TopicDataCompressed &writerTopicData) const { + const TopicDataCompressed &writerTopicData) const +{ for (uint8_t i = 0; i < m_numReaders; ++i) { if (writerTopicData.matchesTopicOf(m_readers[i]->m_attributes) && (writerTopicData.reliabilityKind == ReliabilityKind_t::RELIABLE || m_readers[i]->m_attributes.reliabilityKind == - ReliabilityKind_t::BEST_EFFORT)) { + ReliabilityKind_t::BEST_EFFORT)) { return m_readers[i]; } } @@ -213,12 +238,14 @@ rtps::Reader *Participant::getMatchingReader( } bool Participant::addNewRemoteParticipant( - const ParticipantProxyData &remotePart) { + const ParticipantProxyData &remotePart) +{ Lock lock{m_mutex}; return m_remoteParticipants.add(remotePart); } -bool Participant::removeRemoteParticipant(const GuidPrefix_t &prefix) { +bool Participant::removeRemoteParticipant(const GuidPrefix_t &prefix) +{ auto isElementToRemove = [&](const ParticipantProxyData &proxy) { return proxy.m_guid.prefix == prefix; }; @@ -230,7 +257,8 @@ bool Participant::removeRemoteParticipant(const GuidPrefix_t &prefix) { return m_remoteParticipants.remove(thunk, &isElementToRemove); } -void Participant::removeAllEntitiesOfParticipant(const GuidPrefix_t &prefix) { +void Participant::removeAllEntitiesOfParticipant(const GuidPrefix_t &prefix) +{ for (auto i = 0; i < m_numWriters; i++) { m_writers[i]->removeReaderOfParticipant(prefix); } @@ -241,7 +269,8 @@ void Participant::removeAllEntitiesOfParticipant(const GuidPrefix_t &prefix) { } const rtps::ParticipantProxyData * -Participant::findRemoteParticipant(const GuidPrefix_t &prefix) { +Participant::findRemoteParticipant(const GuidPrefix_t &prefix) +{ auto isElementToFind = [&](const ParticipantProxyData &proxy) { return proxy.m_guid.prefix == prefix; }; @@ -253,7 +282,8 @@ Participant::findRemoteParticipant(const GuidPrefix_t &prefix) { } void Participant::refreshRemoteParticipantLiveliness( - const GuidPrefix_t &prefix) { + const GuidPrefix_t &prefix) +{ auto isElementToFind = [&](const ParticipantProxyData &proxy) { return proxy.m_guid.prefix == prefix; }; @@ -265,7 +295,8 @@ void Participant::refreshRemoteParticipantLiveliness( remoteParticipant->onAliveSignal(); } -bool Participant::hasReaderWithMulticastLocator(ip4_addr_t address) { +bool Participant::hasReaderWithMulticastLocator(ip4_addr_t address) +{ for (uint8_t i = 0; i < m_numReaders; i++) { if (m_readers[i]->m_attributes.multicastLocator.isSameAddress(&address)) { return true; @@ -274,14 +305,19 @@ bool Participant::hasReaderWithMulticastLocator(ip4_addr_t address) { return false; } -uint32_t Participant::getRemoteParticipantCount() { +uint32_t Participant::getRemoteParticipantCount() +{ Lock lock{m_mutex}; return m_remoteParticipants.getNumElements(); } -rtps::MessageReceiver *Participant::getMessageReceiver() { return &m_receiver; } +rtps::MessageReceiver *Participant::getMessageReceiver() +{ + return &m_receiver; +} -void Participant::addHeartbeat(GuidPrefix_t sourceGuidPrefix) { +void Participant::addHeartbeat(GuidPrefix_t sourceGuidPrefix) +{ Lock lock{m_mutex}; for (auto &remote : m_remoteParticipants) { if (remote.m_guid.prefix == sourceGuidPrefix) { @@ -291,14 +327,15 @@ void Participant::addHeartbeat(GuidPrefix_t sourceGuidPrefix) { } } -bool Participant::checkAndResetHeartbeats() { +bool Participant::checkAndResetHeartbeats() +{ Lock lock{m_mutex}; PARTICIPANT_LOG("Have %u remote participants\n", (unsigned int)m_remoteParticipants.getNumElements()); PARTICIPANT_LOG( - "Unmatched remote writers/readers, %u / %u\n", - static_cast(m_sedpAgent.getNumRemoteUnmatchedWriters()), - static_cast(m_sedpAgent.getNumRemoteUnmatchedReaders())); + "Unmatched remote writers/readers, %u / %u\n", + static_cast(m_sedpAgent.getNumRemoteUnmatchedWriters()), + static_cast(m_sedpAgent.getNumRemoteUnmatchedReaders())); for (auto &remote : m_remoteParticipants) { PARTICIPANT_LOG("remote participant age = %u\n", (unsigned int)remote.getAliveSignalAgeInMilliseconds()); @@ -315,9 +352,13 @@ bool Participant::checkAndResetHeartbeats() { return true; } -rtps::SPDPAgent &Participant::getSPDPAgent() { return m_spdpAgent; } +rtps::SPDPAgent &Participant::getSPDPAgent() +{ + return m_spdpAgent; +} -void Participant::addBuiltInEndpoints(BuiltInEndpoints &endpoints) { +void Participant::addBuiltInEndpoints(BuiltInEndpoints &endpoints) +{ m_hasBuilInEndpoints = true; m_spdpAgent.init(*this, endpoints); m_sedpAgent.init(*this, endpoints); @@ -331,6 +372,7 @@ void Participant::addBuiltInEndpoints(BuiltInEndpoints &endpoints) { addReader(endpoints.sedpSubReader); } -void Participant::newMessage(const uint8_t *data, DataSize_t size) { +void Participant::newMessage(const uint8_t *data, DataSize_t size) +{ m_receiver.processMessage(data, size); } diff --git a/src/entities/StatelessReader.cpp b/src/entities/StatelessReader.cpp index da7da12c..5e4401ed 100644 --- a/src/entities/StatelessReader.cpp +++ b/src/entities/StatelessReader.cpp @@ -40,7 +40,8 @@ using rtps::StatelessReader; #define SLR_LOG(...) // #endif -void StatelessReader::init(const TopicData &attributes) { +void StatelessReader::init(const TopicData &attributes) +{ m_attributes = attributes; m_is_initialized_ = true; if (sys_mutex_new(&m_mutex) != ERR_OK) { @@ -48,13 +49,15 @@ void StatelessReader::init(const TopicData &attributes) { } } -void StatelessReader::newChange(const ReaderCacheChange &cacheChange) { +void StatelessReader::newChange(const ReaderCacheChange &cacheChange) +{ if (m_callback != nullptr) { m_callback(m_callee, cacheChange); } } -void StatelessReader::registerCallback(ddsReaderCallback_fp cb, void *callee) { +void StatelessReader::registerCallback(ddsReaderCallback_fp cb, void *callee) +{ if (cb != nullptr) { m_callback = cb; m_callee = callee; // It's okay if this is null @@ -65,7 +68,8 @@ void StatelessReader::registerCallback(ddsReaderCallback_fp cb, void *callee) { } } -bool StatelessReader::addNewMatchedWriter(const WriterProxy &newProxy) { +bool StatelessReader::addNewMatchedWriter(const WriterProxy &newProxy) +{ #if (SLR_VERBOSE && RTPS_GLOBAL_VERBOSE) SLR_LOG("Adding WriterProxy"); printGuid(newProxy.remoteWriterGuid); @@ -74,7 +78,8 @@ bool StatelessReader::addNewMatchedWriter(const WriterProxy &newProxy) { return m_proxies.add(newProxy); } -void StatelessReader::removeWriter(const Guid_t &guid) { +void StatelessReader::removeWriter(const Guid_t &guid) +{ Lock lock(m_mutex); auto isElementToRemove = [&](const WriterProxy &proxy) { return proxy.remoteWriterGuid == guid; @@ -87,7 +92,8 @@ void StatelessReader::removeWriter(const Guid_t &guid) { } void StatelessReader::removeWriterOfParticipant( - const GuidPrefix_t &guidPrefix) { + const GuidPrefix_t &guidPrefix) +{ Lock lock(m_mutex); auto isElementToRemove = [&](const WriterProxy &proxy) { return proxy.remoteWriterGuid.prefix == guidPrefix; @@ -100,7 +106,8 @@ void StatelessReader::removeWriterOfParticipant( } bool StatelessReader::onNewHeartbeat(const SubmessageHeartbeat &, - const GuidPrefix_t &) { + const GuidPrefix_t &) +{ // nothing to do return true; } diff --git a/src/messages/MessageReceiver.cpp b/src/messages/MessageReceiver.cpp index fc6e9fe2..2a7accf4 100644 --- a/src/messages/MessageReceiver.cpp +++ b/src/messages/MessageReceiver.cpp @@ -46,14 +46,16 @@ using rtps::MessageReceiver; MessageReceiver::MessageReceiver(Participant *part) : mp_part(part) {} -void MessageReceiver::resetState() { +void MessageReceiver::resetState() +{ sourceGuidPrefix = GUIDPREFIX_UNKNOWN; sourceVersion = PROTOCOLVERSION; sourceVendor = VENDOR_UNKNOWN; haveTimeStamp = false; } -bool MessageReceiver::processMessage(const uint8_t *data, DataSize_t size) { +bool MessageReceiver::processMessage(const uint8_t *data, DataSize_t size) +{ resetState(); MessageProcessingInfo msgInfo(data, size); @@ -71,7 +73,8 @@ bool MessageReceiver::processMessage(const uint8_t *data, DataSize_t size) { return true; } -bool MessageReceiver::processHeader(MessageProcessingInfo &msgInfo) { +bool MessageReceiver::processHeader(MessageProcessingInfo &msgInfo) +{ Header header; if (!deserializeMessage(msgInfo, header)) { return false; @@ -96,7 +99,8 @@ bool MessageReceiver::processHeader(MessageProcessingInfo &msgInfo) { } bool MessageReceiver::processSubmessage(MessageProcessingInfo &msgInfo, - const SubmessageHeader &submsgHeader) { + const SubmessageHeader &submsgHeader) +{ bool success = false; switch (submsgHeader.submessageId) { @@ -126,19 +130,20 @@ bool MessageReceiver::processSubmessage(MessageProcessingInfo &msgInfo, success = false; } msgInfo.nextPos += - submsgHeader.octetsToNextHeader + SubmessageHeader::getRawSize(); + submsgHeader.octetsToNextHeader + SubmessageHeader::getRawSize(); return success; } bool MessageReceiver::processDataSubmessage( - MessageProcessingInfo &msgInfo, const SubmessageHeader &submsgHeader) { + MessageProcessingInfo &msgInfo, const SubmessageHeader &submsgHeader) +{ SubmessageData dataSubmsg; if (!deserializeMessage(msgInfo, dataSubmsg)) { return false; } const uint8_t *serializedData = - msgInfo.getPointerToCurrentPos() + SubmessageData::getRawSize(); + msgInfo.getPointerToCurrentPos() + SubmessageData::getRawSize(); const DataSize_t size = submsgHeader.octetsToNextHeader - SubmessageData::getRawSize() + @@ -154,14 +159,15 @@ bool MessageReceiver::processDataSubmessage( printf("\n"); #endif reader = mp_part->getReaderByWriterId( - Guid_t{sourceGuidPrefix, dataSubmsg.writerId}); - if (reader != nullptr) + Guid_t{sourceGuidPrefix, dataSubmsg.writerId}); + if (reader != nullptr) { RECV_LOG("Found reader!"); + } } else { reader = mp_part->getReader(dataSubmsg.readerId); #if RECV_VERBOSE && RTPS_GLOBAL_VERBOSE auto reader_by_writer = mp_part->getReaderByWriterId( - Guid_t{sourceGuidPrefix, dataSubmsg.writerId}); + Guid_t{sourceGuidPrefix, dataSubmsg.writerId}); if (reader_by_writer == nullptr && reader != nullptr) { RECV_LOG("FOUND By READER ID, NOT BY WRITER ID ="); @@ -187,7 +193,8 @@ bool MessageReceiver::processDataSubmessage( } bool MessageReceiver::processHeartbeatSubmessage( - MessageProcessingInfo &msgInfo) { + MessageProcessingInfo &msgInfo) +{ SubmessageHeartbeat submsgHB; if (!deserializeMessage(msgInfo, submsgHB)) { return false; @@ -203,7 +210,8 @@ bool MessageReceiver::processHeartbeatSubmessage( } } -bool MessageReceiver::processAckNackSubmessage(MessageProcessingInfo &msgInfo) { +bool MessageReceiver::processAckNackSubmessage(MessageProcessingInfo &msgInfo) +{ SubmessageAckNack submsgAckNack; if (!deserializeMessage(msgInfo, submsgAckNack)) { return false; diff --git a/src/messages/MessageTypes.cpp b/src/messages/MessageTypes.cpp index 54b5cdac..76357016 100644 --- a/src/messages/MessageTypes.cpp +++ b/src/messages/MessageTypes.cpp @@ -28,13 +28,15 @@ Author: i11 - Embedded Software, RWTH Aachen University #include using namespace rtps; -void doCopyAndMoveOn(uint8_t *dst, const uint8_t *&src, size_t size) { +void doCopyAndMoveOn(uint8_t *dst, const uint8_t *&src, size_t size) +{ memcpy(dst, src, size); src += size; } bool rtps::deserializeMessage(const MessageProcessingInfo &info, - Header &header) { + Header &header) +{ if (info.getRemainingSize() < Header::getRawSize()) { return false; } @@ -52,7 +54,8 @@ bool rtps::deserializeMessage(const MessageProcessingInfo &info, } bool rtps::deserializeMessage(const MessageProcessingInfo &info, - SubmessageHeader &header) { + SubmessageHeader &header) +{ if (info.getRemainingSize() < SubmessageHeader::getRawSize()) { return false; } @@ -66,7 +69,8 @@ bool rtps::deserializeMessage(const MessageProcessingInfo &info, } bool rtps::deserializeMessage(const MessageProcessingInfo &info, - SubmessageData &msg) { + SubmessageData &msg) +{ if (info.getRemainingSize() < SubmessageHeader::getRawSize()) { return false; } @@ -81,7 +85,7 @@ bool rtps::deserializeMessage(const MessageProcessingInfo &info, } const uint8_t *currentPos = - info.getPointerToCurrentPos() + SubmessageHeader::getRawSize(); + info.getPointerToCurrentPos() + SubmessageHeader::getRawSize(); doCopyAndMoveOn(reinterpret_cast(&msg.extraFlags), currentPos, sizeof(uint16_t)); @@ -101,7 +105,8 @@ bool rtps::deserializeMessage(const MessageProcessingInfo &info, } bool rtps::deserializeMessage(const MessageProcessingInfo &info, - SubmessageHeartbeat &msg) { + SubmessageHeartbeat &msg) +{ if (info.getRemainingSize() < SubmessageHeartbeat::getRawSize()) { return false; } @@ -110,7 +115,7 @@ bool rtps::deserializeMessage(const MessageProcessingInfo &info, } const uint8_t *currentPos = - info.getPointerToCurrentPos() + SubmessageHeader::getRawSize(); + info.getPointerToCurrentPos() + SubmessageHeader::getRawSize(); doCopyAndMoveOn(msg.readerId.entityKey.data(), currentPos, msg.readerId.entityKey.size()); @@ -132,11 +137,12 @@ bool rtps::deserializeMessage(const MessageProcessingInfo &info, } bool rtps::deserializeMessage(const MessageProcessingInfo &info, - SubmessageAckNack &msg) { + SubmessageAckNack &msg) +{ const DataSize_t remainingSizeAtBeginning = info.getRemainingSize(); if (remainingSizeAtBeginning < SubmessageAckNack:: - getRawSizeWithoutSNSet()) { // Size of SequenceNumberSet unknown + getRawSizeWithoutSNSet()) { // Size of SequenceNumberSet unknown return false; } if (!deserializeMessage(info, msg.header)) { @@ -144,7 +150,7 @@ bool rtps::deserializeMessage(const MessageProcessingInfo &info, } const uint8_t *currentPos = - info.getPointerToCurrentPos() + SubmessageHeader::getRawSize(); + info.getPointerToCurrentPos() + SubmessageHeader::getRawSize(); doCopyAndMoveOn(msg.readerId.entityKey.data(), currentPos, msg.readerId.entityKey.size()); @@ -167,8 +173,8 @@ bool rtps::deserializeMessage(const MessageProcessingInfo &info, if (msg.readerSNState.numBits != 0) { doCopyAndMoveOn( - reinterpret_cast(msg.readerSNState.bitMap.data()), - currentPos, 4 * ((msg.readerSNState.numBits / 32) + 1)); + reinterpret_cast(msg.readerSNState.bitMap.data()), + currentPos, 4 * ((msg.readerSNState.numBits / 32) + 1)); } doCopyAndMoveOn(reinterpret_cast(&msg.count.value), currentPos, sizeof(msg.count.value)); diff --git a/src/rtps.cpp b/src/rtps.cpp index 67c14094..62307c59 100644 --- a/src/rtps.cpp +++ b/src/rtps.cpp @@ -51,7 +51,8 @@ Author: i11 - Embedded Software, RWTH Aachen University static struct netif netif; -static void init(void *arg) { +static void init(void *arg) +{ if (arg == nullptr) { #if INIT_VERBOSE printf("Failed to init. nullptr passed"); @@ -88,7 +89,8 @@ static void init(void *arg) { sys_sem_signal(init_sem); } -void LwIPInit() { +void LwIPInit() +{ /* no stdio-buffering, please! */ setvbuf(stdout, nullptr, _IONBF, 0); @@ -105,7 +107,8 @@ void LwIPInit() { sys_sem_free(&init_sem); } -void rtps::init() { +void rtps::init() +{ // TODO This is not threadsafe. Might cause problems in tests. For now, it // seems to work. static bool initialized = false; diff --git a/src/storages/PBufWrapper.cpp b/src/storages/PBufWrapper.cpp index a99550c0..0b42a4e4 100644 --- a/src/storages/PBufWrapper.cpp +++ b/src/storages/PBufWrapper.cpp @@ -39,12 +39,14 @@ using rtps::PBufWrapper; #define PBUF_WRAP_LOG(...) // #endif -PBufWrapper::PBufWrapper(pbuf *bufferToWrap) : firstElement(bufferToWrap) { +PBufWrapper::PBufWrapper(pbuf *bufferToWrap) : firstElement(bufferToWrap) +{ m_freeSpace = 0; // Assume it to be full } PBufWrapper::PBufWrapper(DataSize_t length) - : firstElement(pbuf_alloc(m_layer, length, m_type)) { + : firstElement(pbuf_alloc(m_layer, length, m_type)) +{ if (isValid()) { m_freeSpace = length; @@ -52,14 +54,19 @@ PBufWrapper::PBufWrapper(DataSize_t length) } // TODO: Uses copy assignment. Improvement possible -PBufWrapper::PBufWrapper(const PBufWrapper &other) { *this = other; } +PBufWrapper::PBufWrapper(const PBufWrapper &other) +{ + *this = other; +} // TODO: Uses move assignment. Improvement possible -PBufWrapper::PBufWrapper(PBufWrapper &&other) noexcept { +PBufWrapper::PBufWrapper(PBufWrapper &&other) noexcept +{ *this = std::move(other); } -PBufWrapper &PBufWrapper::operator=(const PBufWrapper &other) { +PBufWrapper &PBufWrapper::operator=(const PBufWrapper &other) +{ copySimpleMembersAndResetBuffer(other); if (other.firstElement != nullptr) { @@ -69,7 +76,8 @@ PBufWrapper &PBufWrapper::operator=(const PBufWrapper &other) { return *this; } -PBufWrapper &PBufWrapper::operator=(PBufWrapper &&other) noexcept { +PBufWrapper &PBufWrapper::operator=(PBufWrapper &&other) noexcept +{ copySimpleMembersAndResetBuffer(other); if (other.firstElement != nullptr) { @@ -79,7 +87,8 @@ PBufWrapper &PBufWrapper::operator=(PBufWrapper &&other) noexcept { return *this; } -void PBufWrapper::copySimpleMembersAndResetBuffer(const PBufWrapper &other) { +void PBufWrapper::copySimpleMembersAndResetBuffer(const PBufWrapper &other) +{ m_freeSpace = other.m_freeSpace; if (firstElement != nullptr) { @@ -88,13 +97,15 @@ void PBufWrapper::copySimpleMembersAndResetBuffer(const PBufWrapper &other) { } } -PBufWrapper::~PBufWrapper() { +PBufWrapper::~PBufWrapper() +{ if (firstElement != nullptr) { pbuf_free(firstElement); } } -PBufWrapper PBufWrapper::deepCopy() const { +PBufWrapper PBufWrapper::deepCopy() const +{ PBufWrapper clone; clone.copySimpleMembersAndResetBuffer(*this); @@ -110,11 +121,18 @@ PBufWrapper PBufWrapper::deepCopy() const { return clone; } -bool PBufWrapper::isValid() const { return firstElement != nullptr; } +bool PBufWrapper::isValid() const +{ + return firstElement != nullptr; +} -rtps::DataSize_t PBufWrapper::spaceLeft() const { return m_freeSpace; } +rtps::DataSize_t PBufWrapper::spaceLeft() const +{ + return m_freeSpace; +} -rtps::DataSize_t PBufWrapper::spaceUsed() const { +rtps::DataSize_t PBufWrapper::spaceUsed() const +{ if (firstElement == nullptr) { return 0; } @@ -122,7 +140,8 @@ rtps::DataSize_t PBufWrapper::spaceUsed() const { return firstElement->tot_len - m_freeSpace; } -bool PBufWrapper::append(const uint8_t *data, DataSize_t length) { +bool PBufWrapper::append(const uint8_t *data, DataSize_t length) +{ if (data == nullptr) { return false; } @@ -136,7 +155,8 @@ bool PBufWrapper::append(const uint8_t *data, DataSize_t length) { return true; } -void PBufWrapper::append(PBufWrapper &&other) { +void PBufWrapper::append(PBufWrapper &&other) +{ if (this == &other) { return; } @@ -152,7 +172,8 @@ void PBufWrapper::append(PBufWrapper &&other) { other.firstElement = nullptr; } -bool PBufWrapper::reserve(DataSize_t length) { +bool PBufWrapper::reserve(DataSize_t length) +{ auto additionalAllocation = length - m_freeSpace; if (additionalAllocation <= 0) { return true; @@ -161,13 +182,15 @@ bool PBufWrapper::reserve(DataSize_t length) { return increaseSizeBy(additionalAllocation); } -void PBufWrapper::reset() { +void PBufWrapper::reset() +{ if (firstElement != nullptr) { m_freeSpace = firstElement->tot_len; } } -bool PBufWrapper::increaseSizeBy(uint16_t length) { +bool PBufWrapper::increaseSizeBy(uint16_t length) +{ pbuf *allocation = pbuf_alloc(m_layer, length, m_type); if (allocation == nullptr) { return false; diff --git a/thirdparty/Micro-CDR/include/ucdr/common.h b/thirdparty/Micro-CDR/include/ucdr/common.h index 9bb2dfbd..8e7a2902 100644 --- a/thirdparty/Micro-CDR/include/ucdr/common.h +++ b/thirdparty/Micro-CDR/include/ucdr/common.h @@ -27,21 +27,20 @@ extern "C" { #include typedef enum ucdrEndianness { - UCDR_BIG_ENDIANNESS, - UCDR_LITTLE_ENDIANNESS + UCDR_BIG_ENDIANNESS, + UCDR_LITTLE_ENDIANNESS } ucdrEndianness; -typedef struct ucdrBuffer -{ - const uint8_t *init; - const uint8_t *final; - uint8_t *iterator; +typedef struct ucdrBuffer { + const uint8_t *init; + const uint8_t *final; + uint8_t *iterator; - ucdrEndianness endianness; - uint32_t last_data_size; + ucdrEndianness endianness; + uint32_t last_data_size; - bool error; + bool error; } ucdrBuffer; diff --git a/thirdparty/Micro-CDR/src/c/common.c b/thirdparty/Micro-CDR/src/c/common.c index 4af586ad..1924c02c 100644 --- a/thirdparty/Micro-CDR/src/c/common.c +++ b/thirdparty/Micro-CDR/src/c/common.c @@ -17,9 +17,9 @@ #include #if __BIG_ENDIAN__ - const ucdrEndianness UCDR_MACHINE_ENDIANNESS = UCDR_BIG_ENDIANNESS; +const ucdrEndianness UCDR_MACHINE_ENDIANNESS = UCDR_BIG_ENDIANNESS; #else - const ucdrEndianness UCDR_MACHINE_ENDIANNESS = UCDR_LITTLE_ENDIANNESS; +const ucdrEndianness UCDR_MACHINE_ENDIANNESS = UCDR_LITTLE_ENDIANNESS; #endif // ------------------------------------------------------------------- @@ -27,16 +27,14 @@ // ------------------------------------------------------------------- bool ucdr_check_buffer(ucdrBuffer* mb, const uint32_t bytes) { - if(!mb->error) - { - bool fit = mb->iterator + bytes <= mb->final; - if(!fit) - { - mb->error = true; - } + if(!mb->error) { + bool fit = mb->iterator + bytes <= mb->final; + if(!fit) { + mb->error = true; } + } - return !mb->error; + return !mb->error; } // ------------------------------------------------------------------- @@ -44,90 +42,88 @@ bool ucdr_check_buffer(ucdrBuffer* mb, const uint32_t bytes) // ------------------------------------------------------------------- void ucdr_init_buffer(ucdrBuffer* mb, const uint8_t* data, const uint32_t size) { - ucdr_init_buffer_offset(mb, data, size, 0U); + ucdr_init_buffer_offset(mb, data, size, 0U); } void ucdr_init_buffer_offset(ucdrBuffer* mb, const uint8_t* data, const uint32_t size, uint32_t offset) { - ucdr_init_buffer_offset_endian(mb, data, size, offset, UCDR_MACHINE_ENDIANNESS); + ucdr_init_buffer_offset_endian(mb, data, size, offset, UCDR_MACHINE_ENDIANNESS); } void ucdr_init_buffer_offset_endian(ucdrBuffer* mb, const uint8_t* data, const uint32_t size, uint32_t offset, ucdrEndianness endianness) { - mb->init = data; - mb->final = mb->init + size; - mb->iterator = (uint8_t*)mb->init + offset; - mb->last_data_size = 0U; - mb->endianness = endianness; - mb->error = false; + mb->init = data; + mb->final = mb->init + size; + mb->iterator = (uint8_t*)mb->init + offset; + mb->last_data_size = 0U; + mb->endianness = endianness; + mb->error = false; } void ucdr_copy_buffer(ucdrBuffer* mb_dest, const ucdrBuffer* mb_source) { - memcpy(mb_dest, mb_source, sizeof(ucdrBuffer)); + memcpy(mb_dest, mb_source, sizeof(ucdrBuffer)); } void ucdr_reset_buffer(ucdrBuffer* mb) { - ucdr_reset_buffer_offset(mb, 0U); + ucdr_reset_buffer_offset(mb, 0U); } void ucdr_reset_buffer_offset(ucdrBuffer* mb, const uint32_t offset) { - mb->iterator = (uint8_t*) mb->init + offset; - mb->last_data_size = 0U; - mb->error = false; + mb->iterator = (uint8_t*) mb->init + offset; + mb->last_data_size = 0U; + mb->error = false; } void ucdr_align_to(ucdrBuffer* mb, const uint32_t size) { - uint32_t offset = ucdr_buffer_alignment(mb, size); - mb->iterator += offset; - if(mb->iterator > mb->final) - { - mb->iterator = (uint8_t*)mb->final; - } + uint32_t offset = ucdr_buffer_alignment(mb, size); + mb->iterator += offset; + if(mb->iterator > mb->final) { + mb->iterator = (uint8_t*)mb->final; + } - mb->last_data_size = size; + mb->last_data_size = size; } uint32_t ucdr_alignment(uint32_t current_alignment, const uint32_t data_size) { - return ((data_size - (current_alignment % data_size)) & (data_size - 1)); + return ((data_size - (current_alignment % data_size)) & (data_size - 1)); } uint32_t ucdr_buffer_alignment(const ucdrBuffer* mb, const uint32_t data_size) { - if(data_size > mb->last_data_size) - { - return (data_size - ((uint32_t)(mb->iterator - mb->init) % data_size)) & (data_size - 1); - } + if(data_size > mb->last_data_size) { + return (data_size - ((uint32_t)(mb->iterator - mb->init) % data_size)) & (data_size - 1); + } - return 0; + return 0; } size_t ucdr_buffer_size(const ucdrBuffer* mb) { - return (size_t)(mb->final - mb->init); + return (size_t)(mb->final - mb->init); } size_t ucdr_buffer_length(const ucdrBuffer* mb) { - return (size_t)(mb->iterator - mb->init); + return (size_t)(mb->iterator - mb->init); } size_t ucdr_buffer_remaining(const ucdrBuffer* mb) { - return (size_t)(mb->final - mb->iterator); + return (size_t)(mb->final - mb->iterator); } ucdrEndianness ucdr_buffer_endianness(const ucdrBuffer* mb) { - return mb->endianness; + return mb->endianness; } bool ucdr_buffer_has_error(const ucdrBuffer* mb) { - return mb->error; + return mb->error; } diff --git a/thirdparty/Micro-CDR/src/c/types/array.c b/thirdparty/Micro-CDR/src/c/types/array.c index ea8dd431..2345b9be 100644 --- a/thirdparty/Micro-CDR/src/c/types/array.c +++ b/thirdparty/Micro-CDR/src/c/types/array.c @@ -26,190 +26,158 @@ bool ucdr_serialize_array_byte_1(ucdrBuffer* mb, const uint8_t* array, const uint32_t size) { - uint32_t data_size = sizeof(uint8_t); - if(ucdr_check_buffer(mb, size)) - { - memcpy(mb->iterator, array, size); + uint32_t data_size = sizeof(uint8_t); + if(ucdr_check_buffer(mb, size)) { + memcpy(mb->iterator, array, size); - mb->iterator += size; - mb->last_data_size = data_size; - } - return !mb->error; + mb->iterator += size; + mb->last_data_size = data_size; + } + return !mb->error; } bool ucdr_serialize_array_byte_2(ucdrBuffer* mb, const ucdrEndianness endianness, const uint16_t* array, const uint32_t size) { - uint32_t data_size = sizeof(uint16_t); - uint32_t array_size = size * data_size; - uint32_t alignment = ucdr_buffer_alignment(mb, sizeof(uint16_t)); - - if(ucdr_check_buffer(mb, alignment + array_size)) - { - mb->iterator += alignment; - if(UCDR_MACHINE_ENDIANNESS == endianness) - { - memcpy(mb->iterator, array, array_size); - - mb->iterator += array_size; - mb->last_data_size = data_size; - } - else - { - for(uint32_t i = 0; i < size; i++) - { - ucdr_serialize_byte_2(mb, endianness, array + i); - } - } + uint32_t data_size = sizeof(uint16_t); + uint32_t array_size = size * data_size; + uint32_t alignment = ucdr_buffer_alignment(mb, sizeof(uint16_t)); + + if(ucdr_check_buffer(mb, alignment + array_size)) { + mb->iterator += alignment; + if(UCDR_MACHINE_ENDIANNESS == endianness) { + memcpy(mb->iterator, array, array_size); + + mb->iterator += array_size; + mb->last_data_size = data_size; + } else { + for(uint32_t i = 0; i < size; i++) { + ucdr_serialize_byte_2(mb, endianness, array + i); + } } - return !mb->error; + } + return !mb->error; } bool ucdr_serialize_array_byte_4(ucdrBuffer* mb, const ucdrEndianness endianness, const uint32_t* array, const uint32_t size) { - uint32_t data_size = sizeof(uint32_t); - uint32_t array_size = size * data_size; - uint32_t alignment = ucdr_buffer_alignment(mb, sizeof(uint32_t)); - - if(ucdr_check_buffer(mb, alignment + array_size)) - { - mb->iterator += alignment; - - if(UCDR_MACHINE_ENDIANNESS == endianness) - { - memcpy(mb->iterator, array, array_size); - mb->iterator += array_size; - mb->last_data_size = data_size; - } - else - { - for(uint32_t i = 0; i < size; i++) - { - ucdr_serialize_byte_4(mb, endianness, array + i); - } - } + uint32_t data_size = sizeof(uint32_t); + uint32_t array_size = size * data_size; + uint32_t alignment = ucdr_buffer_alignment(mb, sizeof(uint32_t)); + + if(ucdr_check_buffer(mb, alignment + array_size)) { + mb->iterator += alignment; + + if(UCDR_MACHINE_ENDIANNESS == endianness) { + memcpy(mb->iterator, array, array_size); + mb->iterator += array_size; + mb->last_data_size = data_size; + } else { + for(uint32_t i = 0; i < size; i++) { + ucdr_serialize_byte_4(mb, endianness, array + i); + } } - return !mb->error; + } + return !mb->error; } bool ucdr_serialize_array_byte_8(ucdrBuffer* mb, const ucdrEndianness endianness, const uint64_t* array, const uint32_t size) { - uint32_t data_size = sizeof(uint64_t); - uint32_t array_size = size * data_size; - uint32_t alignment = ucdr_buffer_alignment(mb, sizeof(uint64_t)); - - if(ucdr_check_buffer(mb, alignment + array_size)) - { - mb->iterator += alignment; - - if(UCDR_MACHINE_ENDIANNESS == endianness) - { - memcpy(mb->iterator, array, array_size); - mb->iterator += array_size; - mb->last_data_size = data_size; - } - else - { - for(uint32_t i = 0; i < size; i++) - { - ucdr_serialize_byte_8(mb, endianness, array + i); - } - } + uint32_t data_size = sizeof(uint64_t); + uint32_t array_size = size * data_size; + uint32_t alignment = ucdr_buffer_alignment(mb, sizeof(uint64_t)); + + if(ucdr_check_buffer(mb, alignment + array_size)) { + mb->iterator += alignment; + + if(UCDR_MACHINE_ENDIANNESS == endianness) { + memcpy(mb->iterator, array, array_size); + mb->iterator += array_size; + mb->last_data_size = data_size; + } else { + for(uint32_t i = 0; i < size; i++) { + ucdr_serialize_byte_8(mb, endianness, array + i); + } } - return !mb->error; + } + return !mb->error; } bool ucdr_deserialize_array_byte_1(ucdrBuffer* mb, uint8_t* array, const uint32_t size) { - uint32_t data_size = sizeof(uint8_t); - if(ucdr_check_buffer(mb, size)) - { - memcpy(array, mb->iterator, size); + uint32_t data_size = sizeof(uint8_t); + if(ucdr_check_buffer(mb, size)) { + memcpy(array, mb->iterator, size); - mb->iterator += size; - mb->last_data_size = data_size; - } - return !mb->error; + mb->iterator += size; + mb->last_data_size = data_size; + } + return !mb->error; } bool ucdr_deserialize_array_byte_2(ucdrBuffer* mb, const ucdrEndianness endianness, uint16_t* array, const uint32_t size) { - uint32_t data_size = sizeof(uint16_t); - uint32_t array_size = size * data_size; - uint32_t alignment = ucdr_buffer_alignment(mb, sizeof(uint16_t)); - - if(ucdr_check_buffer(mb, alignment + array_size)) - { - mb->iterator += alignment; - - if(UCDR_MACHINE_ENDIANNESS == endianness) - { - memcpy(array, mb->iterator, array_size); - mb->iterator += array_size; - mb->last_data_size = data_size; - } - else - { - for(uint32_t i = 0; i < size; i++) - { - ucdr_deserialize_byte_2(mb, endianness, array + i); - } - } + uint32_t data_size = sizeof(uint16_t); + uint32_t array_size = size * data_size; + uint32_t alignment = ucdr_buffer_alignment(mb, sizeof(uint16_t)); + + if(ucdr_check_buffer(mb, alignment + array_size)) { + mb->iterator += alignment; + + if(UCDR_MACHINE_ENDIANNESS == endianness) { + memcpy(array, mb->iterator, array_size); + mb->iterator += array_size; + mb->last_data_size = data_size; + } else { + for(uint32_t i = 0; i < size; i++) { + ucdr_deserialize_byte_2(mb, endianness, array + i); + } } - return !mb->error; + } + return !mb->error; } bool ucdr_deserialize_array_byte_4(ucdrBuffer* mb, const ucdrEndianness endianness, uint32_t* array, const uint32_t size) { - uint32_t data_size = sizeof(uint32_t); - uint32_t array_size = size * data_size; - uint32_t alignment = ucdr_buffer_alignment(mb, sizeof(uint32_t)); - - if(ucdr_check_buffer(mb, alignment + array_size)) - { - mb->iterator += alignment; - - if(UCDR_MACHINE_ENDIANNESS == endianness) - { - memcpy(array, mb->iterator, array_size); - mb->iterator += array_size; - mb->last_data_size = data_size; - } - else - { - for(uint32_t i = 0; i < size; i++) - { - ucdr_deserialize_byte_4(mb, endianness, array + i); - } - } + uint32_t data_size = sizeof(uint32_t); + uint32_t array_size = size * data_size; + uint32_t alignment = ucdr_buffer_alignment(mb, sizeof(uint32_t)); + + if(ucdr_check_buffer(mb, alignment + array_size)) { + mb->iterator += alignment; + + if(UCDR_MACHINE_ENDIANNESS == endianness) { + memcpy(array, mb->iterator, array_size); + mb->iterator += array_size; + mb->last_data_size = data_size; + } else { + for(uint32_t i = 0; i < size; i++) { + ucdr_deserialize_byte_4(mb, endianness, array + i); + } } - return !mb->error; + } + return !mb->error; } bool ucdr_deserialize_array_byte_8(ucdrBuffer* mb, const ucdrEndianness endianness, uint64_t* array, const uint32_t size) { - uint32_t data_size = sizeof(uint64_t); - uint32_t array_size = size * data_size; - uint32_t alignment = ucdr_buffer_alignment(mb, sizeof(uint64_t)); - - if(ucdr_check_buffer(mb, alignment + array_size)) - { - mb->iterator += alignment; - - if(UCDR_MACHINE_ENDIANNESS == endianness) - { - memcpy(array, mb->iterator, array_size); - mb->iterator += array_size; - mb->last_data_size = data_size; - } - else - { - for(uint32_t i = 0; i < size; i++) - { - ucdr_deserialize_byte_8(mb, endianness, array + i); - } - } + uint32_t data_size = sizeof(uint64_t); + uint32_t array_size = size * data_size; + uint32_t alignment = ucdr_buffer_alignment(mb, sizeof(uint64_t)); + + if(ucdr_check_buffer(mb, alignment + array_size)) { + mb->iterator += alignment; + + if(UCDR_MACHINE_ENDIANNESS == endianness) { + memcpy(array, mb->iterator, array_size); + mb->iterator += array_size; + mb->last_data_size = data_size; + } else { + for(uint32_t i = 0; i < size; i++) { + ucdr_deserialize_byte_8(mb, endianness, array + i); + } } - return !mb->error; + } + return !mb->error; } // ------------------------------------------------------------------- @@ -218,201 +186,201 @@ bool ucdr_deserialize_array_byte_8(ucdrBuffer* mb, const ucdrEndianness endianne bool ucdr_serialize_array_char(ucdrBuffer* mb, const char* array, const uint32_t size) { - return ucdr_serialize_array_byte_1(mb, (uint8_t*)array, size); + return ucdr_serialize_array_byte_1(mb, (uint8_t*)array, size); } bool ucdr_serialize_array_bool(ucdrBuffer* mb, const bool* array, const uint32_t size) { - return ucdr_serialize_array_byte_1(mb, (uint8_t*)array, size); + return ucdr_serialize_array_byte_1(mb, (uint8_t*)array, size); } bool ucdr_serialize_array_uint8_t(ucdrBuffer* mb, const uint8_t* array, const uint32_t size) { - return ucdr_serialize_array_byte_1(mb, array, size); + return ucdr_serialize_array_byte_1(mb, array, size); } bool ucdr_serialize_array_uint16_t(ucdrBuffer* mb, const uint16_t* array, const uint32_t size) { - return ucdr_serialize_array_byte_2(mb, mb->endianness, array, size); + return ucdr_serialize_array_byte_2(mb, mb->endianness, array, size); } bool ucdr_serialize_array_uint32_t(ucdrBuffer* mb, const uint32_t* array, const uint32_t size) { - return ucdr_serialize_array_byte_4(mb, mb->endianness, array, size); + return ucdr_serialize_array_byte_4(mb, mb->endianness, array, size); } bool ucdr_serialize_array_uint64_t(ucdrBuffer* mb, const uint64_t* array, const uint32_t size) { - return ucdr_serialize_array_byte_8(mb, mb->endianness, array, size); + return ucdr_serialize_array_byte_8(mb, mb->endianness, array, size); } bool ucdr_serialize_array_int8_t(ucdrBuffer* mb, const int8_t* array, const uint32_t size) { - return ucdr_serialize_array_byte_1(mb, (uint8_t*)array, size); + return ucdr_serialize_array_byte_1(mb, (uint8_t*)array, size); } bool ucdr_serialize_array_int16_t(ucdrBuffer* mb, const int16_t* array, const uint32_t size) { - return ucdr_serialize_array_byte_2(mb, mb->endianness, (uint16_t*)array, size); + return ucdr_serialize_array_byte_2(mb, mb->endianness, (uint16_t*)array, size); } bool ucdr_serialize_array_int32_t(ucdrBuffer* mb, const int32_t* array, const uint32_t size) { - return ucdr_serialize_array_byte_4(mb, mb->endianness, (uint32_t*)array, size); + return ucdr_serialize_array_byte_4(mb, mb->endianness, (uint32_t*)array, size); } bool ucdr_serialize_array_int64_t(ucdrBuffer* mb, const int64_t* array, const uint32_t size) { - return ucdr_serialize_array_byte_8(mb, mb->endianness, (uint64_t*)array, size); + return ucdr_serialize_array_byte_8(mb, mb->endianness, (uint64_t*)array, size); } bool ucdr_serialize_array_float(ucdrBuffer* mb, const float* array, const uint32_t size) { - return ucdr_serialize_array_byte_4(mb, mb->endianness, (uint32_t*)array, size); + return ucdr_serialize_array_byte_4(mb, mb->endianness, (uint32_t*)array, size); } bool ucdr_serialize_array_double(ucdrBuffer* mb, const double* array, const uint32_t size) { - return ucdr_serialize_array_byte_8(mb, mb->endianness, (uint64_t*)array, size); + return ucdr_serialize_array_byte_8(mb, mb->endianness, (uint64_t*)array, size); } bool ucdr_deserialize_array_char(ucdrBuffer* mb, char* array, const uint32_t size) { - return ucdr_deserialize_array_byte_1(mb, (uint8_t*)array, size); + return ucdr_deserialize_array_byte_1(mb, (uint8_t*)array, size); } bool ucdr_deserialize_array_bool(ucdrBuffer* mb, bool* array, const uint32_t size) { - return ucdr_deserialize_array_byte_1(mb, (uint8_t*)array, size); + return ucdr_deserialize_array_byte_1(mb, (uint8_t*)array, size); } bool ucdr_deserialize_array_uint8_t(ucdrBuffer* mb, uint8_t* array, const uint32_t size) { - return ucdr_deserialize_array_byte_1(mb, array, size); + return ucdr_deserialize_array_byte_1(mb, array, size); } bool ucdr_deserialize_array_uint16_t(ucdrBuffer* mb, uint16_t* array, const uint32_t size) { - return ucdr_deserialize_array_byte_2(mb, mb->endianness, array, size); + return ucdr_deserialize_array_byte_2(mb, mb->endianness, array, size); } bool ucdr_deserialize_array_uint32_t(ucdrBuffer* mb, uint32_t* array, const uint32_t size) { - return ucdr_deserialize_array_byte_4(mb, mb->endianness, array, size); + return ucdr_deserialize_array_byte_4(mb, mb->endianness, array, size); } bool ucdr_deserialize_array_uint64_t(ucdrBuffer* mb, uint64_t* array, const uint32_t size) { - return ucdr_deserialize_array_byte_8(mb, mb->endianness, array, size); + return ucdr_deserialize_array_byte_8(mb, mb->endianness, array, size); } bool ucdr_deserialize_array_int8_t(ucdrBuffer* mb, int8_t* array, const uint32_t size) { - return ucdr_deserialize_array_byte_1(mb, (uint8_t*)array, size); + return ucdr_deserialize_array_byte_1(mb, (uint8_t*)array, size); } bool ucdr_deserialize_array_int16_t(ucdrBuffer* mb, int16_t* array, const uint32_t size) { - return ucdr_deserialize_array_byte_2(mb, mb->endianness, (uint16_t*)array, size); + return ucdr_deserialize_array_byte_2(mb, mb->endianness, (uint16_t*)array, size); } bool ucdr_deserialize_array_int32_t(ucdrBuffer* mb, int32_t* array, const uint32_t size) { - return ucdr_deserialize_array_byte_4(mb, mb->endianness, (uint32_t*)array, size); + return ucdr_deserialize_array_byte_4(mb, mb->endianness, (uint32_t*)array, size); } bool ucdr_deserialize_array_int64_t(ucdrBuffer* mb, int64_t* array, const uint32_t size) { - return ucdr_deserialize_array_byte_8(mb, mb->endianness, (uint64_t*)array, size); + return ucdr_deserialize_array_byte_8(mb, mb->endianness, (uint64_t*)array, size); } bool ucdr_deserialize_array_float(ucdrBuffer* mb, float* array, const uint32_t size) { - return ucdr_deserialize_array_byte_4(mb, mb->endianness, (uint32_t*)array, size); + return ucdr_deserialize_array_byte_4(mb, mb->endianness, (uint32_t*)array, size); } bool ucdr_deserialize_array_double(ucdrBuffer* mb, double* array, const uint32_t size) { - return ucdr_deserialize_array_byte_8(mb, mb->endianness, (uint64_t*)array, size); + return ucdr_deserialize_array_byte_8(mb, mb->endianness, (uint64_t*)array, size); } bool ucdr_serialize_endian_array_uint16_t(ucdrBuffer* mb, const ucdrEndianness endianness, const uint16_t* array, const uint32_t size) { - return ucdr_serialize_array_byte_2(mb, endianness, array, size); + return ucdr_serialize_array_byte_2(mb, endianness, array, size); } bool ucdr_serialize_endian_array_uint32_t(ucdrBuffer* mb, const ucdrEndianness endianness, const uint32_t* array, const uint32_t size) { - return ucdr_serialize_array_byte_4(mb, endianness, array, size); + return ucdr_serialize_array_byte_4(mb, endianness, array, size); } bool ucdr_serialize_endian_array_uint64_t(ucdrBuffer* mb, const ucdrEndianness endianness, const uint64_t* array, const uint32_t size) { - return ucdr_serialize_array_byte_8(mb, endianness, array, size); + return ucdr_serialize_array_byte_8(mb, endianness, array, size); } bool ucdr_serialize_endian_array_int16_t(ucdrBuffer* mb, const ucdrEndianness endianness, const int16_t* array, const uint32_t size) { - return ucdr_serialize_array_byte_2(mb, endianness, (uint16_t*)array, size); + return ucdr_serialize_array_byte_2(mb, endianness, (uint16_t*)array, size); } bool ucdr_serialize_endian_array_int32_t(ucdrBuffer* mb, const ucdrEndianness endianness, const int32_t* array, const uint32_t size) { - return ucdr_serialize_array_byte_4(mb, endianness, (uint32_t*)array, size); + return ucdr_serialize_array_byte_4(mb, endianness, (uint32_t*)array, size); } bool ucdr_serialize_endian_array_int64_t(ucdrBuffer* mb, const ucdrEndianness endianness, const int64_t* array, const uint32_t size) { - return ucdr_serialize_array_byte_8(mb, endianness, (uint64_t*)array, size); + return ucdr_serialize_array_byte_8(mb, endianness, (uint64_t*)array, size); } bool ucdr_serialize_endian_array_float(ucdrBuffer* mb, const ucdrEndianness endianness, const float* array, const uint32_t size) { - return ucdr_serialize_array_byte_4(mb, endianness, (uint32_t*)array, size); + return ucdr_serialize_array_byte_4(mb, endianness, (uint32_t*)array, size); } bool ucdr_serialize_endian_array_double(ucdrBuffer* mb, const ucdrEndianness endianness, const double* array, const uint32_t size) { - return ucdr_serialize_array_byte_8(mb, endianness, (uint64_t*)array, size); + return ucdr_serialize_array_byte_8(mb, endianness, (uint64_t*)array, size); } bool ucdr_deserialize_endian_array_uint16_t(ucdrBuffer* mb, const ucdrEndianness endianness, uint16_t* array, const uint32_t size) { - return ucdr_deserialize_array_byte_2(mb, endianness, array, size); + return ucdr_deserialize_array_byte_2(mb, endianness, array, size); } bool ucdr_deserialize_endian_array_uint32_t(ucdrBuffer* mb, const ucdrEndianness endianness, uint32_t* array, const uint32_t size) { - return ucdr_deserialize_array_byte_4(mb, endianness, array, size); + return ucdr_deserialize_array_byte_4(mb, endianness, array, size); } bool ucdr_deserialize_endian_array_uint64_t(ucdrBuffer* mb, const ucdrEndianness endianness, uint64_t* array, const uint32_t size) { - return ucdr_deserialize_array_byte_8(mb, endianness, array, size); + return ucdr_deserialize_array_byte_8(mb, endianness, array, size); } bool ucdr_deserialize_endian_array_int16_t(ucdrBuffer* mb, const ucdrEndianness endianness, int16_t* array, const uint32_t size) { - return ucdr_deserialize_array_byte_2(mb, endianness, (uint16_t*)array, size); + return ucdr_deserialize_array_byte_2(mb, endianness, (uint16_t*)array, size); } bool ucdr_deserialize_endian_array_int32_t(ucdrBuffer* mb, const ucdrEndianness endianness, int32_t* array, const uint32_t size) { - return ucdr_deserialize_array_byte_4(mb, endianness, (uint32_t*)array, size); + return ucdr_deserialize_array_byte_4(mb, endianness, (uint32_t*)array, size); } bool ucdr_deserialize_endian_array_int64_t(ucdrBuffer* mb, const ucdrEndianness endianness, int64_t* array, const uint32_t size) { - return ucdr_deserialize_array_byte_8(mb, endianness, (uint64_t*)array, size); + return ucdr_deserialize_array_byte_8(mb, endianness, (uint64_t*)array, size); } bool ucdr_deserialize_endian_array_float(ucdrBuffer* mb, const ucdrEndianness endianness, float* array, const uint32_t size) { - return ucdr_deserialize_array_byte_4(mb, endianness, (uint32_t*)array, size); + return ucdr_deserialize_array_byte_4(mb, endianness, (uint32_t*)array, size); } bool ucdr_deserialize_endian_array_double(ucdrBuffer* mb, const ucdrEndianness endianness, double* array, const uint32_t size) { - return ucdr_deserialize_array_byte_8(mb, endianness, (uint64_t*)array, size); + return ucdr_deserialize_array_byte_8(mb, endianness, (uint64_t*)array, size); } diff --git a/thirdparty/Micro-CDR/src/c/types/basic.c b/thirdparty/Micro-CDR/src/c/types/basic.c index 15db7b41..ecb169df 100644 --- a/thirdparty/Micro-CDR/src/c/types/basic.c +++ b/thirdparty/Micro-CDR/src/c/types/basic.c @@ -25,200 +25,174 @@ bool ucdr_serialize_byte_1(ucdrBuffer* mb, const uint8_t* byte) { - uint32_t data_size = sizeof(uint8_t); - if(ucdr_check_buffer(mb, data_size)) - { - *mb->iterator = *byte; + uint32_t data_size = sizeof(uint8_t); + if(ucdr_check_buffer(mb, data_size)) { + *mb->iterator = *byte; - mb->iterator += data_size; - mb->last_data_size = data_size; - } - return !mb->error; + mb->iterator += data_size; + mb->last_data_size = data_size; + } + return !mb->error; } bool ucdr_serialize_byte_2(ucdrBuffer* mb, const ucdrEndianness endianness, const uint16_t* bytes) { - uint32_t data_size = sizeof(uint16_t); - uint32_t alignment = ucdr_buffer_alignment(mb, data_size); - - if(ucdr_check_buffer(mb, alignment + data_size)) - { - mb->iterator += alignment; - - if(UCDR_MACHINE_ENDIANNESS == endianness) - { - memcpy(mb->iterator, bytes, data_size); - } - else - { - uint8_t* bytes_pointer = (uint8_t*)bytes; - *mb->iterator = *(bytes_pointer + 1); - *(mb->iterator + 1) = *bytes_pointer; - } - - mb->iterator += data_size; - mb->last_data_size = data_size; + uint32_t data_size = sizeof(uint16_t); + uint32_t alignment = ucdr_buffer_alignment(mb, data_size); + + if(ucdr_check_buffer(mb, alignment + data_size)) { + mb->iterator += alignment; + + if(UCDR_MACHINE_ENDIANNESS == endianness) { + memcpy(mb->iterator, bytes, data_size); + } else { + uint8_t* bytes_pointer = (uint8_t*)bytes; + *mb->iterator = *(bytes_pointer + 1); + *(mb->iterator + 1) = *bytes_pointer; } - return !mb->error; + + mb->iterator += data_size; + mb->last_data_size = data_size; + } + return !mb->error; } bool ucdr_serialize_byte_4(ucdrBuffer* mb, const ucdrEndianness endianness, const uint32_t* bytes) { - uint32_t data_size = sizeof(uint32_t); - uint32_t alignment = ucdr_buffer_alignment(mb, data_size); - - if(ucdr_check_buffer(mb, alignment + data_size)) - { - mb->iterator += alignment; - - if(UCDR_MACHINE_ENDIANNESS == endianness) - { - memcpy(mb->iterator, bytes, data_size); - } - else - { - uint8_t* bytes_pointer = (uint8_t*)bytes; - *mb->iterator = *(bytes_pointer + 3); - *(mb->iterator + 1) = *(bytes_pointer + 2); - *(mb->iterator + 2) = *(bytes_pointer + 1); - *(mb->iterator + 3) = *bytes_pointer; - } - - mb->iterator += data_size; - mb->last_data_size = data_size; + uint32_t data_size = sizeof(uint32_t); + uint32_t alignment = ucdr_buffer_alignment(mb, data_size); + + if(ucdr_check_buffer(mb, alignment + data_size)) { + mb->iterator += alignment; + + if(UCDR_MACHINE_ENDIANNESS == endianness) { + memcpy(mb->iterator, bytes, data_size); + } else { + uint8_t* bytes_pointer = (uint8_t*)bytes; + *mb->iterator = *(bytes_pointer + 3); + *(mb->iterator + 1) = *(bytes_pointer + 2); + *(mb->iterator + 2) = *(bytes_pointer + 1); + *(mb->iterator + 3) = *bytes_pointer; } - return !mb->error; + + mb->iterator += data_size; + mb->last_data_size = data_size; + } + return !mb->error; } bool ucdr_serialize_byte_8(ucdrBuffer* mb, const ucdrEndianness endianness, const uint64_t* bytes) { - uint32_t data_size = sizeof(uint64_t); - uint32_t alignment = ucdr_buffer_alignment(mb, data_size); - - if(ucdr_check_buffer(mb, alignment + data_size)) - { - mb->iterator += alignment; - - if(UCDR_MACHINE_ENDIANNESS == endianness) - { - memcpy(mb->iterator, bytes, data_size); - } - else - { - uint8_t* bytes_pointer = (uint8_t*)bytes; - *mb->iterator = *(bytes_pointer + 7); - *(mb->iterator + 1) = *(bytes_pointer + 6); - *(mb->iterator + 2) = *(bytes_pointer + 5); - *(mb->iterator + 3) = *(bytes_pointer + 4); - *(mb->iterator + 4) = *(bytes_pointer + 3); - *(mb->iterator + 5) = *(bytes_pointer + 2); - *(mb->iterator + 6) = *(bytes_pointer + 1); - *(mb->iterator + 7) = *bytes_pointer; - } - - mb->iterator += data_size; - mb->last_data_size = data_size; + uint32_t data_size = sizeof(uint64_t); + uint32_t alignment = ucdr_buffer_alignment(mb, data_size); + + if(ucdr_check_buffer(mb, alignment + data_size)) { + mb->iterator += alignment; + + if(UCDR_MACHINE_ENDIANNESS == endianness) { + memcpy(mb->iterator, bytes, data_size); + } else { + uint8_t* bytes_pointer = (uint8_t*)bytes; + *mb->iterator = *(bytes_pointer + 7); + *(mb->iterator + 1) = *(bytes_pointer + 6); + *(mb->iterator + 2) = *(bytes_pointer + 5); + *(mb->iterator + 3) = *(bytes_pointer + 4); + *(mb->iterator + 4) = *(bytes_pointer + 3); + *(mb->iterator + 5) = *(bytes_pointer + 2); + *(mb->iterator + 6) = *(bytes_pointer + 1); + *(mb->iterator + 7) = *bytes_pointer; } - return !mb->error; + + mb->iterator += data_size; + mb->last_data_size = data_size; + } + return !mb->error; } bool ucdr_deserialize_byte_1(ucdrBuffer* mb, uint8_t* byte) { - uint32_t data_size = sizeof(uint8_t); - if(ucdr_check_buffer(mb, data_size)) - { - *byte = *mb->iterator; + uint32_t data_size = sizeof(uint8_t); + if(ucdr_check_buffer(mb, data_size)) { + *byte = *mb->iterator; - mb->iterator += data_size; - mb->last_data_size = data_size; - } - return !mb->error; + mb->iterator += data_size; + mb->last_data_size = data_size; + } + return !mb->error; } bool ucdr_deserialize_byte_2(ucdrBuffer* mb, const ucdrEndianness endianness, uint16_t* bytes) { - uint32_t data_size = sizeof(uint16_t); - uint32_t alignment = ucdr_buffer_alignment(mb, data_size); - - if(ucdr_check_buffer(mb, alignment + data_size)) - { - mb->iterator += alignment; - - if(UCDR_MACHINE_ENDIANNESS == endianness) - { - memcpy(bytes, mb->iterator, data_size); - } - else - { - uint8_t* bytes_pointer = (uint8_t*)bytes; - *bytes_pointer = *(mb->iterator + 1); - *(bytes_pointer + 1) = *mb->iterator ; - } - - mb->iterator += data_size; - mb->last_data_size = data_size; + uint32_t data_size = sizeof(uint16_t); + uint32_t alignment = ucdr_buffer_alignment(mb, data_size); + + if(ucdr_check_buffer(mb, alignment + data_size)) { + mb->iterator += alignment; + + if(UCDR_MACHINE_ENDIANNESS == endianness) { + memcpy(bytes, mb->iterator, data_size); + } else { + uint8_t* bytes_pointer = (uint8_t*)bytes; + *bytes_pointer = *(mb->iterator + 1); + *(bytes_pointer + 1) = *mb->iterator ; } - return !mb->error; + + mb->iterator += data_size; + mb->last_data_size = data_size; + } + return !mb->error; } bool ucdr_deserialize_byte_4(ucdrBuffer* mb, const ucdrEndianness endianness, uint32_t* bytes) { - uint32_t data_size = sizeof(uint32_t); - uint32_t alignment = ucdr_buffer_alignment(mb, data_size); - - if(ucdr_check_buffer(mb, alignment + data_size)) - { - mb->iterator += alignment; - - if(UCDR_MACHINE_ENDIANNESS == endianness) - { - memcpy(bytes, mb->iterator, data_size); - } - else - { - uint8_t* bytes_pointer = (uint8_t*)bytes; - *bytes_pointer = *(mb->iterator + 3); - *(bytes_pointer + 1) = *(mb->iterator + 2); - *(bytes_pointer + 2) = *(mb->iterator + 1); - *(bytes_pointer + 3) = *mb->iterator; - } - - mb->iterator += data_size; - mb->last_data_size = data_size; + uint32_t data_size = sizeof(uint32_t); + uint32_t alignment = ucdr_buffer_alignment(mb, data_size); + + if(ucdr_check_buffer(mb, alignment + data_size)) { + mb->iterator += alignment; + + if(UCDR_MACHINE_ENDIANNESS == endianness) { + memcpy(bytes, mb->iterator, data_size); + } else { + uint8_t* bytes_pointer = (uint8_t*)bytes; + *bytes_pointer = *(mb->iterator + 3); + *(bytes_pointer + 1) = *(mb->iterator + 2); + *(bytes_pointer + 2) = *(mb->iterator + 1); + *(bytes_pointer + 3) = *mb->iterator; } - return !mb->error; + + mb->iterator += data_size; + mb->last_data_size = data_size; + } + return !mb->error; } bool ucdr_deserialize_byte_8(ucdrBuffer* mb, const ucdrEndianness endianness, uint64_t* bytes) { - uint32_t data_size = sizeof(uint64_t); - uint32_t alignment = ucdr_buffer_alignment(mb, data_size); - - if(ucdr_check_buffer(mb, alignment + data_size)) - { - mb->iterator += alignment; - - if(UCDR_MACHINE_ENDIANNESS == endianness) - { - memcpy(bytes, mb->iterator, data_size); - } - else - { - uint8_t* bytes_pointer = (uint8_t*)bytes; - *bytes_pointer = *(mb->iterator + 7); - *(bytes_pointer + 1) = *(mb->iterator + 6); - *(bytes_pointer + 2) = *(mb->iterator + 5); - *(bytes_pointer + 3) = *(mb->iterator + 4); - *(bytes_pointer + 4) = *(mb->iterator + 3); - *(bytes_pointer + 5) = *(mb->iterator + 2); - *(bytes_pointer + 6) = *(mb->iterator + 1); - *(bytes_pointer + 7) = *mb->iterator; - } - - mb->iterator += data_size; - mb->last_data_size = data_size; + uint32_t data_size = sizeof(uint64_t); + uint32_t alignment = ucdr_buffer_alignment(mb, data_size); + + if(ucdr_check_buffer(mb, alignment + data_size)) { + mb->iterator += alignment; + + if(UCDR_MACHINE_ENDIANNESS == endianness) { + memcpy(bytes, mb->iterator, data_size); + } else { + uint8_t* bytes_pointer = (uint8_t*)bytes; + *bytes_pointer = *(mb->iterator + 7); + *(bytes_pointer + 1) = *(mb->iterator + 6); + *(bytes_pointer + 2) = *(mb->iterator + 5); + *(bytes_pointer + 3) = *(mb->iterator + 4); + *(bytes_pointer + 4) = *(mb->iterator + 3); + *(bytes_pointer + 5) = *(mb->iterator + 2); + *(bytes_pointer + 6) = *(mb->iterator + 1); + *(bytes_pointer + 7) = *mb->iterator; } - return !mb->error; + + mb->iterator += data_size; + mb->last_data_size = data_size; + } + return !mb->error; } // ------------------------------------------------------------------- @@ -227,201 +201,201 @@ bool ucdr_deserialize_byte_8(ucdrBuffer* mb, const ucdrEndianness endianness, ui bool ucdr_serialize_char(ucdrBuffer* mb, const char value) { - return ucdr_serialize_byte_1(mb, (uint8_t*)&value); + return ucdr_serialize_byte_1(mb, (uint8_t*)&value); } bool ucdr_serialize_bool(ucdrBuffer* mb, const bool value) { - return ucdr_serialize_byte_1(mb, (uint8_t*)&value); + return ucdr_serialize_byte_1(mb, (uint8_t*)&value); } bool ucdr_serialize_uint8_t(ucdrBuffer* mb, const uint8_t value) { - return ucdr_serialize_byte_1(mb, &value); + return ucdr_serialize_byte_1(mb, &value); } bool ucdr_serialize_uint16_t(ucdrBuffer* mb, const uint16_t value) { - return ucdr_serialize_byte_2(mb, mb->endianness, &value); + return ucdr_serialize_byte_2(mb, mb->endianness, &value); } bool ucdr_serialize_uint32_t(ucdrBuffer* mb, const uint32_t value) { - return ucdr_serialize_byte_4(mb, mb->endianness, &value); + return ucdr_serialize_byte_4(mb, mb->endianness, &value); } bool ucdr_serialize_uint64_t(ucdrBuffer* mb, const uint64_t value) { - return ucdr_serialize_byte_8(mb, mb->endianness, &value); + return ucdr_serialize_byte_8(mb, mb->endianness, &value); } bool ucdr_serialize_int8_t(ucdrBuffer* mb, const int8_t value) { - return ucdr_serialize_byte_1(mb, (uint8_t*)&value); + return ucdr_serialize_byte_1(mb, (uint8_t*)&value); } bool ucdr_serialize_int16_t(ucdrBuffer* mb, const int16_t value) { - return ucdr_serialize_byte_2(mb, mb->endianness, (uint16_t*)&value); + return ucdr_serialize_byte_2(mb, mb->endianness, (uint16_t*)&value); } bool ucdr_serialize_int32_t(ucdrBuffer* mb, const int32_t value) { - return ucdr_serialize_byte_4(mb, mb->endianness, (uint32_t*)&value); + return ucdr_serialize_byte_4(mb, mb->endianness, (uint32_t*)&value); } bool ucdr_serialize_int64_t(ucdrBuffer* mb, const int64_t value) { - return ucdr_serialize_byte_8(mb, mb->endianness, (uint64_t*)&value); + return ucdr_serialize_byte_8(mb, mb->endianness, (uint64_t*)&value); } bool ucdr_serialize_float(ucdrBuffer* mb, const float value) { - return ucdr_serialize_byte_4(mb, mb->endianness, (uint32_t*)&value); + return ucdr_serialize_byte_4(mb, mb->endianness, (uint32_t*)&value); } bool ucdr_serialize_double(ucdrBuffer* mb, const double value) { - return ucdr_serialize_byte_8(mb, mb->endianness, (uint64_t*)&value); + return ucdr_serialize_byte_8(mb, mb->endianness, (uint64_t*)&value); } bool ucdr_deserialize_char(ucdrBuffer* mb, char* value) { - return ucdr_deserialize_byte_1(mb, (uint8_t*)value); + return ucdr_deserialize_byte_1(mb, (uint8_t*)value); } bool ucdr_deserialize_bool(ucdrBuffer* mb, bool* value) { - return ucdr_deserialize_byte_1(mb, (uint8_t*)value); + return ucdr_deserialize_byte_1(mb, (uint8_t*)value); } bool ucdr_deserialize_uint8_t(ucdrBuffer* mb, uint8_t* value) { - return ucdr_deserialize_byte_1(mb, value); + return ucdr_deserialize_byte_1(mb, value); } bool ucdr_deserialize_uint16_t(ucdrBuffer* mb, uint16_t* value) { - return ucdr_deserialize_byte_2(mb, mb->endianness, value); + return ucdr_deserialize_byte_2(mb, mb->endianness, value); } bool ucdr_deserialize_uint32_t(ucdrBuffer* mb, uint32_t* value) { - return ucdr_deserialize_byte_4(mb, mb->endianness, value); + return ucdr_deserialize_byte_4(mb, mb->endianness, value); } bool ucdr_deserialize_uint64_t(ucdrBuffer* mb, uint64_t* value) { - return ucdr_deserialize_byte_8(mb, mb->endianness, value); + return ucdr_deserialize_byte_8(mb, mb->endianness, value); } bool ucdr_deserialize_int8_t(ucdrBuffer* mb, int8_t* value) { - return ucdr_deserialize_byte_1(mb, (uint8_t*)value); + return ucdr_deserialize_byte_1(mb, (uint8_t*)value); } bool ucdr_deserialize_int16_t(ucdrBuffer* mb, int16_t* value) { - return ucdr_deserialize_byte_2(mb, mb->endianness, (uint16_t*)value); + return ucdr_deserialize_byte_2(mb, mb->endianness, (uint16_t*)value); } bool ucdr_deserialize_int32_t(ucdrBuffer* mb, int32_t* value) { - return ucdr_deserialize_byte_4(mb, mb->endianness, (uint32_t*)value); + return ucdr_deserialize_byte_4(mb, mb->endianness, (uint32_t*)value); } bool ucdr_deserialize_int64_t(ucdrBuffer* mb, int64_t* value) { - return ucdr_deserialize_byte_8(mb, mb->endianness, (uint64_t*)value); + return ucdr_deserialize_byte_8(mb, mb->endianness, (uint64_t*)value); } bool ucdr_deserialize_float(ucdrBuffer* mb, float* value) { - return ucdr_deserialize_byte_4(mb, mb->endianness, (uint32_t*)value); + return ucdr_deserialize_byte_4(mb, mb->endianness, (uint32_t*)value); } bool ucdr_deserialize_double(ucdrBuffer* mb, double* value) { - return ucdr_deserialize_byte_8(mb, mb->endianness, (uint64_t*)value); + return ucdr_deserialize_byte_8(mb, mb->endianness, (uint64_t*)value); } bool ucdr_serialize_endian_uint16_t(ucdrBuffer* mb, const ucdrEndianness endianness, const uint16_t value) { - return ucdr_serialize_byte_2(mb, endianness, &value); + return ucdr_serialize_byte_2(mb, endianness, &value); } bool ucdr_serialize_endian_uint32_t(ucdrBuffer* mb, const ucdrEndianness endianness, const uint32_t value) { - return ucdr_serialize_byte_4(mb, endianness, &value); + return ucdr_serialize_byte_4(mb, endianness, &value); } bool ucdr_serialize_endian_uint64_t(ucdrBuffer* mb, const ucdrEndianness endianness, const uint64_t value) { - return ucdr_serialize_byte_8(mb, endianness, &value); + return ucdr_serialize_byte_8(mb, endianness, &value); } bool ucdr_serialize_endian_int16_t(ucdrBuffer* mb, const ucdrEndianness endianness, const int16_t value) { - return ucdr_serialize_byte_2(mb, endianness, (uint16_t*)&value); + return ucdr_serialize_byte_2(mb, endianness, (uint16_t*)&value); } bool ucdr_serialize_endian_int32_t(ucdrBuffer* mb, const ucdrEndianness endianness, const int32_t value) { - return ucdr_serialize_byte_4(mb, endianness, (uint32_t*)&value); + return ucdr_serialize_byte_4(mb, endianness, (uint32_t*)&value); } bool ucdr_serialize_endian_int64_t(ucdrBuffer* mb, const ucdrEndianness endianness, const int64_t value) { - return ucdr_serialize_byte_8(mb, endianness, (uint64_t*)&value); + return ucdr_serialize_byte_8(mb, endianness, (uint64_t*)&value); } bool ucdr_serialize_endian_float(ucdrBuffer* mb, const ucdrEndianness endianness, const float value) { - return ucdr_serialize_byte_4(mb, endianness, (uint32_t*)&value); + return ucdr_serialize_byte_4(mb, endianness, (uint32_t*)&value); } bool ucdr_serialize_endian_double(ucdrBuffer* mb, const ucdrEndianness endianness, const double value) { - return ucdr_serialize_byte_8(mb, endianness, (uint64_t*)&value); + return ucdr_serialize_byte_8(mb, endianness, (uint64_t*)&value); } bool ucdr_deserialize_endian_uint16_t(ucdrBuffer* mb, const ucdrEndianness endianness, uint16_t* value) { - return ucdr_deserialize_byte_2(mb, endianness, value); + return ucdr_deserialize_byte_2(mb, endianness, value); } bool ucdr_deserialize_endian_uint32_t(ucdrBuffer* mb, const ucdrEndianness endianness, uint32_t* value) { - return ucdr_deserialize_byte_4(mb, endianness, value); + return ucdr_deserialize_byte_4(mb, endianness, value); } bool ucdr_deserialize_endian_uint64_t(ucdrBuffer* mb, const ucdrEndianness endianness, uint64_t* value) { - return ucdr_deserialize_byte_8(mb, endianness, value); + return ucdr_deserialize_byte_8(mb, endianness, value); } bool ucdr_deserialize_endian_int16_t(ucdrBuffer* mb, const ucdrEndianness endianness, int16_t* value) { - return ucdr_deserialize_byte_2(mb, endianness, (uint16_t*)value); + return ucdr_deserialize_byte_2(mb, endianness, (uint16_t*)value); } bool ucdr_deserialize_endian_int32_t(ucdrBuffer* mb, const ucdrEndianness endianness, int32_t* value) { - return ucdr_deserialize_byte_4(mb, endianness, (uint32_t*)value); + return ucdr_deserialize_byte_4(mb, endianness, (uint32_t*)value); } bool ucdr_deserialize_endian_int64_t(ucdrBuffer* mb, const ucdrEndianness endianness, int64_t* value) { - return ucdr_deserialize_byte_8(mb, endianness, (uint64_t*)value); + return ucdr_deserialize_byte_8(mb, endianness, (uint64_t*)value); } bool ucdr_deserialize_endian_float(ucdrBuffer* mb, const ucdrEndianness endianness, float* value) { - return ucdr_deserialize_byte_4(mb, endianness, (uint32_t*)value); + return ucdr_deserialize_byte_4(mb, endianness, (uint32_t*)value); } bool ucdr_deserialize_endian_double(ucdrBuffer* mb, const ucdrEndianness endianness, double* value) { - return ucdr_deserialize_byte_8(mb, endianness, (uint64_t*)value); + return ucdr_deserialize_byte_8(mb, endianness, (uint64_t*)value); } diff --git a/thirdparty/Micro-CDR/src/c/types/sequence.c b/thirdparty/Micro-CDR/src/c/types/sequence.c index 5accce07..e6f60777 100644 --- a/thirdparty/Micro-CDR/src/c/types/sequence.c +++ b/thirdparty/Micro-CDR/src/c/types/sequence.c @@ -24,11 +24,10 @@ // ------------------------------------------------------------------- static inline void ucdr_deserialize_sequence_header(ucdrBuffer* mb, ucdrEndianness endianness, uint32_t capacity, uint32_t* size) { - ucdr_deserialize_endian_uint32_t(mb, endianness, size); - if(*size > capacity) - { - mb->error = true; - } + ucdr_deserialize_endian_uint32_t(mb, endianness, size); + if(*size > capacity) { + mb->error = true; + } } // ------------------------------------------------------------------- @@ -36,50 +35,50 @@ static inline void ucdr_deserialize_sequence_header(ucdrBuffer* mb, ucdrEndianne // ------------------------------------------------------------------- bool ucdr_serialize_sequence_byte_1(ucdrBuffer* mb, ucdrEndianness endianness, const uint8_t* array, const uint32_t size) { - ucdr_serialize_endian_uint32_t(mb, endianness, size); - return ucdr_serialize_array_byte_1(mb, array, size); + ucdr_serialize_endian_uint32_t(mb, endianness, size); + return ucdr_serialize_array_byte_1(mb, array, size); } bool ucdr_serialize_sequence_byte_2(ucdrBuffer* mb, ucdrEndianness endianness, const uint16_t* array, const uint32_t size) { - ucdr_serialize_endian_uint32_t(mb, endianness, size); - return ucdr_serialize_array_byte_2(mb, endianness, array, size); + ucdr_serialize_endian_uint32_t(mb, endianness, size); + return ucdr_serialize_array_byte_2(mb, endianness, array, size); } bool ucdr_serialize_sequence_byte_4(ucdrBuffer* mb, ucdrEndianness endianness, const uint32_t* array, const uint32_t size) { - ucdr_serialize_endian_uint32_t(mb, endianness, size); - return ucdr_serialize_array_byte_4(mb, endianness, array, size); + ucdr_serialize_endian_uint32_t(mb, endianness, size); + return ucdr_serialize_array_byte_4(mb, endianness, array, size); } bool ucdr_serialize_sequence_byte_8(ucdrBuffer* mb, ucdrEndianness endianness, const uint64_t* array, const uint32_t size) { - ucdr_serialize_endian_uint32_t(mb, endianness, size); - return ucdr_serialize_array_byte_8(mb, endianness, array, size); + ucdr_serialize_endian_uint32_t(mb, endianness, size); + return ucdr_serialize_array_byte_8(mb, endianness, array, size); } bool ucdr_deserialize_sequence_byte_1(ucdrBuffer* mb, ucdrEndianness endianness, uint8_t* array, const uint32_t array_capacity, uint32_t* size) { - ucdr_deserialize_sequence_header(mb, endianness, array_capacity, size); - return ucdr_deserialize_array_byte_1(mb, array, *size); + ucdr_deserialize_sequence_header(mb, endianness, array_capacity, size); + return ucdr_deserialize_array_byte_1(mb, array, *size); } bool ucdr_deserialize_sequence_byte_2(ucdrBuffer* mb, ucdrEndianness endianness, uint16_t* array, const uint32_t array_capacity, uint32_t* size) { - ucdr_deserialize_sequence_header(mb, endianness, array_capacity, size); - return ucdr_deserialize_array_byte_2(mb, endianness, array, *size); + ucdr_deserialize_sequence_header(mb, endianness, array_capacity, size); + return ucdr_deserialize_array_byte_2(mb, endianness, array, *size); } bool ucdr_deserialize_sequence_byte_4(ucdrBuffer* mb, ucdrEndianness endianness, uint32_t* array, const uint32_t array_capacity, uint32_t* size) { - ucdr_deserialize_sequence_header(mb, endianness, array_capacity, size); - return ucdr_deserialize_array_byte_4(mb, endianness, array, *size); + ucdr_deserialize_sequence_header(mb, endianness, array_capacity, size); + return ucdr_deserialize_array_byte_4(mb, endianness, array, *size); } bool ucdr_deserialize_sequence_byte_8(ucdrBuffer* mb, ucdrEndianness endianness, uint64_t* array, const uint32_t array_capacity, uint32_t* size) { - ucdr_deserialize_sequence_header(mb, endianness, array_capacity, size); - return ucdr_deserialize_array_byte_8(mb, endianness, array, *size); + ucdr_deserialize_sequence_header(mb, endianness, array_capacity, size); + return ucdr_deserialize_array_byte_8(mb, endianness, array, *size); } // ------------------------------------------------------------------- @@ -88,241 +87,241 @@ bool ucdr_deserialize_sequence_byte_8(ucdrBuffer* mb, ucdrEndianness endianness, bool ucdr_serialize_sequence_char(ucdrBuffer* mb, const char* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_1(mb, mb->endianness, (uint8_t*)array, size); + return ucdr_serialize_sequence_byte_1(mb, mb->endianness, (uint8_t*)array, size); } bool ucdr_serialize_sequence_bool(ucdrBuffer* mb, const bool* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_1(mb, mb->endianness, (uint8_t*)array, size); + return ucdr_serialize_sequence_byte_1(mb, mb->endianness, (uint8_t*)array, size); } bool ucdr_serialize_sequence_uint8_t(ucdrBuffer* mb, const uint8_t* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_1(mb, mb->endianness, (uint8_t*)array, size); + return ucdr_serialize_sequence_byte_1(mb, mb->endianness, (uint8_t*)array, size); } bool ucdr_serialize_sequence_uint16_t(ucdrBuffer* mb, const uint16_t* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_2(mb, mb->endianness, (uint16_t*)array, size); + return ucdr_serialize_sequence_byte_2(mb, mb->endianness, (uint16_t*)array, size); } bool ucdr_serialize_sequence_uint32_t(ucdrBuffer* mb, const uint32_t* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_4(mb, mb->endianness, (uint32_t*)array, size); + return ucdr_serialize_sequence_byte_4(mb, mb->endianness, (uint32_t*)array, size); } bool ucdr_serialize_sequence_uint64_t(ucdrBuffer* mb, const uint64_t* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_8(mb, mb->endianness, (uint64_t*)array, size); + return ucdr_serialize_sequence_byte_8(mb, mb->endianness, (uint64_t*)array, size); } bool ucdr_serialize_sequence_int8_t(ucdrBuffer* mb, const int8_t* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_1(mb, mb->endianness, (uint8_t*)array, size); + return ucdr_serialize_sequence_byte_1(mb, mb->endianness, (uint8_t*)array, size); } bool ucdr_serialize_sequence_int16_t(ucdrBuffer* mb, const int16_t* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_2(mb, mb->endianness, (uint16_t*)array, size); + return ucdr_serialize_sequence_byte_2(mb, mb->endianness, (uint16_t*)array, size); } bool ucdr_serialize_sequence_int32_t(ucdrBuffer* mb, const int32_t* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_4(mb, mb->endianness, (uint32_t*)array, size); + return ucdr_serialize_sequence_byte_4(mb, mb->endianness, (uint32_t*)array, size); } bool ucdr_serialize_sequence_int64_t(ucdrBuffer* mb, const int64_t* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_8(mb, mb->endianness, (uint64_t*)array, size); + return ucdr_serialize_sequence_byte_8(mb, mb->endianness, (uint64_t*)array, size); } bool ucdr_serialize_sequence_float(ucdrBuffer* mb, const float* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_4(mb, mb->endianness, (uint32_t*)array, size); + return ucdr_serialize_sequence_byte_4(mb, mb->endianness, (uint32_t*)array, size); } bool ucdr_serialize_sequence_double(ucdrBuffer* mb, const double* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_8(mb, mb->endianness, (uint64_t*)array, size); + return ucdr_serialize_sequence_byte_8(mb, mb->endianness, (uint64_t*)array, size); } bool ucdr_deserialize_sequence_char(ucdrBuffer* mb, char* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_1(mb, mb->endianness, (uint8_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_1(mb, mb->endianness, (uint8_t*)array, array_capacity, size); } bool ucdr_deserialize_sequence_bool(ucdrBuffer* mb, bool* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_1(mb, mb->endianness, (uint8_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_1(mb, mb->endianness, (uint8_t*)array, array_capacity, size); } bool ucdr_deserialize_sequence_uint8_t(ucdrBuffer* mb, uint8_t* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_1(mb, mb->endianness, (uint8_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_1(mb, mb->endianness, (uint8_t*)array, array_capacity, size); } bool ucdr_deserialize_sequence_uint16_t(ucdrBuffer* mb, uint16_t* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_2(mb, mb->endianness, (uint16_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_2(mb, mb->endianness, (uint16_t*)array, array_capacity, size); } bool ucdr_deserialize_sequence_uint32_t(ucdrBuffer* mb, uint32_t* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_4(mb, mb->endianness, (uint32_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_4(mb, mb->endianness, (uint32_t*)array, array_capacity, size); } bool ucdr_deserialize_sequence_uint64_t(ucdrBuffer* mb, uint64_t* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_8(mb, mb->endianness, (uint64_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_8(mb, mb->endianness, (uint64_t*)array, array_capacity, size); } bool ucdr_deserialize_sequence_int8_t(ucdrBuffer* mb, int8_t* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_1(mb, mb->endianness, (uint8_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_1(mb, mb->endianness, (uint8_t*)array, array_capacity, size); } bool ucdr_deserialize_sequence_int16_t(ucdrBuffer* mb, int16_t* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_2(mb, mb->endianness, (uint16_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_2(mb, mb->endianness, (uint16_t*)array, array_capacity, size); } bool ucdr_deserialize_sequence_int32_t(ucdrBuffer* mb, int32_t* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_4(mb, mb->endianness, (uint32_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_4(mb, mb->endianness, (uint32_t*)array, array_capacity, size); } bool ucdr_deserialize_sequence_int64_t(ucdrBuffer* mb, int64_t* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_8(mb, mb->endianness, (uint64_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_8(mb, mb->endianness, (uint64_t*)array, array_capacity, size); } bool ucdr_deserialize_sequence_float(ucdrBuffer* mb, float* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_4(mb, mb->endianness, (uint32_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_4(mb, mb->endianness, (uint32_t*)array, array_capacity, size); } bool ucdr_deserialize_sequence_double(ucdrBuffer* mb, double* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_8(mb, mb->endianness, (uint64_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_8(mb, mb->endianness, (uint64_t*)array, array_capacity, size); } bool ucdr_serialize_endian_sequence_char(ucdrBuffer* mb, const ucdrEndianness endianness, const char* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_1(mb, endianness, (uint8_t*)array, size); + return ucdr_serialize_sequence_byte_1(mb, endianness, (uint8_t*)array, size); } bool ucdr_serialize_endian_sequence_bool(ucdrBuffer* mb, const ucdrEndianness endianness, const bool* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_1(mb, endianness, (uint8_t*)array, size); + return ucdr_serialize_sequence_byte_1(mb, endianness, (uint8_t*)array, size); } bool ucdr_serialize_endian_sequence_uint8_t(ucdrBuffer* mb, const ucdrEndianness endianness, const uint8_t* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_1(mb, endianness, (uint8_t*)array, size); + return ucdr_serialize_sequence_byte_1(mb, endianness, (uint8_t*)array, size); } bool ucdr_serialize_endian_sequence_uint16_t(ucdrBuffer* mb, const ucdrEndianness endianness, const uint16_t* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_2(mb, endianness, (uint16_t*)array, size); + return ucdr_serialize_sequence_byte_2(mb, endianness, (uint16_t*)array, size); } bool ucdr_serialize_endian_sequence_uint32_t(ucdrBuffer* mb, const ucdrEndianness endianness, const uint32_t* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_4(mb, endianness, (uint32_t*)array, size); + return ucdr_serialize_sequence_byte_4(mb, endianness, (uint32_t*)array, size); } bool ucdr_serialize_endian_sequence_uint64_t(ucdrBuffer* mb, const ucdrEndianness endianness, const uint64_t* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_8(mb, endianness, (uint64_t*)array, size); + return ucdr_serialize_sequence_byte_8(mb, endianness, (uint64_t*)array, size); } bool ucdr_serialize_endian_sequence_int8_t(ucdrBuffer* mb, const ucdrEndianness endianness, const int8_t* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_1(mb, endianness, (uint8_t*)array, size); + return ucdr_serialize_sequence_byte_1(mb, endianness, (uint8_t*)array, size); } bool ucdr_serialize_endian_sequence_int16_t(ucdrBuffer* mb, const ucdrEndianness endianness, const int16_t* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_2(mb, endianness, (uint16_t*)array, size); + return ucdr_serialize_sequence_byte_2(mb, endianness, (uint16_t*)array, size); } bool ucdr_serialize_endian_sequence_int32_t(ucdrBuffer* mb, const ucdrEndianness endianness, const int32_t* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_4(mb, endianness, (uint32_t*)array, size); + return ucdr_serialize_sequence_byte_4(mb, endianness, (uint32_t*)array, size); } bool ucdr_serialize_endian_sequence_int64_t(ucdrBuffer* mb, const ucdrEndianness endianness, const int64_t* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_8(mb, endianness, (uint64_t*)array, size); + return ucdr_serialize_sequence_byte_8(mb, endianness, (uint64_t*)array, size); } bool ucdr_serialize_endian_sequence_float(ucdrBuffer* mb, const ucdrEndianness endianness, const float* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_4(mb, endianness, (uint32_t*)array, size); + return ucdr_serialize_sequence_byte_4(mb, endianness, (uint32_t*)array, size); } bool ucdr_serialize_endian_sequence_double(ucdrBuffer* mb, const ucdrEndianness endianness, const double* array, const uint32_t size) { - return ucdr_serialize_sequence_byte_8(mb, endianness, (uint64_t*)array, size); + return ucdr_serialize_sequence_byte_8(mb, endianness, (uint64_t*)array, size); } bool ucdr_deserialize_endian_sequence_char(ucdrBuffer* mb, const ucdrEndianness endianness, char* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_1(mb, endianness, (uint8_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_1(mb, endianness, (uint8_t*)array, array_capacity, size); } bool ucdr_deserialize_endian_sequence_bool(ucdrBuffer* mb, const ucdrEndianness endianness, bool* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_1(mb, endianness, (uint8_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_1(mb, endianness, (uint8_t*)array, array_capacity, size); } bool ucdr_deserialize_endian_sequence_uint8_t(ucdrBuffer* mb, const ucdrEndianness endianness, uint8_t* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_1(mb, endianness, (uint8_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_1(mb, endianness, (uint8_t*)array, array_capacity, size); } bool ucdr_deserialize_endian_sequence_uint16_t(ucdrBuffer* mb, const ucdrEndianness endianness, uint16_t* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_2(mb, endianness, (uint16_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_2(mb, endianness, (uint16_t*)array, array_capacity, size); } bool ucdr_deserialize_endian_sequence_uint32_t(ucdrBuffer* mb, const ucdrEndianness endianness, uint32_t* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_4(mb, endianness, (uint32_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_4(mb, endianness, (uint32_t*)array, array_capacity, size); } bool ucdr_deserialize_endian_sequence_uint64_t(ucdrBuffer* mb, const ucdrEndianness endianness, uint64_t* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_8(mb, endianness, (uint64_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_8(mb, endianness, (uint64_t*)array, array_capacity, size); } bool ucdr_deserialize_endian_sequence_int8_t(ucdrBuffer* mb, const ucdrEndianness endianness, int8_t* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_1(mb, endianness, (uint8_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_1(mb, endianness, (uint8_t*)array, array_capacity, size); } bool ucdr_deserialize_endian_sequence_int16_t(ucdrBuffer* mb, const ucdrEndianness endianness, int16_t* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_2(mb, endianness, (uint16_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_2(mb, endianness, (uint16_t*)array, array_capacity, size); } bool ucdr_deserialize_endian_sequence_int32_t(ucdrBuffer* mb, const ucdrEndianness endianness, int32_t* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_4(mb, endianness, (uint32_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_4(mb, endianness, (uint32_t*)array, array_capacity, size); } bool ucdr_deserialize_endian_sequence_int64_t(ucdrBuffer* mb, const ucdrEndianness endianness, int64_t* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_8(mb, endianness, (uint64_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_8(mb, endianness, (uint64_t*)array, array_capacity, size); } bool ucdr_deserialize_endian_sequence_float(ucdrBuffer* mb, const ucdrEndianness endianness, float* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_4(mb, endianness, (uint32_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_4(mb, endianness, (uint32_t*)array, array_capacity, size); } bool ucdr_deserialize_endian_sequence_double(ucdrBuffer* mb, const ucdrEndianness endianness, double* array, const uint32_t array_capacity, uint32_t* size) { - return ucdr_deserialize_sequence_byte_8(mb, endianness, (uint64_t*)array, array_capacity, size); + return ucdr_deserialize_sequence_byte_8(mb, endianness, (uint64_t*)array, array_capacity, size); } diff --git a/thirdparty/Micro-CDR/src/c/types/string.c b/thirdparty/Micro-CDR/src/c/types/string.c index de0760fe..e2adae59 100644 --- a/thirdparty/Micro-CDR/src/c/types/string.c +++ b/thirdparty/Micro-CDR/src/c/types/string.c @@ -24,22 +24,22 @@ bool ucdr_serialize_string(ucdrBuffer* mb, const char* string) { - return ucdr_serialize_sequence_char(mb, string, (uint32_t)strlen(string) + 1); + return ucdr_serialize_sequence_char(mb, string, (uint32_t)strlen(string) + 1); } bool ucdr_deserialize_string(ucdrBuffer* mb, char* string, const uint32_t string_capacity) { - uint32_t length; - return ucdr_deserialize_sequence_char(mb, string, string_capacity, &length); + uint32_t length; + return ucdr_deserialize_sequence_char(mb, string, string_capacity, &length); } bool ucdr_serialize_endian_string(ucdrBuffer* mb, ucdrEndianness endianness, const char* string) { - return ucdr_serialize_endian_sequence_char(mb, endianness, string, (uint32_t)strlen(string) + 1); + return ucdr_serialize_endian_sequence_char(mb, endianness, string, (uint32_t)strlen(string) + 1); } bool ucdr_deserialize_endian_string(ucdrBuffer* mb, ucdrEndianness endianness, char* string, const uint32_t string_capacity) { - uint32_t length; - return ucdr_deserialize_endian_sequence_char(mb, endianness, string, string_capacity, &length); + uint32_t length; + return ucdr_deserialize_endian_sequence_char(mb, endianness, string, string_capacity, &length); } diff --git a/thirdparty/lwip/default_netif.c b/thirdparty/lwip/default_netif.c index 472906f3..d18706cc 100644 --- a/thirdparty/lwip/default_netif.c +++ b/thirdparty/lwip/default_netif.c @@ -1,8 +1,8 @@ /* * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, @@ -11,72 +11,72 @@ * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * This file is part of the lwIP TCP/IP stack. - * + * * Author: Adam Dunkels * */ #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) - #include "lwip/opt.h" +#include "lwip/opt.h" - #include "lwip/netif.h" - #include "lwip/ip_addr.h" - #include "lwip/tcpip.h" - #include "../pcapif.h" - #include "examples/example_app/default_netif.h" +#include "lwip/netif.h" +#include "lwip/ip_addr.h" +#include "lwip/tcpip.h" +#include "../pcapif.h" +#include "examples/example_app/default_netif.h" - static struct netif netif; +static struct netif netif; - #if LWIP_IPV4 - #define NETIF_ADDRS ipaddr, netmask, gw, - void init_default_netif(const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw) - #else - #define NETIF_ADDRS - void init_default_netif(void) - #endif - { - #if NO_SYS - netif_add(&netif, NETIF_ADDRS NULL, pcapif_init, netif_input); - #else /* NO_SYS */ - netif_add(&netif, NETIF_ADDRS NULL, pcapif_init, tcpip_input); - #endif /* NO_SYS */ - netif_set_default(&netif); - } +#if LWIP_IPV4 +#define NETIF_ADDRS ipaddr, netmask, gw, +void init_default_netif(const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw) +#else +#define NETIF_ADDRS +void init_default_netif(void) +#endif +{ +#if NO_SYS + netif_add(&netif, NETIF_ADDRS NULL, pcapif_init, netif_input); +#else /* NO_SYS */ + netif_add(&netif, NETIF_ADDRS NULL, pcapif_init, tcpip_input); +#endif /* NO_SYS */ + netif_set_default(&netif); +} - void - default_netif_poll(void) - { - #if !PCAPIF_RX_USE_THREAD - /* check for packets and link status*/ - pcapif_poll(&netif); - /* When pcapif_poll comes back, there are not packets, so sleep to - prevent 100% CPU load. Don't do this in an embedded system since it - increases latency! */ - sys_msleep(1); - #else /* !PCAPIF_RX_USE_THREAD */ - sys_msleep(50); - #endif /* !PCAPIF_RX_USE_THREAD */ - } +void +default_netif_poll(void) +{ +#if !PCAPIF_RX_USE_THREAD + /* check for packets and link status*/ + pcapif_poll(&netif); + /* When pcapif_poll comes back, there are not packets, so sleep to + prevent 100% CPU load. Don't do this in an embedded system since it + increases latency! */ + sys_msleep(1); +#else /* !PCAPIF_RX_USE_THREAD */ + sys_msleep(50); +#endif /* !PCAPIF_RX_USE_THREAD */ +} - void - default_netif_shutdown(void) - { - /* release the pcap library... */ - pcapif_shutdown(&netif); - } +void +default_netif_shutdown(void) +{ + /* release the pcap library... */ + pcapif_shutdown(&netif); +} #endif diff --git a/thirdparty/lwip/default_netif.h b/thirdparty/lwip/default_netif.h index c247ea08..cd7aa349 100644 --- a/thirdparty/lwip/default_netif.h +++ b/thirdparty/lwip/default_netif.h @@ -1,8 +1,8 @@ /* * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, @@ -11,21 +11,21 @@ * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * This file is part of the lwIP TCP/IP stack. - * + * * Author: Adam Dunkels * */ diff --git a/thirdparty/lwip/lwipopts.h b/thirdparty/lwip/lwipopts.h index 8ad30854..15b28826 100644 --- a/thirdparty/lwip/lwipopts.h +++ b/thirdparty/lwip/lwipopts.h @@ -313,7 +313,7 @@ a lot of data that needs to be copied, this should be set high. */ /* The following defines must be done even in OPTTEST mode: */ #ifdef __cplusplus -extern "C"{ +extern "C" { #endif #if !defined(NO_SYS) || !NO_SYS /* default is 0 */