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 : #ifndef CO_VERSIONEDSLAVECM_H
22 : #define CO_VERSIONEDSLAVECM_H
23 :
24 : #include "objectCM.h" // base class
25 : #include "objectDataIStream.h" // member
26 : #include "objectSlaveDataOStream.h" // member
27 :
28 : #include <lunchbox/mtQueue.h> // member
29 : #include <lunchbox/pool.h> // member
30 : #include <lunchbox/thread.h> // thread-safety macro
31 :
32 : namespace co
33 : {
34 : class Node;
35 :
36 : /**
37 : * An object change manager handling changes for versioned slave instances.
38 : */
39 : class VersionedSlaveCM : public ObjectCM
40 : {
41 : public:
42 : VersionedSlaveCM( Object* object, uint32_t masterInstanceID );
43 : virtual ~VersionedSlaveCM();
44 :
45 33 : void init() override {}
46 :
47 : /**
48 : * @name Versioning
49 : */
50 : //@{
51 : uint128_t commit( const uint32_t incarnation ) override;
52 : uint128_t sync( const uint128_t& version ) override;
53 :
54 : uint128_t getHeadVersion() const override;
55 1367 : uint128_t getVersion() const override { return _version; }
56 : //@}
57 :
58 134 : bool isMaster() const override { return false; }
59 :
60 32 : uint32_t getMasterInstanceID() const override
61 32 : { return _masterInstanceID; }
62 33 : void setMasterNode( NodePtr node ) override { _master = node; }
63 34 : NodePtr getMasterNode() override { return _master; }
64 :
65 0 : bool addSlave( const MasterCMCommand& ) override
66 0 : { LBDONTCALL; return false; }
67 0 : void removeSlaves( NodePtr ) override {}
68 :
69 : void applyMapData( const uint128_t& version ) override;
70 : void addInstanceDatas( const ObjectDataIStreamDeque&,
71 : const uint128_t& startVersion ) override;
72 : private:
73 : /** The current version. */
74 : uint128_t _version;
75 :
76 : /** istream for receiving the current version */
77 : ObjectDataIStream* _currentIStream;
78 :
79 : /** The change queue. */
80 : lunchbox::MTQueue< ObjectDataIStream* > _queuedVersions;
81 :
82 : /** Cached input streams (+decompressor) */
83 : lunchbox::Pool< ObjectDataIStream, true > _iStreamCache;
84 :
85 : /** The output stream for slave object commits. */
86 : ObjectSlaveDataOStream _ostream;
87 :
88 : /** The node holding the master object. */
89 : NodePtr _master;
90 :
91 : /** The instance identifier of the master object. */
92 : uint32_t _masterInstanceID;
93 :
94 : void _syncToHead();
95 : void _releaseStream( ObjectDataIStream* stream );
96 : void _sendAck();
97 :
98 : /** Apply the data in the input stream to the object */
99 : void _unpackOneVersion( ObjectDataIStream* is );
100 :
101 : /* The command handlers. */
102 : bool _cmdData( ICommand& command );
103 :
104 66 : LB_TS_VAR( _cmdThread );
105 66 : LB_TS_VAR( _rcvThread );
106 : };
107 : }
108 :
109 : #endif // CO_VERSIONEDSLAVECM_H
|