#include "gats/protocolgats.h" #include "gats/gatsstream.h" #include #include using namespace Bu; 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( pClient, pObj ); } } void Gats::ProtocolGats::writeObject( Gats::Object *pObj ) { pStream->writeObject( pObj ); }