Remote Call Framework 3.3
FileIoThreadPool.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2022, Delta V Software. All rights reserved.
6 // https://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF under GPL terms.
12 //
13 // Version: 3.3
14 // Contact: support <at> deltavsoft.com
15 //
16 //******************************************************************************
17 
18 #ifndef INCLUDE_RCF_FILEIOTHREADPOOL_HPP
19 #define INCLUDE_RCF_FILEIOTHREADPOOL_HPP
20 
21 #include <deque>
22 #include <memory>
23 
24 #include <RCF/ByteBuffer.hpp>
25 #include <RCF/Exception.hpp>
26 #include <RCF/Export.hpp>
27 #include <RCF/ThreadLibrary.hpp>
28 #include <RCF/ThreadPool.hpp>
29 
30 namespace RCF {
31 
32  class FileIoRequest;
33  typedef std::shared_ptr<FileIoRequest> FileIoRequestPtr;
34 
35  class FileHandle;
36  typedef std::shared_ptr<FileHandle> FileHandlePtr;
37 
38  class RCF_EXPORT FileIoThreadPool
39  {
40  public:
41  FileIoThreadPool();
42  ~FileIoThreadPool();
43 
44  void stop();
45  void registerOp(FileIoRequestPtr opPtr);
46  void unregisterOp(FileIoRequestPtr opPtr);
47 
48  void setSerializeFileIo(bool serializeFileIo);
49 
50  private:
51 
52  friend class FileIoRequest;
53 
54  bool ioTask();
55  void stopIoTask();
56 
57  bool mSerializeFileIo;
58 
59  RCF::Mutex mOpsMutex;
60  RCF::Condition mOpsCondition;
61  std::deque< FileIoRequestPtr > mOpsQueued;
62  std::deque< FileIoRequestPtr > mOpsInProgress;
63 
64  RCF::ThreadPool mThreadPool;
65 
66  RCF::Mutex mCompletionMutex;
67  RCF::Condition mCompletionCondition;
68  };
69 
70  class RCF_EXPORT FileIoRequest :
71  public std::enable_shared_from_this<FileIoRequest>
72  {
73  public:
74  FileIoRequest();
75  ~FileIoRequest();
76 
77  bool isInitiated();
78  bool isCompleted();
79  void complete();
80  void initiateRead(FileHandlePtr finPtr, RCF::ByteBuffer buffer);
81  void initateWrite(FileHandlePtr foutPtr, RCF::ByteBuffer buffer);
82 
83  std::uint64_t getBytesTransferred();
84 
85  private:
86 
87  friend class FileIoThreadPool;
88 
89  void doTransfer();
90 
91  FileIoThreadPool & mFts;
92 
93  FileHandlePtr mFinPtr;
94  FileHandlePtr mFoutPtr;
95 
96  RCF::ByteBuffer mBuffer;
97  std::uint64_t mBytesTransferred;
98  bool mInitiated;
99  bool mCompleted;
100  RCF::Exception mError;
101  };
102 
103  RCF_EXPORT FileIoThreadPool & getFileIoThreadPool();
104 
105 
106 } // namespace RCF
107 
108 #endif // ! INCLUDE_RCF_FILEIOTHREADPOOL_HPP
Base class for all RCF exceptions.
Definition: Exception.hpp:67
Represents a server-side thread pool.
Definition: ThreadPool.hpp:78
Definition: ByteBuffer.hpp:39
Definition: AmiIoHandler.hpp:23