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