maemodeploystep.h 7.05 KB
Newer Older
1
2
3
4
/**************************************************************************
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6
7
8
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
con's avatar
con committed
9
** No Commercial Usage
10
**
con's avatar
con committed
11
12
13
14
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
15
16
17
18
19
20
21
22
23
24
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
con's avatar
con committed
25
26
27
28
29
30
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
31
32
33
**
**************************************************************************/

34
35
36
#ifndef MAEMODEPLOYSTEP_H
#define MAEMODEPLOYSTEP_H

37
#include "maemodeployable.h"
38
#include "maemodeployables.h"
39
#include "maemodeviceconfigurations.h"
40
#include "maemomountspecification.h"
41
42

#include <coreplugin/ssh/sftpdefs.h>
43
44
#include <projectexplorer/buildstep.h>

45
46
47
48
49
50
51
52
#include <QtCore/QHash>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QPair>
#include <QtCore/QSharedPointer>

QT_BEGIN_NAMESPACE
class QEventLoop;
Christian Kandeler's avatar
Christian Kandeler committed
53
class QProcess;
ck's avatar
ck committed
54
class QTimer;
55
56
57
58
59
60
61
62
QT_END_NAMESPACE

namespace Core {
class SftpChannel;
class SshConnection;
class SshRemoteProcess;
}

63
namespace Qt4ProjectManager {
64
class Qt4BuildConfiguration;
65
namespace Internal {
ck's avatar
ck committed
66
class MaemoRemoteMounter;
67
class MaemoDeviceConfig;
68
class MaemoPackageCreationStep;
69
class AbstractMaemoToolChain;
70
class MaemoUsedPortsGatherer;
71
72
73
74
75
76

class MaemoDeployStep : public ProjectExplorer::BuildStep
{
    Q_OBJECT
    friend class MaemoDeployStepFactory;
public:
Tobias Hunger's avatar
Tobias Hunger committed
77
    MaemoDeployStep(ProjectExplorer::BuildStepList *bc);
78

79
    virtual ~MaemoDeployStep();
80
    QSharedPointer<const MaemoDeviceConfig> deviceConfig() const { return m_deviceConfig; }
81
    const AbstractQt4MaemoTarget *maemotarget() const;
82
    void setDeviceConfig(int i);
83
84
85
    bool currentlyNeedsDeployment(const QString &host,
        const MaemoDeployable &deployable) const;
    void setDeployed(const QString &host, const MaemoDeployable &deployable);
86
    QSharedPointer<MaemoDeployables> deployables() const { return m_deployables; }
87
    QSharedPointer<Core::SshConnection> sshConnection() const { return m_connection; }
88

89
90
    bool isDeployToSysrootEnabled() const { return m_deployToSysroot; }
    void setDeployToSysrootEnabled(bool deploy) { m_deployToSysroot = deploy; }
Christian Kandeler's avatar
Christian Kandeler committed
91

92
93
    Q_INVOKABLE void stop();

94
95
96
signals:
    void done();
    void error();
97
    void deviceConfigChanged();
98
99
100
101
102

private slots:
    void start();
    void handleConnected();
    void handleConnectionFailure();
ck's avatar
ck committed
103
104
105
    void handleMounted();
    void handleUnmounted();
    void handleMountError(const QString &errorMsg);
106
    void handleMountDebugOutput(const QString &output);
ck's avatar
ck committed
107
108
    void handleProgressReport(const QString &progressMsg);
    void handleCopyProcessFinished(int exitStatus);
Christian Kandeler's avatar
Christian Kandeler committed
109
110
111
    void handleSysrootInstallerFinished();
    void handleSysrootInstallerOutput();
    void handleSysrootInstallerErrorOutput();
112
113
114
    void handleSftpChannelInitialized();
    void handleSftpChannelInitializationFailed(const QString &error);
    void handleSftpJobFinished(Core::SftpJobId job, const QString &error);
115
    void handleSftpChannelClosed();
116
    void handleInstallationFinished(int exitStatus);
Christian Kandeler's avatar
Christian Kandeler committed
117
118
    void handleDeviceInstallerOutput(const QByteArray &output);
    void handleDeviceInstallerErrorOutput(const QByteArray &output);
119
120
    void handlePortsGathererError(const QString &errorMsg);
    void handlePortListReady();
121
    void handleDeviceConfigurationsUpdated();
122
123

private:
124
125
126
127
128
129
130
    enum State {
        Inactive, StopRequested, InstallingToSysroot, Connecting,
        UnmountingOldDirs, UnmountingCurrentDirs, GatheringPorts, Mounting,
        InstallingToDevice, UnmountingCurrentMounts, CopyingFile,
        InitializingSftp, Uploading
    };

Tobias Hunger's avatar
Tobias Hunger committed
131
    MaemoDeployStep(ProjectExplorer::BuildStepList *bc,
132
133
134
135
136
        MaemoDeployStep *other);
    virtual bool init();
    virtual void run(QFutureInterface<bool> &fi);
    virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
    virtual bool immutable() const { return true; }
137
138
139
140
141
    virtual QVariantMap toMap() const;
    virtual bool fromMap(const QVariantMap &map);

