aboutsummaryrefslogtreecommitdiff
path: root/c++-libbu++/src/protocolgats.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c++-libbu++/src/protocolgats.cpp')
-rw-r--r--c++-libbu++/src/protocolgats.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/c++-libbu++/src/protocolgats.cpp b/c++-libbu++/src/protocolgats.cpp
new file mode 100644
index 0000000..827eb65
--- /dev/null
+++ b/c++-libbu++/src/protocolgats.cpp
@@ -0,0 +1,56 @@
1#include "gats/protocolgats.h"
2#include "gats/gatsstream.h"
3
4#include <bu/client.h>
5
6#include <bu/sio.h>
7using namespace Bu;
8
9Gats::ProtocolGats::ProtocolGats() :
10 pStream( NULL ),
11 pUsedClient( NULL )
12{
13}
14
15Gats::ProtocolGats::~ProtocolGats()
16{
17 delete pStream;
18 pStream = NULL;
19}
20
21void Gats::ProtocolGats::onNewConnection( Bu::Client *pClient )
22{
23 if( pStream == NULL )
24 {
25 pStream = new Gats::GatsStream( *pClient );
26 pUsedClient = pClient;
27 }
28}
29
30void Gats::ProtocolGats::onNewData( Bu::Client *pClient )
31{
32 if( pStream == NULL )
33 {
34 pStream = new Gats::GatsStream( *pClient );
35 pUsedClient = pClient;
36 }
37 else if( pClient != pUsedClient )
38 {
39 throw Bu::ExceptionBase("ProtocolGats requires that you maintain a "
40 "1:1 relationship between client and protocol objects.");
41 }
42
43 for(;;)
44 {
45 Gats::Object *pObj = pStream->readObject();
46 if( pObj == NULL )
47 break;
48 onNewObject( pClient, pObj );
49 }
50}
51
52void Gats::ProtocolGats::writeObject( Gats::Object *pObj )
53{
54 pStream->writeObject( pObj );
55}
56