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