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
105 ,
bool nocheckConnection =
false 106 ,
const std::string& prefix =
"unet" );
112 inline const std::string getName()
const 118 void setLockUpdate(
bool st ) noexcept;
119 bool isLockUpdate()
const noexcept;
121 void resetTimeout() noexcept;
123 bool isInitOK()
const noexcept;
124 bool isRecvOK()
const noexcept;
125 size_t getLostPacketsNum()
const noexcept;
127 void setReceiveTimeout( timeout_t msec ) noexcept;
128 void setReceivePause( timeout_t msec ) noexcept;
129 void setUpdatePause( timeout_t msec ) noexcept;
130 void setLostTimeout( timeout_t msec ) noexcept;
131 void setPrepareTime( timeout_t msec ) noexcept;
132 void setCheckConnectionPause( timeout_t msec ) noexcept;
133 void setMaxDifferens(
unsigned long set ) noexcept;
134 void setEvrunTimeout(timeout_t msec ) noexcept;
135 void setInitPause( timeout_t msec ) noexcept;
140 void setMaxProcessingCount(
int set ) noexcept;
142 void forceUpdate() noexcept;
144 inline std::string getAddress()
const noexcept
148 inline int getPort()
const noexcept
160 typedef sigc::slot<void, const std::shared_ptr<UNetReceiver>&,
Event> EventSlot;
161 void connectEvent( EventSlot sl ) noexcept;
172 static UpdateStrategy strToUpdateStrategy(
const std::string& s ) noexcept;
193 inline std::shared_ptr<DebugStream> getLog()
198 virtual const std::string getShortInfo()
const noexcept;
202 const std::shared_ptr<SMInterface> shm;
203 std::shared_ptr<DebugStream> unetlog;
205 bool receive() noexcept;
206 void step() noexcept;
207 void update() noexcept;
208 void updateThread() noexcept;
209 void callback( ev::io& watcher,
int revents ) noexcept;
210 void readEvent( ev::io& watcher ) noexcept;
211 void updateEvent( ev::periodic& watcher,
int revents ) noexcept;
212 void checkConnectionEvent( ev::periodic& watcher,
int revents ) noexcept;
213 void statisticsEvent( ev::periodic& watcher,
int revents ) noexcept;
214 void initEvent( ev::timer& watcher,
int revents ) noexcept;
215 virtual void evprepare(
const ev::loop_ref& eloop ) noexcept
override;
216 virtual void evfinish(
const ev::loop_ref& eloop ) noexcept
override;
217 virtual std::string wname()
const noexcept
override 222 void initIterators() noexcept;
223 bool createConnection(
bool throwEx =
false );
224 void checkConnection();
230 public std::binary_function<UniSetUDP::UDPMessage, UniSetUDP::UDPMessage, bool>
235 return lhs.num > rhs.num;
239 typedef std::priority_queue<UniSetUDP::UDPMessage, std::vector<UniSetUDP::UDPMessage>,
PacketCompare> PacketQueue;
244 timeout_t recvpause = { 10 };
245 timeout_t updatepause = { 100 };
247 std::unique_ptr<UDPReceiveU> udp;
250 Poco::Net::SocketAddress saddr;
253 ev::periodic evCheckConnection;
254 ev::periodic evStatistic;
255 ev::periodic evUpdate;
256 ev::timer evInitPause;
261 size_t recvCount = { 0 };
262 size_t upCount = { 0 };
265 size_t statRecvPerSec = { 0 };
266 size_t statUpPerSec = { 0 };
268 std::unique_ptr< ThreadCreator<UNetReceiver> > upThread;
273 double checkConnectionTime = { 10.0 };
274 std::mutex checkConnMutex;
278 timeout_t recvTimeout = { 5000 };
279 timeout_t prepareTime = { 2000 };
280 timeout_t evrunTimeout = { 15000 };
281 timeout_t lostTimeout = { 200 };
283 double initPause = { 5.0 };
284 std::atomic_bool initOK = {
false };
287 size_t lostPackets = { 0 };
290 IOController::IOStateList::iterator itRespond;
291 bool respondInvert = {
false };
293 IOController::IOStateList::iterator itLostPackets;
295 std::atomic_bool activated = {
false };
300 std::mutex packMutex;
306 size_t maxDifferens = { 20 };
309 bool waitClean = {
false };
312 size_t maxProcessingCount = { 100 };
314 std::atomic_bool lockUpdate = {
false };
323 IOController::IOStateList::iterator ioit;
329 typedef std::vector<CacheItem> CacheVec;
333 cache_init_ok(
false) {}
335 bool cache_init_ok = {
false };
340 typedef std::unordered_map<long, CacheInfo> CacheMap;
341 CacheMap d_icache_map;
342 CacheMap a_icache_map;
344 bool d_cache_init_ok = {
false };
345 bool a_cache_init_ok = {
false };
353 #endif // UNetReceiver_H_ Пассивный таймер
Definition: PassiveTimer.h:92
The CommonEventLoop class Реализация механизма "один eventloop, много подписчиков" (libev)...
Definition: CommonEventLoop.h:54
Definition: CommonEventLoop.h:14
Definition: UNetReceiver.h:168
Definition: CommonEventLoop.h:18
Definition: UNetReceiver.h:157
const ObjectId DefaultObjectId
Definition: UniSetTypes.h:69
Definition: UDPPacket.h:105
Definition: UDPPacket.h:95
Definition: UNetReceiver.h:229
Event
Definition: UNetReceiver.h:154
void setUpdateStrategy(UpdateStrategy set)
функция должна вызываться до первого вызова start()
Definition: UNetReceiver.cc:968
Definition: UNetReceiver.h:180
Definition: UNetReceiver.h:156
Definition: UNetReceiver.h:99
UpdateStrategy
Definition: UNetReceiver.h:165
Definition: UNetReceiver.h:169
long ObjectId
Definition: UniSetTypes_i.idl:30