configSerializer.cpp

00001 
00002 /* Copyright (c) 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 "configSerializer.h"
00019 
00020 #include "canvas.h"
00021 #include "config.h"
00022 #include "compound.h"
00023 #include "layout.h"
00024 #include "observer.h"
00025 #include "segment.h"
00026 #include "view.h"
00027 
00028 #include "../lib/client/configDeserializer.h" // header not installed
00029 
00030 #include <eq/net/dataIStream.h>
00031 #include <eq/net/dataOStream.h>
00032 
00033 namespace eq
00034 {
00035 namespace server
00036 {
00037 namespace
00038 {
00039 class SerializerVisitor : public ConfigVisitor
00040 {
00041 public:
00042     SerializerVisitor( net::DataOStream& os ) : _os( os ) {}
00043     virtual ~SerializerVisitor(){}
00044 
00045     virtual VisitorResult visit( Observer* observer )
00046         { 
00047             _registerObject( observer->getConfig(), observer );
00048             _os << eq::ConfigDeserializer::TYPE_OBSERVER << observer->getID();
00049             return TRAVERSE_CONTINUE; 
00050         }
00051 
00052     virtual VisitorResult visit( Segment* segment )
00053         { 
00054             _registerObject( segment->getConfig(), segment );
00055             return TRAVERSE_CONTINUE; 
00056         }
00057 
00058     virtual VisitorResult visitPost( Canvas* canvas )
00059         { 
00060             _registerObject( canvas->getConfig(), canvas );
00061             _os << eq::ConfigDeserializer::TYPE_CANVAS << canvas->getID();
00062             return TRAVERSE_CONTINUE; 
00063         }
00064 
00065     virtual VisitorResult visit( View* view )
00066         { 
00067             _registerObject( view->getConfig(), view );
00068             return TRAVERSE_CONTINUE; 
00069         }
00070 
00071     virtual VisitorResult visitPost( Layout* layout )
00072         { 
00073             _registerObject( layout->getConfig(), layout );
00074             _os << eq::ConfigDeserializer::TYPE_LAYOUT << layout->getID();
00075             return TRAVERSE_CONTINUE; 
00076         }
00077 
00078 private:
00079     net::DataOStream& _os;
00080 
00081     void _registerObject( net::Session* session, net::Object* object )
00082         {
00083             EQASSERT( session );
00084             EQASSERT( object->getID() == EQ_ID_INVALID );
00085             
00086             session->registerObject( object );
00087         }
00088 };
00089 }
00090 
00091 void ConfigSerializer::getInstanceData( net::DataOStream& os )
00092 {
00093     os << _config->getLatency() 
00094        << _config->getFAttribute( Config::FATTR_EYE_BASE );
00095 
00096     SerializerVisitor serializer( os );
00097     _config->accept( serializer );
00098     os << eq::ConfigDeserializer::TYPE_LAST; // end token
00099 
00100 #ifdef EQ_TRANSMISSION_API
00101 #  error TODO transmit node identifiers of used nodes
00102 #endif
00103 }
00104 
00105 }
00106 }
Generated on Mon Aug 10 18:58:32 2009 for Equalizer 0.9 by  doxygen 1.5.8