Roboid Control for C++ 0.4
Loading...
Searching...
No Matches
D:/Cpp/RoboidControl-cpp/Participant.h
1#pragma once
2
3#include "Messages/IMessage.h"
4#include "Thing.h"
5
6namespace RoboidControl {
7
8constexpr int MAX_THING_COUNT = 256;
9
12 public:
17 Participant* Get(const char* ipAddress, unsigned int port);
21 Participant* Get(unsigned char networkID);
22
27 Participant* Add(const char* ipAddress, unsigned int port);
30 void Add(Participant* participant);
31
34 void Remove(Participant* participant);
35
36 private:
37#if defined(NO_STD)
38 public:
39 Participant** GetAll() const;
40 int count = 0;
41
42 private:
43 Participant** participants;
44#else
45 public:
48 const std::list<Participant*>& GetAll() const;
49
50 private:
52 std::list<Participant*> participants;
53#endif
54};
55
63#pragma region Init
64
65 public:
73 Participant(const char* ipAddress, int port);
76
81 static void ReplaceLocalParticipant(Participant& newParticipant);
82
83#pragma endregion Init
84
85#pragma region Properties
86
87 public:
89 const char* name = "Participant";
90
94 const char* ipAddress = "0.0.0.0";
98 unsigned int port = 0;
99
101 unsigned char networkId = 0;
102
104 Thing* root = nullptr;
105
106 public:
107#if defined(NO_STD)
108 unsigned char thingCount = 0;
109 Thing* things[MAX_THING_COUNT];
110#else
112 std::list<Thing*> things;
113#endif
117 Thing* Get(unsigned char thingId);
121 void Add(Thing* thing, bool checkId = true);
124 void Remove(Thing* thing);
125
126#pragma endregion Properties
127
128#pragma region Update
129
130 public:
132 virtual void Update();
133
134#pragma endregion Update
135
136#pragma region Send
137
138 public:
139 char buffer[1024];
140
141 virtual bool Send(IMessage* msg);
142
143#pragma endregion Send
144
145#pragma region Participant Registry
146
147 public:
148 static ParticipantRegistry registry;
149
150#pragma endregion Participant Registry
151};
152
153} // namespace RoboidControl
Root structure for all communcation messages.
Definition IMessage.h:6
A participant is a device which manages things. It can communicate with other participant to synchron...
Definition Participant.h:62
void Add(Thing *thing, bool checkId=true)
Add a new thing for this participant.
Definition Participant.cpp:98
Thing * root
The root thing for this participant.
Definition Participant.h:104
Thing * Get(unsigned char thingId)
Find a thing managed by this participant.
Definition Participant.cpp:87
const char * name
The name of the participant.
Definition Participant.h:89
Participant()
Create a generic participant.
Definition Participant.cpp:22
static void ReplaceLocalParticipant(Participant &newParticipant)
Replace the local participant.
Definition Participant.cpp:17
unsigned char networkId
The network Id to identify the participant.
Definition Participant.h:101
unsigned int port
The port number for UDP communication with the participant.
Definition Participant.h:98
virtual void Update()
Update all things for this participant.
Definition Participant.cpp:52
const char * ipAddress
The Ip Address of a participant.
Definition Participant.h:94
void Remove(Thing *thing)
Remove a thing for this participant.
Definition Participant.cpp:136
~Participant()
Destructor for the participant.
Definition Participant.cpp:47
std::list< Thing * > things
The things managed by this participant.
Definition Participant.h:112
static Participant * LocalParticipant
The local participant for this application.
Definition Participant.h:78
class which manages all known participants
Definition Participant.h:11
const std::list< Participant * > & GetAll() const
Get all participants.
Participant * Add(const char *ipAddress, unsigned int port)
Add a participant with the given details.
Definition Participant.cpp:193
Participant * Get(const char *ipAddress, unsigned int port)
Retrieve a participant by its address.
Definition Participant.cpp:161
void Remove(Participant *participant)
Remove a participant.
Definition Participant.cpp:225
A thing is the primitive building block.
Definition Thing.h:20