RCFProto

- Main Page
- Classes
- Files

- File List

All Classes Functions Typedefs
ZlibCompressionFilter.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_ZLIBCOMPRESSIONFILTER_HPP
20 #define INCLUDE_RCF_ZLIBCOMPRESSIONFILTER_HPP
21
22 #include <memory>
23 #include <vector>
24
25 #include <boost/noncopyable.hpp>
26
27 #include <RCF/Filter.hpp>
28 #include <RCF/Export.hpp>
29
30 namespace RCF {
31
32 static const int ZlibDefaultBufferSize = 4096;
33
34 class ZlibCompressionReadFilter;
35 class ZlibCompressionWriteFilter;
36 class ZlibDll;
37
38 class RCF_EXPORT ZlibCompressionFilterBase :
39 public Filter,
40 boost::noncopyable
41 {
42 public:
43 ZlibCompressionFilterBase(bool stateful, bool serverSide);
44
45 private:
46
47 ZlibDll & mZlibDll;
48
49 void resetState();
50
51 void read(const ByteBuffer &byteBuffer, std::size_t bytesRequested);
52 void write(const std::vector<ByteBuffer> &byteBuffers);
53 void onReadCompleted(const ByteBuffer &byteBuffer);
54 void onWriteCompleted(std::size_t bytesTransferred);
55
56 enum IoState
57 {
58 Ready,
59 Reading,
60 Writing
61 };
62
63 // input state
64 IoState mPreState;
65
66 friend class ZlibCompressionReadFilter;
67 friend class ZlibCompressionWriteFilter;
68
69 boost::shared_ptr<ZlibCompressionReadFilter> mReadFilter;
70 boost::shared_ptr<ZlibCompressionWriteFilter> mWriteFilter;
71 };
72
73 class ServerSide {};
74
75 class RCF_EXPORT ZlibStatelessCompressionFilter :
76 public ZlibCompressionFilterBase
77 {
78 private:
79 friend class ZlibStatelessCompressionFilterFactory;
80
81 ZlibStatelessCompressionFilter(
82 ServerSide *) :
83 ZlibCompressionFilterBase(false, true)
84 {}
85
86 public:
87 ZlibStatelessCompressionFilter() :
88 ZlibCompressionFilterBase(false, false)
89 {}
90
91 int getFilterId() const;
92 };
93
94 class RCF_EXPORT ZlibStatefulCompressionFilter :
95 public ZlibCompressionFilterBase
96 {
97 private:
98 friend class ZlibStatefulCompressionFilterFactory;
99
100 ZlibStatefulCompressionFilter(
101 ServerSide *) :
102 ZlibCompressionFilterBase(true, true)
103 {}
104
105 public:
106 ZlibStatefulCompressionFilter() :
107 ZlibCompressionFilterBase(true, false)
108 {}
109
110 int getFilterId() const;
111 };
112
113 class ZlibStatelessCompressionFilterFactory :
114 public FilterFactory
115 {
116 public:
117 ZlibStatelessCompressionFilterFactory();
118
119 FilterPtr createFilter(RcfServer & server);
120 int getFilterId();
121 };
122
123 class ZlibStatefulCompressionFilterFactory :
124 public FilterFactory
125 {
126 public:
127 ZlibStatefulCompressionFilterFactory();
128
129 FilterPtr createFilter(RcfServer & server);
130 int getFilterId();
131 };
132
133 typedef ZlibStatefulCompressionFilter ZlibCompressionFilter;
134 typedef boost::shared_ptr<ZlibCompressionFilter> ZlibCompressionFilterPtr;
135
136 typedef ZlibStatefulCompressionFilterFactory ZlibCompressionFilterFactory;
137 typedef boost::shared_ptr<ZlibCompressionFilterFactory> ZlibCompressionFilterFactoryPtr;
138
139 } // namespace RCF
140
141 #endif // ! INCLUDE_RCF_ZLIBCOMPRESSIONFILTER_HPP