tools/qtestlib/wince/cetcpsyncserver/commands.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the tools applications of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    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
       
    55 inline void debugOutput(int level, const char* text)
       
    56 {
       
    57     if (level >= DEBUG_LEVEL)
       
    58         qDebug() << text;
       
    59 }
       
    60 
       
    61 inline void debugOutput(int level, const QString &text)
       
    62 {
       
    63     if (level >= DEBUG_LEVEL)
       
    64         qDebug() << text;
       
    65 }
       
    66 // Basic abtract command class
       
    67 class AbstractCommand : public QObject
       
    68 {
       
    69     Q_OBJECT
       
    70 public:
       
    71     AbstractCommand();
       
    72     virtual ~AbstractCommand();
       
    73 
       
    74     void setSocket(QTcpSocket*);
       
    75     QTcpSocket* socket();
       
    76 
       
    77     void reportSuccess();
       
    78     void reportError();
       
    79 
       
    80 public slots:
       
    81     virtual void dataReceived(QByteArray&);
       
    82     virtual void commandFinished();
       
    83 
       
    84 private slots:
       
    85     void _readData();
       
    86     void _disconnect();
       
    87 
       
    88 private:
       
    89     QTcpSocket* m_socket;
       
    90 };
       
    91 
       
    92 // File Creation class
       
    93 class CreateFileCommand : public AbstractCommand
       
    94 {
       
    95     Q_OBJECT
       
    96 public:
       
    97     CreateFileCommand();
       
    98     ~CreateFileCommand();
       
    99 
       
   100 public slots:
       
   101     void dataReceived(QByteArray&);
       
   102     void commandFinished();
       
   103 
       
   104 private:
       
   105     CreateFileOptions m_options;
       
   106     QFile m_file;
       
   107     int m_dataCount;
       
   108 };
       
   109 
       
   110 inline AbstractCommand* instCreateFile() { return new CreateFileCommand(); }
       
   111 
       
   112 // Directory Creation class
       
   113 class CreateDirectoryCommand : public AbstractCommand
       
   114 {
       
   115     Q_OBJECT
       
   116 public:
       
   117     CreateDirectoryCommand();
       
   118     ~CreateDirectoryCommand();
       
   119     
       
   120 public slots:
       
   121     void dataReceived(QByteArray&);
       
   122     void commandFinished();
       
   123 };
       
   124 inline AbstractCommand* instCreateDirectory() { return new CreateDirectoryCommand(); }
       
   125 
       
   126 // File copy class
       
   127 class CopyFileCommand : public AbstractCommand
       
   128 {
       
   129     Q_OBJECT
       
   130 public:
       
   131     CopyFileCommand();
       
   132     ~CopyFileCommand();
       
   133     
       
   134 public slots:
       
   135     void dataReceived(QByteArray&);
       
   136     void commandFinished();
       
   137 };
       
   138 inline AbstractCommand* instCopyFile() { return new CopyFileCommand(); }
       
   139 
       
   140 // Copy directory class
       
   141 class CopyDirectoryCommand : public AbstractCommand
       
   142 {
       
   143     Q_OBJECT
       
   144 public:
       
   145     CopyDirectoryCommand();
       
   146     ~CopyDirectoryCommand();
       
   147 
       
   148 public slots:
       
   149     void dataReceived(QByteArray&);
       
   150     void commandFinished();
       
   151 private:
       
   152     bool copyDir(const QString &from, const QString &to, bool recursive);
       
   153 };
       
   154 inline AbstractCommand* instCopyDirectory() { return new CopyDirectoryCommand(); }
       
   155 
       
   156 // Delete File class
       
   157 class DeleteFileCommand : public AbstractCommand
       
   158 {
       
   159     Q_OBJECT
       
   160 public:
       
   161     DeleteFileCommand();
       
   162     ~DeleteFileCommand();
       
   163 public slots:
       
   164     void dataReceived(QByteArray&);
       
   165     void commandFinished();
       
   166 };
       
   167 inline AbstractCommand* instDeleteFile() { return new DeleteFileCommand(); }
       
   168 
       
   169 // Delete Directory class
       
   170 class DeleteDirectoryCommand : public AbstractCommand
       
   171 {
       
   172     Q_OBJECT
       
   173 public:
       
   174     DeleteDirectoryCommand();
       
   175     ~DeleteDirectoryCommand();
       
   176 public slots:
       
   177     void dataReceived(QByteArray&);
       
   178     void commandFinished();
       
   179 private:
       
   180     bool deleteDirectory(const QString &dirName, bool recursive, bool failIfContentExists);
       
   181 };
       
   182 inline AbstractCommand* instDeleteDirectory() { return new DeleteDirectoryCommand(); }
       
   183 
       
   184 // Execute application class
       
   185 class ExecuteCommand : public AbstractCommand
       
   186 {
       
   187     Q_OBJECT
       
   188 public:
       
   189     ExecuteCommand();
       
   190     ~ExecuteCommand();
       
   191 public slots:
       
   192     void dataReceived(QByteArray&);
       
   193     void commandFinished();
       
   194 private:
       
   195     void _doExecute();
       
   196     QString m_program;
       
   197     QStringList m_arguments;
       
   198     int m_argumentCount;
       
   199     bool m_waitFinished;
       
   200     int m_timeout;
       
   201 };
       
   202 inline AbstractCommand* instExecution() { return new ExecuteCommand(); }
       
   203 
       
   204 // Read File class
       
   205 class ReadFileCommand : public AbstractCommand
       
   206 {
       
   207     Q_OBJECT
       
   208 public:
       
   209     ReadFileCommand();
       
   210     ~ReadFileCommand();
       
   211 public slots:
       
   212     void dataReceived(QByteArray&);
       
   213     void commandFinished();
       
   214 private:
       
   215     QString m_fileName;
       
   216     QFile m_file;
       
   217     qint64 m_currentPos;
       
   218     qint64 m_fileSize;
       
   219 };
       
   220 inline AbstractCommand* instReadFile() { return new ReadFileCommand(); }
       
   221 
       
   222 // Read Directory class
       
   223 class ReadDirectoryCommand : public AbstractCommand
       
   224 {
       
   225     Q_OBJECT
       
   226 public:
       
   227     ReadDirectoryCommand();
       
   228     ~ReadDirectoryCommand();
       
   229 public slots:
       
   230     void dataReceived(QByteArray&);
       
   231     void commandFinished();
       
   232 private:
       
   233     QString m_dirName;
       
   234     QDir m_dir;
       
   235     QDirIterator* m_iterator;
       
   236 };
       
   237 inline AbstractCommand* instReadDirectory() { return new ReadDirectoryCommand(); }
       
   238 
       
   239 // Read File Time class
       
   240 class FileTimeCommand : public AbstractCommand
       
   241 {
       
   242     Q_OBJECT
       
   243 public:
       
   244     FileTimeCommand();
       
   245     ~FileTimeCommand();
       
   246 public slots:
       
   247     void dataReceived(QByteArray&);
       
   248     void commandFinished();
       
   249 };
       
   250 inline AbstractCommand* instFileTime() { return new FileTimeCommand(); }
       
   251 
       
   252 // Time stamp class
       
   253 class TimeStampCommand : public AbstractCommand
       
   254 {
       
   255     Q_OBJECT
       
   256 public:
       
   257     TimeStampCommand();
       
   258     ~TimeStampCommand();
       
   259 public slots:
       
   260     void dataReceived(QByteArray&);
       
   261     void commandFinished();
       
   262 };
       
   263 inline AbstractCommand* instTimeStamp() { return new TimeStampCommand(); }
       
   264 
       
   265 // Access part
       
   266 typedef AbstractCommand* (*instantiator)();
       
   267 
       
   268 struct CommandInfo
       
   269 {
       
   270     CommandInfo(const QString &name, instantiator func) : commandName(name) , commandFunc(func) { }
       
   271     QString commandName;
       
   272     instantiator commandFunc;
       
   273 };
       
   274 
       
   275 inline 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