1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
36 #include "trkdevice.h"
39 #include <QtCore/QObject>
40 #include <QtCore/QVariant>
41 #include <QtCore/QSharedPointer>
47 struct LauncherPrivate;
49 typedef QSharedPointer<TrkDevice> TrkDevicePtr;
51 class SYMBIANUTILS_EXPORT Launcher : public QObject
54 Q_DISABLE_COPY(Launcher)
56 typedef void (Launcher::*TrkCallBack)(const TrkResult &);
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
69 ActionCopyInstall = ActionCopy | ActionInstall,
72 ActionCopyRun = ActionCopy | ActionRun,
73 ActionInstallRun = ActionInstall | ActionRun,
74 ActionCopyInstallRun = ActionCopy | ActionInstall | ActionRun
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
83 DeviceDescriptionReceived };
85 explicit Launcher(trk::Launcher::Actions startupActions = trk::Launcher::ActionPingOnly,
86 const TrkDevicePtr &trkDevice = TrkDevicePtr(),
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);
106 InstallationMode installationMode() const;
107 char installationDrive() const;
109 bool serialFrame() const;
110 // Close device or leave it open
111 bool closeDevice() const;
112 void setCloseDevice(bool c);
114 TrkDevicePtr trkDevice() const;
116 // becomes valid after successful execution of ActionPingOnly
117 QString deviceDescription(unsigned verbose = 0u) const;
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,
123 QString *errorMessage);
124 // Preliminary release of device, disconnecting the signal.
125 static void releaseToDeviceManager(Launcher *l);
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,
138 static QString msgStopped(uint pid, uint tid, uint address, const QString &why);
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);
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);
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);
174 void handleResult(const trk::TrkResult &data);
175 void slotWaitingForTrk();
178 // kill process and breakpoints
180 void disconnectTrk();
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);
202 void copyFileToRemote();
203 void copyFileFromRemote();
204 void installRemotePackageSilently();
205 void installRemotePackageByUser();
206 void installRemotePackage();
207 void startInferiorIfNeeded();
208 void handleFinished();
210 void logMessage(const QString &msg);
211 void setState(State s);