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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/** \file ServerCatchcopy.h
\brief Define the server of catchcopy
\author alpha_one_x86
\licence GPL3, see the file COPYING */
#ifndef SERVERCATCHCOPY_H
#define SERVERCATCHCOPY_H
#include <QObject>
#include <QLocalSocket>
#include <QLocalServer>
#include <vector>
#include <string>
#include <QByteArray>
#include <QTimer>
/// \brief Define the server of catchcopy
class ServerCatchcopy : public QObject
{
Q_OBJECT
public:
ServerCatchcopy();
~ServerCatchcopy();
/// \brief return if is listening
bool isListening() const;
/// \brief try listen
bool listen();
/// \brief try close the server
void close();
/// \brief get the error string on the QLocalServer
const std::string errorStringServer() const;
/// \brief get the general error string
const std::string errorString() const;
/// \brief set the name of the server
void setName(const std::string & name);
/// \brief get the name
std::string getName() const;
/// \brief to get a client list
std::vector<std::string> clientsList() const;
private:
std::string pathSocket;
std::string name;
std::string error_string;
QLocalServer server;
uint32_t idNextClient;
struct Client
{
uint32_t id;
QLocalSocket *socket;
QByteArray data;
bool haveData;
uint32_t dataSize;
bool firstProtocolReplied;
QList<uint32_t> queryNoReplied;
QTimer *detectTimeOut;
std::string name;
};
QList<Client> clientList;
struct LinkGlobalToLocalClient
{
uint32_t idClient;
uint32_t orderId;
uint32_t globalOrderId;
};
QList<LinkGlobalToLocalClient> LinkGlobalToLocalClientList;
enum inputReturnType{Ok,Replied,ExtensionWrong,WrongArgument,WrongArgumentListSize,UnknowOrder};
inputReturnType parseInputCurrentProtocol(const uint32_t &client,const uint32_t &orderId,const std::vector<std::string> &returnList);
bool clientIdFound(const uint32_t &id) const;
uint32_t nextOrderId;
QList<uint32_t> orderList;
uint32_t incrementOrderId();
void emitNewCopyWithoutDestination(const uint32_t &client,const uint32_t &orderId,const std::vector<std::string> &sources);
void emitNewCopy(const uint32_t &client,const uint32_t &orderId,const std::vector<std::string> &sources,const std::string &destination);
void emitNewMoveWithoutDestination(const uint32_t &client,const uint32_t &orderId,const std::vector<std::string> &sources);
void emitNewMove(const uint32_t &client,const uint32_t &orderId,const std::vector<std::string> &sources,const std::string &destination);
bool checkDataIntegrity(const QByteArray &data);
protected:
void parseInput(const uint32_t &client,const uint32_t &orderId,const std::vector<std::string> &returnList);
private slots:
void newConnection();
void connectionError(const QLocalSocket::LocalSocketError &error);
void disconnected();
void readyRead();
void checkTimeOut();
public slots:
/// \brief disconnect one client
void disconnectClient(const uint32_t &id);
/// \brief reply to a client with std::vector<std::string>
void reply(const uint32_t &client,const uint32_t &orderId,const uint32_t &returnCode,const std::vector<std::string> &returnList);
/// \brief reply to a client
void reply(const uint32_t &client,const uint32_t &orderId,const uint32_t &returnCode,const std::string &returnString);
//reply
/// \brief send if the protocol is supported
void protocolSupported(const uint32_t &client,const uint32_t &orderId,const bool &value);
/// \brief send incorrect arguement list size
void incorrectArgumentListSize(const uint32_t &client,const uint32_t &orderId);
/// \brief send incorrect arguement
void incorrectArgument(const uint32_t &client,const uint32_t &orderId);
/// \brief the client is registred
void clientRegistered(const uint32_t &client,const uint32_t &orderId);
/// \brief send the server name
void serverName(const uint32_t &client,const uint32_t &orderId,const std::string &name);
/// \brief send the copy is finished
void copyFinished(const uint32_t &client,const uint32_t &orderId,const bool &withError);
/// \brief send the copy is canceled
void copyCanceled(const uint32_t &client,const uint32_t &orderId);
/// \brief send the copy is finished by global is order
void copyFinished(const uint32_t &globalOrderId,const bool &withError);
/// \brief send copy cancel by global is order
void copyCanceled(const uint32_t &globalOrderId);
/// \brief send the unknow order
void unknowOrder(const uint32_t &client,const uint32_t &orderId);
signals:
/// \brief send connected client
void connectedClient(const uint32_t &id);
/// \brief send disconnect client
void disconnectedClient(const uint32_t &id);
/// \brief have new query
void newQuery(const uint32_t &client,const uint32_t &orderId,const std::vector<std::string> &returnList);
/// \brief have new error
void error(const std::string &error);
void communicationError(const std::string &error);
//query
/// \brief ask the protocol compatility
void askProtocolCompatibility(const uint32_t &client,const uint32_t &orderId,const std::string &version);
/// \brief ask protocol extension
void askProtocolExtension(const uint32_t &client,const uint32_t &orderId,const std::string &extension);
/// \brief ask protocol extension with version
void askProtocolExtension(const uint32_t &client,const uint32_t &orderId,const std::string &extension,const std::string &version);
/// \brief send the client name, without query id
void clientName(const uint32_t &client,const std::string &name);
/// \brief send the client have ask the server name
void askServerName(const uint32_t &client,const uint32_t &orderId);
/// \brief copy is send, by globalOrderId, without destination
void newCopyWithoutDestination(const uint32_t &globalOrderId,const std::vector<std::string> &sources);
/// \brief copy is send, by globalOrderId, with destination
void newCopy(const uint32_t &globalOrderId,const std::vector<std::string> &sources,const std::string &destination);
/// \brief move is send, by globalOrderId, without destination
void newMoveWithoutDestination(const uint32_t &globalOrderId,const std::vector<std::string> &sources);
/// \brief move is send, by globalOrderId, with destination
void newMove(const uint32_t &globalOrderId,const std::vector<std::string> &sources,const std::string &destination);
};
#endif // SERVERCATCHCOPY_H
|