17 #ifndef UNetReceiver_H_ 18 #define UNetReceiver_H_ 24 #include <unordered_map> 25 #include <sigc++/sigc++.h> 27 #include "UniSetObject.h" 30 #include "SMInterface.h" 31 #include "SharedMemory.h" 32 #include "UDPPacket.h" 33 #include "CommonEventLoop.h" 101 public std::enable_shared_from_this<UNetReceiver>
104 UNetReceiver(
const std::string& host,
int port,
const std::shared_ptr<SMInterface>& smi,
bool nocheckConnection =
false );
110 inline const std::string getName()
const 116 void setLockUpdate(
bool st ) noexcept;
117 bool isLockUpdate()
const noexcept;
119 void resetTimeout() noexcept;
121 bool isInitOK()
const noexcept;
122 bool isRecvOK()
const noexcept;
123 size_t getLostPacketsNum()
const noexcept;
125 void setReceiveTimeout( timeout_t msec ) noexcept;
126 void setReceivePause( timeout_t msec ) noexcept;
127 void setUpdatePause( timeout_t msec ) noexcept;
128 void setLostTimeout( timeout_t msec ) noexcept;
129 void setPrepareTime( timeout_t msec ) noexcept;
130 void setCheckConnectionPause( timeout_t msec ) noexcept;
131 void setMaxDifferens(
unsigned long set ) noexcept;
132 void setEvrunTimeout(timeout_t msec ) noexcept;
133 void setInitPause( timeout_t msec ) noexcept;
138 void setMaxProcessingCount(
int set ) noexcept;
140 void forceUpdate() noexcept;
142 inline std::string getAddress()
const noexcept
146 inline int getPort()
const noexcept
158 typedef sigc::slot<void, const std::shared_ptr<UNetReceiver>&,
Event> EventSlot;
159 void connectEvent( EventSlot sl ) noexcept;
170 static UpdateStrategy strToUpdateStrategy(
const std::string& s ) noexcept;
191 inline std::shared_ptr<DebugStream> getLog()
196 virtual const std::string getShortInfo()
const noexcept;
200 const std::shared_ptr<SMInterface> shm;
201 std::shared_ptr<DebugStream> unetlog;
203 bool receive() noexcept;
204 void step() noexcept;
205 void update() noexcept;
206 void updateThread() noexcept;
207 void callback( ev::io& watcher,
int revents ) noexcept;
208 void readEvent( ev::io& watcher ) noexcept;
209 void updateEvent( ev::periodic& watcher,
int revents ) noexcept;
210 void checkConnectionEvent( ev::periodic& watcher,
int revents ) noexcept;
211 void statisticsEvent( ev::periodic& watcher,
int revents ) noexcept;
212 void initEvent( ev::timer& watcher,
int revents ) noexcept;
213 virtual void evprepare(
const ev::loop_ref& eloop ) noexcept
override;
214 virtual void evfinish(
const ev::loop_ref& eloop ) noexcept
override;
215 virtual std::string wname()
const noexcept
override 220 void initIterators() noexcept;
221 bool createConnection(
bool throwEx =
false );
222 void checkConnection();
228 public std::binary_function<UniSetUDP::UDPMessage, UniSetUDP::UDPMessage, bool>
233 return lhs.num > rhs.num;
237 typedef std::priority_queue<UniSetUDP::UDPMessage, std::vector<UniSetUDP::UDPMessage>,
PacketCompare> PacketQueue;
242 timeout_t recvpause = { 10 };
243 timeout_t updatepause = { 100 };
245 std::unique_ptr<UDPReceiveU> udp;
248 Poco::Net::SocketAddress saddr;
251 ev::periodic evCheckConnection;
252 ev::periodic evStatistic;
253 ev::periodic evUpdate;
254 ev::timer evInitPause;
259 size_t recvCount = { 0 };
260 size_t upCount = { 0 };
263 size_t statRecvPerSec = { 0 };
264 size_t statUpPerSec = { 0 };
266 std::unique_ptr< ThreadCreator<UNetReceiver> > upThread;
271 double checkConnectionTime = { 10.0 };
272 std::mutex checkConnMutex;
276 timeout_t recvTimeout = { 5000 };
277 timeout_t prepareTime = { 2000 };
278 timeout_t evrunTimeout = { 15000 };
279 timeout_t lostTimeout = { 200 };
281 double initPause = { 5.0 };
282 std::atomic_bool initOK = {
false };
285 size_t lostPackets = { 0 };
288 IOController::IOStateList::iterator itRespond;
289 bool respondInvert = {
false };
291 IOController::IOStateList::iterator itLostPackets;
293 std::atomic_bool activated = {
false };
298 std::mutex packMutex;
304 size_t maxDifferens = { 20 };
307 bool waitClean = {
false };
310 size_t maxProcessingCount = { 100 };
312 std::atomic_bool lockUpdate = {
false };
321 IOController::IOStateList::iterator ioit;
327 typedef std::vector<CacheItem> CacheVec;
331 cache_init_ok(
false) {}
333 bool cache_init_ok = {
false };
338 typedef std::unordered_map<long, CacheInfo> CacheMap;
339 CacheMap d_icache_map;
340 CacheMap a_icache_map;
342 bool d_cache_init_ok = {
false };
343 bool a_cache_init_ok = {
false };
351 #endif // UNetReceiver_H_ Пассивный таймер
Definition: PassiveTimer.h:92
The CommonEventLoop class Реализация механизма "один eventloop, много подписчиков" (libev)...
Definition: CommonEventLoop.h:54
Definition: CallbackTimer.h:29
Definition: UNetReceiver.h:166
Definition: CommonEventLoop.h:18
Definition: UNetReceiver.h:155
const ObjectId DefaultObjectId
Definition: UniSetTypes.h:69
Definition: UDPPacket.h:93
Definition: UDPPacket.h:83
Definition: UNetReceiver.h:227
Event
Definition: UNetReceiver.h:152
void setUpdateStrategy(UpdateStrategy set)
функция должна вызываться до первого вызова start()
Definition: UNetReceiver.cc:962
Definition: UNetReceiver.h:178
Definition: UNetReceiver.h:154
Definition: UNetReceiver.h:99
UpdateStrategy
Definition: UNetReceiver.h:163
Definition: UNetReceiver.h:167
long ObjectId
Definition: UniSetTypes_i.idl:30