Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 6d9543aa

Přidáno uživatelem Jakub Hejman před téměř 4 roky(ů)

Re #8899 - Server data reception

Zobrazit rozdíly:

deltarobot/curvedataserver.h
6 6
#include <QTcpSocket>
7 7
#include <map>
8 8
#include <mutex>
9

  
10

  
11
#include "../element/trajectory.hpp" //obsahuje MAX_CURVE_SIZE kterou se ridi sendNewCurve 4D
9
#include <thread>
12 10

  
13 11
class CurveDataServer : QObject
14 12
{
......
16 14

  
17 15
public:
18 16
    struct Client {
19
        static const size_t BUF_SIZE = 32;
17
        static const size_t BUF_SIZE = 4096;
20 18
        static const size_t MESSAGE_ID_SIZE = 2;
21 19

  
22 20
        QTcpSocket* socket;
23
        std::map<long, long> ping;  ///< key: ping ID;  value: ping timestamp (msec);
24
        long latency;               ///< client's latency
25
        long lastPong;              ///< timestamp of last pong
21
        std::map<uint64_t, uint64_t> ping;  ///< key: ping ID;  value: ping timestamp (msec);
22
        uint64_t latency;               ///< client's latency
23
        uint64_t lastPong;              ///< timestamp of last pong
26 24

  
27 25
        char buf[BUF_SIZE];
28 26
        size_t bufUsed;
29 27

  
28
        bool magic = false;
29
        bool version = false;
30
        bool initialized = false;
31

  
30 32
        Client(QTcpSocket* socket);
31 33
    };
32 34

  
......
38 40
    void sendTargetDirection(float x, float y, float z);
39 41
    void sendNewCurve(QList<QVector4D> &points);
40 42
    void sendNewCurve(QList<QVector3D> &points);
43
    void sendCurve(Client &client);
44

  
45
    void processPings();            ///< send pings, check timeouts
41 46

  
42 47
public slots:
43 48
    void onNewConnection();
......
48 53
    QList<Client>::iterator clientOf(QTcpSocket *socket);
49 54

  
50 55
    void handleMessage(Client& client, uint16_t messageId, void* content);
56
    void handleProtocolMagic(Client& client, char* content);
57
    void handleVersion(Client& client, uint8_t content);
58
    void handlePong(Client& client, uint64_t* content);
59
    void handleEOT(Client& client, char* content);
60

  
61
    void validPreamble(Client& client);
62
    void removeSocket(QTcpSocket *socket);
63
    void terminateConnection(Client& client, std::string&& reason);
64
    void sendPing(Client& client);
51 65

  
52 66
    void sendPreamble(QTcpSocket *socket);
53 67
    void sendProtocolMagic(QTcpSocket *socket);
54 68
    void sendVersion(QTcpSocket *socket);
55 69
    void sendEot(QTcpSocket *socket, std::string&& message);
56 70

  
71
    void sendMessageToAllConnected(QByteArray &message);
72

  
73
    void threadFunction();
74

  
57 75
    QTcpServer _server;
76
    std::thread _pingThread;
77

  
78
    volatile bool _threadIsRunning = true;
58 79

  
59 80
    std::recursive_mutex _socketsLock;
60 81
    QList<Client> _sockets;
82

  
83
    std::recursive_mutex _currentCurveLock;
84
    QList<QVector3D> _currentCurve;
61 85
};
62 86

  
63 87
#endif // CURVEDATASERVER_H

Také k dispozici: Unified diff