source: trunk/tools/qtestlib/wince/cetcpsyncserver/commands.h@ 651

Last change on this file since 651 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

  • Property svn:eol-style set to native
File size: 8.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the tools applications of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41#ifndef COMMANDS_INCL
42#define COMMANDS_INCL
43
44#include "transfer_global.h"
45
46#include <QtNetwork/QTcpSocket>
47#include <QtCore/QString>
48#include <QtCore/QFile>
49#include <QtCore/QDir>
50#include <QtCore/QDirIterator>
51#include <windows.h>
52
53// debug output
54#define DEBUG_LEVEL 2
55inline void debugOutput(int level, const char* text)
56{
57 if (level >= DEBUG_LEVEL)
58 qDebug() << text;
59}
60
61inline void debugOutput(int level, const QString &text)
62{
63 if (level >= DEBUG_LEVEL)
64 qDebug() << text;
65}
66// Basic abtract command class
67class AbstractCommand : public QObject
68{
69 Q_OBJECT
70public:
71 AbstractCommand();
72 virtual ~AbstractCommand();
73
74 void setSocket(QTcpSocket*);
75 QTcpSocket* socket();
76
77 void reportSuccess();
78 void reportError();
79
80public slots:
81 virtual void dataReceived(QByteArray&);
82 virtual void commandFinished();
83
84private slots:
85 void _readData();
86 void _disconnect();
87
88private:
89 QTcpSocket* m_socket;
90};
91
92// File Creation class
93class CreateFileCommand : public AbstractCommand
94{
95 Q_OBJECT
96public:
97 CreateFileCommand();
98 ~CreateFileCommand();
99
100public slots:
101 void dataReceived(QByteArray&);
102 void commandFinished();
103
104private:
105 CreateFileOptions m_options;
106 QFile m_file;
107 int m_dataCount;
108};
109
110inline AbstractCommand* instCreateFile() { return new CreateFileCommand(); }
111
112// Directory Creation class
113class CreateDirectoryCommand : public AbstractCommand
114{
115 Q_OBJECT
116public:
117 CreateDirectoryCommand();
118 ~CreateDirectoryCommand();
119
120public slots:
121 void dataReceived(QByteArray&);
122 void commandFinished();
123};
124inline AbstractCommand* instCreateDirectory() { return new CreateDirectoryCommand(); }
125
126// File copy class
127class CopyFileCommand : public AbstractCommand
128{
129 Q_OBJECT
130public:
131 CopyFileCommand();
132 ~CopyFileCommand();
133
134public slots:
135 void dataReceived(QByteArray&);
136 void commandFinished();
137};
138inline AbstractCommand* instCopyFile() { return new CopyFileCommand(); }
139
140// Copy directory class
141class CopyDirectoryCommand : public AbstractCommand
142{
143 Q_OBJECT
144public:
145 CopyDirectoryCommand();
146 ~CopyDirectoryCommand();
147
148public slots:
149 void dataReceived(QByteArray&);
150 void commandFinished();
151private:
152 bool copyDir(const QString &from, const QString &to, bool recursive);
153};
154inline AbstractCommand* instCopyDirectory() { return new CopyDirectoryCommand(); }
155
156// Delete File class
157class DeleteFileCommand : public AbstractCommand
158{
159 Q_OBJECT
160public:
161 DeleteFileCommand();
162 ~DeleteFileCommand();
163public slots:
164 void dataReceived(QByteArray&);
165 void commandFinished();
166};
167inline AbstractCommand* instDeleteFile() { return new DeleteFileCommand(); }
168
169// Delete Directory class
170class DeleteDirectoryCommand : public AbstractCommand
171{
172 Q_OBJECT
173public:
174 DeleteDirectoryCommand();
175 ~DeleteDirectoryCommand();
176public slots:
177 void dataReceived(QByteArray&);
178 void commandFinished();
179private:
180 bool deleteDirectory(const QString &dirName, bool recursive, bool failIfContentExists);
181};
182inline AbstractCommand* instDeleteDirectory() { return new DeleteDirectoryCommand(); }
183
184// Execute application class
185class ExecuteCommand : public AbstractCommand
186{
187 Q_OBJECT
188public:
189 ExecuteCommand();
190 ~ExecuteCommand();
191public slots:
192 void dataReceived(QByteArray&);
193 void commandFinished();
194private:
195 void _doExecute();
196 QString m_program;
197 QStringList m_arguments;
198 int m_argumentCount;
199 bool m_waitFinished;
200 int m_timeout;
201};
202inline AbstractCommand* instExecution() { return new ExecuteCommand(); }
203
204// Read File class
205class ReadFileCommand : public AbstractCommand
206{
207 Q_OBJECT
208public:
209 ReadFileCommand();
210 ~ReadFileCommand();
211public slots:
212 void dataReceived(QByteArray&);
213 void commandFinished();
214private:
215 QString m_fileName;
216 QFile m_file;
217 qint64 m_currentPos;
218 qint64 m_fileSize;
219};
220inline AbstractCommand* instReadFile() { return new ReadFileCommand(); }
221
222// Read Directory class
223class ReadDirectoryCommand : public AbstractCommand
224{
225 Q_OBJECT
226public:
227 ReadDirectoryCommand();
228 ~ReadDirectoryCommand();
229public slots:
230 void dataReceived(QByteArray&);
231 void commandFinished();
232private:
233 QString m_dirName;
234 QDir m_dir;
235 QDirIterator* m_iterator;
236};
237inline AbstractCommand* instReadDirectory() { return new ReadDirectoryCommand(); }
238
239// Read File Time class
240class FileTimeCommand : public AbstractCommand
241{
242 Q_OBJECT
243public:
244 FileTimeCommand();
245 ~FileTimeCommand();
246public slots:
247 void dataReceived(QByteArray&);
248 void commandFinished();
249};
250inline AbstractCommand* instFileTime() { return new FileTimeCommand(); }
251
252// Time stamp class
253class TimeStampCommand : public AbstractCommand
254{
255 Q_OBJECT
256public:
257 TimeStampCommand();
258 ~TimeStampCommand();
259public slots:
260 void dataReceived(QByteArray&);
261 void commandFinished();
262};
263inline AbstractCommand* instTimeStamp() { return new TimeStampCommand(); }
264
265// Access part
266typedef AbstractCommand* (*instantiator)();
267
268struct CommandInfo
269{
270 CommandInfo(const QString &name, instantiator func) : commandName(name) , commandFunc(func) { }
271 QString commandName;
272 instantiator commandFunc;
273};
274
275inline QList<CommandInfo> availableCommands()
276{
277 QList<CommandInfo> list;
278 list.append(CommandInfo(QLatin1String(COMMAND_CREATE_FILE), instCreateFile));
279 list.append(CommandInfo(QLatin1String(COMMAND_CREATE_DIRECTORY), instCreateDirectory));
280 list.append(CommandInfo(QLatin1String(COMMAND_COPY_FILE), instCopyFile));
281 list.append(CommandInfo(QLatin1String(COMMAND_COPY_DIRECTORY), instCopyDirectory));
282 list.append(CommandInfo(QLatin1String(COMMAND_DELETE_FILE), instDeleteFile));
283 list.append(CommandInfo(QLatin1String(COMMAND_DELETE_DIRECTORY), instDeleteDirectory));
284 list.append(CommandInfo(QLatin1String(COMMAND_EXECUTE), instExecution));
285 list.append(CommandInfo(QLatin1String(COMMAND_READ_FILE), instReadFile));
286 list.append(CommandInfo(QLatin1String(COMMAND_READ_DIRECTORY), instReadDirectory));
287 list.append(CommandInfo(QLatin1String(COMMAND_FILE_TIME), instFileTime));
288 list.append(CommandInfo(QLatin1String(COMMAND_TIME_STAMP), instTimeStamp));
289 return list;
290}
291
292#endif
Note: See TracBrowser for help on using the repository browser.