diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-08-21 04:39:47 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-08-21 04:39:47 +0000 |
commit | 7f17eeb7fccd52b7049f9f598121130dfd1b55ae (patch) | |
tree | 8afca1e4459f0bc719941514009f046cd77f88ed /src | |
parent | a83e9babede7ab5bc8e1ac6c7ee3784b91bd8452 (diff) | |
download | libbu++-7f17eeb7fccd52b7049f9f598121130dfd1b55ae.tar.gz libbu++-7f17eeb7fccd52b7049f9f598121130dfd1b55ae.tar.bz2 libbu++-7f17eeb7fccd52b7049f9f598121130dfd1b55ae.tar.xz libbu++-7f17eeb7fccd52b7049f9f598121130dfd1b55ae.zip |
Client now inherits from stream. This could be cool, it could really mess\nthings up. We shall see. In other news, I'm adding a Bu::StreamStack class\nthat will let you easily manage dynamic stream/filter sets.
Diffstat (limited to '')
-rw-r--r-- | src/client.cpp | 107 | ||||
-rw-r--r-- | src/client.h | 45 | ||||
-rw-r--r-- | src/streamstack.cpp | 86 | ||||
-rw-r--r-- | src/streamstack.h | 47 |
4 files changed, 250 insertions, 35 deletions
diff --git a/src/client.cpp b/src/client.cpp index 095dd91..789cda4 100644 --- a/src/client.cpp +++ b/src/client.cpp | |||
@@ -125,62 +125,62 @@ bool Bu::Client::isOpen() | |||
125 | return pTopStream->isOpen(); | 125 | return pTopStream->isOpen(); |
126 | } | 126 | } |
127 | 127 | ||
128 | void Bu::Client::write( const Bu::FString &sData ) | 128 | size_t Bu::Client::write( const Bu::FString &sData ) |
129 | { | 129 | { |
130 | qbWrite.write( sData.getStr(), sData.getSize() ); | 130 | return qbWrite.write( sData.getStr(), sData.getSize() ); |
131 | } | 131 | } |
132 | 132 | ||
133 | void Bu::Client::write( const void *pData, int nBytes ) | 133 | size_t Bu::Client::write( const void *pData, size_t nBytes ) |
134 | { | 134 | { |
135 | qbWrite.write( pData, nBytes ); | 135 | return qbWrite.write( pData, nBytes ); |
136 | } | 136 | } |
137 | 137 | ||
138 | void Bu::Client::write( int8_t nData ) | 138 | size_t Bu::Client::write( int8_t nData ) |
139 | { | 139 | { |
140 | qbWrite.write( (const char *)&nData, sizeof(nData) ); | 140 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
141 | } | 141 | } |
142 | 142 | ||
143 | void Bu::Client::write( int16_t nData ) | 143 | size_t Bu::Client::write( int16_t nData ) |
144 | { | 144 | { |
145 | qbWrite.write( (const char *)&nData, sizeof(nData) ); | 145 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
146 | } | 146 | } |
147 | 147 | ||
148 | void Bu::Client::write( int32_t nData ) | 148 | size_t Bu::Client::write( int32_t nData ) |
149 | { | 149 | { |
150 | qbWrite.write( (const char *)&nData, sizeof(nData) ); | 150 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
151 | } | 151 | } |
152 | 152 | ||
153 | void Bu::Client::write( int64_t nData ) | 153 | size_t Bu::Client::write( int64_t nData ) |
154 | { | 154 | { |
155 | qbWrite.write( (const char *)&nData, sizeof(nData) ); | 155 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
156 | } | 156 | } |
157 | 157 | ||
158 | void Bu::Client::write( uint8_t nData ) | 158 | size_t Bu::Client::write( uint8_t nData ) |
159 | { | 159 | { |
160 | qbWrite.write( (const char *)&nData, sizeof(nData) ); | 160 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
161 | } | 161 | } |
162 | 162 | ||
163 | void Bu::Client::write( uint16_t nData ) | 163 | size_t Bu::Client::write( uint16_t nData ) |
164 | { | 164 | { |
165 | qbWrite.write( (const char *)&nData, sizeof(nData) ); | 165 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
166 | } | 166 | } |
167 | 167 | ||
168 | void Bu::Client::write( uint32_t nData ) | 168 | size_t Bu::Client::write( uint32_t nData ) |
169 | { | 169 | { |
170 | qbWrite.write( (const char *)&nData, sizeof(nData) ); | 170 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
171 | } | 171 | } |
172 | 172 | ||
173 | void Bu::Client::write( uint64_t nData ) | 173 | size_t Bu::Client::write( uint64_t nData ) |
174 | { | 174 | { |
175 | qbWrite.write( (const char *)&nData, sizeof(nData) ); | 175 | return qbWrite.write( (const char *)&nData, sizeof(nData) ); |
176 | } | 176 | } |
177 | 177 | ||
178 | int Bu::Client::read( void *pData, int nBytes ) | 178 | size_t Bu::Client::read( void *pData, size_t nBytes ) |
179 | { | 179 | { |
180 | return qbRead.read( pData, nBytes ); | 180 | return qbRead.read( pData, nBytes ); |
181 | } | 181 | } |
182 | 182 | ||
183 | int Bu::Client::peek( void *pData, int nBytes, int nOffset ) | 183 | size_t Bu::Client::peek( void *pData, int nBytes, int nOffset ) |
184 | { | 184 | { |
185 | return qbRead.peek( pData, nBytes, nOffset ); | 185 | return qbRead.peek( pData, nBytes, nOffset ); |
186 | } | 186 | } |
@@ -237,3 +237,66 @@ void Bu::Client::tick() | |||
237 | pProto->onTick( this ); | 237 | pProto->onTick( this ); |
238 | } | 238 | } |
239 | 239 | ||
240 | long Bu::Client::tell() | ||
241 | { | ||
242 | } | ||
243 | |||
244 | void Bu::Client::seek( long offset ) | ||
245 | { | ||
246 | } | ||
247 | |||
248 | void Bu::Client::setPos( long pos ) | ||
249 | { | ||
250 | } | ||
251 | |||
252 | void Bu::Client::setPosEnd( long pos ) | ||
253 | { | ||
254 | } | ||
255 | |||
256 | bool Bu::Client::isEos() | ||
257 | { | ||
258 | return true; | ||
259 | } | ||
260 | |||
261 | void Bu::Client::flush() | ||
262 | { | ||
263 | } | ||
264 | |||
265 | bool Bu::Client::canRead() | ||
266 | { | ||
267 | return qbRead.getSize() > 0; | ||
268 | } | ||
269 | |||
270 | bool Bu::Client::canWrite() | ||
271 | { | ||
272 | return true; | ||
273 | } | ||
274 | |||
275 | bool Bu::Client::isReadable() | ||
276 | { | ||
277 | return true; | ||
278 | } | ||
279 | |||
280 | bool Bu::Client::isWritable() | ||
281 | { | ||
282 | return true; | ||
283 | } | ||
284 | |||
285 | bool Bu::Client::isSeekable() | ||
286 | { | ||
287 | return false; | ||
288 | } | ||
289 | |||
290 | bool Bu::Client::isBlocking() | ||
291 | { | ||
292 | return false; | ||
293 | } | ||
294 | |||
295 | void Bu::Client::setBlocking( bool bBlocking ) | ||
296 | { | ||
297 | } | ||
298 | |||
299 | void Bu::Client::setSize( long iSize ) | ||
300 | { | ||
301 | } | ||
302 | |||
diff --git a/src/client.h b/src/client.h index 5a933ca..105d48f 100644 --- a/src/client.h +++ b/src/client.h | |||
@@ -23,7 +23,7 @@ namespace Bu | |||
23 | /** | 23 | /** |
24 | *@ingroup Serving | 24 | *@ingroup Serving |
25 | */ | 25 | */ |
26 | class Client | 26 | class Client : public Bu::Stream |
27 | { | 27 | { |
28 | public: | 28 | public: |
29 | Client( Bu::Socket *pSocket, Bu::ClientLinkFactory *pfLink ); | 29 | Client( Bu::Socket *pSocket, Bu::ClientLinkFactory *pfLink ); |
@@ -34,18 +34,18 @@ namespace Bu | |||
34 | 34 | ||
35 | //Bu::FString &getInput(); | 35 | //Bu::FString &getInput(); |
36 | //Bu::FString &getOutput(); | 36 | //Bu::FString &getOutput(); |
37 | void write( const Bu::FString &sData ); | 37 | size_t write( const Bu::FString &sData ); |
38 | void write( const void *pData, int nBytes ); | 38 | size_t write( const void *pData, size_t nBytes ); |
39 | void write( int8_t nData ); | 39 | size_t write( int8_t nData ); |
40 | void write( int16_t nData ); | 40 | size_t write( int16_t nData ); |
41 | void write( int32_t nData ); | 41 | size_t write( int32_t nData ); |
42 | void write( int64_t nData ); | 42 | size_t write( int64_t nData ); |
43 | void write( uint8_t nData ); | 43 | size_t write( uint8_t nData ); |
44 | void write( uint16_t nData ); | 44 | size_t write( uint16_t nData ); |
45 | void write( uint32_t nData ); | 45 | size_t write( uint32_t nData ); |
46 | void write( uint64_t nData ); | 46 | size_t write( uint64_t nData ); |
47 | int read( void *pData, int nBytes ); | 47 | size_t read( void *pData, size_t nBytes ); |
48 | int peek( void *pData, int nBytes, int nOffset=0 ); | 48 | size_t peek( void *pData, int nBytes, int nOffset=0 ); |
49 | void seek( int nBytes ); | 49 | void seek( int nBytes ); |
50 | long getInputSize(); | 50 | long getInputSize(); |
51 | long getOutputSize(); | 51 | long getOutputSize(); |
@@ -94,6 +94,25 @@ namespace Bu | |||
94 | lFilts.prepend( pFlt ); | 94 | lFilts.prepend( pFlt ); |
95 | } | 95 | } |
96 | 96 | ||
97 | /* | ||
98 | * These are required to qualify as a stream, I dunno how many will | ||
99 | * be implemented. | ||
100 | */ | ||
101 | virtual long tell(); | ||
102 | virtual void seek( long offset ); | ||
103 | virtual void setPos( long pos ); | ||
104 | virtual void setPosEnd( long pos ); | ||
105 | virtual bool isEos(); | ||
106 | virtual void flush(); | ||
107 | virtual bool canRead(); | ||
108 | virtual bool canWrite(); | ||
109 | virtual bool isReadable(); | ||
110 | virtual bool isWritable(); | ||
111 | virtual bool isSeekable(); | ||
112 | virtual bool isBlocking(); | ||
113 | virtual void setBlocking( bool bBlocking=true ); | ||
114 | virtual void setSize( long iSize ); | ||
115 | |||
97 | private: | 116 | private: |
98 | typedef Bu::List<Bu::Stream *> FilterList; | 117 | typedef Bu::List<Bu::Stream *> FilterList; |
99 | FilterList lFilts; | 118 | FilterList lFilts; |
diff --git a/src/streamstack.cpp b/src/streamstack.cpp new file mode 100644 index 0000000..9e45cc4 --- /dev/null +++ b/src/streamstack.cpp | |||
@@ -0,0 +1,86 @@ | |||
1 | #include "bu/streamstack.h" | ||
2 | |||
3 | Bu::StreamStack::StreamStack() | ||
4 | { | ||
5 | } | ||
6 | |||
7 | Bu::StreamStack::~StreamStack() | ||
8 | { | ||
9 | } | ||
10 | |||
11 | void Bu::StreamStack::close() | ||
12 | { | ||
13 | } | ||
14 | |||
15 | size_t Bu::StreamStack::read( void *pBuf, size_t nBytes ) | ||
16 | { | ||
17 | } | ||
18 | |||
19 | size_t Bu::StreamStack::write( const void *pBuf, size_t nBytes ) | ||
20 | { | ||
21 | } | ||
22 | |||
23 | size_t Bu::StreamStack::write( const Bu::FString &sBuf ) | ||
24 | { | ||
25 | } | ||
26 | |||
27 | long Bu::StreamStack::tell() | ||
28 | { | ||
29 | } | ||
30 | |||
31 | void Bu::StreamStack::seek( long offset ) | ||
32 | { | ||
33 | } | ||
34 | |||
35 | void Bu::StreamStack::setPos( long pos ) | ||
36 | { | ||
37 | } | ||
38 | |||
39 | void Bu::StreamStack::setPosEnd( long pos ) | ||
40 | { | ||
41 | } | ||
42 | |||
43 | bool Bu::StreamStack::isEos() | ||
44 | { | ||
45 | } | ||
46 | |||
47 | bool Bu::StreamStack::isOpen() | ||
48 | { | ||
49 | } | ||
50 | |||
51 | void Bu::StreamStack::flush() | ||
52 | { | ||
53 | } | ||
54 | |||
55 | bool Bu::StreamStack::canRead() | ||
56 | { | ||
57 | } | ||
58 | |||
59 | bool Bu::StreamStack::canWrite() | ||
60 | { | ||
61 | } | ||
62 | |||
63 | bool Bu::StreamStack::isReadable() | ||
64 | { | ||
65 | } | ||
66 | |||
67 | bool Bu::StreamStack::isWritable() | ||
68 | { | ||
69 | } | ||
70 | |||
71 | bool Bu::StreamStack::isSeekable() | ||
72 | { | ||
73 | } | ||
74 | |||
75 | bool Bu::StreamStack::isBlocking() | ||
76 | { | ||
77 | } | ||
78 | |||
79 | void Bu::StreamStack::setBlocking( bool bBlocking ) | ||
80 | { | ||
81 | } | ||
82 | |||
83 | void Bu::StreamStack::setSize( long iSize ) | ||
84 | { | ||
85 | } | ||
86 | |||
diff --git a/src/streamstack.h b/src/streamstack.h new file mode 100644 index 0000000..03d8d8f --- /dev/null +++ b/src/streamstack.h | |||
@@ -0,0 +1,47 @@ | |||
1 | #ifndef BU_STREAM_STACK_H | ||
2 | #define BU_STREAM_STACK_H | ||
3 | |||
4 | #include "bu/stream.h" | ||
5 | |||
6 | namespace Bu | ||
7 | { | ||
8 | class StreamStack : public Bu::Stream | ||
9 | { | ||
10 | public: | ||
11 | StreamStack(); | ||
12 | virtual ~StreamStack(); | ||
13 | |||
14 | |||
15 | // | ||
16 | // Everything below here merely passes on the call to the top of the | ||
17 | // stream stack. | ||
18 | // | ||
19 | |||
20 | virtual void close(); | ||
21 | virtual size_t read( void *pBuf, size_t nBytes ); | ||
22 | virtual size_t write( const void *pBuf, size_t nBytes ); | ||
23 | |||
24 | virtual size_t write( const Bu::FString &sBuf ); | ||
25 | virtual long tell(); | ||
26 | virtual void seek( long offset ); | ||
27 | virtual void setPos( long pos ); | ||
28 | virtual void setPosEnd( long pos ); | ||
29 | virtual bool isEos(); | ||
30 | virtual bool isOpen(); | ||
31 | virtual void flush(); | ||
32 | virtual bool canRead(); | ||
33 | virtual bool canWrite(); | ||
34 | virtual bool isReadable(); | ||
35 | virtual bool isWritable(); | ||
36 | virtual bool isSeekable(); | ||
37 | virtual bool isBlocking(); | ||
38 | virtual void setBlocking( bool bBlocking=true ); | ||
39 | virtual void setSize( long iSize ); | ||
40 | |||
41 | private: | ||
42 | typedef Bu::List<Bu::Stream *> FilterList; | ||
43 | FilterList lFilts; | ||
44 | }; | ||
45 | }; | ||
46 | |||
47 | #endif | ||