From 2a72923397d866f33221b9d32a3f9653d1a960e7 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 25 Aug 2010 04:57:43 +0000 Subject: Updates to protocolgats...it should work now. --- src/protocolgats.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- src/protocolgats.h | 6 ++++++ 2 files changed, 46 insertions(+), 1 deletion(-) (limited to 'src') 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 @@ #include "gats/protocolgats.h" +#include "gats/gatsstream.h" -Gats::ProtocolGats::ProtocolGats() +#include + +Gats::ProtocolGats::ProtocolGats() : + pStream( NULL ), + pUsedClient( NULL ) { } Gats::ProtocolGats::~ProtocolGats() { + delete pStream; + pStream = NULL; +} + +void Gats::ProtocolGats::onNewConnection( Bu::Client *pClient ) +{ + if( pStream == NULL ) + { + pStream = new Gats::GatsStream( *pClient ); + pUsedClient = pClient; + } } void Gats::ProtocolGats::onNewData( Bu::Client *pClient ) { + if( pStream == NULL ) + { + pStream = new Gats::GatsStream( *pClient ); + pUsedClient = pClient; + } + else if( pClient != pUsedClient ) + { + throw Bu::ExceptionBase("ProtocolGats requires that you maintain a " + "1:1 relationship between client and protocol objects."); + } + + for(;;) + { + Gats::Object *pObj = pStream->readObject(); + if( pObj == NULL ) + break; + onNewObject( pObj ); + } +} + +void Gats::ProtocolGats::writeObject( Gats::Object *pObj ) +{ + pStream->writeObject( pObj ); } 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 @@ namespace Gats { class Object; + class GatsStream; class ProtocolGats : public Bu::Protocol { @@ -13,11 +14,16 @@ namespace Gats ProtocolGats(); virtual ~ProtocolGats(); + virtual void onNewConnection( Bu::Client *pClient ); virtual void onNewData( Bu::Client *pClient ); virtual void onNewObject( Gats::Object *pObj )=0; + void writeObject( Gats::Object *pObj ); + private: + Gats::GatsStream *pStream; + Bu::Client *pUsedClient; }; }; -- cgit v1.2.3