#pragma once #include "Thing.h" namespace RoboidControl { /// @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 { public: /// @brief The Ip Address of a participant. When the participant is local, this contains 0.0.0.0 const char *ipAddress = "0.0.0.0"; /// @brief The port number for UDP communication with the participant. This is 0 for isolated participants. int port = 0; /// @brief The network Id to identify the participant. /// @note This field is likely to disappear in future versions unsigned char networkId = 0; /// @brief Default constructor Participant(); /// @brief Create a new participant with the given communcation info /// @param ipAddress The IP address of the participant /// @param port The port of the participant Participant(const char *ipAddress, int port); /// @brief Destructor for the participant ~Participant(); protected: /// @brief The list of things managed by this participant std::list things; public: /// @brief Find a thing managed by this participant /// @param networkId The network ID for the thing /// @param thingId The ID of the thing /// @return The thing if found or nullptr when no thing has been found /// @note The use of the network ID is likely to disappear in future versions. Thing *Get(unsigned char networkId, unsigned char thingId); /// @brief Add a new thing for this participant. /// @param thing The thing to add /// @param checkId Checks the thing ID of the thing. If it is 0, a new thing Id will be assigned. void Add(Thing *thing, bool checkId = true); /// @brief Remove a thing for this participant /// @param thing The thing to remove void Remove(Thing *thing); }; } // namespace Control