21 #ifndef INCLUDE_RCF_FILESTREAM_HPP 22 #define INCLUDE_RCF_FILESTREAM_HPP 24 #include <RCF/Config.hpp> 26 #if RCF_FEATURE_FILETRANSFER==0 27 #error RCF_FEATURE_FILETRANSFER=1 must be defined 30 #include <RCF/ByteBuffer.hpp> 31 #include <RCF/Exception.hpp> 33 #include <RCF/Export.hpp> 35 #include <RCF/ThreadLibrary.hpp> 36 #include <RCF/Tools.hpp> 42 #if RCF_FEATURE_BOOST_SERIALIZATION==1 43 #include <boost/serialization/vector.hpp> 44 #include <boost/serialization/shared_ptr.hpp> 55 class RCF_EXPORT FileHandle
67 FileHandle(
const Path& filePath, OpenMode mode);
70 void open(
const Path& filePath, OpenMode mode);
73 void seek(std::uint64_t newPos);
76 std::size_t read(
const ByteBuffer& buffer);
77 std::size_t write(
const ByteBuffer& buffer);
79 Exception err()
const;
87 OpenMode mOpenMode = Read;
88 std::size_t mBeginPos = 0;
92 typedef std::shared_ptr< FileHandle > FileHandlePtr;
95 typedef std::shared_ptr<FileUploadInfo> FileUploadInfoPtr;
101 typedef std::shared_ptr<FileStreamImpl> FileStreamImplPtr;
105 class RCF_EXPORT FileInfo
112 std::uint64_t mFileStartPos;
113 std::uint64_t mFileSize;
114 std::uint32_t mFileCrc;
115 std::string mRenameFile;
116 std::uint64_t mLastWriteTime;
118 #if RCF_FEATURE_SF==1 122 #if RCF_FEATURE_BOOST_SERIALIZATION==1 123 template<
typename Archive>
124 void serialize(Archive & ar,
const unsigned int)
126 RCF_UNUSED_VARIABLE(ar);
127 RCF_THROW(Exception(RcfError_BSerFileTransferNotSupported));
133 class RCF_EXPORT FileManifest
136 typedef std::vector< FileInfo > Files;
143 FileManifest(
const Path& pathToFiles);
145 std::uint64_t getTotalByteSize()
const;
147 #if RCF_FEATURE_SF==1 151 #if RCF_FEATURE_BOOST_SERIALIZATION==1 152 template<
typename Archive>
153 void serialize(Archive & ar,
const unsigned int)
155 RCF_UNUSED_VARIABLE(ar);
156 RCF_THROW(Exception(RcfError_BSerFileTransferNotSupported));
162 class RCF_EXPORT FileStreamImpl :
public std::enable_shared_from_this<FileStreamImpl>
175 FileStreamImpl(
const std::string & filePath);
176 FileStreamImpl(
const FileManifest & manifest);
180 void serializeGeneric(
182 std::function<
void(std::uint32_t &, Direction &)> serializeImpl);
184 #if RCF_FEATURE_SF==1 185 void serializeImplSf(
SF::Archive & ar, std::uint32_t & transferId, Direction & dir);
189 #if RCF_FEATURE_BOOST_SERIALIZATION==1 191 template<
typename Archive>
192 void serializeImplBser(Archive & ar, std::uint32_t & transferId, Direction & dir)
194 ar & transferId & dir;
197 template<
typename Archive>
198 void serialize(Archive & ar,
const unsigned int)
200 RCF_UNUSED_VARIABLE(ar);
201 RCF_THROW(Exception(RcfError_BSerFileTransferNotSupported));
206 std::string mUploadId;
207 Path mDownloadToPath;
208 FileManifest mManifest;
209 std::uint32_t mTransferRateBps;
210 std::uint32_t mSessionLocalId;
212 Direction mDirection;
215 class RCF_EXPORT FileStream
220 FileStream(FileStreamImplPtr implPtr);
221 FileStream(
const std::string & filePath);
222 FileStream(
const FileManifest & manifest);
227 FileStream & operator=(
const FileStream & rhs)
229 *mImplPtr = *rhs.mImplPtr;
234 std::string getLocalPath()
const;
235 FileManifest & getManifest()
const;
238 void setDownloadToPath(
const std::string & downloadToPath);
239 std::string getDownloadToPath()
const;
241 void setTransferRateBps(std::uint32_t transferRateBps);
242 std::uint32_t getTransferRateBps();
248 FileStreamImplPtr mImplPtr;
250 #if RCF_FEATURE_SF==1 254 #if RCF_FEATURE_BOOST_SERIALIZATION==1 255 template<
typename Archive>
256 void serialize(Archive & ar,
const unsigned int)
258 RCF_UNUSED_VARIABLE(ar);
259 RCF_THROW(Exception(RcfError_BSerFileTransferNotSupported));
291 bool isEmpty()
const;
293 std::uint32_t mFileIndex;
294 std::uint64_t mOffset;
297 #if RCF_FEATURE_SF==1 301 #if RCF_FEATURE_BOOST_SERIALIZATION==1 302 template<
typename Archive>
303 void serialize(Archive & ar,
const unsigned int)
305 RCF_UNUSED_VARIABLE(ar);
306 RCF_THROW(
Exception(RcfError_BSerFileTransferNotSupported));
312 class FileTransferRequest
315 FileTransferRequest();
319 std::uint32_t mChunkSize;
321 #if RCF_FEATURE_SF==1 325 #if RCF_FEATURE_BOOST_SERIALIZATION==1 326 template<
typename Archive>
327 void serialize(Archive & ar,
const unsigned int)
329 RCF_UNUSED_VARIABLE(ar);
330 RCF_THROW(
Exception(RcfError_BSerFileTransferNotSupported));
347 void setQuota(std::uint32_t quotaBps);
349 std::uint32_t calculateLineSpeedLimit();
364 std::uint32_t mQuotaBps;
366 std::set<FileDownloadInfo *> mDownloadsInProgress;
367 std::set<FileUploadInfo *> mUploadsInProgress;
376 std::uint32_t mBandwidthLimitBps = 0;
382 std::uint64_t mStartPos = 0;
385 std::uint64_t mEndPos = 0;
391 std::uint32_t mChunkSize = 0;
397 #endif // ! INCLUDE_RCF_FILESTREAM_HPP Represents an archive, in which serialized objects are stored.
Definition: Archive.hpp:32
RCF_FILESYSTEM_NS::path Path
Typedef for standard C++ path type.
Definition: FileSystem.hpp:35
FileProgressCallback mProgressCallback
Progress callback. Called during the transfer to provide progress information.
Definition: FileStream.hpp:388
Path mDownloadPath
Local path a file is being downloaded to. Only relevant to downloads.
Definition: FileStream.hpp:273
Client side options for downloading and uploading files.
Definition: FileStream.hpp:371
std::shared_ptr< BandwidthQuota > BandwidthQuotaPtr
Reference counted wrapper for RCF::BandwidthQuota.
Definition: RcfFwd.hpp:127
Controls the client side of a RCF connection.
Definition: ClientStub.hpp:82
Server-side information about a file download taking place from a RcfServer.
Definition: FileTransferService.hpp:98
Base class for all RCF exceptions.
Definition: Exception.hpp:64
std::function< void(const FileTransferProgress &, RemoteCallAction &)> FileProgressCallback
Describes user-provided callback functions for client-side monitoring of a file transfer (download or...
Definition: RcfFwd.hpp:131
Definition: ByteBuffer.hpp:189
BandwidthQuotaPtr mBandwidthQuotaPtr
Bandwidth quota associated with the transfer.
Definition: FileStream.hpp:379
Describes a unit of bandwidth, to be used by downloads or uploads, for a single connection or a group...
Definition: FileStream.hpp:337
std::uint64_t mBytesTotalToTransfer
Total number of bytes that are to be transferred.
Definition: FileStream.hpp:276
Definition: ByteBuffer.hpp:40
Definition: AmiIoHandler.hpp:24
Server-side information about a file upload taking place to a RcfServer.
Definition: FileTransferService.hpp:66
std::uint64_t mBytesTransferredSoFar
Bytes that have been transferred so far.
Definition: FileStream.hpp:279
Describes progress of a file download or upload.
Definition: FileStream.hpp:266
std::uint32_t mServerLimitBps
Bandwidth limit (bytes per second) imposed by server, if any.
Definition: FileStream.hpp:282