-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipc.h
125 lines (104 loc) · 2.3 KB
/
ipc.h
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
117
118
119
120
121
122
123
124
125
#ifndef IPC_H
#define IPC_H
/*
Формат сообщения:
1 : запрос/ответ |
4 : команда/результат |
2 : размер данных | минимальный размер сообщения = 7 байт
x : данные
*/
#include <QApplication>
#include "jconfig.h"
#define IPC_DEF_KEY "terminal"
#define IPC_DEF_TIMEOUT 1000 // ms
#define IPC_DEF_TIMER 10 // ms
#define IPC_SIZE 256
class Ipc : public QObject
{
Q_OBJECT
public:
enum Mode
{
ModeApplication,
ModeManager
};
enum Cmd
{
CmdNone,
CmdStatus,
CmdStop,
CmdPid,
CmdConfigRead,
CmdLogReopen,
CmdStateSave
};
enum Result
{
ResultOk,
ResultNotImplemented,
ResultFail,
ResultTimedOut
};
enum State
{
StateNone,
StateStarting,
StateRunning,
StateError,
StateStopping
};
enum Error
{
ErrorNone,
ErrorAlreadyExists,
ErrorNotFound,
ErrorShmem,
ErrorOther
};
struct Message
{
unsigned char sender;
unsigned code;
unsigned short dataSize;
};
Ipc(const JConfig &conf, enum Mode mode);
~Ipc();
bool connect(enum Cmd code, const QObject *reciever, const char *member);
bool connect(enum Result code, const QObject *reciever, const char *member);
bool cmd(enum Cmd code);
bool reply(enum Result code, const QByteArray &data = QByteArray());
inline enum Mode mode() { return m_mode; }
inline enum Error error() { return m_error; }
public slots:
void disable();
signals:
// cmds
void status();
void stop();
void configRead();
void logReopen();
void stateSave();
// results
void ok(enum Cmd, QByteArray data);
void notImplemented(enum Cmd);
void fail(enum Cmd, QByteArray errmsg);
void timedOut(enum Cmd);
protected:
void timerEvent(QTimerEvent *event);
private:
QSharedMemory m_shared;
int m_timer, m_timerId, m_timeout;
enum Mode m_mode;
QTime m_cmdSent;
QList<enum Cmd> m_cmdConnected;
QList<enum Result> m_resultConnected;
enum State m_state;
enum Error m_error;
enum Cmd m_sentCmd;
void stopTimer();
bool send(unsigned int code, const QByteArray &data, bool gLocked = false);
bool send(unsigned int code, bool gLocked = false);
void notify(enum Cmd code);
void notify(enum Result code, QByteArray data);
};
#endif // IPC_H