/* * Copyright (C) 2007-2012 Xagasoft, All rights reserved. * * This file is part of the libgats library and is released under the * terms of the license contained in the file LICENSE. */ #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 ); }