maemoremotemounter.h 4.61 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#ifndef MAEMOREMOTEMOUNTER_H
#define MAEMOREMOTEMOUNTER_H

33
#include "maemodeviceconfigurations.h"
34
35
36
37
38
39
#include "maemomountspecification.h"

#include <coreplugin/ssh/sftpdefs.h>

#include <QtCore/QList>
#include <QtCore/QObject>
40
#include <QtCore/QProcess>
41
42
43
#include <QtCore/QSharedPointer>
#include <QtCore/QString>

44
QT_FORWARD_DECLARE_CLASS(QTimer);
45
46
47
48
49
50
51
52
53
54

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

namespace Qt4ProjectManager {
namespace Internal {
class MaemoToolChain;
55
class MaemoUsedPortsGatherer;
56
57
58
59
60

class MaemoRemoteMounter : public QObject
{
    Q_OBJECT
public:
61
    MaemoRemoteMounter(QObject *parent);
62
    ~MaemoRemoteMounter();
63
    void setToolchain(const MaemoToolChain *toolchain) { m_toolChain = toolchain; }
64
    void addMountSpecification(const MaemoMountSpecification &mountSpec,
ck's avatar
ck committed
65
        bool mountAsRoot);
66
    bool hasValidMountSpecifications() const;
67
    void resetMountSpecifications() { m_mountSpecs.clear(); }
68
69
    void mount(MaemoPortList *freePorts,
        const MaemoUsedPortsGatherer *portsGatherer);
70
71
72
73
74
75
76
77
78
79
    void unmount();
    void stop();

    // Must be connected already.
    void setConnection(const QSharedPointer<Core::SshConnection> &connection);

signals:
    void mounted();
    void unmounted();
    void error(const QString &reason);
80
    void reportProgress(const QString &progressOutput);
81
    void debugOutput(const QString &output);
82
83
84
85
86

private slots:
    void handleUploaderInitialized();
    void handleUploaderInitializationFailed(const QString &reason);
    void handleUploadFinished(Core::SftpJobId jobId, const QString &error);
87
    void handleUtfsClientsStarted();
88
    void handleUtfsClientsFinished(int exitStatus);
ck's avatar
ck committed
89
    void handleUtfsClientStderr(const QByteArray &output);
90
91
92
    void handleUnmountProcessFinished(int exitStatus);
    void handleUmountStderr(const QByteArray &output);
    void handleUtfsServerError(QProcess::ProcessError procError);
93
94
95
    void handleUtfsServerFinished(int exitCode,
        QProcess::ExitStatus exitStatus);
    void handleUtfsServerTimeout();
96
    void handleUtfsServerStderr();
97
    void startUtfsServers();
98
99

private:
100
101
102
103
104
105
106
    enum State {
        Inactive, Unmounting, UploaderInitializing, UploadRunning,
        UtfsClientsStarting, UtfsClientsStarted, UtfsServersStarted
    };

    void setState(State newState);

107
108
    void deployUtfsClient();
    void startUtfsClients();
109
110
    void killUtfsServer(QProcess *proc);
    void killAllUtfsServers();
111
112
113
    QString utfsClientOnDevice() const;
    QString utfsServer() const;

114
    const MaemoToolChain *m_toolChain;
115
    QTimer * const m_utfsServerTimer;
ck's avatar
ck committed
116
117

    struct MountInfo {
118
119
        MountInfo(const MaemoMountSpecification &m, bool root)
            : mountSpec(m), mountAsRoot(root), remotePort(-1) {}
ck's avatar
ck committed
120
121
        MaemoMountSpecification mountSpec;
        bool mountAsRoot;
122
        int remotePort;
ck's avatar
ck committed
123
    };
124
125

    QSharedPointer<Core::SshConnection> m_connection;
ck's avatar
ck committed
126
    QList<MountInfo> m_mountSpecs;
127
128
129
130
131
132
    QSharedPointer<Core::SftpChannel> m_utfsClientUploader;
    QSharedPointer<Core::SshRemoteProcess> m_mountProcess;
    QSharedPointer<Core::SshRemoteProcess> m_unmountProcess;
    Core::SftpJobId m_uploadJobId;

    typedef QSharedPointer<QProcess> ProcPtr;
133
    QList<ProcPtr> m_utfsServers;
134

ck's avatar
ck committed
135
136
    QByteArray m_utfsClientStderr;
    QByteArray m_umountStderr;
137
138
    MaemoPortList *m_freePorts;
    const MaemoUsedPortsGatherer *m_portsGatherer;
139
140

    State m_state;
141
142
143
144
145
146
};

} // namespace Internal
} // namespace Qt4ProjectManager

#endif // MAEMOREMOTEMOUNTER_H