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" 34 #include "UNetTransport.h" 101 public std::enable_shared_from_this<UNetReceiver>
104 UNetReceiver( std::unique_ptr<UNetReceiveTransport>&& transport,
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 getTransportID()
const noexcept
146 return transport->ID();
156 typedef sigc::slot<void, const std::shared_ptr<UNetReceiver>&,
Event> EventSlot;
157 void connectEvent( EventSlot sl ) noexcept;
168 static UpdateStrategy strToUpdateStrategy(
const std::string& s ) noexcept;
189 inline std::shared_ptr<DebugStream> getLog()
194 virtual const std::string getShortInfo() const noexcept;
201 bool receive() noexcept;
202 void step() noexcept;
203 void update() noexcept;
204 void updateThread() noexcept;
205 void callback( ev::io& watcher,
int revents ) noexcept;
206 void readEvent( ev::io& watcher ) noexcept;
207 void updateEvent( ev::periodic& watcher,
int revents ) noexcept;
208 void checkConnectionEvent( ev::periodic& watcher,
int revents ) noexcept;
209 void statisticsEvent( ev::periodic& watcher,
int revents ) noexcept;
210 void initEvent( ev::timer& watcher,
int revents ) noexcept;
211 virtual
void evprepare( const ev::loop_ref& eloop ) noexcept override;
212 virtual
void evfinish(const ev::loop_ref& eloop ) noexcept override;
213 virtual std::
string wname() const noexcept
override 218 void initIterators() noexcept;
219 bool createConnection(
bool throwEx = false );
220 void checkConnection();
231 return lhs.num > rhs.num;
235 typedef std::priority_queue<UniSetUDP::UDPMessage, std::vector<UniSetUDP::UDPMessage>,
PacketCompare> PacketQueue;
240 timeout_t recvpause = { 10 };
241 timeout_t updatepause = { 100 };
243 std::unique_ptr<UNetReceiveTransport> transport;
247 ev::periodic evCheckConnection;
248 ev::periodic evStatistic;
249 ev::periodic evUpdate;
250 ev::timer evInitPause;
255 size_t recvCount = { 0 };
256 size_t upCount = { 0 };
259 size_t statRecvPerSec = { 0 };
260 size_t statUpPerSec = { 0 };
262 std::unique_ptr< ThreadCreator<UNetReceiver> > upThread;
265 static CommonEventLoop loop;
267 double checkConnectionTime = { 10.0 };
268 std::mutex checkConnMutex;
270 PassiveTimer ptRecvTimeout;
271 PassiveTimer ptPrepare;
272 timeout_t recvTimeout = { 5000 };
273 timeout_t prepareTime = { 2000 };
274 timeout_t evrunTimeout = { 15000 };
275 timeout_t lostTimeout = { 200 };
277 double initPause = { 5.0 };
278 std::atomic_bool initOK = {
false };
280 PassiveTimer ptLostTimeout;
281 size_t lostPackets = { 0 };
284 IOController::IOStateList::iterator itRespond;
285 bool respondInvert = {
false };
287 IOController::IOStateList::iterator itLostPackets;
289 std::atomic_bool activated = {
false };
292 UniSetUDP::UDPMessage pack;
293 UniSetUDP::UDPPacket r_buf;
294 std::mutex packMutex;
300 size_t maxDifferens = { 20 };
303 bool waitClean = {
false };
306 size_t maxProcessingCount = { 100 };
308 std::atomic_bool lockUpdate = {
false };
317 IOController::IOStateList::iterator ioit;
323 typedef std::vector<CacheItem> CacheVec;
327 cache_init_ok(false) {}
329 bool cache_init_ok = {
false };
334 typedef std::unordered_map<long, CacheInfo> CacheMap;
335 CacheMap d_icache_map;
336 CacheMap a_icache_map;
338 bool d_cache_init_ok = {
false };
339 bool a_cache_init_ok = {
false };
341 void initDCache( UniSetUDP::UDPMessage& pack,
bool force =
false ) noexcept;
342 void initACache( UniSetUDP::UDPMessage& pack,
bool force = false ) noexcept;
347 #endif // UNetReceiver_H_ Definition: DebugStream.h:61
Definition: SMInterface.h:31
Definition: CommonEventLoop.h:14
Definition: UNetReceiver.h:164
Definition: CommonEventLoop.h:18
Definition: UNetReceiver.h:153
const ObjectId DefaultObjectId
Definition: UniSetTypes.h:69
Definition: UDPPacket.h:106
Definition: UNetReceiver.h:225
Event
Definition: UNetReceiver.h:150
void setUpdateStrategy(UpdateStrategy set)
функция должна вызываться до первого вызова start()
Definition: UNetReceiver.cc:953
Definition: UNetReceiver.h:176
Definition: UNetReceiver.h:152
Definition: UNetReceiver.h:99
UpdateStrategy
Definition: UNetReceiver.h:161
Definition: UNetReceiver.h:165
long ObjectId
Definition: UniSetTypes_i.idl:30