configDeserializer.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 "configDeserializer.h"
00019 
00020 #include "canvas.h"
00021 #include "config.h"
00022 #include "global.h"
00023 #include "layout.h"
00024 #include "nodeFactory.h"
00025 #include "view.h"
00026 
00027 #include <eq/net/dataIStream.h>
00028 #include <eq/net/dataOStream.h>
00029 
00030 namespace eq
00031 {
00032 void ConfigDeserializer::applyInstanceData( net::DataIStream& is )
00033 {
00034     is >> _config->_latency >> _config->_eyeBase;
00035 
00036     NodeFactory* nodeFactory = Global::getNodeFactory();
00037     
00038     // Clean up - should never be necessary
00039     EQASSERT( _config->_canvases.empty( ));
00040     for( CanvasVector::const_iterator i = _config->_canvases.begin();
00041          i != _config->_canvases.end(); ++i )
00042     {
00043         Canvas* canvas = *i;
00044         canvas->deregister();
00045         nodeFactory->releaseCanvas( canvas );
00046     }
00047     _config->_canvases.clear();
00048 
00049     EQASSERT( _config->_layouts.empty( ));
00050     for( LayoutVector::const_iterator i = _config->_layouts.begin();
00051          i != _config->_layouts.end(); ++i )
00052     {
00053         Layout* layout = *i;
00054         layout->deregister();
00055         nodeFactory->releaseLayout( layout );
00056     }
00057     _config->_layouts.clear();
00058 
00059     // map all config children
00060     net::ObjectVector objects; // save objects to convert to master
00061     Type type;
00062     for( is >> type; type != TYPE_LAST; is >> type )
00063     {
00064         uint32_t id;
00065         is >> id;
00066         EQASSERT( id != EQ_ID_INVALID );
00067 
00068         switch( type )
00069         {
00070             case TYPE_OBSERVER:
00071             {
00072                 Observer* observer = nodeFactory->createObserver();
00073                 EQASSERT( observer );
00074                 _config->_addObserver( observer );
00075 
00076                 EQCHECK( _config->mapObject( observer, id )); //OPT: async map
00077                 objects.push_back( observer );
00078                 break;
00079             }
00080                 
00081             case TYPE_CANVAS:
00082             {
00083                 Canvas* canvas = nodeFactory->createCanvas();
00084                 EQASSERT( canvas );
00085                 _config->_addCanvas( canvas );
00086 
00087                 EQCHECK( _config->mapObject( canvas, id )); //OPT: async mapping
00088                 objects.push_back( canvas );
00089                 break;
00090             }
00091 
00092             case TYPE_LAYOUT:
00093             {
00094                 Layout* layout = nodeFactory->createLayout();
00095                 EQASSERT( layout );
00096                 _config->_addLayout( layout );
00097 
00098                 EQCHECK( _config->mapObject( layout, id )); //OPT: async mapping
00099                 // RO, don't convert to master
00100                 break;
00101             }
00102                 
00103             default:
00104                 EQUNIMPLEMENTED;
00105         }
00106     }
00107 
00108     // Convert objects to master after all the mapping has happened, since the
00109     // objects refer to each other using identifiers during deserialization.
00110     for( net::ObjectVector::const_iterator i = objects.begin();
00111          i != objects.end(); ++i )
00112     {
00113         (*i)->becomeMaster();
00114     }
00115 }
00116 
00117 }
Generated on Mon Aug 10 18:58:32 2009 for Equalizer 0.9 by  doxygen 1.5.8