Line data Source code
1 :
2 : /* Copyright (c) 2007-2016, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 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 34 : void init() override {}
46 :
47 : /** @name Versioning */
48 : //@{
49 : uint128_t commit( const uint32_t incarnation ) override;
50 : uint128_t sync( const uint128_t& version ) override;
51 :
52 : uint128_t getHeadVersion() const override;
53 1366 : uint128_t getVersion() const override { return _version; }
54 : //@}
55 :
56 138 : bool isMaster() const override { return false; }
57 :
58 33 : uint32_t getMasterInstanceID() const override
59 33 : { return _masterInstanceID; }
60 34 : void setMasterNode( NodePtr node ) override { _master = node; }
61 35 : NodePtr getMasterNode() override { return _master; }
62 :
63 0 : bool addSlave( const MasterCMCommand& ) override
64 0 : { LBDONTCALL; return false; }
65 0 : void removeSlaves( NodePtr ) override {}
66 :
67 : void applyMapData( const uint128_t& version ) override;
68 : void addInstanceDatas( const ObjectDataIStreamDeque&,
69 : const uint128_t& startVersion ) override;
70 : private:
71 : /** The current version. */
72 : uint128_t _version;
73 :
74 : /** istream for receiving the current version */
75 : ObjectDataIStream* _currentIStream;
76 :
77 : /** The change queue. */
78 : lunchbox::MTQueue< ObjectDataIStream* > _queuedVersions;
79 :
80 : /** Cached input streams (+decompressor) */
81 : lunchbox::Pool< ObjectDataIStream, true > _iStreamCache;
82 :
83 : /** The output stream for slave object commits. */
84 : ObjectSlaveDataOStream _ostream;
85 :
86 : /** The node holding the master object. */
87 : NodePtr _master;
88 :
89 : /** The instance identifier of the master object. */
90 : uint32_t _masterInstanceID;
91 :
92 : void _syncToHead();
93 : void _releaseStream( ObjectDataIStream* stream );
94 : void _sendAck();
95 :
96 : /** Apply the data in the input stream to the object */
97 : void _unpackOneVersion( ObjectDataIStream* is );
98 :
99 : /* The command handlers. */
100 : bool _cmdData( ICommand& command );
101 :
102 68 : LB_TS_VAR( _cmdThread );
103 68 : LB_TS_VAR( _rcvThread );
104 : };
105 : }
106 :
107 : #endif // CO_VERSIONEDSLAVECM_H
|