OSDN Git Service

Merge branch 'master' of scm.dev.nokia.troll.no:creator/mainline
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / ssh / sftpoperation_p.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** Commercial Usage
10 **
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 **
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.
24 **
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
27 **
28 **************************************************************************/
29
30 #ifndef SFTPOPERATION_P_H
31 #define SFTPOPERATION_P_H
32
33 #include "sftpdefs.h"
34
35 #include <QtCore/QByteArray>
36 #include <QtCore/QList>
37 #include <QtCore/QMap>
38 #include <QtCore/QSharedPointer>
39
40 QT_BEGIN_NAMESPACE
41 class QFile;
42 QT_END_NAMESPACE
43
44 namespace Core {
45 namespace Internal {
46
47 class SftpOutgoingPacket;
48
49 struct AbstractSftpOperation
50 {
51     typedef QSharedPointer<AbstractSftpOperation> Ptr;
52     enum Type {
53         ListDir, MakeDir, RmDir, Rm, Rename, CreateFile, Download, UploadFile
54     };
55
56     AbstractSftpOperation(SftpJobId jobId);
57     virtual ~AbstractSftpOperation();
58     virtual Type type() const=0;
59     virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet)=0;
60
61     const SftpJobId jobId;
62
63 private:
64     AbstractSftpOperation(const AbstractSftpOperation &);
65     AbstractSftpOperation &operator=(const AbstractSftpOperation &);
66 };
67
68 struct SftpUploadDir;
69
70 struct SftpMakeDir : public AbstractSftpOperation
71 {
72     typedef QSharedPointer<SftpMakeDir> Ptr;
73
74     SftpMakeDir(SftpJobId jobId, const QString &path,
75         const QSharedPointer<SftpUploadDir> &parentJob = QSharedPointer<SftpUploadDir>());
76     virtual Type type() const { return MakeDir; }
77     virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
78
79     const QSharedPointer<SftpUploadDir> parentJob;
80     const QString remoteDir;
81 };
82
83 struct SftpRmDir : public AbstractSftpOperation
84 {
85     typedef QSharedPointer<SftpRmDir> Ptr;
86
87     SftpRmDir(SftpJobId jobId, const QString &path);
88     virtual Type type() const { return RmDir; }
89     virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
90
91     const QString remoteDir;
92 };
93
94 struct SftpRm : public AbstractSftpOperation
95 {
96     typedef QSharedPointer<SftpRm> Ptr;
97
98     SftpRm(SftpJobId jobId, const QString &path);
99     virtual Type type() const { return Rm; }
100     virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
101
102     const QString remoteFile;
103 };
104
105 struct SftpRename : public AbstractSftpOperation
106 {
107     typedef QSharedPointer<SftpRename> Ptr;
108
109     SftpRename(SftpJobId jobId, const QString &oldPath, const QString &newPath);
110     virtual Type type() const { return Rename; }
111     virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
112
113     const QString oldPath;
114     const QString newPath;
115 };
116
117
118 struct AbstractSftpOperationWithHandle : public AbstractSftpOperation
119 {
120     typedef QSharedPointer<AbstractSftpOperationWithHandle> Ptr;
121     enum State { Inactive, OpenRequested, Open, CloseRequested };
122
123     AbstractSftpOperationWithHandle(SftpJobId jobId, const QString &remotePath);
124     ~AbstractSftpOperationWithHandle();
125
126     const QString remotePath;
127     QByteArray remoteHandle;
128     State state;
129     bool hasError;
130 };
131
132
133 struct SftpListDir : public AbstractSftpOperationWithHandle
134 {
135     typedef QSharedPointer<SftpListDir> Ptr;
136
137     SftpListDir(SftpJobId jobId, const QString &path);
138     virtual Type type() const { return ListDir; }
139     virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
140 };
141
142
143 struct SftpCreateFile : public AbstractSftpOperationWithHandle
144 {
145     typedef QSharedPointer<SftpCreateFile> Ptr;
146
147     SftpCreateFile(SftpJobId jobId, const QString &path, SftpOverwriteMode mode);
148     virtual Type type() const { return CreateFile; }
149     virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
150
151     const SftpOverwriteMode mode;
152 };
153
154 struct AbstractSftpTransfer : public AbstractSftpOperationWithHandle
155 {
156     typedef QSharedPointer<AbstractSftpTransfer> Ptr;
157
158     AbstractSftpTransfer(SftpJobId jobId, const QString &remotePath,
159         const QSharedPointer<QFile> &localFile);
160     ~AbstractSftpTransfer();
161     void calculateInFlightCount(quint32 chunkSize);
162
163     static const int MaxInFlightCount;
164
165     const QSharedPointer<QFile> localFile;
166     quint64 fileSize;
167     quint64 offset;
168     int inFlightCount;
169     bool statRequested;
170 };
171
172 struct SftpDownload : public AbstractSftpTransfer
173 {
174     typedef QSharedPointer<SftpDownload> Ptr;
175     SftpDownload(SftpJobId jobId, const QString &remotePath,
176         const QSharedPointer<QFile> &localFile);
177     virtual Type type() const { return Download; }
178     virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
179
180     QMap<quint32, quint32> offsets;
181     SftpJobId eofId;
182 };
183
184 struct SftpUploadFile : public AbstractSftpTransfer
185 {
186     typedef QSharedPointer<SftpUploadFile> Ptr;
187
188     SftpUploadFile(SftpJobId jobId, const QString &remotePath,
189         const QSharedPointer<QFile> &localFile, SftpOverwriteMode mode,
190         const QSharedPointer<SftpUploadDir> &parentJob = QSharedPointer<SftpUploadDir>());
191     virtual Type type() const { return UploadFile; }
192     virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
193
194     const QSharedPointer<SftpUploadDir> parentJob;
195     SftpOverwriteMode mode;
196 };
197
198 // Composite operation.
199 struct SftpUploadDir
200 {
201     typedef QSharedPointer<SftpUploadDir> Ptr;
202
203     struct Dir {
204         Dir(const QString &l, const QString &r) : localDir(l), remoteDir(r) {}
205         QString localDir;
206         QString remoteDir;
207     };
208
209     SftpUploadDir(SftpJobId jobId) : jobId(jobId), hasError(false) {}
210     ~SftpUploadDir();
211
212     void setError()
213     {
214         hasError = true;
215         uploadsInProgress.clear();
216         mkdirsInProgress.clear();
217     }
218
219     const SftpJobId jobId;
220     bool hasError;
221     QList<SftpUploadFile::Ptr> uploadsInProgress;
222     QMap<SftpMakeDir::Ptr, Dir> mkdirsInProgress;
223 };
224
225 } // namespace Internal
226 } // namespace Core
227
228 #endif // SFTPOPERATION_P_H