OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / shared / symbianutils / launcher.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33 #ifndef LAUNCHER_H
34 #define LAUNCHER_H
35
36 #include "trkdevice.h"
37 #include "trkutils.h"
38
39 #include <QtCore/QObject>
40 #include <QtCore/QVariant>
41 #include <QtCore/QSharedPointer>
42
43 namespace trk {
44
45 struct TrkResult;
46 struct TrkMessage;
47 struct LauncherPrivate;
48
49 typedef QSharedPointer<TrkDevice> TrkDevicePtr;
50
51 class SYMBIANUTILS_EXPORT Launcher : public QObject
52 {
53     Q_OBJECT
54     Q_DISABLE_COPY(Launcher)
55 public:
56     typedef void (Launcher::*TrkCallBack)(const TrkResult &);
57
58     enum InstallationMode {
59         InstallationModeSilent  = 0x1,
60         InstallationModeUser = 0x2,
61         InstallationModeSilentAndUser = InstallationModeSilent|InstallationModeUser
62                                     //first attempt is silent and if it fails then the user installation is launched
63     };
64
65     enum Actions {
66         ActionPingOnly = 0x0,
67         ActionCopy = 0x1,
68         ActionInstall = 0x2,
69         ActionCopyInstall = ActionCopy | ActionInstall,
70         ActionRun = 0x4,
71         ActionDownload = 0x8,
72         ActionCopyRun = ActionCopy | ActionRun,
73         ActionInstallRun = ActionInstall | ActionRun,
74         ActionCopyInstallRun = ActionCopy | ActionInstall | ActionRun
75     };
76
77     enum State { Disconnected, Connecting, Connected,
78                  WaitingForTrk, // This occurs only if the initial ping times out after
79                                 // a reasonable timeout, indicating that Trk is not
80                                 // running. Note that this will never happen with
81                                 // Bluetooth as communication immediately starts
82                                 // after connecting.
83                  DeviceDescriptionReceived };
84
85     explicit Launcher(trk::Launcher::Actions startupActions = trk::Launcher::ActionPingOnly,
86                       const TrkDevicePtr &trkDevice = TrkDevicePtr(),
87                       QObject *parent = 0);
88     ~Launcher();
89
90     State state() const;
91
92     void addStartupActions(trk::Launcher::Actions startupActions);
93     void setTrkServerName(const QString &name);
94     QString trkServerName() const;
95     void setFileName(const QString &name);
96     void setCopyFileNames(const QStringList &srcName, const QStringList &dstName);
97     void setDownloadFileName(const QString &srcName, const QString &dstName);
98     void setInstallFileNames(const QStringList &names);
99     void setCommandLineArgs(const QString &args);
100     bool startServer(QString *errorMessage);
101     void setInstallationMode(InstallationMode installation);
102     void setInstallationDrive(char drive);
103     void setVerbose(int v);
104     void setSerialFrame(bool b);
105
106     InstallationMode installationMode() const;
107     char installationDrive() const;
108
109     bool serialFrame() const;
110     // Close device or leave it open
111     bool closeDevice() const;
112     void setCloseDevice(bool c);
113
114     TrkDevicePtr trkDevice() const;
115
116     // becomes valid after successful execution of ActionPingOnly
117     QString deviceDescription(unsigned verbose = 0u) const;
118
119     // Acquire a device from SymbianDeviceManager, return 0 if not available.
120     // The device will be released on destruction.
121     static Launcher *acquireFromDeviceManager(const QString &serverName,
122                                               QObject *parent,
123                                               QString *errorMessage);
124     // Preliminary release of device, disconnecting the signal.
125     static void releaseToDeviceManager(Launcher *l);
126
127     // Create Trk message to start a process.
128     static QByteArray startProcessMessage(const QString &executable,
129                                           const QString &arguments);
130     // Create Trk message to read memory
131     static QByteArray readMemoryMessage(uint pid, uint tid, uint from, uint len);
132     static QByteArray readRegistersMessage(uint pid, uint tid);
133     // Parse a TrkNotifyStopped message
134     static bool parseNotifyStopped(const QByteArray &a,
135                                    uint *pid, uint *tid, uint *address,
136                                    QString *why = 0);
137     // Helper message
138     static QString msgStopped(uint pid, uint tid, uint address, const QString &why);
139
140 signals:
141     void deviceDescriptionReceived(const QString &port, const QString &description);
142     void copyingStarted(const QString &fileName);
143     void canNotConnect(const QString &errorMessage);
144     void canNotCreateFile(const QString &filename, const QString &errorMessage);
145     void canNotOpenFile(const QString &filename, const QString &errorMessage);
146     void canNotOpenLocalFile(const QString &filename, const QString &errorMessage);
147     void canNotWriteFile(const QString &filename, const QString &errorMessage);
148     void canNotCloseFile(const QString &filename, const QString &errorMessage);
149     void installingStarted(const QString &packageName);
150     void canNotInstall(const QString &packageFilename, const QString &errorMessage);
151     void installingFinished();
152     void startingApplication();
153     void applicationRunning(uint pid);
154     void canNotRun(const QString &errorMessage);
155     void finished();
156     void applicationOutputReceived(const QString &output);
157     void copyProgress(int percent);
158     void stateChanged(int);
159     void processStopped(uint pc, uint pid, uint tid, const QString& reason);
160     void processResumed(uint pid, uint tid);
161     void libraryLoaded(const trk::Library &lib);
162     void libraryUnloaded(const trk::Library &lib);
163     void registersAndCallStackReadComplete(const QList<uint>& registers, const QByteArray& stack);
164     // Emitted by the destructor, for releasing devices of SymbianDeviceManager by name
165     void destroyed(const QString &serverName);
166
167 public slots:
168     void terminate();
169     void resumeProcess(uint pid, uint tid);
170     //can be used to obtain traceback after a breakpoint / exception
171     void getRegistersAndCallStack(uint pid, uint tid);
172
173 private slots:
174     void handleResult(const trk::TrkResult &data);
175     void slotWaitingForTrk();
176
177 private:
178     // kill process and breakpoints
179     void cleanUp();
180     void disconnectTrk();
181
182     void handleRemoteProcessKilled(const TrkResult &result);
183     void handleConnect(const TrkResult &result);
184     void handleFileCreation(const TrkResult &result);
185     void handleFileOpened(const TrkResult &result);
186     void handleCopy(const TrkResult &result);
187     void handleRead(const TrkResult &result);
188     void continueCopying(uint lastCopiedBlockSize = 0);
189     void continueReading();
190     void closeRemoteFile(bool failed = false);
191     void handleFileCopied(const TrkResult &result);
192     void handleInstallPackageFinished(const TrkResult &result);
193     void handleCpuType(const TrkResult &result);
194     void handleCreateProcess(const TrkResult &result);
195     void handleWaitForFinished(const TrkResult &result);
196     void handleStop(const TrkResult &result);
197     void handleSupportMask(const TrkResult &result);
198     void handleTrkVersion(const TrkResult &result);
199     void handleReadRegisters(const TrkResult &result);
200     void handleReadStack(const TrkResult &result);
201
202     void copyFileToRemote();
203     void copyFileFromRemote();
204     void installRemotePackageSilently();
205     void installRemotePackageByUser();
206     void installRemotePackage();
207     void startInferiorIfNeeded();
208     void handleFinished();
209
210     void logMessage(const QString &msg);
211     void setState(State s);
212
213     LauncherPrivate *d;
214 };
215
216 } // namespace Trk
217
218 #endif // LAUNCHER_H