summaryrefslogtreecommitdiff
path: root/plugins/Listener/catchcopy-v0002/catchcopy-api-0002/ClientCatchcopy.h
blob: 4c15890dcde1b23681e9008cbe0886ed9e3319cf (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
/** \file ClientCatchcopy.h
\brief Define the catchcopy client
\author alpha_one_x86
\licence GPL3, see the file COPYING */

#ifndef CLIENTCATCHCOPY_H
#define CLIENTCATCHCOPY_H

#include <QObject>
#include <QLocalSocket>
#include <QStringList>
#include <QString>
#include <QByteArray>
#include <QTimer>

/// \brief Define the catchcopy client
class ClientCatchcopy : public QObject
{
	Q_OBJECT
	public:
		ClientCatchcopy();
		/// \brief get the socket stat
		QLocalSocket::LocalSocketState state();
		/// \brief error string about the socket
		const QString errorStringSocket();
		/// \brief general error string
		const QString errorString();
	public slots:
		void connectToServer();
		void disconnectFromServer();
		//to test and internal use
		/// \brief to send order
		quint32 sendProtocol();
		/// \brief ask the server name
		quint32 askServerName();
		/// \brief set the client name
		quint32 setClientName(const QString & name);
		/// \brief check protocol extension
		quint32 checkProtocolExtension(const QString & name);
		/// \brief check protocol extension and version
		quint32 checkProtocolExtension(const QString & name,const QString & version);
		/// \brief add copy with destination
		quint32 addCopyWithDestination(const QStringList & sources,const QString & destination);
		/// \brief add copy without destination
		quint32 addCopyWithoutDestination(const QStringList & sources);
		/// \brief add move with destination
		quint32 addMoveWithDestination(const QStringList & sources,const QString & destination);
		/// \brief add move without destination
		quint32 addMoveWithoutDestination(const QStringList & sources);
		/// \brief to send stream of string list
		quint32 sendRawOrderList(const QStringList & order);
	signals:
		/// \brief is connected
		void connected();
		/// \brief is disconnected
		void disconnected();
		/// \brief the socket state have changed
		void stateChanged(QLocalSocket::LocalSocketState socketState);
		/// \brief send the error string
		void error(QString error);
		/// \brief send socket error
		void errorSocket(QLocalSocket::LocalSocketError socketError);
		/// \brief have new reply
		void newReply(quint32 orderId,quint32 returnCode,QStringList returnList);
		/// \brief have data send
		void dataSend(quint32 orderId,QByteArray data);
		/// \brief have data send by string list
		void dataSend(quint32 orderId,QStringList data);
		/// \brief have unknow reply
		void unknowReply(quint32 orderId);
		//reply
		/// \brief protocol is supported
		void protocolSupported(quint32 orderId);
		/// \brief incorrect argument list size
		void incorrectArgumentListSize(quint32 orderId);
		/// \brief incorrect argument
		void incorrectArgument(quint32 orderId);
		/// \brief protocol not supported
		void protocolNotSupported(quint32 orderId);
		/// \brief protocol extension supported
		void protocolExtensionSupported(quint32 orderId,bool isSupported);
		/// \brief client is registred
		void clientRegistered(quint32 orderId);
		/// \brief have the server name
		void serverName(quint32 orderId,QString name);
		/// \brief copy finished
		void copyFinished(quint32 orderId,bool withError);
		/// \brief copy canceled
		void copyCanceled(quint32 orderId);
		/// \brief have unknow order
		void unknowOrder(quint32 orderId); //the server have not understand the order
	private:
		QLocalSocket socket;
		QString error_string;
		quint32 idNextOrder;
		QByteArray data;
		bool haveData;
		int dataSize;
		quint32 orderIdFirstSendProtocol;
		QTimer detectTimeOut;
		bool sendProtocolReplied;
		QList<quint32> notRepliedQuery;
		bool checkDataIntegrity(QByteArray data);
	private slots:
		void readyRead();
		void disconnectedFromSocket();
		void socketIsConnected();
		void checkTimeOut();
	protected:
		bool parseReply(quint32 orderId,quint32 returnCode,QStringList returnList);
};

#endif // CLIENTCATCHCOPY_H