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