staticSlaveCM.cpp

00001 
00002 /* Copyright (c) 2007-2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #include "staticSlaveCM.h"
00019 
00020 #include "command.h"
00021 #include "commands.h"
00022 #include "log.h"
00023 #include "object.h"
00024 #include "objectInstanceDataIStream.h"
00025 #include "session.h"
00026 
00027 #include <eq/base/scopedMutex.h>
00028 
00029 using namespace eq::base;
00030 using namespace std;
00031 
00032 namespace eq
00033 {
00034 namespace net
00035 {
00036 StaticSlaveCM::StaticSlaveCM( Object* object )
00037         : _object( object )
00038         , _currentIStream( new ObjectInstanceDataIStream )
00039 {
00040     registerCommand( CMD_OBJECT_INSTANCE_DATA,
00041            CommandFunc<StaticSlaveCM>( this, &StaticSlaveCM::_cmdInstanceData ),
00042                      0 );
00043     registerCommand( CMD_OBJECT_INSTANCE,
00044                CommandFunc<StaticSlaveCM>( this, &StaticSlaveCM::_cmdInstance ),
00045                      0 );
00046 }
00047 
00048 StaticSlaveCM::~StaticSlaveCM()
00049 {
00050     delete _currentIStream;
00051     _currentIStream = 0;
00052 }
00053 
00054 //---------------------------------------------------------------------------
00055 // command handlers
00056 //---------------------------------------------------------------------------
00057 CommandResult StaticSlaveCM::_cmdInstanceData( Command& command )
00058 {
00059     EQASSERT( _currentIStream );
00060     _currentIStream->addDataPacket( command );
00061     return eq::net::COMMAND_HANDLED;
00062 }
00063 
00064 CommandResult StaticSlaveCM::_cmdInstance( Command& command )
00065 {
00066     EQASSERT( _currentIStream );
00067     _currentIStream->addDataPacket( command );
00068  
00069     const ObjectInstancePacket* packet = 
00070         command.getPacket<ObjectInstancePacket>();
00071     _currentIStream->setVersion( packet->version );
00072 
00073     EQLOG( LOG_OBJECTS ) << "id " << _object->getID() << "." 
00074                          << _object->getInstanceID() << " ready" << endl;
00075     return eq::net::COMMAND_HANDLED;
00076 }
00077 
00078 void StaticSlaveCM::applyMapData()
00079 {
00080     EQASSERT( _currentIStream );
00081     _currentIStream->waitReady();
00082 
00083     _object->applyInstanceData( *_currentIStream );
00084 
00085     delete _currentIStream;
00086     _currentIStream = 0;
00087 
00088     EQLOG( LOG_OBJECTS ) << "Mapped initial data for " << _object->getID()
00089                          << "." << _object->getInstanceID() << " ready" << endl;
00090 }
00091 
00092 }
00093 }
Generated on Mon Aug 10 18:58:41 2009 for Equalizer 0.9 by  doxygen 1.5.8