LCOV - code coverage report
Current view: top level - co - versionedMasterCM.h (source / functions) Hit Total Coverage
Test: Collage Lines: 13 18 72.2 %
Date: 2015-11-03 13:48:53 Functions: 13 16 81.2 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2010-2014, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *                    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_MASTERCM_H
      22             : #define CO_MASTERCM_H
      23             : 
      24             : #include "objectCM.h" // base class
      25             : #include "dataIStreamQueue.h" // member
      26             : #include <co/types.h>
      27             : 
      28             : #include <lunchbox/mtQueue.h> // member
      29             : #include <lunchbox/pool.h>    // member
      30             : #include <lunchbox/stdExt.h>  // member
      31             : #include <lunchbox/thread.h>  // thread-safety check
      32             : 
      33             : namespace co
      34             : {
      35             :     /**
      36             :      * @internal
      37             :      * The base class for versioned master change managers.
      38             :      */
      39             :     class VersionedMasterCM : public ObjectCM
      40             :     {
      41             :     protected:
      42             :         typedef lunchbox::ScopedWrite Mutex;
      43             : 
      44             :     public:
      45             :         explicit VersionedMasterCM( Object* object );
      46             :         virtual ~VersionedMasterCM();
      47             : 
      48          12 :         void init() override {}
      49             : 
      50             :         /** @name Versioning */
      51             :         //@{
      52             :         uint128_t sync( const uint128_t& version ) override;
      53             : 
      54           0 :         uint128_t getHeadVersion() const override
      55           0 :             { Mutex mutex( _slaves ); return _version; }
      56         197 :         uint128_t getVersion() const override
      57         197 :             { Mutex mutex( _slaves ); return _version; }
      58             :         //@}
      59             : 
      60         136 :         bool isMaster() const override { return true; }
      61           0 :         uint32_t getMasterInstanceID() const override
      62           0 :             { LBDONTCALL; return CO_INSTANCE_INVALID; }
      63             : 
      64             :         bool addSlave( const MasterCMCommand& command ) override;
      65             :         void removeSlave( NodePtr node, const uint32_t instanceID ) override;
      66             :         void removeSlaves( NodePtr node ) override;
      67          12 :         const Nodes getSlaveNodes() const override
      68          12 :             { Mutex mutex( _slaves ); return *_slaves; }
      69             : 
      70             :     protected:
      71             :         /** The list of subscribed slave nodes. */
      72             :         lunchbox::Lockable< Nodes > _slaves;
      73             : 
      74             :         /** The current version. */
      75             :         uint128_t _version;
      76             : 
      77             :         /** Maximum master version allowed to commit. */
      78             :         lunchbox::Monitor< uint64_t > _maxVersion;
      79             : 
      80             :     private:
      81         298 :         struct SlaveData
      82             :         {
      83         134 :             SlaveData() : maxVersion( std::numeric_limits< uint64_t >::max( ))
      84         134 :                         , instanceID( LB_UNDEFINED_UINT32 ) {}
      85          34 :             bool operator == ( const SlaveData& rhs ) const
      86          34 :                 { return node == rhs.node && instanceID == rhs.instanceID; }
      87             : 
      88             :             NodePtr node;
      89             :             uint64_t maxVersion;
      90             :             uint32_t instanceID;
      91             :         };
      92             :         typedef std::vector< SlaveData > SlaveDatas;
      93             :         typedef SlaveDatas::const_iterator SlaveDatasCIter;
      94             :         typedef SlaveDatas::iterator SlaveDatasIter;
      95             : 
      96             :         /** Additional slave data. */
      97             :         SlaveDatas _slaveData;
      98             : 
      99             :         /** Slave commit queue. */
     100             :         DataIStreamQueue _slaveCommits;
     101             : 
     102             :         uint128_t _apply( ObjectDataIStream* is );
     103             :         void _updateMaxVersion();
     104             : 
     105             :         /* The command handlers. */
     106             :         bool _cmdSlaveDelta( ICommand& command );
     107             :         bool _cmdMaxVersion( ICommand& command );
     108           0 :         bool _cmdDiscard( ICommand& ) { return true; }
     109             : 
     110          24 :         LB_TS_VAR( _cmdThread );
     111          24 :         LB_TS_VAR( _rcvThread );
     112             :     };
     113             : }
     114             : 
     115             : #endif // CO_MASTERCM_H

Generated by: LCOV version 1.11