#pragma once #include "Messages/IMessage.h" #include "Thing.h" namespace RoboidControl { constexpr int MAX_THING_COUNT = 256; /// @brief A participant is a device which manages things. /// It can communicate with other participant to synchronise the state of /// things. This class is used to register the things the participant is /// managing. It also maintains the communcation information to contact the /// participant. It is used as a basis for the local participant, but also as a /// reference to remote participants. class Participant { #pragma region Init public: /// @brief Create a generic participant Participant(); /// @brief Create a new participant with the given communcation info /// @param ipAddress The IP address of the participant /// @param port The UDP port of the participant /// @remarks This does not belong here, it should move to ParticipantUDP or /// something like that in the future Participant(const char* ipAddress, int port); /// @brief Destructor for the participant ~Participant(); /// @brief The local participant for this application static Participant* LocalParticipant; /// @brief Replace the local participant /// @param newParticipant The new local Participant static void ReplaceLocalParticipant(Participant& newParticipant); #pragma endregion Init #pragma region Properties public: /// @brief The name of the participant const char* name = "Participant"; /// @brief The network Id to identify the participant unsigned char networkId = 0; /// @brief The root thing for this participant Thing* root = nullptr; public: #if defined(NO_STD) unsigned char thingCount = 0; Thing* things[MAX_THING_COUNT]; #else /// @brief The things managed by this participant std::list things; #endif /// @brief Find a thing managed by this participant /// @param networkId The network ID of the thing /// @param thingId The ID of the thing /// @return The thing if found, nullptr when no thing has been found Thing* Get(unsigned char networkId, unsigned char thingId); /// @brief Add a new thing for this participant. /// @param thing The thing to add /// @param checkId If true, the thing.id is regenerated if it is zero void Add(Thing* thing, bool checkId = true); /// @brief Remove a thing for this participant /// @param thing The thing to remove void Remove(Thing* thing); #pragma endregion Properties #pragma region Update public: /// @brief Update all things for this participant virtual void Update(bool recurse = true); #pragma endregion Update #pragma region Send public: char buffer[1024]; virtual bool Send(IMessage* msg); #pragma endregion Send }; } // namespace RoboidControl