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 2 : StaticSlaveCM::StaticSlaveCM(Object* object)
36 : : ObjectCM(object)
37 2 : , _currentIStream(new ObjectDataIStream)
38 : {
39 2 : LBASSERT(_object);
40 2 : LBASSERT(object->getLocalNode());
41 :
42 2 : object->registerCommand(CMD_OBJECT_INSTANCE,
43 4 : CmdFunc(this, &StaticSlaveCM::_cmdInstance), 0);
44 2 : }
45 :
46 6 : StaticSlaveCM::~StaticSlaveCM()
47 : {
48 2 : delete _currentIStream;
49 2 : _currentIStream = 0;
50 4 : }
51 :
52 2 : void StaticSlaveCM::applyMapData(const uint128_t& version LB_UNUSED)
53 : {
54 2 : LBASSERT(_currentIStream);
55 2 : LBASSERTINFO(version == VERSION_FIRST || version == VERSION_NONE, version);
56 2 : _currentIStream->waitReady();
57 :
58 2 : LBASSERT(_object);
59 2 : LBASSERTINFO(_currentIStream->getVersion() == VERSION_FIRST ||
60 : _currentIStream->getVersion() == VERSION_NONE,
61 : _currentIStream->getVersion());
62 2 : LBASSERT(_currentIStream->hasInstanceData());
63 :
64 2 : if (_currentIStream->hasData()) // not VERSION_NONE
65 1 : _object->applyInstanceData(*_currentIStream);
66 :
67 2 : LBASSERTINFO(!_currentIStream->hasData(),
68 : "Object " << typeid(*_object).name()
69 : << " did not unpack all data");
70 :
71 2 : delete _currentIStream;
72 2 : _currentIStream = 0;
73 :
74 2 : LBLOG(LOG_OBJECTS) << "Mapped initial data for " << _object->getID() << "."
75 2 : << _object->getInstanceID() << " ready" << std::endl;
76 2 : }
77 :
78 0 : void StaticSlaveCM::addInstanceDatas(const ObjectDataIStreamDeque& cache,
79 : const uint128_t& /* start */)
80 : {
81 0 : LB_TS_THREAD(_rcvThread);
82 0 : LBASSERT(_currentIStream);
83 0 : LBASSERT(_currentIStream->getDataSize() == 0);
84 0 : LBASSERT(cache.size() == 1);
85 0 : if (cache.empty())
86 0 : return;
87 :
88 0 : ObjectDataIStream* stream = cache.front();
89 0 : LBASSERT(stream);
90 0 : LBASSERT(stream->isReady());
91 0 : LBASSERT(stream->getVersion() == VERSION_FIRST);
92 :
93 0 : if (!stream->isReady() || stream->getVersion() != VERSION_FIRST)
94 0 : return;
95 :
96 0 : LBLOG(LOG_OBJECTS) << "Adding cached instance data" << std::endl;
97 0 : delete _currentIStream;
98 0 : _currentIStream = new ObjectDataIStream(*stream);
99 : }
100 :
101 : //---------------------------------------------------------------------------
102 : // command handlers
103 : //---------------------------------------------------------------------------
104 2 : bool StaticSlaveCM::_cmdInstance(ICommand& command)
105 : {
106 2 : LB_TS_THREAD(_rcvThread);
107 2 : LBASSERT(_currentIStream);
108 2 : _currentIStream->addDataCommand(command);
109 :
110 2 : if (_currentIStream->isReady())
111 2 : LBLOG(LOG_OBJECTS) << "id " << _object->getID() << "."
112 2 : << _object->getInstanceID() << " ready" << std::endl;
113 :
114 2 : return true;
115 : }
116 63 : }
|