Line data Source code
1 :
2 : /* Copyright (c) 2007-2014, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 2011-2012, Daniel Nachbaur <danielnachbaur@gmail.com>
4 : *
5 : * This file is part of Collage <https://github.com/Eyescale/Collage>
6 : *
7 : * This library is free software; you can redistribute it and/or modify it under
8 : * the terms of the GNU Lesser General Public License version 2.1 as published
9 : * by the Free Software Foundation.
10 : *
11 : * This library is distributed in the hope that it will be useful, but WITHOUT
12 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 : * details.
15 : *
16 : * You should have received a copy of the GNU Lesser General Public License
17 : * along with this library; if not, write to the Free Software Foundation, Inc.,
18 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 : */
20 :
21 : #include "staticSlaveCM.h"
22 :
23 : #include "log.h"
24 : #include "object.h"
25 : #include "objectCommand.h"
26 : #include "objectDataICommand.h"
27 : #include "objectDataIStream.h"
28 :
29 : #include <lunchbox/scopedMutex.h>
30 :
31 : namespace co
32 : {
33 : typedef CommandFunc< StaticSlaveCM > CmdFunc;
34 :
35 8 : StaticSlaveCM::StaticSlaveCM( Object* object )
36 : : ObjectCM( object )
37 8 : , _currentIStream( new ObjectDataIStream )
38 : {
39 8 : LBASSERT( _object );
40 8 : LBASSERT( object->getLocalNode( ));
41 :
42 8 : object->registerCommand( CMD_OBJECT_INSTANCE,
43 16 : CmdFunc( this, &StaticSlaveCM::_cmdInstance ), 0 );
44 8 : }
45 :
46 24 : StaticSlaveCM::~StaticSlaveCM()
47 : {
48 8 : delete _currentIStream;
49 8 : _currentIStream = 0;
50 16 : }
51 :
52 8 : void StaticSlaveCM::applyMapData( const uint128_t& version LB_UNUSED )
53 : {
54 8 : LBASSERT( _currentIStream );
55 8 : LBASSERTINFO( version == VERSION_FIRST || version == VERSION_NONE,
56 : version );
57 8 : _currentIStream->waitReady();
58 :
59 8 : LBASSERT( _object );
60 8 : LBASSERTINFO( _currentIStream->getVersion() == VERSION_FIRST ||
61 : _currentIStream->getVersion() == VERSION_NONE,
62 : _currentIStream->getVersion( ));
63 8 : LBASSERT( _currentIStream->hasInstanceData( ));
64 :
65 8 : if( _currentIStream->hasData( )) // not VERSION_NONE
66 7 : _object->applyInstanceData( *_currentIStream );
67 :
68 8 : LBASSERTINFO( !_currentIStream->hasData(),
69 : "Object " << typeid( *_object ).name() <<
70 : " did not unpack all data" );
71 :
72 8 : delete _currentIStream;
73 8 : _currentIStream = 0;
74 :
75 8 : LBLOG( LOG_OBJECTS ) << "Mapped initial data for " << _object->getID()
76 0 : << "." << _object->getInstanceID() << " ready"
77 8 : << std::endl;
78 8 : }
79 :
80 0 : void StaticSlaveCM::addInstanceDatas( const ObjectDataIStreamDeque& cache,
81 : const uint128_t& /* start */ )
82 : {
83 0 : LB_TS_THREAD( _rcvThread );
84 0 : LBASSERT( _currentIStream );
85 0 : LBASSERT( _currentIStream->getDataSize() == 0 );
86 0 : LBASSERT( cache.size() == 1 );
87 0 : if( cache.empty( ))
88 0 : return;
89 :
90 0 : ObjectDataIStream* stream = cache.front();
91 0 : LBASSERT( stream );
92 0 : LBASSERT( stream->isReady( ));
93 0 : LBASSERT( stream->getVersion() == VERSION_FIRST );
94 :
95 0 : if( !stream->isReady() || stream->getVersion() != VERSION_FIRST )
96 0 : return;
97 :
98 0 : LBLOG( LOG_OBJECTS ) << "Adding cached instance data" << std::endl;
99 0 : delete _currentIStream;
100 0 : _currentIStream = new ObjectDataIStream( *stream );
101 : }
102 :
103 : //---------------------------------------------------------------------------
104 : // command handlers
105 : //---------------------------------------------------------------------------
106 8 : bool StaticSlaveCM::_cmdInstance( ICommand& command )
107 : {
108 8 : LB_TS_THREAD( _rcvThread );
109 8 : LBASSERT( _currentIStream );
110 8 : _currentIStream->addDataCommand( command );
111 :
112 8 : if( _currentIStream->isReady( ))
113 8 : LBLOG( LOG_OBJECTS ) << "id " << _object->getID() << "."
114 0 : << _object->getInstanceID() << " ready"
115 8 : << std::endl;
116 :
117 8 : return true;
118 : }
119 :
120 66 : }
|