1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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.
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 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
28 **************************************************************************/
30 #ifndef SFTPOPERATION_P_H
31 #define SFTPOPERATION_P_H
35 #include <QtCore/QByteArray>
36 #include <QtCore/QList>
37 #include <QtCore/QMap>
38 #include <QtCore/QSharedPointer>
47 class SftpOutgoingPacket;
49 struct AbstractSftpOperation
51 typedef QSharedPointer<AbstractSftpOperation> Ptr;
53 ListDir, MakeDir, RmDir, Rm, Rename, CreateFile, Download, UploadFile
56 AbstractSftpOperation(SftpJobId jobId);
57 virtual ~AbstractSftpOperation();
58 virtual Type type() const=0;
59 virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet)=0;
61 const SftpJobId jobId;
64 AbstractSftpOperation(const AbstractSftpOperation &);
65 AbstractSftpOperation &operator=(const AbstractSftpOperation &);
70 struct SftpMakeDir : public AbstractSftpOperation
72 typedef QSharedPointer<SftpMakeDir> Ptr;
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);
79 const QSharedPointer<SftpUploadDir> parentJob;
80 const QString remoteDir;
83 struct SftpRmDir : public AbstractSftpOperation
85 typedef QSharedPointer<SftpRmDir> Ptr;
87 SftpRmDir(SftpJobId jobId, const QString &path);
88 virtual Type type() const { return RmDir; }
89 virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
91 const QString remoteDir;
94 struct SftpRm : public AbstractSftpOperation
96 typedef QSharedPointer<SftpRm> Ptr;
98 SftpRm(SftpJobId jobId, const QString &path);
99 virtual Type type() const { return Rm; }
100 virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
102 const QString remoteFile;
105 struct SftpRename : public AbstractSftpOperation
107 typedef QSharedPointer<SftpRename> Ptr;
109 SftpRename(SftpJobId jobId, const QString &oldPath, const QString &newPath);
110 virtual Type type() const { return Rename; }
111 virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
113 const QString oldPath;
114 const QString newPath;
118 struct AbstractSftpOperationWithHandle : public AbstractSftpOperation
120 typedef QSharedPointer<AbstractSftpOperationWithHandle> Ptr;
121 enum State { Inactive, OpenRequested, Open, CloseRequested };
123 AbstractSftpOperationWithHandle(SftpJobId jobId, const QString &remotePath);
124 ~AbstractSftpOperationWithHandle();
126 const QString remotePath;
127 QByteArray remoteHandle;
133 struct SftpListDir : public AbstractSftpOperationWithHandle
135 typedef QSharedPointer<SftpListDir> Ptr;
137 SftpListDir(SftpJobId jobId, const QString &path);
138 virtual Type type() const { return ListDir; }
139 virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
143 struct SftpCreateFile : public AbstractSftpOperationWithHandle
145 typedef QSharedPointer<SftpCreateFile> Ptr;
147 SftpCreateFile(SftpJobId jobId, const QString &path, SftpOverwriteMode mode);
148 virtual Type type() const { return CreateFile; }
149 virtual SftpOutgoingPacket &initialPacket(SftpOutgoingPacket &packet);
151 const SftpOverwriteMode mode;
154 struct AbstractSftpTransfer : public AbstractSftpOperationWithHandle
156 typedef QSharedPointer<AbstractSftpTransfer> Ptr;
158 AbstractSftpTransfer(SftpJobId jobId, const QString &remotePath,
159 const QSharedPointer<QFile> &localFile);
160 ~AbstractSftpTransfer();
161 void calculateInFlightCount(quint32 chunkSize);
163 static const int MaxInFlightCount;
165 const QSharedPointer<QFile> localFile;
172 struct SftpDownload : public AbstractSftpTransfer
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);
180 QMap<quint32, quint32> offsets;
184 struct SftpUploadFile : public AbstractSftpTransfer
186 typedef QSharedPointer<SftpUploadFile> Ptr;
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);
194 const QSharedPointer<SftpUploadDir> parentJob;
195 SftpOverwriteMode mode;
198 // Composite operation.
201 typedef QSharedPointer<SftpUploadDir> Ptr;
204 Dir(const QString &l, const QString &r) : localDir(l), remoteDir(r) {}
209 SftpUploadDir(SftpJobId jobId) : jobId(jobId), hasError(false) {}
215 uploadsInProgress.clear();
216 mkdirsInProgress.clear();
219 const SftpJobId jobId;
221 QList<SftpUploadFile::Ptr> uploadsInProgress;
222 QMap<SftpMakeDir::Ptr, Dir> mkdirsInProgress;
225 } // namespace Internal
228 #endif // SFTPOPERATION_P_H