-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathagent_qtmonkey_communication.hpp
116 lines (101 loc) · 2.47 KB
/
agent_qtmonkey_communication.hpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#pragma once
#include <cstdint>
#include <memory>
#include <QAtomicInt>
#include <QtCore/QBasicTimer>
#include <QtCore/QObject>
#include <QtNetwork/QTcpServer>
#include <QtNetwork/QTcpSocket>
#include "shared_resource.hpp"
namespace qt_monkey_agent
{
namespace Private
{
class Script;
enum class PacketTypeForAgent : uint32_t {
RunScript,
SetScriptFileName,
// TODO: may be we need stuff bellow?
SetBreakPointInScript,
ContinueScript,
HaltScript,
CloseAck,
};
enum class PacketTypeForMonkey : uint32_t {
NewUserAppEvent,
ScriptError,
ScriptEnd,
ScriptLog,
// TODO: may be need?
ScriptStopOnBreakPoint,
Close,
};
class CommunicationMonkeyPart
#ifndef Q_MOC_RUN
final
#endif
: public QObject
{
Q_OBJECT
signals:
void newUserAppEvent(QString);
void scriptError(QString);
void scriptEnd();
void scriptLog(QString);
void error(QString);
void agentReadyToRunScript();
public:
explicit CommunicationMonkeyPart(QObject *parent = nullptr);
void sendCommand(PacketTypeForAgent pt, const QString &);
bool isConnectedState() const;
void close();
const std::pair<QString, QString> &requiredProcessEnvironment() const
{
return envPrefs_;
}
private slots:
void handleNewConnection();
void readDataFromClientSocket();
void flushSendData();
void clientDisconnected();
void connectionError(QAbstractSocket::SocketError);
private:
std::unique_ptr<QTcpServer> controlSock_;
QTcpSocket *curClient_ = nullptr;
QByteArray sendBuf_;
QByteArray recvBuf_;
std::pair<QString, QString> envPrefs_;
};
class CommunicationAgentPart
#ifndef Q_MOC_RUN
final
#endif
: public QObject
{
Q_OBJECT
signals:
void error(const QString &);
void runScript(const qt_monkey_agent::Private::Script &);
public:
explicit CommunicationAgentPart(QObject *parent = nullptr) : QObject(parent)
{
}
void sendCommand(PacketTypeForMonkey pt, const QString &);
bool connectToMonkey();
void flushSendData();
bool hasCloseAck();
private slots:
void sendData();
void readCommands();
void connectionError(QAbstractSocket::SocketError);
private:
QTcpSocket sock_;
QBasicTimer timer_;
qt_monkey_common::SharedResource<QByteArray> sendBuf_;
QByteArray recvBuf_;
QString currentScriptFileName_;
QAtomicInt close_ack_{0};
void timerEvent(QTimerEvent *) override;
};
} // namespace Private
} // namespace qt_monkey_agent