diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-03-25 20:00:08 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-03-25 20:00:08 +0000 |
commit | 469bbcf0701e1eb8a6670c23145b0da87357e178 (patch) | |
tree | b5b062a16e46a6c5d3410b4e574cd0cc09057211 /src/stable/client.h | |
parent | ee1b79396076edc4e30aefb285fada03bb45e80d (diff) | |
download | libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.gz libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.bz2 libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.xz libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.zip |
Code is all reorganized. We're about ready to release. I should write up a
little explenation of the arrangement.
Diffstat (limited to 'src/stable/client.h')
-rw-r--r-- | src/stable/client.h | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/src/stable/client.h b/src/stable/client.h new file mode 100644 index 0000000..119c2c1 --- /dev/null +++ b/src/stable/client.h | |||
@@ -0,0 +1,133 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #ifndef BU_CLIENT_H | ||
9 | #define BU_CLIENT_H | ||
10 | |||
11 | #include <stdint.h> | ||
12 | |||
13 | #include "bu/config.h" | ||
14 | #include "bu/string.h" | ||
15 | #include "bu/queuebuf.h" | ||
16 | |||
17 | namespace Bu | ||
18 | { | ||
19 | class Protocol; | ||
20 | class Stream; | ||
21 | class TcpSocket; | ||
22 | class ClientLinkFactory; | ||
23 | |||
24 | /** | ||
25 | *@ingroup Serving | ||
26 | */ | ||
27 | class Client : public Bu::Stream | ||
28 | { | ||
29 | public: | ||
30 | Client( Bu::TcpSocket *pSocket, Bu::ClientLinkFactory *pfLink ); | ||
31 | virtual ~Client(); | ||
32 | |||
33 | void processInput(); | ||
34 | void processOutput(); | ||
35 | |||
36 | //Bu::String &getInput(); | ||
37 | //Bu::String &getOutput(); | ||
38 | Bu::size write( const Bu::String &sData ); | ||
39 | Bu::size write( const void *pData, Bu::size nBytes ); | ||
40 | Bu::size write( int8_t nData ); | ||
41 | Bu::size write( int16_t nData ); | ||
42 | Bu::size write( int32_t nData ); | ||
43 | Bu::size write( int64_t nData ); | ||
44 | Bu::size write( uint8_t nData ); | ||
45 | Bu::size write( uint16_t nData ); | ||
46 | Bu::size write( uint32_t nData ); | ||
47 | Bu::size write( uint64_t nData ); | ||
48 | Bu::size read( void *pData, Bu::size nBytes ); | ||
49 | Bu::size peek( void *pData, int nBytes, int nOffset=0 ); | ||
50 | // void seek( int nBytes ); | ||
51 | Bu::size getInputSize(); | ||
52 | Bu::size getOutputSize(); | ||
53 | |||
54 | void setProtocol( Protocol *pProto ); | ||
55 | Bu::Protocol *getProtocol(); | ||
56 | void clearProtocol(); | ||
57 | |||
58 | bool isOpen(); | ||
59 | void close(); | ||
60 | void tick(); | ||
61 | |||
62 | const Bu::TcpSocket *getSocket() const; | ||
63 | |||
64 | void disconnect(); | ||
65 | bool wantsDisconnect(); | ||
66 | |||
67 | class ClientLink *getLink(); | ||
68 | |||
69 | void onMessage( const Bu::String &sMsg ); | ||
70 | |||
71 | bool hasOutput() { return qbWrite.getSize() > 0; } | ||
72 | bool hasInput() { return qbRead.getSize() > 0; } | ||
73 | |||
74 | template<typename filter> | ||
75 | void pushFilter() | ||
76 | { | ||
77 | filter *pFlt = new filter( *pTopStream ); | ||
78 | pTopStream = pFlt; | ||
79 | lFilts.prepend( pFlt ); | ||
80 | } | ||
81 | |||
82 | template<typename filter, typename p1t> | ||
83 | void pushFilter( p1t p1 ) | ||
84 | { | ||
85 | filter *pFlt = new filter( *pTopStream, p1 ); | ||
86 | pTopStream = pFlt; | ||
87 | lFilts.prepend( pFlt ); | ||
88 | } | ||
89 | |||
90 | template<typename filter, typename p1t, typename p2t> | ||
91 | void pushFilter( p1t p1, p2t p2 ) | ||
92 | { | ||
93 | filter *pFlt = new filter( *pTopStream, p1, p2 ); | ||
94 | pTopStream = pFlt; | ||
95 | lFilts.prepend( pFlt ); | ||
96 | } | ||
97 | |||
98 | /* | ||
99 | * These are required to qualify as a stream, I dunno how many will | ||
100 | * be implemented. | ||
101 | */ | ||
102 | virtual Bu::size tell(); | ||
103 | virtual void seek( Bu::size offset ); | ||
104 | virtual void setPos( Bu::size pos ); | ||
105 | virtual void setPosEnd( Bu::size pos ); | ||
106 | virtual bool isEos(); | ||
107 | virtual void flush(); | ||
108 | virtual bool canRead(); | ||
109 | virtual bool canWrite(); | ||
110 | virtual bool isReadable(); | ||
111 | virtual bool isWritable(); | ||
112 | virtual bool isSeekable(); | ||
113 | virtual bool isBlocking(); | ||
114 | virtual void setBlocking( bool bBlocking=true ); | ||
115 | virtual void setSize( Bu::size iSize ); | ||
116 | virtual size getSize() const; | ||
117 | virtual size getBlockSize() const; | ||
118 | virtual Bu::String getLocation() const; | ||
119 | |||
120 | private: | ||
121 | typedef Bu::List<Bu::Stream *> FilterList; | ||
122 | FilterList lFilts; | ||
123 | Bu::Stream *pTopStream; | ||
124 | Bu::TcpSocket *pSocket; | ||
125 | Bu::Protocol *pProto; | ||
126 | Bu::QueueBuf qbRead; | ||
127 | Bu::QueueBuf qbWrite; | ||
128 | bool bWantsDisconnect; | ||
129 | class Bu::ClientLinkFactory *pfLink; | ||
130 | }; | ||
131 | } | ||
132 | |||
133 | #endif | ||