1
/****************************************************************************
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
7
** This file is part of the tools applications of the Qt Toolkit.
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
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.
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.
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
40
****************************************************************************/
42
#include "qtcesterconnection.h"
46
static void showUsage()
48
cout << "cetcpsync is meant to be used by cetest internally." << endl
49
<< "For usage instructions remoteconnection.h could be useful." << endl;
52
const int debugLevel = 0;
53
void debugOutput(const QString& text, int level)
55
if (level <= debugLevel)
56
cout << qPrintable(text) << endl;
62
Exception(const QString& msg = QString())
66
QString message() { return m_message; }
72
class TooFewParametersException : public Exception
75
TooFewParametersException(const QLatin1String& cmd, int expectedParameterCount)
77
m_message = QLatin1String("Command ") + cmd + QLatin1String(" needs at least ");
78
m_message.append(QString::number(expectedParameterCount));
79
m_message.append(QLatin1String(" parameters."));
83
static void fileTimeFromString(FILETIME& ft, const QString& str)
85
int idx = str.indexOf("*");
88
ft.dwLowDateTime = str.left(idx).toULong();
89
ft.dwHighDateTime = str.mid(idx+1).toULong();
92
static QString fileTimeToString(FILETIME& ft)
94
return QString::number(ft.dwLowDateTime) + "*" + QString::number(ft.dwHighDateTime);
97
static int execCommand(const QLatin1String& cmd, int argc, char* argv[])
101
QtCesterConnection connection;
102
if (cmd == "copyFileToDevice") {
104
throw TooFewParametersException(cmd, 3);
105
success = connection.copyFileToDevice(argv[0], argv[1], argv[2] == "true");
106
} else if (cmd == "copyDirectoryToDevice") {
108
throw TooFewParametersException(cmd, 3);
109
success = connection.copyDirectoryToDevice(argv[0], argv[1], argv[2] == "true");
110
} else if (cmd == "copyFileFromDevice") {
112
throw TooFewParametersException(cmd, 3);
113
success = connection.copyFileFromDevice(argv[0], argv[1], argv[2] == "true");
114
} else if (cmd == "copyDirectoryFromDevice") {
116
throw TooFewParametersException(cmd, 3);
117
success = connection.copyDirectoryFromDevice(argv[0], argv[1], argv[2] == "true");
118
} else if (cmd == "timeStampForLocalFileTime") {
120
throw TooFewParametersException(cmd, 1);
122
fileTimeFromString(ft, argv[0]);
123
success = connection.timeStampForLocalFileTime(&ft);
125
cout << qPrintable(fileTimeToString(ft));
126
} else if (cmd == "fileCreationTime") {
128
throw TooFewParametersException(cmd, 1);
130
success = connection.fileCreationTime(argv[0], &ft);
132
cout << qPrintable(fileTimeToString(ft));
133
} else if (cmd == "copyFile") {
135
throw TooFewParametersException(cmd, 3);
136
success = connection.copyFile(argv[0], argv[1], argv[2] == "true");
137
} else if (cmd == "copyDirectory") {
139
throw TooFewParametersException(cmd, 3);
140
success = connection.copyDirectory(argv[0], argv[1], argv[2] == "true");
141
} else if (cmd == "deleteFile") {
143
throw TooFewParametersException(cmd, 1);
144
success = connection.deleteFile(argv[0]);
145
} else if (cmd == "deleteDirectory") {
147
throw TooFewParametersException(cmd, 3);
148
success = connection.deleteDirectory(argv[0], argv[1] == "true", argv[2] == "true");
149
} else if (cmd == "moveFile") {
151
throw TooFewParametersException(cmd, 3);
152
success = connection.moveFile(argv[0], argv[1], argv[2] == "true");
153
} else if (cmd == "moveDirectory") {
155
throw TooFewParametersException(cmd, 3);
156
success = connection.moveDirectory(argv[0], argv[1], argv[2] == "true");
157
} else if (cmd == "createDirectory") {
159
throw TooFewParametersException(cmd, 2);
160
success = connection.createDirectory(argv[0], argv[1] == "true");
161
} else if (cmd == "execute") {
163
throw TooFewParametersException(cmd, 3);
164
int timeout = QString(argv[2]).toInt();
165
success = connection.execute(argv[0], argv[1], timeout, &retval);
166
} else if (cmd == "noop") {
170
throw Exception("unknown command");
173
return success ? retval : 1;
176
int main(int argc, char *argv[])
183
QLatin1String param(argv[1]);
186
result = execCommand(param, argc - 2, argv + 2);
187
} catch (Exception e) {
188
cerr << "Error: " << qPrintable(e.message());