20 #ifndef INCLUDE_RCF_FILESTREAM_HPP 21 #define INCLUDE_RCF_FILESTREAM_HPP 23 #include <RCF/Config.hpp> 25 #if RCF_FEATURE_FILETRANSFER==0 26 #error RCF_FEATURE_FILETRANSFER=1 must be defined 29 #include <RCF/ByteBuffer.hpp> 30 #include <RCF/Exception.hpp> 32 #include <RCF/Export.hpp> 34 #include <RCF/ThreadLibrary.hpp> 35 #include <RCF/Tools.hpp> 41 #if RCF_FEATURE_BOOST_SERIALIZATION==1 42 #include <boost/serialization/vector.hpp> 43 #include <boost/serialization/shared_ptr.hpp> 54 class RCF_EXPORT FileHandle
66 FileHandle(
const Path& filePath, OpenMode mode);
69 void open(
const Path& filePath, OpenMode mode);
72 void seek(std::uint64_t newPos);
75 std::size_t read(
const ByteBuffer& buffer);
76 std::size_t write(
const ByteBuffer& buffer);
78 Exception err()
const;
86 OpenMode mOpenMode = Read;
87 std::size_t mBeginPos = 0;
91 typedef std::shared_ptr< FileHandle > FileHandlePtr;
94 typedef std::shared_ptr<FileUploadInfo> FileUploadInfoPtr;
100 typedef std::shared_ptr<FileStreamImpl> FileStreamImplPtr;
104 class RCF_EXPORT FileInfo
111 std::uint64_t mFileStartPos;
112 std::uint64_t mFileSize;
113 std::uint32_t mFileCrc;
114 std::string mRenameFile;
115 std::uint64_t mLastWriteTime;
117 #if RCF_FEATURE_SF==1 121 #if RCF_FEATURE_BOOST_SERIALIZATION==1 122 template<
typename Archive>
123 void serialize(Archive & ar,
const unsigned int)
125 RCF_UNUSED_VARIABLE(ar);
126 RCF_THROW(Exception(RcfError_BSerFileTransferNotSupported));
132 class RCF_EXPORT FileManifest
135 typedef std::vector< FileInfo > Files;
142 FileManifest(
const Path& pathToFiles);
144 std::uint64_t getTotalByteSize()
const;
146 #if RCF_FEATURE_SF==1 150 #if RCF_FEATURE_BOOST_SERIALIZATION==1 151 template<
typename Archive>
152 void serialize(Archive & ar,
const unsigned int)
154 RCF_UNUSED_VARIABLE(ar);
155 RCF_THROW(Exception(RcfError_BSerFileTransferNotSupported));
161 class RCF_EXPORT FileStreamImpl :
public std::enable_shared_from_this<FileStreamImpl>
174 FileStreamImpl(
const std::string & filePath);
175 FileStreamImpl(
const FileManifest & manifest);
179 void serializeGeneric(
181 std::function<
void(std::uint32_t &, Direction &)> serializeImpl);
183 #if RCF_FEATURE_SF==1 184 void serializeImplSf(
SF::Archive & ar, std::uint32_t & transferId, Direction & dir);
188 #if RCF_FEATURE_BOOST_SERIALIZATION==1 190 template<
typename Archive>
191 void serializeImplBser(Archive & ar, std::uint32_t & transferId, Direction & dir)
193 ar & transferId & dir;
196 template<
typename Archive>
197 void serialize(Archive & ar,
const unsigned int)
199 RCF_UNUSED_VARIABLE(ar);
200 RCF_THROW(Exception(RcfError_BSerFileTransferNotSupported));
205 std::string mUploadId;
206 Path mDownloadToPath;
207 FileManifest mManifest;
208 std::uint32_t mTransferRateBps;
209 std::uint32_t mSessionLocalId;
211 Direction mDirection;
214 class RCF_EXPORT FileStream
219 FileStream(FileStreamImplPtr implPtr);
220 FileStream(
const std::string & filePath);
221 FileStream(
const FileManifest & manifest);
226 FileStream & operator=(
const FileStream & rhs)
228 *mImplPtr = *rhs.mImplPtr;
233 std::string getLocalPath()
const;
234 FileManifest & getManifest()
const;
237 void setDownloadToPath(
const std::string & downloadToPath);
238 std::string getDownloadToPath()
const;
240 void setTransferRateBps(std::uint32_t transferRateBps);
241 std::uint32_t getTransferRateBps();
247 FileStreamImplPtr mImplPtr;
249 #if RCF_FEATURE_SF==1 253 #if RCF_FEATURE_BOOST_SERIALIZATION==1 254 template<
typename Archive>
255 void serialize(Archive & ar,
const unsigned int)
257 RCF_UNUSED_VARIABLE(ar);
258 RCF_THROW(Exception(RcfError_BSerFileTransferNotSupported));
290 bool isEmpty()
const;
292 std::uint32_t mFileIndex;
293 std::uint64_t mOffset;
296 #if RCF_FEATURE_SF==1 300 #if RCF_FEATURE_BOOST_SERIALIZATION==1 301 template<
typename Archive>
302 void serialize(Archive & ar,
const unsigned int)
304 RCF_UNUSED_VARIABLE(ar);
305 RCF_THROW(
Exception(RcfError_BSerFileTransferNotSupported));
311 class FileTransferRequest
314 FileTransferRequest();
318 std::uint32_t mChunkSize;
320 #if RCF_FEATURE_SF==1 324 #if RCF_FEATURE_BOOST_SERIALIZATION==1 325 template<
typename Archive>
326 void serialize(Archive & ar,
const unsigned int)
328 RCF_UNUSED_VARIABLE(ar);
329 RCF_THROW(
Exception(RcfError_BSerFileTransferNotSupported));
346 void setQuota(std::uint32_t quotaBps);
348 std::uint32_t calculateLineSpeedLimit();
363 std::uint32_t mQuotaBps;
365 std::set<FileDownloadInfo *> mDownloadsInProgress;
366 std::set<FileUploadInfo *> mUploadsInProgress;
375 std::uint32_t mBandwidthLimitBps = 0;
381 std::uint64_t mStartPos = 0;
384 std::uint64_t mEndPos = 0;
390 std::uint32_t mChunkSize = 0;
396 #endif // ! INCLUDE_RCF_FILESTREAM_HPP Represents an archive, in which serialized objects are stored.
Definition: Archive.hpp:31
RCF_FILESYSTEM_NS::path Path
Typedef for standard C++ path type.
Definition: FileSystem.hpp:31
FileProgressCallback mProgressCallback
Progress callback. Called during the transfer to provide progress information.
Definition: FileStream.hpp:387
Path mDownloadPath
Local path a file is being downloaded to. Only relevant to downloads.
Definition: FileStream.hpp:272
Client side options for downloading and uploading files.
Definition: FileStream.hpp:370
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:97
Base class for all RCF exceptions.
Definition: Exception.hpp:67
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:188
BandwidthQuotaPtr mBandwidthQuotaPtr
Bandwidth quota associated with the transfer.
Definition: FileStream.hpp:378
Describes a unit of bandwidth, to be used by downloads or uploads, for a single connection or a group...
Definition: FileStream.hpp:336
std::uint64_t mBytesTotalToTransfer
Total number of bytes that are to be transferred.
Definition: FileStream.hpp:275
Definition: ByteBuffer.hpp:39
Definition: AmiIoHandler.hpp:23
Server-side information about a file upload taking place to a RcfServer.
Definition: FileTransferService.hpp:65
std::uint64_t mBytesTransferredSoFar
Bytes that have been transferred so far.
Definition: FileStream.hpp:278
Describes progress of a file download or upload.
Definition: FileStream.hpp:265
std::uint32_t mServerLimitBps
Bandwidth limit (bytes per second) imposed by server, if any.
Definition: FileStream.hpp:281