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"
104 public std::enable_shared_from_this<UNetReceiver>
107 UNetReceiver( std::unique_ptr<UNetReceiveTransport>&& transport,
const std::shared_ptr<SMInterface>& smi
108 ,
bool nocheckConnection =
false
109 ,
const std::string& prefix =
"unet" );
115 inline std::string getName()
const noexcept
121 void setLockUpdate(
bool st ) noexcept;
122 bool isLockUpdate()
const noexcept;
124 void resetTimeout() noexcept;
126 bool isInitOK()
const noexcept;
127 bool isRecvOK()
const noexcept;
128 size_t getLostPacketsNum()
const noexcept;
130 void setReceiveTimeout( timeout_t msec ) noexcept;
131 void setUpdatePause( timeout_t msec ) noexcept;
132 void setLostTimeout( timeout_t msec ) noexcept;
133 void setPrepareTime( timeout_t msec ) noexcept;
134 void setCheckConnectionPause( timeout_t msec ) noexcept;
135 void setMaxDifferens(
unsigned long set ) noexcept;
136 void setEvrunTimeout(timeout_t msec ) noexcept;
137 void setInitPause( timeout_t msec ) noexcept;
138 void setBufferSize(
size_t sz ) noexcept;
139 void setMaxReceiveAtTime(
size_t sz ) noexcept;
140 void setIgnoreCRC(
bool set ) noexcept;
145 void forceUpdate() noexcept;
147 inline std::string getTransportID()
const noexcept
149 return transport->ID();
159 typedef sigc::slot<void, const std::shared_ptr<UNetReceiver>&,
Event> EventSlot;
160 void connectEvent( EventSlot sl ) noexcept;
163 inline std::shared_ptr<DebugStream> getLog() noexcept
168 std::string getShortInfo() const noexcept;
172 const std::shared_ptr<SMInterface> shm;
182 ReceiveRetCode receive() noexcept;
183 void update() noexcept;
184 void callback( ev::io& watcher,
int revents ) noexcept;
185 void readEvent( ev::io& watcher ) noexcept;
186 void updateEvent( ev::periodic& watcher,
int revents ) noexcept;
187 void checkConnectionEvent( ev::periodic& watcher,
int revents ) noexcept;
188 void statisticsEvent( ev::periodic& watcher,
int revents ) noexcept;
189 void onForceUpdate( ev::async& watcher,
int revents ) noexcept;
190 void initEvent( ev::timer& watcher,
int revents ) noexcept;
191 virtual
void evprepare( const ev::loop_ref& eloop ) noexcept override;
192 virtual
void evfinish(const ev::loop_ref& eloop ) noexcept override;
193 virtual std::
string wname() const noexcept
override
198 void initIterators() noexcept;
199 bool createConnection(
bool throwEx = false );
200 bool checkConnection();
201 size_t rnext(
size_t num );
206 timeout_t updatepause = { 100 };
208 std::unique_ptr<UNetReceiveTransport> transport;
212 ev::periodic evCheckConnection;
213 ev::periodic evStatistic;
214 ev::periodic evUpdate;
215 ev::timer evInitPause;
216 ev::async evForceUpdate;
219 size_t recvCount = { 0 };
220 size_t upCount = { 0 };
221 std::chrono::steady_clock::time_point t_start;
222 std::chrono::steady_clock::time_point t_end;
223 std::chrono::steady_clock::time_point t_stats;
228 float recvPerSec = {0};
229 float upPerSec = {0};
230 size_t upProcessingTime_microsec = {0};
231 size_t recvProcessingTime_microsec = {0};
237 static CommonEventLoop loop;
239 double checkConnectionTime = { 10.0 };
240 std::mutex checkConnMutex;
242 PassiveTimer ptRecvTimeout;
243 PassiveTimer ptPrepare;
244 timeout_t recvTimeout = { 5000 };
245 timeout_t prepareTime = { 2000 };
246 timeout_t evrunTimeout = { 15000 };
247 timeout_t lostTimeout = { 200 };
248 size_t maxReceiveCount = { 5 };
250 double initPause = { 5.0 };
251 std::atomic_bool initOK = {
false };
253 PassiveTimer ptLostTimeout;
254 size_t lostPackets = { 0 };
257 IOController::IOStateList::iterator itRespond;
258 bool respondInvert = {
false };
260 IOController::IOStateList::iterator itLostPackets;
262 std::atomic_bool activated = {
false };
264 size_t cbufSize = { 100 };
265 std::vector<UniSetUDP::UDPMessage> cbuf;
268 UniSetUDP::UDPMessage* pack;
273 size_t maxDifferens = { 20 };
275 std::atomic_bool lockUpdate = {
false };
284 IOController::IOStateList::iterator ioit;
289 typedef std::vector<CacheItem> CacheVec;
296 CacheInfo(): crc(0) {}
300 typedef std::unordered_map<long, CacheInfo> CacheMap;
301 CacheMap d_icache_map;
302 CacheMap a_icache_map;
304 bool ignoreCRC = {
false };
306 CacheInfo* getDCache( UniSetUDP::UDPMessage* upack ) noexcept;
307 CacheInfo* getACache( UniSetUDP::UDPMessage* pack ) noexcept;
Definition: DebugStream.h:62
Definition: CommonEventLoop.h:19
Definition: UNetReceiver.h:105
Event
Definition: UNetReceiver.h:154
@ evTimeout
Definition: UNetReceiver.h:156
@ evOK
Definition: UNetReceiver.h:155
Definition: CommonEventLoop.h:15
const ObjectId DefaultObjectId
Definition: UniSetTypes.h:70
long ObjectId
Definition: UniSetTypes_i.idl:30