summaryrefslogtreecommitdiffstats
path: root/tests/arthur/baselineserver/src/baselineserver.h
blob: 8cd9f56d8b39d91e46f6b9108ccae324a8ce923e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef BASELINESERVER_H
#define BASELINESERVER_H

#include <QStringList>
#include <QTcpServer>
#include <QThread>
#include <QTcpSocket>
#include "baselineprotocol.h"
#include <QScopedPointer>
#include <QTimer>
#include <QDateTime>

// #seconds between update checks
#define HEARTBEAT 10

class BaselineServer : public QTcpServer
{
    Q_OBJECT

public:
    BaselineServer(QObject *parent = 0);

    static QString storagePath();

protected:
    void incomingConnection(int socketDescriptor);

private slots:
    void heartbeat();

private:
    QTimer *heartbeatTimer;
    QDateTime meLastMod;
    static QString storage;
};



class BaselineThread : public QThread
{
    Q_OBJECT

public:
    BaselineThread(int socketDescriptor, QObject *parent);
    void run();

private:
    int socketDescriptor;
};


class BaselineHandler : public QObject
{
    Q_OBJECT

public:
    BaselineHandler(int socketDescriptor);

private slots:
    void receiveRequest();
    void receiveDisconnect();

private:
    void provideBaseline(const QByteArray &caseId);
    void storeImage(const QByteArray &imageBlock, bool isBaseline);
    QString pathForCaseId(const QByteArray &caseId, bool isBaseline = true);

    BaselineProtocol proto;
    PlatformInfo plat;
    bool connectionEstablished;
    QString runId;
};

#endif // BASELINESERVER_H