LCOV - code coverage report
Current view: top level - eq/fabric - config.h (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 21 29 72.4 %
Date: 2014-06-18 Functions: 24 42 57.1 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2005-2013, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *                    2010, Cedric Stalder <cedric Stalder@gmail.com>
       4             :  *                    2011, Daniel Nachbaur <danielnachbaur@gmail.com>
       5             :  *
       6             :  * This library is free software; you can redistribute it and/or modify it under
       7             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       8             :  * by the Free Software Foundation.
       9             :  *
      10             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      11             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      12             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      13             :  * details.
      14             :  *
      15             :  * You should have received a copy of the GNU Lesser General Public License
      16             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      17             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      18             :  */
      19             : 
      20             : #ifndef EQFABRIC_CONFIG_H
      21             : #define EQFABRIC_CONFIG_H
      22             : 
      23             : #include <eq/fabric/api.h>
      24             : #include <eq/fabric/types.h>         // typedefs
      25             : #include <eq/fabric/object.h>        // DIRTY_CUSTOM enum
      26             : 
      27             : namespace eq
      28             : {
      29             : namespace fabric
      30             : {
      31             :     /** Base data class for a configuration. @sa eq::Config */
      32             :     template< class S, class C, class O, class L, class CV, class N, class V >
      33             :     class Config : public Object
      34             :     {
      35             :     public:
      36             :         typedef std::vector< O* >  Observers; //!< A vector of observers
      37             :         typedef std::vector< L* >  Layouts;   //!< A vector of layouts
      38             :         typedef std::vector< CV* > Canvases;  //!< A vector of canvases
      39             :         typedef std::vector< N* >  Nodes;     //!< A vector of nodes
      40             : 
      41             :         /** @name Data Access */
      42             :         //@{
      43             :         /** @return the local server proxy. @version 1.0 */
      44             :         EQFABRIC_INL lunchbox::RefPtr< S > getServer();
      45             : 
      46             :         /** @return the local server proxy. @version 1.0 */
      47             :         EQFABRIC_INL lunchbox::RefPtr< const S > getServer() const;
      48             : 
      49             :         /** @return the vector of observers, app-node only. @version 1.0 */
      50        3983 :         const Observers& getObservers() const { return _observers; }
      51             : 
      52             :         /** @return the vector of layouts, app-node only. @version 1.0 */
      53        3889 :         const Layouts& getLayouts() const { return _layouts; }
      54             : 
      55             :         /** @return the vector of canvases, app-node only. @version 1.0 */
      56        3651 :         const Canvases& getCanvases() const { return _canvases; }
      57             : 
      58             :         /**
      59             :          * @internal
      60             :          * @return the timeout in ms or LB_TIMEOUT_INDEFINITE for failures.
      61             :          */
      62             :         EQFABRIC_INL uint32_t getTimeout() const;
      63             : 
      64             :         /**
      65             :          * @return the vector of nodes instantiated in this process.
      66             :          * @version 1.0
      67             :          */
      68        7269 :         const Nodes& getNodes() const { return _nodes; }
      69             : 
      70             :         EQFABRIC_INL N* findAppNode(); //!< @internal
      71             :         EQFABRIC_INL const N* findAppNode() const; //!< @internal
      72             : 
      73             :         /**
      74             :          * Perform a depth-first traversal of this config.
      75             :          *
      76             :          * @param visitor the visitor.
      77             :          * @return the result of the visitor traversal.
      78             :          * @version 1.0
      79             :          */
      80             :         EQFABRIC_INL VisitorResult accept( V& visitor );
      81             : 
      82             :         /** Const-version of accept(). @version 1.0 */
      83             :         EQFABRIC_INL VisitorResult accept( V& visitor ) const;
      84             : 
      85             :         /** @return the entity of the given identifier, or 0. @version 1.0 */
      86             :         template< typename T > EQFABRIC_INL T* find( const uint128_t& id );
      87             : 
      88             :         /** @return the entity of the given identifier, or 0. @version 1.0 */
      89             :         template< typename T >
      90             :         EQFABRIC_INL const T* find( const uint128_t& id ) const;
      91             : 
      92             :         /** @return the first entity of the given name, or 0. @version 1.0 */
      93             :         template< typename T >
      94             :         EQFABRIC_INL T* find( const std::string& name );
      95             : 
      96             :         /** @return the first entity of the given name, or 0. @version 1.0 */
      97             :         template< typename T >
      98             :         EQFABRIC_INL const T* find( const std::string& name ) const;
      99             : 
     100             :         /** @internal @return the observer at the given path. */
     101             :         O* getObserver( const ObserverPath& path );
     102             : 
     103             :         /** @internal @return the layout at the given path. */
     104             :         L* getLayout( const LayoutPath& path );
     105             : 
     106             :         /** @internal @return the canvas at the given path. */
     107             :         CV* getCanvas( const CanvasPath& path );
     108             : 
     109             :         /** @internal */
     110             :         template< typename T > void find( const uint128_t& id, T** result );
     111             : 
     112             :         /** @internal */
     113             :         template< typename T > void find( const std::string& name,
     114             :                                           const T** result ) const;
     115             : 
     116             :         /** @internal Update or init the given canvas in a running config. */
     117          10 :         virtual void updateCanvas( CV* ) { /* NOP */ }
     118             : 
     119             :         /** @internal Init the given canvas in a running config. */
     120           0 :         virtual void exitCanvas( CV* ) { /* NOP */ }
     121             :         //@}
     122             : 
     123             :         /** @name Attributes */
     124             :         //@{
     125             :         // Note: also update string array initialization in config.ipp
     126             : 
     127             :         /** Floating-point attributes */
     128             :         enum FAttribute
     129             :         {
     130             :             FATTR_EYE_BASE, //!< The default interocular distance in meters
     131             :             FATTR_VERSION,  //!< The version of the file loaded
     132             :             FATTR_LAST,
     133             :             FATTR_ALL = FATTR_LAST + 5
     134             :         };
     135             : 
     136             :         /** Integer attributes. */
     137             :         enum IAttribute
     138             :         {
     139             :             IATTR_ROBUSTNESS, //!< Tolerate resource failures
     140             :             IATTR_LAST,
     141             :             IATTR_ALL = IATTR_LAST + 5
     142             :         };
     143             : 
     144             :         /** @internal */
     145        1701 :         void setFAttribute( const FAttribute attr, const float value )
     146        1701 :             { _fAttributes[attr] = value; }
     147             :         /** @internal */
     148        1393 :         void setIAttribute( const IAttribute attr, const int32_t value )
     149        1393 :             { _iAttributes[attr] = value; }
     150             : 
     151             :         /** @return the given floating-point attribute. */
     152         557 :         float getFAttribute( const FAttribute attr ) const
     153         557 :             { return _fAttributes[attr]; }
     154             : 
     155             :         /** @return the given integer attribute. */
     156         156 :         int32_t getIAttribute( const IAttribute attr ) const
     157         156 :             { return _iAttributes[attr]; }
     158             : 
     159             :         /** @internal */
     160             :         static const std::string& getFAttributeString( const FAttribute attr );
     161             :         /** @internal */
     162             :         static const std::string& getIAttributeString( const IAttribute attr );
     163             :         //@}
     164             : 
     165             : 
     166             :         /** @name Operations */
     167             :         //@{
     168             :         /**
     169             :          * Set the maximum accepted latency for this config.
     170             :          *
     171             :          * The latency is defined as the maximum number of frames between the
     172             :          * start of a frame and the finish of the last rendering task for that
     173             :          * frame. Setting the latency of a running config finishes all pending
     174             :          * frames.
     175             :          *
     176             :          * @param latency the latency.
     177             :          * @version 1.0
     178             :          */
     179             :         virtual void setLatency( const uint32_t latency );
     180             : 
     181             :         /** @return the latency of this config. @version 1.0 */
     182         765 :         uint32_t getLatency() const { return _data.latency; }
     183             : 
     184             :         /** @internal Restore the last backup. */
     185             :         EQFABRIC_INL virtual void restore();
     186             :         //@}
     187             : 
     188           0 :         virtual void output( std::ostream& ) const {} //!< @internal
     189             :         void create( O** observer ); //!< @internal
     190             :         void release( O* observer ); //!< @internal
     191             :         void create( L** layout );   //!< @internal
     192             :         void release( L* layout );   //!< @internal
     193             :         void create( CV** canvas );  //!< @internal
     194             :         void release( CV* canvas );  //!< @internal
     195             :         void create( N** node );     //!< @internal
     196             :         void release( N* node );     //!< @internal
     197             : 
     198             :     protected:
     199             :         /** @internal Construct a new config. */
     200             :         EQFABRIC_INL Config( lunchbox::RefPtr< S > parent );
     201             : 
     202             :         /** @internal Destruct a config. */
     203             :         EQFABRIC_INL virtual ~Config();
     204             : 
     205             :         /** @internal */
     206             :         EQFABRIC_INL virtual void attach( const uint128_t& id,
     207             :                                           const uint32_t instanceID );
     208             : 
     209             :         /** @internal */
     210             :         EQFABRIC_INL virtual void serialize( co::DataOStream& os,
     211             :                                              const uint64_t dirtyBits );
     212             :         EQFABRIC_INL virtual void deserialize( co::DataIStream& is,
     213             :                                                const uint64_t dirtyBits );
     214             :         EQFABRIC_INL virtual void notifyDetach();
     215             : 
     216             :         /** @internal Execute the slave remove request. */
     217           0 :         virtual void _removeChild( const uint128_t& )
     218           0 :             { LBUNIMPLEMENTED; }
     219             : 
     220             :         template< class, class, class, class, class, class >
     221             :         friend class Server;
     222             : 
     223             :         void setAppNodeID( const co::NodeID& nodeID ); //!< @internal
     224             :         /** @internal */
     225         200 :         const co::NodeID& getAppNodeID() const { return _appNodeID; }
     226             : 
     227             :         /** @internal */
     228             :         EQFABRIC_INL EventOCommand sendError( co::NodePtr node,
     229             :                                               const uint32_t event,
     230             :                                               const uint128_t& originator,
     231             :                                               const uint32_t error );
     232             : 
     233           0 :         virtual void changeLatency( const uint32_t ) { /* NOP */ }//!< @internal
     234           0 :         virtual bool mapViewObjects() const { return false; } //!< @internal
     235          92 :         virtual bool mapNodeObjects() const { return false; } //!< @internal
     236             : 
     237             :         /** @internal */
     238         416 :         virtual VisitorResult _acceptCompounds( V& )
     239         416 :             { return TRAVERSE_CONTINUE; }
     240             :         /** @internal */
     241           0 :         virtual VisitorResult _acceptCompounds( V& ) const
     242           0 :             { return TRAVERSE_CONTINUE; }
     243             :         template< class C2, class V2 >
     244             :         friend VisitorResult _acceptImpl( C2*, V2& );
     245             : 
     246             :         N* _findNode( const uint128_t& id ); //!< @internal
     247             : 
     248             :         /** @internal */
     249             :         EQFABRIC_INL virtual uint128_t commit( const uint32_t incarnation =
     250             :                                                CO_COMMIT_NEXT );
     251             :         //@}
     252             : 
     253             :     private:
     254             :         /** The parent server. */
     255             :         lunchbox::RefPtr< S > _server;
     256             : 
     257             :         /** Float attributes. */
     258             :         float _fAttributes[FATTR_ALL];
     259             : 
     260             :         /** Integer attributes. */
     261             :         int32_t _iAttributes[IATTR_ALL];
     262             : 
     263             :         /** The list of observers. */
     264             :         Observers _observers;
     265             : 
     266             :         /** The list of layouts. */
     267             :         Layouts _layouts;
     268             : 
     269             :         /** The list of canvases. */
     270             :         Canvases _canvases;
     271             : 
     272             :         /** The list of nodes. */
     273             :         Nodes _nodes;
     274             : 
     275             :         /** The node identifier of the node running the application thread. */
     276             :         co::NodeID _appNodeID;
     277             : 
     278             :         struct BackupData
     279             :         {
     280         470 :             BackupData() : latency( 1 ) {}
     281             : 
     282             :             /** The latency between frame start and end frame, in frames. */
     283             :             uint32_t latency;
     284             :         }
     285             :             _data, _backup;
     286             : 
     287             :         struct Private;
     288             :         Private* _private; // placeholder for binary-compatible changes
     289             : 
     290             :         enum DirtyBits
     291             :         {
     292             :             DIRTY_MEMBER     = Object::DIRTY_CUSTOM << 0,
     293             :             DIRTY_LATENCY    = Object::DIRTY_CUSTOM << 1,
     294             :             DIRTY_ATTRIBUTES = Object::DIRTY_CUSTOM << 2,
     295             :             DIRTY_NODES      = Object::DIRTY_CUSTOM << 3,
     296             :             DIRTY_OBSERVERS  = Object::DIRTY_CUSTOM << 4,
     297             :             DIRTY_LAYOUTS    = Object::DIRTY_CUSTOM << 5,
     298             :             DIRTY_CANVASES   = Object::DIRTY_CUSTOM << 6,
     299             :             DIRTY_CONFIG_BITS =
     300             :                 DIRTY_MEMBER | DIRTY_ATTRIBUTES | DIRTY_OBSERVERS |
     301             :                 DIRTY_LAYOUTS | DIRTY_CANVASES | DIRTY_NODES | DIRTY_LATENCY
     302             :         };
     303             : 
     304             :         /** @internal @return the bits to be re-committed by the master. */
     305           9 :         virtual uint64_t getRedistributableBits() const
     306           9 :             { return DIRTY_CONFIG_BITS; }
     307             : 
     308             :         template< class, class > friend class Observer;
     309             :         void _addObserver( O* observer );
     310             :         bool _removeObserver( O* observer );
     311             : 
     312             :         template< class, class, class > friend class Layout;
     313             :         void _addLayout( L* layout );
     314             :         bool _removeLayout( L* layout );
     315             : 
     316             :         template< class, class, class, class > friend class Canvas;
     317             :         void _addCanvas( CV* canvas );
     318             :         bool _removeCanvas( CV* canvas );
     319             : 
     320             :         template< class, class, class, class > friend class Node;
     321             :         void _addNode( N* node );
     322             :         EQFABRIC_INL bool _removeNode( N* node );
     323             : 
     324             :         typedef co::CommandFunc< Config< S, C, O, L, CV, N, V > > CmdFunc;
     325             :         bool _cmdNewLayout( co::ICommand& command );
     326             :         bool _cmdNewCanvas( co::ICommand& command );
     327             :         bool _cmdNewObserver( co::ICommand& command );
     328             :         bool _cmdNewEntityReply( co::ICommand& command );
     329             :     };
     330             : 
     331             :     template< class S, class C, class O, class L, class CV, class N, class V >
     332             :     EQFABRIC_INL std::ostream& operator << ( std::ostream& os,
     333             :                                  const Config< S, C, O, L, CV, N, V >& config );
     334             : }
     335             : }
     336             : #endif // EQFABRIC_CONFIG_H

Generated by: LCOV version 1.10