Revize 0cda8e8d
Přidáno uživatelem Oto Šťáva před téměř 4 roky(ů)
deltarobot/curvedataserver.h | ||
---|---|---|
4 | 4 |
#include <QObject> |
5 | 5 |
#include <QTcpServer> |
6 | 6 |
#include <QTcpSocket> |
7 |
#include <map> |
|
8 |
#include <mutex> |
|
7 | 9 |
|
8 | 10 |
class CurveDataServer : QObject |
9 | 11 |
{ |
10 | 12 |
Q_OBJECT |
11 | 13 |
|
12 | 14 |
public: |
13 |
CurveDataServer(); |
|
15 |
struct Client { |
|
16 |
static const size_t BUF_SIZE = 32; |
|
17 |
static const size_t MESSAGE_ID_SIZE = 2; |
|
18 |
|
|
19 |
QTcpSocket* socket; |
|
20 |
std::map<long, long> ping; ///< key: ping ID; value: ping timestamp (msec); |
|
21 |
long latency; ///< client's latency |
|
22 |
long lastPong; ///< timestamp of last pong |
|
23 |
|
|
24 |
char buf[BUF_SIZE]; |
|
25 |
size_t bufUsed; |
|
26 |
|
|
27 |
Client(QTcpSocket* socket); |
|
28 |
}; |
|
29 |
|
|
30 |
explicit CurveDataServer(); |
|
31 |
~CurveDataServer(); |
|
32 |
|
|
14 | 33 |
void sendActuatorPosition(float x, float y, float z); |
15 | 34 |
|
16 | 35 |
public slots: |
... | ... | |
19 | 38 |
void onReadyRead(); |
20 | 39 |
|
21 | 40 |
private: |
22 |
QByteArray *putFloatIntoMessage(QByteArray *message, int index, float f); |
|
41 |
QList<Client>::iterator clientOf(QTcpSocket *socket); |
|
42 |
|
|
43 |
void handleMessage(Client& client, uint16_t messageId, void* content); |
|
44 |
|
|
23 | 45 |
void sendPreamble(QTcpSocket *socket); |
24 | 46 |
void sendProtocolMagic(QTcpSocket *socket); |
25 | 47 |
void sendVersion(QTcpSocket *socket); |
48 |
void sendEot(QTcpSocket *socket, std::string&& message); |
|
26 | 49 |
|
27 | 50 |
QTcpServer _server; |
28 |
QList<QTcpSocket*> _sockets; |
|
51 |
|
|
52 |
std::recursive_mutex _socketsLock; |
|
53 |
QList<Client> _sockets; |
|
29 | 54 |
}; |
30 | 55 |
|
31 | 56 |
#endif // CURVEDATASERVER_H |
Také k dispozici: Unified diff
Re #8735 - Implement base server message retrieval