LCOV - code coverage report
Current view: top level - eq/server/equalizers - viewEqualizer.h (source / functions) Hit Total Coverage
Test: Equalizer Lines: 3 8 37.5 %
Date: 2016-07-30 05:04:55 Functions: 2 6 33.3 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2009-2013, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or modify it under
       5             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       6             :  * by the Free Software Foundation.
       7             :  *
       8             :  * This library is distributed in the hope that it will be useful, but WITHOUT
       9             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      10             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      11             :  * details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      15             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      16             :  */
      17             : 
      18             : #ifndef EQS_VIEWEQUALIZER_H
      19             : #define EQS_VIEWEQUALIZER_H
      20             : 
      21             : #include "equalizer.h"          // base class
      22             : #include "../channelListener.h" // nested base class
      23             : 
      24             : #include <lunchbox/hash.h>
      25             : #include <deque>
      26             : #include <map>
      27             : 
      28             : namespace eq
      29             : {
      30             : namespace server
      31             : {
      32             :     std::ostream& operator << ( std::ostream& os, const ViewEqualizer* );
      33             : 
      34             :     /**
      35             :      * An Equalizer allocating resources to multiple destination channels of a
      36             :      * single view.
      37             :      */
      38             :     class ViewEqualizer : public Equalizer
      39             :     {
      40             :     public:
      41             :         EQSERVER_API ViewEqualizer();
      42             :         ViewEqualizer( const ViewEqualizer& from );
      43             :         virtual ~ViewEqualizer();
      44          16 :         void toStream( std::ostream& os ) const final { os << this; }
      45             : 
      46             :         /** @sa Equalizer::attach. */
      47             :         void attach( Compound* compound ) final;
      48             : 
      49             :         /** @sa CompoundListener::notifyUpdatePre */
      50             :         void notifyUpdatePre( Compound* compound,
      51             :                               const uint32_t frameNumber ) final;
      52             : 
      53           0 :         uint32_t getType() const final { return fabric::VIEW_EQUALIZER; }
      54             : 
      55             :     protected:
      56          96 :         void notifyChildAdded( Compound*, Compound* ) override
      57          96 :             { LBASSERT( _listeners.empty( )); }
      58           0 :         void notifyChildRemove( Compound*, Compound* ) override
      59           0 :             { LBASSERT( _listeners.empty( )); }
      60             : 
      61             :     private:
      62           0 :         class Listener : public ChannelListener
      63             :         {
      64             :         public:
      65             :             Listener();
      66             :             virtual ~Listener();
      67             : 
      68             :             void update( Compound* compound );
      69             :             void clear();
      70             : 
      71             :             virtual void notifyLoadData( Channel* channel,
      72             :                                          uint32_t frameNumber,
      73             :                                          const Statistics& statistics,
      74             :                                          const Viewport& region );
      75             :             struct Load
      76             :             {
      77             :                 static Load NONE;
      78             : 
      79             :                 Load( const uint32_t frame_, const uint32_t missing_,
      80             :                       const int64_t time_ );
      81             :                 bool operator == ( const Load& rhs ) const;
      82             : 
      83             :                 uint32_t frame;
      84             :                 uint32_t missing;
      85             :                 uint32_t nResources;
      86             :                 int64_t time;
      87             :             };
      88             : 
      89             :             /** @return the frame number of the youngest complete load. */
      90             :             uint32_t findYoungestLoad( const uint32_t frame ) const;
      91             :             /** Delete older loads and return the load belonging to the frame.*/
      92             :             const Load& useLoad( const uint32_t frameNumber );
      93             :             /** Insert a new, empty load for the given frame. */
      94             :             void newLoad( const uint32_t frameNumber, const uint32_t nChannels);
      95             :             /** @return the size of the history stash. */
      96           0 :             size_t getNLoads() const { return _loads.size(); }
      97             : 
      98             :         private:
      99             :             typedef lunchbox::PtrHash< Channel*, uint32_t > TaskIDHash;
     100             :             TaskIDHash _taskIDs;
     101             : 
     102             :             typedef std::deque< Load > LoadDeque;
     103             :             LoadDeque _loads;
     104             : 
     105             :             Load& _getLoad( const uint32_t frameNumber );
     106             :             friend std::ostream& operator << ( std::ostream& os,
     107             :                                                const ViewEqualizer::Listener& );
     108             :         };
     109             :         friend std::ostream& operator << ( std::ostream& os,
     110             :                                            const ViewEqualizer::Listener& );
     111             :         friend std::ostream& operator << ( std::ostream& os,
     112             :                                          const ViewEqualizer::Listener::Load& );
     113             : 
     114             :         typedef std::vector< Listener::Load > Loads;
     115             :         typedef std::vector< Listener > Listeners;
     116             :         /** Per-child listener gathering load data. */
     117             :         Listeners _listeners;
     118             : 
     119             :         /** The total number of available resources. */
     120             :         size_t _nPipes;
     121             : 
     122             :         /** Update channel load subscription. */
     123             :         void _updateListeners();
     124             :         /** Update resource count. */
     125             :         void _updateResources();
     126             :         /** Assign resources to children. */
     127             :         void _update( const uint32_t frameNumber );
     128             :         /** Find the frame number to use for update. */
     129             :         uint32_t _findInputFrameNumber() const;
     130             :     };
     131             :     std::ostream& operator << ( std::ostream& os,
     132             :                                 const ViewEqualizer::Listener& listener );
     133             :     std::ostream& operator << ( std::ostream& os,
     134             :                                 const ViewEqualizer::Listener::Load& load );
     135             : }
     136             : }
     137             : 
     138             : #endif // EQS_VIEWEQUALIZER_H

Generated by: LCOV version 1.11