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 inline bool isLockUpdate()
const noexcept
122 void resetTimeout() noexcept;
124 inline bool isRecvOK()
const noexcept
128 inline size_t getLostPacketsNum()
const noexcept
133 void setReceiveTimeout( timeout_t msec ) noexcept;
134 void setReceivePause( timeout_t msec ) noexcept;
135 void setUpdatePause( timeout_t msec ) noexcept;
136 void setLostTimeout( timeout_t msec ) noexcept;
137 void setPrepareTime( timeout_t msec ) noexcept;
138 void setCheckConnectionPause( timeout_t msec ) noexcept;
139 void setMaxDifferens(
unsigned long set ) noexcept;
144 void setMaxProcessingCount(
int set ) noexcept;
146 void forceUpdate() noexcept;
148 inline std::string getAddress()
const noexcept
152 inline int getPort()
const noexcept
164 typedef sigc::slot<void, const std::shared_ptr<UNetReceiver>&,
Event> EventSlot;
165 void connectEvent( EventSlot sl ) noexcept;
176 static UpdateStrategy strToUpdateStrategy(
const std::string& s ) noexcept;
197 inline std::shared_ptr<DebugStream> getLog()
202 virtual const std::string getShortInfo() const noexcept;
209 bool receive() noexcept;
210 void step() noexcept;
211 void update() noexcept;
212 void updateThread() noexcept;
213 void callback( ev::io& watcher,
int revents ) noexcept;
214 void readEvent( ev::io& watcher ) noexcept;
215 void updateEvent( ev::periodic& watcher,
int revents ) noexcept;
216 void checkConnectionEvent( ev::periodic& watcher,
int revents ) noexcept;
217 void statisticsEvent( ev::periodic& watcher,
int revents ) noexcept;
218 virtual
void evprepare( const ev::loop_ref& eloop ) noexcept override;
219 virtual
void evfinish(const ev::loop_ref& eloop ) noexcept override;
220 virtual std::
string wname() const noexcept
override
225 void initIterators() noexcept;
226 bool createConnection(
bool throwEx = false );
227 void checkConnection();
233 public std::binary_function<UniSetUDP::
UDPMessage, UniSetUDP::UDPMessage,
bool>
238 return lhs.num > rhs.num;
242 typedef std::priority_queue<UniSetUDP::UDPMessage, std::vector<UniSetUDP::UDPMessage>,
PacketCompare> PacketQueue;
247 timeout_t recvpause = { 10 };
248 timeout_t updatepause = { 100 };
250 std::shared_ptr<UDPReceiveU> udp;
253 Poco::Net::SocketAddress saddr;
256 ev::periodic evCheckConnection;
257 ev::periodic evStatistic;
258 ev::periodic evUpdate;
263 size_t recvCount = { 0 };
264 size_t upCount = { 0 };
267 size_t statRecvPerSec = { 0 };
268 size_t statUpPerSec = { 0 };
270 std::shared_ptr< ThreadCreator<UNetReceiver> > upThread;
273 static CommonEventLoop loop;
275 double checkConnectionTime = { 10.0 };
276 std::mutex checkConnMutex;
278 PassiveTimer ptRecvTimeout;
279 PassiveTimer ptPrepare;
280 timeout_t recvTimeout = { 5000 };
281 timeout_t prepareTime = { 2000 };
282 timeout_t lostTimeout = { 200 };
283 PassiveTimer ptLostTimeout;
284 size_t lostPackets = { 0 };
287 IOController::IOStateList::iterator itRespond;
288 bool respondInvert = {
false };
290 IOController::IOStateList::iterator itLostPackets;
292 std::atomic_bool activated = {
false };
295 UniSetUDP::UDPMessage pack;
296 UniSetUDP::UDPPacket r_buf;
297 std::mutex packMutex;
303 size_t maxDifferens = { 20 };
306 bool waitClean = {
false };
309 size_t maxProcessingCount = { 100 };
311 std::atomic_bool lockUpdate = {
false };
320 IOController::IOStateList::iterator ioit;
326 typedef std::vector<CacheItem> CacheVec;
330 cache_init_ok(false) {}
332 bool cache_init_ok = {
false };
337 typedef std::unordered_map<long, CacheInfo> CacheMap;
338 CacheMap d_icache_map;
339 CacheMap a_icache_map;
341 bool d_cache_init_ok = {
false };
342 bool a_cache_init_ok = {
false };
344 void initDCache( UniSetUDP::UDPMessage& pack,
bool force =
false ) noexcept;
345 void initACache( UniSetUDP::UDPMessage& pack,
bool force = false ) noexcept;
350 #endif // UNetReceiver_H_