viewEqualizer.h

00001 
00002 /* Copyright (c) 2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #ifndef EQS_VIEWEQUALIZER_H
00019 #define EQS_VIEWEQUALIZER_H
00020 
00021 #include "equalizer.h"          // base class
00022 #include "../channelListener.h" // nested base class
00023 
00024 #include <eq/client/types.h>
00025 #include <eq/base/hash.h>
00026 #include <deque>
00027 #include <map>
00028 
00029 namespace eq
00030 {
00031 namespace server
00032 {
00033     class Compound;
00034     class ViewEqualizer;
00035     std::ostream& operator << ( std::ostream& os, const ViewEqualizer* );
00036 
00041     class ViewEqualizer : public Equalizer
00042     {
00043     public:            
00044         ViewEqualizer();
00045         ViewEqualizer( const ViewEqualizer& from );
00046         virtual ~ViewEqualizer();
00047         virtual Equalizer* clone() const { return new ViewEqualizer(*this); }
00048         virtual void toStream( std::ostream& os ) const { os << this; }
00049             
00051         virtual void attach( Compound* compound );
00052         
00054         virtual void notifyUpdatePre( Compound* compound, 
00055                                       const uint32_t frameNumber );
00056 
00057     protected:        
00058         virtual void notifyChildAdded( Compound* compound, Compound* child )
00059             { EQASSERT( _listeners.empty( )); }
00060         virtual void notifyChildRemove( Compound* compound, Compound* child )
00061             { EQASSERT( _listeners.empty( )); }
00062 
00063     private:
00064         class Listener : public ChannelListener
00065         {
00066         public:
00067             Listener();
00068             virtual ~Listener();
00069 
00070             void update( Compound* compound );
00071             void clear();
00072 
00073             virtual void notifyLoadData( Channel* channel, 
00074                                          const uint32_t frameNumber,
00075                                          const uint32_t nStatistics,
00076                                          const eq::Statistic* statistics );
00077             struct Load
00078             {
00079                 static Load NONE;
00080 
00081                 Load( const uint32_t frame_, const uint32_t missing_,
00082                       const int64_t time_ );
00083                 bool operator == ( const Load& rhs ) const;
00084 
00085                 uint32_t frame;
00086                 uint32_t missing;
00087                 uint32_t nResources;
00088                 int64_t time;
00089             };
00090 
00092             uint32_t findYoungestLoad() const;
00094             const Load& useLoad( const uint32_t frameNumber );
00096             void newLoad( const uint32_t frameNumber, const uint32_t nChannels);
00098             size_t getNLoads() const { return _loads.size(); }
00099 
00100         private:
00101             typedef base::PtrHash< Channel*, uint32_t > TaskIDHash;
00102             TaskIDHash _taskIDs;
00103 
00104             typedef std::deque< Load > LoadDeque;
00105             LoadDeque _loads;
00106 
00107             Load& _getLoad( const uint32_t frameNumber );
00108             friend std::ostream& operator << ( std::ostream& os, 
00109                                                const ViewEqualizer::Listener& );
00110         };
00111         friend std::ostream& operator << ( std::ostream& os, 
00112                                            const ViewEqualizer::Listener& );
00113         friend std::ostream& operator << ( std::ostream& os, 
00114                                          const ViewEqualizer::Listener::Load& );
00115 
00116         typedef std::vector< Listener::Load > LoadVector;
00117         typedef std::vector< Listener > ListenerVector;
00119         ListenerVector _listeners;
00120 
00122         size_t _nPipes;
00123 
00125         void _updateListeners();
00127         void _updateResources();
00129         void _update( const uint32_t frameNumber );
00131         uint32_t _findInputFrameNumber() const;
00132     };
00133     std::ostream& operator << ( std::ostream& os,
00134                                 const ViewEqualizer::Listener& listener );
00135     std::ostream& operator << ( std::ostream& os, 
00136                                 const ViewEqualizer::Listener::Load& load );
00137 }
00138 }
00139 
00140 #endif // EQS_VIEWEQUALIZER_H
Generated on Mon Aug 10 18:58:41 2009 for Equalizer 0.9 by  doxygen 1.5.8