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 **************************************************************************/
34 #ifndef MAEMODEPLOYSTEP_H
35 #define MAEMODEPLOYSTEP_H
37 #include "maemodeployable.h"
38 #include "maemodeployables.h"
39 #include "maemodeviceconfigurations.h"
40 #include "maemomountspecification.h"
42 #include <utils/ssh/sftpdefs.h>
43 #include <projectexplorer/buildstep.h>
45 #include <QtCore/QHash>
46 #include <QtCore/QList>
47 #include <QtCore/QMap>
48 #include <QtCore/QPair>
49 #include <QtCore/QSharedPointer>
60 class SshRemoteProcess;
63 namespace Qt4ProjectManager {
64 class Qt4BuildConfiguration;
66 class MaemoRemoteMounter;
67 class MaemoDeviceConfig;
68 class MaemoPackageCreationStep;
70 class MaemoUsedPortsGatherer;
72 class MaemoDeployStep : public ProjectExplorer::BuildStep
75 friend class MaemoDeployStepFactory;
77 MaemoDeployStep(ProjectExplorer::BuildStepList *bc);
79 virtual ~MaemoDeployStep();
80 QSharedPointer<const MaemoDeviceConfig> deviceConfig() const { return m_deviceConfig; }
81 const AbstractQt4MaemoTarget *maemotarget() const;
82 void setDeviceConfig(int i);
83 bool currentlyNeedsDeployment(const QString &host,
84 const MaemoDeployable &deployable) const;
85 void setDeployed(const QString &host, const MaemoDeployable &deployable);
86 QSharedPointer<MaemoDeployables> deployables() const { return m_deployables; }
87 QSharedPointer<Utils::SshConnection> sshConnection() const { return m_connection; }
88 MaemoPortList freePorts() const;
90 bool isDeployToSysrootEnabled() const { return m_deployToSysroot; }
91 void setDeployToSysrootEnabled(bool deploy) { m_deployToSysroot = deploy; }
93 Q_INVOKABLE void stop();
98 void deviceConfigChanged();
102 void handleConnected();
103 void handleConnectionFailure();
104 void handleMounted();
105 void handleUnmounted();
106 void handleMountError(const QString &errorMsg);
107 void handleMountDebugOutput(const QString &output);
108 void handleProgressReport(const QString &progressMsg);
109 void handleCopyProcessFinished(int exitStatus);
110 void handleSysrootInstallerFinished();
111 void handleSysrootInstallerOutput();
112 void handleSysrootInstallerErrorOutput();
113 void handleSftpChannelInitialized();
114 void handleSftpChannelInitializationFailed(const QString &error);
115 void handleSftpJobFinished(Utils::SftpJobId job, const QString &error);
116 void handleSftpChannelClosed();
117 void handleInstallationFinished(int exitStatus);
118 void handleDeviceInstallerOutput(const QByteArray &output);
119 void handleDeviceInstallerErrorOutput(const QByteArray &output);
120 void handlePortsGathererError(const QString &errorMsg);
121 void handlePortListReady();
122 void handleDeviceConfigurationsUpdated();
126 Inactive, StopRequested, InstallingToSysroot, Connecting,
127 UnmountingOldDirs, UnmountingCurrentDirs, GatheringPorts, Mounting,
128 InstallingToDevice, UnmountingCurrentMounts, CopyingFile,
129 InitializingSftp, Uploading
132 MaemoDeployStep(ProjectExplorer::BuildStepList *bc,
133 MaemoDeployStep *other);
135 virtual void run(QFutureInterface<bool> &fi);
136 virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
137 virtual bool immutable() const { return true; }
138 virtual QVariantMap toMap() const;
139 virtual bool fromMap(const QVariantMap &map);
142 void raiseError(const QString &error);
143 void writeOutput(const QString &text, OutputFormat = MessageOutput);
144 void addDeployTimesToMap(QVariantMap &map) const;
145 void getDeployTimesFromMap(const QVariantMap &map);
146 const MaemoPackageCreationStep *packagingStep() const;
147 QString deployMountPoint() const;
148 const MaemoToolChain *toolChain() const;
149 void copyNextFileToDevice();
150 void installToSysroot();
151 QString uploadDir() const;
152 void connectToDevice();
153 void unmountOldDirs();
155 void prepareSftpConnection();
156 void runPackageInstaller(const QString &packageFilePath);
157 void setState(State newState);
159 void setDeviceConfig(MaemoDeviceConfig::Id internalId);
160 const Qt4BuildConfiguration *qt4BuildConfiguration() const;
162 static const QLatin1String Id;
164 QSharedPointer<MaemoDeployables> m_deployables;
165 QSharedPointer<Utils::SshConnection> m_connection;
166 QProcess *m_sysrootInstaller;
167 typedef QPair<MaemoDeployable, QSharedPointer<Utils::SshRemoteProcess> > DeviceDeployAction;
168 QScopedPointer<DeviceDeployAction> m_currentDeviceDeployAction;
169 QList<MaemoDeployable> m_filesToCopy;
170 MaemoRemoteMounter *m_mounter;
171 bool m_deployToSysroot;
172 QSharedPointer<Utils::SftpChannel> m_uploader;
173 QSharedPointer<Utils::SshRemoteProcess> m_deviceInstaller;
176 typedef QPair<MaemoDeployable, QString> DeployablePerHost;
177 QHash<DeployablePerHost, QDateTime> m_lastDeployed;
178 QSharedPointer<const MaemoDeviceConfig> m_deviceConfig;
179 QSharedPointer<const MaemoDeviceConfig> m_cachedDeviceConfig;
180 MaemoUsedPortsGatherer *m_portsGatherer;
181 MaemoPortList m_freePorts;
182 QByteArray m_installerStderr;
187 class MaemoDeployEventHandler : public QObject
191 MaemoDeployEventHandler(MaemoDeployStep *deployStep,
192 QFutureInterface<bool> &future);
195 void handleDeployingDone();
196 void handleDeployingFailed();
197 void checkForCanceled();
200 MaemoDeployStep * const m_deployStep;
201 const QFutureInterface<bool> m_future;
202 QEventLoop * const m_eventLoop;
206 } // namespace Internal
207 } // namespace Qt4ProjectManager
209 #endif // MAEMODEPLOYSTEP_H