Porting mros2 as an Mbed library.

Dependents:   mbed-os-example-mros2 example-mbed-mros2-sub-pose example-mbed-mros2-pub-twist example-mbed-mros2-mturtle-teleop

Committer:
smoritaemb
Date:
Sat Mar 19 09:23:37 2022 +0900
Revision:
7:c80f65422d99
Parent:
0:580aba13d1a1
Merge test_assortment_of_msgs branch.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
smoritaemb 0:580aba13d1a1 1 /*
smoritaemb 0:580aba13d1a1 2 The MIT License
smoritaemb 0:580aba13d1a1 3 Copyright (c) 2019 Lehrstuhl Informatik 11 - RWTH Aachen University
smoritaemb 0:580aba13d1a1 4 Permission is hereby granted, free of charge, to any person obtaining a copy
smoritaemb 0:580aba13d1a1 5 of this software and associated documentation files (the "Software"), to deal
smoritaemb 0:580aba13d1a1 6 in the Software without restriction, including without limitation the rights
smoritaemb 0:580aba13d1a1 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
smoritaemb 0:580aba13d1a1 8 copies of the Software, and to permit persons to whom the Software is
smoritaemb 0:580aba13d1a1 9 furnished to do so, subject to the following conditions:
smoritaemb 0:580aba13d1a1 10 The above copyright notice and this permission notice shall be included in
smoritaemb 0:580aba13d1a1 11 all copies or substantial portions of the Software.
smoritaemb 0:580aba13d1a1 12 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
smoritaemb 0:580aba13d1a1 13 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
smoritaemb 0:580aba13d1a1 14 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
smoritaemb 0:580aba13d1a1 15 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
smoritaemb 0:580aba13d1a1 16 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
smoritaemb 0:580aba13d1a1 17 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
smoritaemb 0:580aba13d1a1 18 THE SOFTWARE
smoritaemb 0:580aba13d1a1 19
smoritaemb 0:580aba13d1a1 20 This file is part of embeddedRTPS.
smoritaemb 0:580aba13d1a1 21
smoritaemb 0:580aba13d1a1 22 Author: i11 - Embedded Software, RWTH Aachen University
smoritaemb 0:580aba13d1a1 23 */
smoritaemb 0:580aba13d1a1 24
smoritaemb 0:580aba13d1a1 25 #ifndef RTPS_PARTICIPANT_H
smoritaemb 0:580aba13d1a1 26 #define RTPS_PARTICIPANT_H
smoritaemb 0:580aba13d1a1 27
smoritaemb 0:580aba13d1a1 28 #include "rtps/common/types.h"
smoritaemb 0:580aba13d1a1 29 #include "rtps/config.h"
smoritaemb 0:580aba13d1a1 30 #include "rtps/discovery/SEDPAgent.h"
smoritaemb 0:580aba13d1a1 31 #include "rtps/discovery/SPDPAgent.h"
smoritaemb 0:580aba13d1a1 32 #include "rtps/messages/MessageReceiver.h"
smoritaemb 0:580aba13d1a1 33
smoritaemb 0:580aba13d1a1 34 namespace rtps {
smoritaemb 0:580aba13d1a1 35
smoritaemb 0:580aba13d1a1 36 class Writer;
smoritaemb 0:580aba13d1a1 37 class Reader;
smoritaemb 0:580aba13d1a1 38
smoritaemb 0:580aba13d1a1 39 class Participant {
smoritaemb 0:580aba13d1a1 40 public:
smoritaemb 0:580aba13d1a1 41 GuidPrefix_t m_guidPrefix;
smoritaemb 0:580aba13d1a1 42 ParticipantId_t m_participantId;
smoritaemb 0:580aba13d1a1 43
smoritaemb 0:580aba13d1a1 44 Participant();
smoritaemb 0:580aba13d1a1 45 explicit Participant(const GuidPrefix_t &guidPrefix,
smoritaemb 0:580aba13d1a1 46 ParticipantId_t participantId);
smoritaemb 0:580aba13d1a1 47
smoritaemb 0:580aba13d1a1 48 // Not allowed because the message receiver contains a pointer to the
smoritaemb 0:580aba13d1a1 49 // participant
smoritaemb 0:580aba13d1a1 50 Participant(const Participant &) = delete;
smoritaemb 0:580aba13d1a1 51 Participant(Participant &&) = delete;
smoritaemb 0:580aba13d1a1 52 Participant &operator=(const Participant &) = delete;
smoritaemb 0:580aba13d1a1 53 Participant &operator=(Participant &&) = delete;
smoritaemb 0:580aba13d1a1 54
smoritaemb 0:580aba13d1a1 55 ~Participant();
smoritaemb 0:580aba13d1a1 56 bool isValid();
smoritaemb 0:580aba13d1a1 57
smoritaemb 0:580aba13d1a1 58 void reuse(const GuidPrefix_t &guidPrefix, ParticipantId_t participantId);
smoritaemb 0:580aba13d1a1 59
smoritaemb 0:580aba13d1a1 60 std::array<uint8_t, 3> getNextUserEntityKey();
smoritaemb 0:580aba13d1a1 61
smoritaemb 0:580aba13d1a1 62 // Actually the only two function that should be used by the user
smoritaemb 0:580aba13d1a1 63 bool registerOnNewPublisherMatchedCallback(void (*callback)(void *arg),
smoritaemb 0:580aba13d1a1 64 void *args);
smoritaemb 0:580aba13d1a1 65 bool registerOnNewSubscriberMatchedCallback(void (*callback)(void *arg),
smoritaemb 0:580aba13d1a1 66 void *args);
smoritaemb 0:580aba13d1a1 67
smoritaemb 0:580aba13d1a1 68 //! Not-thread-safe function to add a writer
smoritaemb 0:580aba13d1a1 69 Writer *addWriter(Writer *writer);
smoritaemb 0:580aba13d1a1 70 bool isWritersFull();
smoritaemb 0:580aba13d1a1 71
smoritaemb 0:580aba13d1a1 72 //! Not-thread-safe function to add a reader
smoritaemb 0:580aba13d1a1 73 Reader *addReader(Reader *reader);
smoritaemb 0:580aba13d1a1 74 bool isReadersFull();
smoritaemb 0:580aba13d1a1 75
smoritaemb 0:580aba13d1a1 76 //! (Probably) Thread safe if writers cannot be removed
smoritaemb 0:580aba13d1a1 77 Writer *getWriter(EntityId_t id) const;
smoritaemb 0:580aba13d1a1 78 Writer *getMatchingWriter(const TopicData &topicData) const;
smoritaemb 0:580aba13d1a1 79 //! (Probably) Thread safe if readers cannot be removed
smoritaemb 0:580aba13d1a1 80 Reader *getReader(EntityId_t id) const;
smoritaemb 0:580aba13d1a1 81 Reader *getMatchingReader(const TopicData &topicData) const;
smoritaemb 0:580aba13d1a1 82
smoritaemb 0:580aba13d1a1 83 bool addNewRemoteParticipant(const ParticipantProxyData &remotePart);
smoritaemb 0:580aba13d1a1 84 bool removeRemoteParticipant(const GuidPrefix_t &prefix);
smoritaemb 0:580aba13d1a1 85 const ParticipantProxyData *findRemoteParticipant(const GuidPrefix_t &prefix);
smoritaemb 0:580aba13d1a1 86 uint32_t getRemoteParticipantCount();
smoritaemb 0:580aba13d1a1 87 MessageReceiver *getMessageReceiver();
smoritaemb 0:580aba13d1a1 88
smoritaemb 0:580aba13d1a1 89 void addBuiltInEndpoints(BuiltInEndpoints &endpoints);
smoritaemb 0:580aba13d1a1 90 void newMessage(const uint8_t *data, DataSize_t size);
smoritaemb 0:580aba13d1a1 91
smoritaemb 0:580aba13d1a1 92 private:
smoritaemb 0:580aba13d1a1 93 MessageReceiver m_receiver;
smoritaemb 0:580aba13d1a1 94 bool m_hasBuilInEndpoints = false;
smoritaemb 0:580aba13d1a1 95 std::array<uint8_t, 3> m_nextUserEntityId{{0, 0, 1}};
smoritaemb 0:580aba13d1a1 96 std::array<Writer *, Config::NUM_WRITERS_PER_PARTICIPANT> m_writers{};
smoritaemb 0:580aba13d1a1 97 uint8_t m_numWriters = 0;
smoritaemb 0:580aba13d1a1 98 std::array<Reader *, Config::NUM_READERS_PER_PARTICIPANT> m_readers{};
smoritaemb 0:580aba13d1a1 99 uint8_t m_numReaders = 0;
smoritaemb 0:580aba13d1a1 100
smoritaemb 0:580aba13d1a1 101 MemoryPool<ParticipantProxyData, Config::SPDP_MAX_NUMBER_FOUND_PARTICIPANTS>
smoritaemb 0:580aba13d1a1 102 m_remoteParticipants;
smoritaemb 0:580aba13d1a1 103
smoritaemb 0:580aba13d1a1 104 SPDPAgent m_spdpAgent;
smoritaemb 0:580aba13d1a1 105 SEDPAgent m_sedpAgent;
smoritaemb 0:580aba13d1a1 106 };
smoritaemb 0:580aba13d1a1 107 } // namespace rtps
smoritaemb 0:580aba13d1a1 108
smoritaemb 0:580aba13d1a1 109 #endif // RTPS_PARTICIPANT_H