diff options
Diffstat (limited to 'src/conduit.cpp')
-rw-r--r-- | src/conduit.cpp | 226 |
1 files changed, 226 insertions, 0 deletions
diff --git a/src/conduit.cpp b/src/conduit.cpp index bb99526..cfa93d8 100644 --- a/src/conduit.cpp +++ b/src/conduit.cpp | |||
@@ -5,3 +5,229 @@ | |||
5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include "bu/conduit.h" | ||
9 | |||
10 | Bu::Conduit::Conduit( int iBlockSize ) : | ||
11 | qb( iBlockSize ), | ||
12 | bBlocking( true ), | ||
13 | bOpen( true ) | ||
14 | { | ||
15 | } | ||
16 | |||
17 | Bu::Conduit::~Conduit() | ||
18 | { | ||
19 | } | ||
20 | |||
21 | void Bu::Conduit::close() | ||
22 | { | ||
23 | im.lock(); | ||
24 | // qb.close(); | ||
25 | bOpen = false; | ||
26 | |||
27 | cBlock.signal(); | ||
28 | im.unlock(); | ||
29 | } | ||
30 | |||
31 | #include <stdio.h> | ||
32 | Bu::size Bu::Conduit::read( void *pBuf, Bu::size nBytes ) | ||
33 | { | ||
34 | if( !isOpen() ) | ||
35 | { | ||
36 | return 0; | ||
37 | } | ||
38 | im.lock(); | ||
39 | if( bBlocking ) | ||
40 | { | ||
41 | im.unlock(); | ||
42 | cBlock.lock(); | ||
43 | for(;;) | ||
44 | { | ||
45 | im.lock(); | ||
46 | if( qb.getSize() == 0 && bOpen == false ) | ||
47 | { | ||
48 | im.unlock(); | ||
49 | cBlock.unlock(); | ||
50 | return 0; | ||
51 | } | ||
52 | else if( qb.getSize() > 0 ) | ||
53 | { | ||
54 | im.unlock(); | ||
55 | break; | ||
56 | } | ||
57 | im.unlock(); | ||
58 | |||
59 | cBlock.wait(); | ||
60 | } | ||
61 | |||
62 | im.lock(); | ||
63 | Bu::size iRet = qb.read( pBuf, nBytes ); | ||
64 | im.unlock(); | ||
65 | |||
66 | cBlock.unlock(); | ||
67 | return iRet; | ||
68 | } | ||
69 | else | ||
70 | { | ||
71 | Bu::size iRet = qb.read( pBuf, nBytes ); | ||
72 | im.unlock(); | ||
73 | |||
74 | return iRet; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | Bu::size Bu::Conduit::peek( void *pBuf, Bu::size nBytes ) | ||
79 | { | ||
80 | im.lock(); | ||
81 | Bu::size iRet = qb.peek( pBuf, nBytes ); | ||
82 | im.unlock(); | ||
83 | |||
84 | return iRet; | ||
85 | } | ||
86 | |||
87 | Bu::size Bu::Conduit::peek( void *pBuf, Bu::size nBytes, Bu::size nSkip ) | ||
88 | { | ||
89 | im.lock(); | ||
90 | Bu::size iRet = qb.peek( pBuf, nBytes, nSkip ); | ||
91 | im.unlock(); | ||
92 | |||
93 | return iRet; | ||
94 | } | ||
95 | |||
96 | Bu::size Bu::Conduit::write( const void *pBuf, Bu::size nBytes ) | ||
97 | { | ||
98 | im.lock(); | ||
99 | if( bOpen == false ) | ||
100 | { | ||
101 | im.unlock(); | ||
102 | return 0; | ||
103 | } | ||
104 | Bu::size sRet = qb.write( pBuf, nBytes ); | ||
105 | cBlock.signal(); | ||
106 | im.unlock(); | ||
107 | |||
108 | return sRet; | ||
109 | } | ||
110 | |||
111 | Bu::size Bu::Conduit::tell() | ||
112 | { | ||
113 | im.lock(); | ||
114 | Bu::size sRet = qb.tell(); | ||
115 | im.unlock(); | ||
116 | return sRet; | ||
117 | } | ||
118 | |||
119 | void Bu::Conduit::seek( Bu::size offset ) | ||
120 | { | ||
121 | } | ||
122 | |||
123 | void Bu::Conduit::setPos( Bu::size pos ) | ||
124 | { | ||
125 | } | ||
126 | |||
127 | void Bu::Conduit::setPosEnd( Bu::size pos ) | ||
128 | { | ||
129 | } | ||
130 | |||
131 | bool Bu::Conduit::isEos() | ||
132 | { | ||
133 | im.lock(); | ||
134 | bool bRet = qb.isEos(); | ||
135 | im.unlock(); | ||
136 | return bRet; | ||
137 | } | ||
138 | |||
139 | bool Bu::Conduit::isOpen() | ||
140 | { | ||
141 | im.lock(); | ||
142 | bool bRet = bOpen || (qb.getSize() > 0); | ||
143 | im.unlock(); | ||
144 | return bRet; | ||
145 | } | ||
146 | |||
147 | void Bu::Conduit::flush() | ||
148 | { | ||
149 | } | ||
150 | |||
151 | bool Bu::Conduit::canRead() | ||
152 | { | ||
153 | im.lock(); | ||
154 | bool bRet = qb.canRead(); | ||
155 | im.unlock(); | ||
156 | return bRet; | ||
157 | } | ||
158 | |||
159 | bool Bu::Conduit::canWrite() | ||
160 | { | ||
161 | im.lock(); | ||
162 | bool bRet = qb.canWrite(); | ||
163 | im.unlock(); | ||
164 | return bRet; | ||
165 | } | ||
166 | |||
167 | bool Bu::Conduit::isReadable() | ||
168 | { | ||
169 | im.lock(); | ||
170 | bool bRet = qb.isReadable(); | ||
171 | im.unlock(); | ||
172 | return bRet; | ||
173 | } | ||
174 | |||
175 | bool Bu::Conduit::isWritable() | ||
176 | { | ||
177 | im.lock(); | ||
178 | bool bRet = qb.isWritable(); | ||
179 | im.unlock(); | ||
180 | return bRet; | ||
181 | } | ||
182 | |||
183 | bool Bu::Conduit::isSeekable() | ||
184 | { | ||
185 | im.lock(); | ||
186 | bool bRet = qb.isSeekable(); | ||
187 | im.unlock(); | ||
188 | return bRet; | ||
189 | } | ||
190 | |||
191 | bool Bu::Conduit::isBlocking() | ||
192 | { | ||
193 | im.lock(); | ||
194 | bool bRet = bBlocking; | ||
195 | im.unlock(); | ||
196 | return bRet; | ||
197 | } | ||
198 | |||
199 | void Bu::Conduit::setBlocking( bool bBlocking ) | ||
200 | { | ||
201 | im.lock(); | ||
202 | this->bBlocking = bBlocking; | ||
203 | im.unlock(); | ||
204 | } | ||
205 | |||
206 | void Bu::Conduit::setSize( Bu::size iSize ) | ||
207 | { | ||
208 | } | ||
209 | |||
210 | Bu::size Bu::Conduit::getSize() const | ||
211 | { | ||
212 | im.lock(); | ||
213 | Bu::size sRet = qb.getSize(); | ||
214 | im.unlock(); | ||
215 | return sRet; | ||
216 | } | ||
217 | |||
218 | Bu::size Bu::Conduit::getBlockSize() const | ||
219 | { | ||
220 | im.lock(); | ||
221 | Bu::size sRet = qb.getBlockSize(); | ||
222 | im.unlock(); | ||
223 | return sRet; | ||
224 | } | ||
225 | |||
226 | Bu::String Bu::Conduit::getLocation() const | ||
227 | { | ||
228 | im.lock(); | ||
229 | Bu::String sRet = qb.getLocation(); | ||
230 | im.unlock(); | ||
231 | return sRet; | ||
232 | } | ||
233 | |||