Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 9360266c

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

  • ID 9360266c1be920813d9c8f9016e2003a5f8ae1f1
  • Rodič 93572855

Re #8735 - Server data retrieval structure

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);
41 44

  
42 45
public slots:
43 46
    void onNewConnection();
......
48 51
    QList<Client>::iterator clientOf(QTcpSocket *socket);
49 52

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

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

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

  
69
    void sendMessageToAllConnected(QByteArray &message);
70

  
71
    void threadFunction();
72

  
57 73
    QTcpServer _server;
74
    std::thread _pingThread;
75

  
76
    volatile bool _threadIsRunning = true;
58 77

  
59 78
    std::recursive_mutex _socketsLock;
60 79
    QList<Client> _sockets;
80

  
81
    std::recursive_mutex _currentCurveLock;
82
    QList<QVector3D> _currentCurve;
61 83
};
62 84

  
63 85
#endif // CURVEDATASERVER_H

Také k dispozici: Unified diff