RCFProto

- Main Page
- Classes
- Files

- File List

All Classes Functions Typedefs
FileIoThreadPool.hpp
1
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2013, 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: 2.0
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 <fstream>
24 #include <boost/shared_ptr.hpp>
25
26 #include <RCF/ByteBuffer.hpp>
27 #include <RCF/Exception.hpp>
28 #include <RCF/Export.hpp>
29 #include <RCF/ThreadLibrary.hpp>
30 #include <RCF/ThreadPool.hpp>
31
32 namespace RCF {
33
34 class FileIoRequest;
35 typedef boost::shared_ptr<FileIoRequest> FileIoRequestPtr;
36
37 class RCF_EXPORT FileIoThreadPool
38 {
39 public:
40 FileIoThreadPool();
41 ~FileIoThreadPool();
42
43 void stop();
44 void registerOp(FileIoRequestPtr opPtr);
45 void unregisterOp(FileIoRequestPtr opPtr);
46
47 void setSerializeFileIo(bool serializeFileIo);
48
49 private:
50
51 friend class FileIoRequest;
52
53 bool ioTask();
54 void stopIoTask();
55
56 bool mSerializeFileIo;
57
58 RCF::Mutex mOpsMutex;
59 RCF::Condition mOpsCondition;
60 std::deque< FileIoRequestPtr > mOpsQueued;
61 std::deque< FileIoRequestPtr > mOpsInProgress;
62
63 RCF::ThreadPool mThreadPool;
64
65 RCF::Mutex mCompletionMutex;
66 RCF::Condition mCompletionCondition;
67 };
68
69 typedef boost::shared_ptr< std::ifstream > IfstreamPtr;
70 typedef boost::shared_ptr< std::ofstream > OfstreamPtr;
71
72 class RCF_EXPORT FileIoRequest :
73 public boost::enable_shared_from_this<FileIoRequest>
74 {
75 public:
76 FileIoRequest();
77 ~FileIoRequest();
78
79 bool isInitiated();
80 bool isCompleted();
81 void complete();
82 void initiateRead(IfstreamPtr finPtr, RCF::ByteBuffer buffer);
83 void initateWrite(OfstreamPtr foutPtr, RCF::ByteBuffer buffer);
84
85 boost::uint64_t getBytesTransferred();
86
87 private:
88
89 friend class FileIoThreadPool;
90
91 void doTransfer();
92
93 FileIoThreadPool & mFts;
94
95 IfstreamPtr mFinPtr;
96 OfstreamPtr mFoutPtr;
97
98 RCF::ByteBuffer mBuffer;
99 boost::uint64_t mBytesTransferred;
100 bool mInitiated;
101 bool mCompleted;
102 RCF::Exception mError;
103 };
104
105 RCF_EXPORT FileIoThreadPool & getFileIoThreadPool();
106
107
108 } // namespace RCF
109
110 #endif // ! INCLUDE_RCF_FILEIOTHREADPOOL_HPP