author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
#include <iostream> |
|
42 |
#include "qtcesterconnection.h" |
|
43 |
||
44 |
using namespace std; |
|
45 |
||
46 |
static void showUsage() |
|
47 |
{ |
|
48 |
cout << "cetcpsync is meant to be used by cetest internally." << endl |
|
49 |
<< "For usage instructions remoteconnection.h could be useful." << endl; |
|
50 |
} |
|
51 |
||
52 |
const int debugLevel = 0; |
|
53 |
void debugOutput(const QString& text, int level) |
|
54 |
{ |
|
55 |
if (level <= debugLevel) |
|
56 |
cout << qPrintable(text) << endl; |
|
57 |
} |
|
58 |
||
59 |
class Exception |
|
60 |
{ |
|
61 |
public: |
|
62 |
Exception(const QString& msg = QString()) |
|
63 |
: m_message(msg) |
|
64 |
{} |
|
65 |
||
66 |
QString message() { return m_message; } |
|
67 |
||
68 |
protected: |
|
69 |
QString m_message; |
|
70 |
}; |
|
71 |
||
72 |
class TooFewParametersException : public Exception |
|
73 |
{ |
|
74 |
public: |
|
75 |
TooFewParametersException(const QLatin1String& cmd, int expectedParameterCount) |
|
76 |
{ |
|
77 |
m_message = QLatin1String("Command ") + cmd + QLatin1String(" needs at least "); |
|
78 |
m_message.append(QString::number(expectedParameterCount)); |
|
79 |
m_message.append(QLatin1String(" parameters.")); |
|
80 |
} |
|
81 |
}; |
|
82 |
||
83 |
static void fileTimeFromString(FILETIME& ft, const QString& str) |
|
84 |
{ |
|
85 |
int idx = str.indexOf("*"); |
|
86 |
if (idx <= 0) |
|
87 |
return; |
|
88 |
ft.dwLowDateTime = str.left(idx).toULong(); |
|
89 |
ft.dwHighDateTime = str.mid(idx+1).toULong(); |
|
90 |
} |
|
91 |
||
92 |
static QString fileTimeToString(FILETIME& ft) |
|
93 |
{ |
|
94 |
return QString::number(ft.dwLowDateTime) + "*" + QString::number(ft.dwHighDateTime); |
|
95 |
} |
|
96 |
||
97 |
static int execCommand(const QLatin1String& cmd, int argc, char* argv[]) |
|
98 |
{ |
|
99 |
int retval = 0; |
|
100 |
bool success = true; |
|
101 |
QtCesterConnection connection; |
|
102 |
if (cmd == "copyFileToDevice") { |
|
103 |
if (argc < 3) |
|
104 |
throw TooFewParametersException(cmd, 3); |
|
105 |
success = connection.copyFileToDevice(argv[0], argv[1], argv[2] == "true"); |
|
106 |
} else if (cmd == "copyDirectoryToDevice") { |
|
107 |
if (argc < 3) |
|
108 |
throw TooFewParametersException(cmd, 3); |
|
109 |
success = connection.copyDirectoryToDevice(argv[0], argv[1], argv[2] == "true"); |
|
110 |
} else if (cmd == "copyFileFromDevice") { |
|
111 |
if (argc < 3) |
|
112 |
throw TooFewParametersException(cmd, 3); |
|
113 |
success = connection.copyFileFromDevice(argv[0], argv[1], argv[2] == "true"); |
|
114 |
} else if (cmd == "copyDirectoryFromDevice") { |
|
115 |
if (argc < 3) |
|
116 |
throw TooFewParametersException(cmd, 3); |
|
117 |
success = connection.copyDirectoryFromDevice(argv[0], argv[1], argv[2] == "true"); |
|
118 |
} else if (cmd == "timeStampForLocalFileTime") { |
|
119 |
if (argc < 1) |
|
120 |
throw TooFewParametersException(cmd, 1); |
|
121 |
FILETIME ft; |
|
122 |
fileTimeFromString(ft, argv[0]); |
|
123 |
success = connection.timeStampForLocalFileTime(&ft); |
|
124 |
if (success) |
|
125 |
cout << qPrintable(fileTimeToString(ft)); |
|
126 |
} else if (cmd == "fileCreationTime") { |
|
127 |
if (argc < 1) |
|
128 |
throw TooFewParametersException(cmd, 1); |
|
129 |
FILETIME ft; |
|
130 |
success = connection.fileCreationTime(argv[0], &ft); |
|
131 |
if (success) |
|
132 |
cout << qPrintable(fileTimeToString(ft)); |
|
133 |
} else if (cmd == "copyFile") { |
|
134 |
if (argc < 3) |
|
135 |
throw TooFewParametersException(cmd, 3); |
|
136 |
success = connection.copyFile(argv[0], argv[1], argv[2] == "true"); |
|
137 |
} else if (cmd == "copyDirectory") { |
|
138 |
if (argc < 3) |
|
139 |
throw TooFewParametersException(cmd, 3); |
|
140 |
success = connection.copyDirectory(argv[0], argv[1], argv[2] == "true"); |
|
141 |
} else if (cmd == "deleteFile") { |
|
142 |
if (argc < 1) |
|
143 |
throw TooFewParametersException(cmd, 1); |
|
144 |
success = connection.deleteFile(argv[0]); |
|
145 |
} else if (cmd == "deleteDirectory") { |
|
146 |
if (argc < 3) |
|
147 |
throw TooFewParametersException(cmd, 3); |
|
148 |
success = connection.deleteDirectory(argv[0], argv[1] == "true", argv[2] == "true"); |
|
149 |
} else if (cmd == "moveFile") { |
|
150 |
if (argc < 3) |
|
151 |
throw TooFewParametersException(cmd, 3); |
|
152 |
success = connection.moveFile(argv[0], argv[1], argv[2] == "true"); |
|
153 |
} else if (cmd == "moveDirectory") { |
|
154 |
if (argc < 3) |
|
155 |
throw TooFewParametersException(cmd, 3); |
|
156 |
success = connection.moveDirectory(argv[0], argv[1], argv[2] == "true"); |
|
157 |
} else if (cmd == "createDirectory") { |
|
158 |
if (argc < 2) |
|
159 |
throw TooFewParametersException(cmd, 2); |
|
160 |
success = connection.createDirectory(argv[0], argv[1] == "true"); |
|
161 |
} else if (cmd == "execute") { |
|
162 |
if (argc < 3) |
|
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") { |
|
167 |
// do nothing :) |
|
168 |
success = true; |
|
169 |
} else { |
|
170 |
throw Exception("unknown command"); |
|
171 |
} |
|
172 |
||
173 |
return success ? retval : 1; |
|
174 |
} |
|
175 |
||
176 |
int main(int argc, char *argv[]) |
|
177 |
{ |
|
178 |
if (argc <= 1) { |
|
179 |
showUsage(); |
|
180 |
return 0; |
|
181 |
} |
|
182 |
||
183 |
QLatin1String param(argv[1]); |
|
184 |
int result = 1; |
|
185 |
try { |
|
186 |
result = execCommand(param, argc - 2, argv + 2); |
|
187 |
} catch (Exception e) { |
|
188 |
cerr << "Error: " << qPrintable(e.message()); |
|
189 |
} |
|
190 |
return result; |
|
191 |
} |