    void ctor();
    void raiseError(const QString &error);
Christian Kandeler's avatar
Christian Kandeler committed
142
    void writeOutput(const QString &text, OutputFormat = MessageOutput);
143
144
145
    void addDeployTimesToMap(QVariantMap &map) const;
    void getDeployTimesFromMap(const QVariantMap &map);
    const MaemoPackageCreationStep *packagingStep() const;
ck's avatar
ck committed
146
    QString deployMountPoint() const;
147
    const AbstractMaemoToolChain *toolChain() const;
148
    void copyNextFileToDevice();
Christian Kandeler's avatar
Christian Kandeler committed
149
    void installToSysroot();
150
    QString uploadDir() const;
151
152
153
154
    void connectToDevice();
    void unmountOldDirs();
    void setupMount();
    void prepareSftpConnection();
Christian Kandeler's avatar
Christian Kandeler committed
155
    void runPackageInstaller(const QString &packageFilePath);
156
157
    void setState(State newState);
    void unmount();
158
    void setDeviceConfig(MaemoDeviceConfig::Id internalId);
159
    const Qt4BuildConfiguration *qt4BuildConfiguration() const;
160
161

    static const QLatin1String Id;
162

163
    QSharedPointer<MaemoDeployables> m_deployables;
164
    QSharedPointer<Core::SshConnection> m_connection;
Christian Kandeler's avatar
Christian Kandeler committed
165
    QProcess *m_sysrootInstaller;
166
167
    typedef QPair<MaemoDeployable, QSharedPointer<Core::SshRemoteProcess> > DeviceDeployAction;
    QScopedPointer<DeviceDeployAction> m_currentDeviceDeployAction;
ck's avatar
ck committed
168
169
    QList<MaemoDeployable> m_filesToCopy;
    MaemoRemoteMounter *m_mounter;
Christian Kandeler's avatar
Christian Kandeler committed
170
    bool m_deployToSysroot;
171
    QSharedPointer<Core::SftpChannel> m_uploader;
Christian Kandeler's avatar
Christian Kandeler committed
172
    QSharedPointer<Core::SshRemoteProcess> m_deviceInstaller;
ck's avatar
ck committed
173
174

    bool m_needsInstall;
175
176
    typedef QPair<MaemoDeployable, QString> DeployablePerHost;
    QHash<DeployablePerHost, QDateTime> m_lastDeployed;
177
178
    QSharedPointer<const MaemoDeviceConfig> m_deviceConfig;
    QSharedPointer<const MaemoDeviceConfig> m_cachedDeviceConfig;
179
180
    MaemoUsedPortsGatherer *m_portsGatherer;
    MaemoPortList m_freePorts;
181
    QByteArray m_installerStderr;
182
    State m_state;
183
    bool m_hasError;
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
};

class MaemoDeployEventHandler : public QObject
{
    Q_OBJECT
public:
    MaemoDeployEventHandler(MaemoDeployStep *deployStep,
        QFutureInterface<bool> &future);

private slots:
    void handleDeployingDone();
    void handleDeployingFailed();
    void checkForCanceled();

private:
199
    MaemoDeployStep * const m_deployStep;
200
201
    const QFutureInterface<bool> m_future;
    QEventLoop * const m_eventLoop;
202
    bool m_error;
203
204
205
206
207
208
};

} // namespace Internal
} // namespace Qt4ProjectManager

#endif // MAEMODEPLOYSTEP_H