LCOV - code coverage report
Current view: top level - eq/server - config.h (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 20 23 87.0 %
Date: 2014-06-18 Functions: 17 20 85.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2005-2013, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *               2010-2011, Daniel Nachbaur <danielnachbaur@gmail.com>
       4             :  *                    2010, Cedric Stalder <cedric Stalder@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 EQSERVER_CONFIG_H
      21             : #define EQSERVER_CONFIG_H
      22             : 
      23             : #include "api.h"
      24             : #include "types.h"
      25             : #include "server.h"        // used in inline method
      26             : #include "state.h"         // enum
      27             : #include "visitorResult.h" // enum
      28             : 
      29             : #include <eq/client/event.h>
      30             : #include <eq/fabric/config.h> // base class
      31             : #include <lunchbox/monitor.h> // member
      32             : 
      33             : #include <iostream>
      34             : #include <vector>
      35             : 
      36             : namespace eq
      37             : {
      38             : namespace server
      39             : {
      40             :     /** The config. */
      41             :     class Config : public fabric::Config< Server, Config, Observer, Layout,
      42             :                                           Canvas, Node, ConfigVisitor >
      43             :     {
      44             :     public:
      45             :         typedef fabric::Config< Server, Config, Observer, Layout, Canvas, Node,
      46             :                                 ConfigVisitor > Super;
      47             : 
      48             :         /** Construct a new config. */
      49             :         EQSERVER_API Config( ServerPtr parent );
      50             :         virtual ~Config();
      51             : 
      52             :         /**
      53             :          * @name Data Access.
      54             :          */
      55             :         //@{
      56             :         Channel* getChannel( const ChannelPath& path );
      57             :         Segment* getSegment( const SegmentPath& path );
      58             :         View* getView( const ViewPath& path );
      59             : 
      60          10 :         bool isRunning() const { return ( _state == STATE_RUNNING ); }
      61           4 :         bool isUsed() const { return _state != STATE_UNUSED; }
      62          10 :         bool isAutoConfig() const
      63          10 :             { return getName().find( " autoconfig" ) != std::string::npos; }
      64             : 
      65         215 :         co::CommandQueue* getMainThreadQueue()
      66         215 :             { return getServer()->getMainThreadQueue(); }
      67         157 :         co::CommandQueue* getCommandThreadQueue()
      68         157 :             { return getServer()->getCommandThreadQueue(); }
      69             : 
      70             :         /**
      71             :          * Adds a new compound to this config.
      72             :          *
      73             :          * @param compound the compound.
      74             :          */
      75             :         EQSERVER_API void addCompound( Compound* compound );
      76             : 
      77             :         /**
      78             :          * Removes a compound from this config.
      79             :          *
      80             :          * @param compound the compound
      81             :          * @return <code>true</code> if the compound was removed,
      82             :          *         <code>false</code> otherwise.
      83             :          */
      84             :         EQSERVER_API bool removeCompound( Compound* compound );
      85             : 
      86             :         /** @return the vector of compounds. */
      87        1672 :         const Compounds& getCompounds() const { return _compounds; }
      88             : 
      89             :         /**
      90             :          * Find the first channel of a given name.
      91             :          *
      92             :          * @param name the name of the channel to find
      93             :          * @return the first channel with the name, or <code>0</code> if no
      94             :          *         channel with the name exists.
      95             :          */
      96             :         const Channel* findChannel( const std::string& name ) const;
      97             : 
      98             :         /**
      99             :          * Find the channel for the given view/segment intersection.
     100             :          *
     101             :          * @param segment the segment.
     102             :          * @param view the view.
     103             :          * @return the channel for updating the view/segment intersection.
     104             :          */
     105             :         EQSERVER_API Channel* findChannel( const Segment* segment,
     106             :                                            const View* view );
     107             : 
     108             :         /** @return the application node, or 0. */
     109             :         EQSERVER_API Node* findApplicationNode();
     110             :         //@}
     111             : 
     112             :         /** @sa fabric::Config::changeLatency() */
     113             :         virtual void changeLatency( const uint32_t latency );
     114             : 
     115             :         /**
     116             :          * Set the network node running the application thread.
     117             :          *
     118             :          * @param node the application node.
     119             :          */
     120             :         void setApplicationNetNode( co::NodePtr node );
     121             : 
     122             :         /** @return network node running the application thread. */
     123             :         co::NodePtr findApplicationNetNode();
     124             : 
     125             :         /** @internal set auto-configured server connections */
     126           5 :         void setServerConnections( const co::Connections& connections )
     127           5 :             { _connections = connections; }
     128             : 
     129             :         /** @internal @return the auto-configured server connections */
     130           8 :         const co::Connections& getServerConnections() const
     131           8 :             { return _connections; }
     132             : 
     133             :         /**
     134             :          * Set the name of the render client executable.
     135             :          *
     136             :          * @param rc the name of the render client executable.
     137             :          */
     138          10 :         void setRenderClient( const std::string& rc ){ _renderClient = rc; }
     139             : 
     140             :         /** @return the name of the render client executable. */
     141           0 :         const std::string& getRenderClient() const { return _renderClient; }
     142             : 
     143             :         /**
     144             :          * Set the working directory for render client.
     145             :          *
     146             :          * @param workDir the working directory for the  render client.
     147             :          */
     148          10 :         void setWorkDir( const std::string& workDir ){ _workDir = workDir; }
     149             : 
     150             :         /** @return the working directory for the  render client. */
     151           0 :         const std::string& getWorkDir() const { return _workDir; }
     152             : 
     153             :         /** Notify that a node of this config has finished a frame. */
     154             :         void notifyNodeFrameFinished( const uint32_t frameNumber );
     155             : 
     156             :         // Used by Server::releaseConfig() to make sure config is exited
     157             :         bool exit();
     158             : 
     159             :         /** Register the config and all shared object children. */
     160             :         void register_();
     161             : 
     162             :         /** Deregister all shared objects and the config. */
     163             :         void deregister();
     164             : 
     165             :         /** Commit the config for the current frame. */
     166             :         uint128_t commit();
     167             : 
     168             :         virtual void restore();
     169             : 
     170             :         EventOCommand sendError( const uint32_t type,
     171             :                                  const uint128_t& originator,
     172             :                                  const uint32_t error );
     173             : 
     174             :         /** Return the initID, used for late initialization  */
     175             :         uint128_t getInitID(){ return _initID; }
     176             : 
     177             :         /** Activate the given canvas after it is complete (dest channels). */
     178             :         virtual void activateCanvas( Canvas* canvas );
     179             : 
     180             :         /** Initialize the given canvas in a running configuration */
     181             :         virtual void updateCanvas( Canvas* canvas );
     182             : 
     183             :         /** Request a finish of outstanding frames on next frame */
     184          16 :         void postNeedsFinish() { _needsFinish = true; }
     185             : 
     186             :         /** @internal @return the last finished frame */
     187          16 :         uint32_t getFinishedFrame() const { return _finishedFrame.get(); }
     188             : 
     189             :         /** @internal */
     190             :         virtual VisitorResult _acceptCompounds( ConfigVisitor& visitor );
     191             :         /** @internal */
     192             :         virtual VisitorResult _acceptCompounds( ConfigVisitor& visitor ) const;
     193             : 
     194             :         void output( std::ostream& os ) const; //!< @internal
     195           0 :         virtual bool mapViewObjects() const { return true; } //!< @internal
     196         113 :         virtual bool mapNodeObjects() const { return true; } //!< @internal
     197             : 
     198             :     protected:
     199             :         /** @internal */
     200             :         virtual void attach( const uint128_t& id, const uint32_t instanceID );
     201             : 
     202             :         /** @internal Execute the slave remove request. */
     203             :         virtual void removeChild( const uint128_t& id );
     204             : 
     205             :     private:
     206             :         Config( const Config& from );
     207             : 
     208             :         /** The initID for late initialization. */
     209             :         uint128_t _initID;
     210             : 
     211             :         /** The list of compounds. */
     212             :         Compounds _compounds;
     213             : 
     214             :         /** Auto-configured server connections. */
     215             :         co::Connections _connections;
     216             : 
     217             :         /** The name of the render client executable. */
     218             :         std::string _renderClient;
     219             : 
     220             :         /** The working directory of the render client. */
     221             :         std::string _workDir;
     222             : 
     223             :         /** The last started frame, or 0. */
     224             :         uint32_t _currentFrame;
     225             : 
     226             :         /** The eternal frame commit counter, starting at 1 (#66). */
     227             :         uint32_t _incarnation;
     228             : 
     229             :         /** The last finished frame, or 0. */
     230             :         lunchbox::Monitor< uint32_t > _finishedFrame;
     231             : 
     232             :         State _state;
     233             : 
     234             :         bool _needsFinish; //!< true after runtime changes
     235             : 
     236             :         int64_t _lastCheck;
     237             : 
     238             :         struct Private;
     239             :         Private* _private; // placeholder for binary-compatible changes
     240             : 
     241             :         /**
     242             :          * @name Operations
     243             :          */
     244             :         //@{
     245             :         bool _updateRunning(); //!< @return true on success, false on error
     246             : 
     247             :         void _updateCanvases();
     248             :         bool _connectNodes();
     249             :         bool _connectNode( Node* node );
     250             :         bool _syncConnectNode( Node* node, const lunchbox::Clock& clock );
     251             :         void _startNodes();
     252             :         lunchbox::Request< void > _createConfig( Node* node );
     253             :         bool _updateNodes();
     254             :         void _stopNodes();
     255             :         template< class T >
     256             :         void _deleteEntities( const std::vector< T* >& entities );
     257             :         void _syncClock();
     258             :         void _verifyFrameFinished( const uint32_t frameNumber );
     259             :         bool _init( const uint128_t& initID );
     260             : 
     261             :         void _startFrame( const uint128_t& frameID );
     262             :         void _flushAllFrames();
     263             :         //@}
     264             : 
     265             :         virtual Observer* createObserver();
     266             :         virtual void releaseObserver( Observer* observer );
     267             :         virtual Layout* createLayout();
     268             :         virtual void releaseLayout( Layout* layout );
     269             :         virtual Canvas* createCanvas();
     270             :         virtual void releaseCanvas( Canvas* canvas );
     271             : 
     272             :         /** @internal Post deletion for the given child, returns true if found*/
     273             :         template< class T > bool _postDelete( const uint128_t& id );
     274             : 
     275             :         /** The command functions. */
     276             :         bool _cmdInit( co::ICommand& command );
     277             :         bool _cmdExit( co::ICommand& command );
     278             :         bool _cmdUpdate( co::ICommand& command );
     279             :         bool _cmdStartFrame( co::ICommand& command );
     280             :         bool _cmdStopFrames( co::ICommand& command );
     281             :         bool _cmdFinishAllFrames( co::ICommand& command );
     282             :         bool _cmdCreateReply( co::ICommand& command );
     283             :         bool _cmdFreezeLoadBalancing( co::ICommand& command );
     284             :         bool _cmdCheckFrame( co::ICommand& command );
     285             : 
     286         429 :         LB_TS_VAR( _cmdThread );
     287         429 :         LB_TS_VAR( _mainThread );
     288             :     };
     289             : }
     290             : }
     291             : #endif // EQSERVER_CONFIG_H

Generated by: LCOV version 1.10