S Morita / mbed-mros2

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Participant.h Source File

Participant.h

00001 /*
00002 The MIT License
00003 Copyright (c) 2019 Lehrstuhl Informatik 11 - RWTH Aachen University
00004 Permission is hereby granted, free of charge, to any person obtaining a copy
00005 of this software and associated documentation files (the "Software"), to deal
00006 in the Software without restriction, including without limitation the rights
00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008 copies of the Software, and to permit persons to whom the Software is
00009 furnished to do so, subject to the following conditions:
00010 The above copyright notice and this permission notice shall be included in
00011 all copies or substantial portions of the Software.
00012 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00013 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00014 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00015 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00016 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00017 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00018 THE SOFTWARE
00019 
00020 This file is part of embeddedRTPS.
00021 
00022 Author: i11 - Embedded Software, RWTH Aachen University
00023 */
00024 
00025 #ifndef RTPS_PARTICIPANT_H
00026 #define RTPS_PARTICIPANT_H
00027 
00028 #include "rtps/common/types.h"
00029 #include "rtps/config.h"
00030 #include "rtps/discovery/SEDPAgent.h"
00031 #include "rtps/discovery/SPDPAgent.h"
00032 #include "rtps/messages/MessageReceiver.h"
00033 
00034 namespace rtps {
00035 
00036 class Writer;
00037 class Reader;
00038 
00039 class Participant {
00040 public:
00041   GuidPrefix_t m_guidPrefix;
00042   ParticipantId_t m_participantId;
00043 
00044   Participant();
00045   explicit Participant(const GuidPrefix_t &guidPrefix,
00046                        ParticipantId_t participantId);
00047 
00048   // Not allowed because the message receiver contains a pointer to the
00049   // participant
00050   Participant(const Participant &) = delete;
00051   Participant(Participant &&) = delete;
00052   Participant &operator=(const Participant &) = delete;
00053   Participant &operator=(Participant &&) = delete;
00054 
00055   ~Participant();
00056   bool isValid();
00057 
00058   void reuse(const GuidPrefix_t &guidPrefix, ParticipantId_t participantId);
00059 
00060   std::array<uint8_t, 3> getNextUserEntityKey();
00061 
00062   // Actually the only two function that should be used by the user
00063   bool registerOnNewPublisherMatchedCallback(void (*callback)(void *arg),
00064                                              void *args);
00065   bool registerOnNewSubscriberMatchedCallback(void (*callback)(void *arg),
00066                                               void *args);
00067 
00068   //! Not-thread-safe function to add a writer
00069   Writer *addWriter(Writer *writer);
00070   bool isWritersFull();
00071 
00072   //! Not-thread-safe function to add a reader
00073   Reader *addReader(Reader *reader);
00074   bool isReadersFull();
00075 
00076   //! (Probably) Thread safe if writers cannot be removed
00077   Writer *getWriter(EntityId_t id) const;
00078   Writer *getMatchingWriter(const TopicData &topicData) const;
00079   //! (Probably) Thread safe if readers cannot be removed
00080   Reader *getReader(EntityId_t id) const;
00081   Reader *getMatchingReader(const TopicData &topicData) const;
00082 
00083   bool addNewRemoteParticipant(const ParticipantProxyData &remotePart);
00084   bool removeRemoteParticipant(const GuidPrefix_t &prefix);
00085   const ParticipantProxyData *findRemoteParticipant(const GuidPrefix_t &prefix);
00086   uint32_t getRemoteParticipantCount();
00087   MessageReceiver *getMessageReceiver();
00088 
00089   void addBuiltInEndpoints(BuiltInEndpoints &endpoints);
00090   void newMessage(const uint8_t *data, DataSize_t size);
00091 
00092 private:
00093   MessageReceiver m_receiver;
00094   bool m_hasBuilInEndpoints = false;
00095   std::array<uint8_t, 3> m_nextUserEntityId{{0, 0, 1}};
00096   std::array<Writer *, Config::NUM_WRITERS_PER_PARTICIPANT> m_writers{};
00097   uint8_t m_numWriters = 0;
00098   std::array<Reader *, Config::NUM_READERS_PER_PARTICIPANT> m_readers{};
00099   uint8_t m_numReaders = 0;
00100 
00101   MemoryPool<ParticipantProxyData, Config::SPDP_MAX_NUMBER_FOUND_PARTICIPANTS>
00102       m_remoteParticipants;
00103 
00104   SPDPAgent m_spdpAgent;
00105   SEDPAgent m_sedpAgent;
00106 };
00107 } // namespace rtps
00108 
00109 #endif // RTPS_PARTICIPANT_H