summaryrefslogtreecommitdiff
path: root/test-client-catchcopy/catchcopy-api-0002/ServerCatchcopy.h
blob: 5f7af35bc4daa4163f11a93b43d80e89b16aca9e (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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/** \file ServerCatchcopy.h
\brief Define the server of catchcopy
\author alpha_one_x86
\version 0002
\date 2010 */

#ifndef SERVERCATCHCOPY_H
#define SERVERCATCHCOPY_H

#include <QObject>
#include <QLocalSocket>
#include <QLocalServer>
#include <QStringList>
#include <QString>
#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();
		/// \brief try listen
		bool listen();
		/// \brief try close the server
		void close();
		/// \brief get the error string on the QLocalServer
		const QString errorStringServer();
		/// \brief get the general error string
		const QString errorString();
		/// \brief set if automatic reply is used 
		void setAutoReply(bool value);
		/// \brief get if autoReply is set
		bool getAutoReply();
		/// \brief set the name of the server
		void setName(const QString & name);
		/// \brief get the name
		QString getName();
	private:
		QString pathSocket;
		QString name;
		QString error_string;
		QLocalServer server;
		quint32 idNextClient;
		struct Client
		{
			quint32 id;
			QLocalSocket *socket;
			QByteArray data;
			bool haveData;
			quint32 dataSize;
			bool firstProtocolReplied;
			QList<quint32> queryNoReplied;
			QTimer *detectTimeOut;
		};
		QList<Client> ClientList;
		struct LinkGlobalToLocalClient
		{
			quint32 idClient;
			quint32 orderId;
			quint32 globalOrderId;
		};
		QList<LinkGlobalToLocalClient> LinkGlobalToLocalClientList;
		enum inputReturnType{Ok,Replied,ExtensionWrong,WrongArgument,WrongArgumentListSize,UnknowOrder};
		inputReturnType parseInputCurrentProtocol(quint32 client,quint32 orderId,QStringList returnList);
		bool autoReply;
		bool clientIdFound(quint32 id);
		quint32 nextOrderId;
		QList<quint32> orderList;
		quint32 incrementOrderId();
		void emitNewCopy(quint32 client,quint32 orderId,QStringList sources);
		void emitNewCopy(quint32 client,quint32 orderId,QStringList sources,QString destination);
		void emitNewMove(quint32 client,quint32 orderId,QStringList sources);
		void emitNewMove(quint32 client,quint32 orderId,QStringList sources,QString destination);
		bool checkDataIntegrity(QByteArray data);
	protected:
		void parseInput(quint32 client,quint32 orderId,QStringList returnList);
	private slots:
		void newConnection();
		void connectionError(QLocalSocket::LocalSocketError error);
		void disconnected();
		void readyRead();
		void checkTimeOut();
	public slots:
		/// \brief disconnect one client
		void disconnectClient(quint32 id);
		/// \brief reply to a client with QStringList
		void reply(quint32 client,quint32 orderId,quint32 returnCode,QStringList returnList);
		/// \brief reply to a client
		void reply(quint32 client,quint32 orderId,quint32 returnCode,QString returnString);
		//reply
		/// \brief send if the protocol is supported
		void protocolSupported(quint32 client,quint32 orderId,bool value);
		/// \brief send incorrect arguement list size
		void incorrectArgumentListSize(quint32 client,quint32 orderId);
		/// \brief send incorrect arguement
		void incorrectArgument(quint32 client,quint32 orderId);
		/// \brief send if protocol extension is supported
		void protocolExtensionSupported(quint32 client,quint32 orderId,bool value);
		/// \brief the client is registred
		void clientRegistered(quint32 client,quint32 orderId);
		/// \brief send the server name
		void serverName(quint32 client,quint32 orderId,QString name);
		/// \brief send the copy is finished
		void copyFinished(quint32 client,quint32 orderId,bool withError);
		/// \brief send the copy is canceled
		void copyCanceled(quint32 client,quint32 orderId);
		/// \brief send the copy is finished by global is order
		void copyFinished(quint32 globalOrderId,bool withError);
		/// \brief send copy cancel by global is order
		void copyCanceled(quint32 globalOrderId);
		/// \brief send the unknow order
		void unknowOrder(quint32 client,quint32 orderId);
	signals:
		/// \brief send connected client
		void connectedClient(quint32 id);
		/// \brief send disconnect client
		void disconnectedClient(quint32 id);
		/// \brief have new query
		void newQuery(quint32 client,quint32 orderId,QStringList returnList);
		/// \brief send new data as string list
		void dataSend(quint32 client,quint32 orderId,quint32 returnCode,QStringList returnList);
		/// \brief send new data as raw data
		void dataSend(quint32 client,quint32 orderId,quint32 returnCode,QByteArray block);
		/// \brief have new error
		void error(QString error);
		//query
		/// \brief ask the protocol compatility
		void askProtocolCompatibility(quint32 client,quint32 orderId,QString version);
		/// \brief ask protocol extension
		void askProtocolExtension(quint32 client,quint32 orderId,QString extension);
		/// \brief ask protocol extension with version
		void askProtocolExtension(quint32 client,quint32 orderId,QString extension,QString version);
		/// \brief send the client name, with query id
		void clientName(quint32 client,quint32 orderId,QString name);
		/// \brief send the client name, without query id
		void clientName(quint32 client,QString name);
		/// \brief send the client have ask the server name
		void askServerName(quint32 client,quint32 orderId);
		/// \brief copy is send, without destination
		void newCopy(quint32 client,quint32 orderId,QStringList sources);
		/// \brief copy is send, with destination
		void newCopy(quint32 client,quint32 orderId,QStringList sources,QString destination);
		/// \brief move is send, without destination
		void newMove(quint32 client,quint32 orderId,QStringList sources);
		/// \brief move is send, with destination
		void newMove(quint32 client,quint32 orderId,QStringList sources,QString destination);
		/// \brief copy is send, by globalOrderId, without destination
		void newCopy(quint32 globalOrderId,QStringList sources);
		/// \brief copy is send, by globalOrderId, with destination
		void newCopy(quint32 globalOrderId,QStringList sources,QString destination);
		/// \brief move is send, by globalOrderId, without destination
		void newMove(quint32 globalOrderId,QStringList sources);
		/// \brief move is send, by globalOrderId, with destination
		void newMove(quint32 globalOrderId,QStringList sources,QString destination);
};

#endif // SERVERCATCHCOPY_H