LCOV - code coverage report
Current view: top level - eq/server - node.h (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 16 17 94.1 %
Date: 2014-06-18 Functions: 13 14 92.9 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2005-2014, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *                    2010, Cedric Stalder <cedric Stalder@gmail.com>
       4             :  *                    2012, 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 EQSERVER_NODE_H
      21             : #define EQSERVER_NODE_H
      22             : 
      23             : #include "config.h"                // used in inline method
      24             : #include "state.h"                 // enum
      25             : #include "types.h"
      26             : 
      27             : #include <eq/fabric/node.h> // base class
      28             : 
      29             : #include <co/barrier.h>
      30             : #include <co/bufferConnection.h>
      31             : #include <co/connectionDescription.h>
      32             : #include <co/node.h>
      33             : 
      34             : #include <vector>
      35             : 
      36             : namespace eq
      37             : {
      38             : namespace server
      39             : {
      40             : /** The node. */
      41             : class Node : public fabric::Node< Config, Node, Pipe, NodeVisitor >
      42             : {
      43             : public:
      44             :     /** Construct a new Node. */
      45             :     EQSERVER_API Node( Config* parent );
      46             : 
      47             :     virtual ~Node();
      48             : 
      49             :     /** @name Data Access. */
      50             :     //@{
      51             :     ServerPtr getServer();
      52             :     ConstServerPtr getServer() const;
      53             : 
      54          33 :     co::NodePtr getNode() const { return _node; }
      55          12 :     void setNode( co::NodePtr node ) { _node = node; }
      56             : 
      57         271 :     void setHost( const std::string& host ) { _host = host; }
      58         198 :     const std::string& getHost() const { return _host; }
      59             : 
      60             :     Channel* getChannel( const ChannelPath& path );
      61             : 
      62             :     /** @return the state of this node. */
      63         110 :     State getState()    const { return _state.get(); }
      64             : 
      65             :     /** @internal */
      66           0 :     void setState( const State state ) { _state = state; }
      67             : 
      68             :     co::CommandQueue* getMainThreadQueue();
      69             :     co::CommandQueue* getCommandThreadQueue();
      70             : 
      71             :     /** Increase node activition count. */
      72             :     void activate();
      73             : 
      74             :     /** Decrease node activition count. */
      75             :     void deactivate();
      76             : 
      77             :     /** @return if this pipe is actively used for rendering. */
      78         174 :     bool isActive() const { return ( _active != 0 ); }
      79             : 
      80             :     /** @return if this node is running. */
      81          33 :     bool isRunning() const { return _state == STATE_RUNNING; }
      82             : 
      83             :     /** @return if this node is stopped. */
      84           8 :     bool isStopped() const { return _state == STATE_STOPPED; }
      85             : 
      86             :     /**
      87             :      * Add additional tasks this pipe, and all its parents, might
      88             :      * potentially execute.
      89             :      */
      90             :     void addTasks( const uint32_t tasks );
      91             : 
      92             :     /** The last drawing channel for this entity. */
      93          10 :     void setLastDrawPipe( const Pipe* pipe )
      94          10 :     { _lastDrawPipe = pipe; }
      95           7 :     const Pipe* getLastDrawPipe() const { return _lastDrawPipe;}
      96             : 
      97             :     /** @return the number of the last finished frame. @internal */
      98          15 :     uint32_t getFinishedFrame() const { return _finishedFrame; }
      99             :     //@}
     100             : 
     101             :     /**
     102             :      * @name Operations
     103             :      */
     104             :     //@{
     105             :     /** Connect the render slave node process. */
     106             :     bool connect();
     107             : 
     108             :     /** Launch the render slave node process. */
     109             :     bool launch();
     110             : 
     111             :     /** Synchronize the connection of a render slave launch. */
     112             :     bool syncLaunch( const lunchbox::Clock& time );
     113             : 
     114             :     /** Start initializing this entity. */
     115             :     void configInit( const uint128_t& initID, const uint32_t frameNumber );
     116             : 
     117             :     /** Sync initialization of this entity. */
     118             :     bool syncConfigInit();
     119             : 
     120             :     /** Start exiting this entity. */
     121             :     void configExit();
     122             : 
     123             :     /** Sync exit of this entity. */
     124             :     bool syncConfigExit();
     125             : 
     126             :     /**
     127             :      * Trigger the rendering of a new frame for this node.
     128             :      *
     129             :      * @param frameID a per-frame identifier passed to all rendering
     130             :      *                methods.
     131             :      * @param frameNumber the number of the frame.
     132             :      */
     133             :     void update( const uint128_t& frameID, const uint32_t frameNumber );
     134             : 
     135             :     /**
     136             :      * Flush the processing of frames, including frameNumber.
     137             :      *
     138             :      * @param frameNumber the number of the frame.
     139             :      */
     140             :     void flushFrames( const uint32_t frameNumber );
     141             : 
     142             :     /** Synchronize the completion of the rendering of a frame. */
     143             :     void finishFrame( const uint32_t frame );
     144             :     //@}
     145             : 
     146             :     /**
     147             :      * @name Barrier Cache
     148             :      *
     149             :      * Caches barriers for which this node is the master.
     150             :      */
     151             :     //@{
     152             :     /**
     153             :      * Get a new barrier of height 0.
     154             :      *
     155             :      * @return the barrier.
     156             :      */
     157             :     co::Barrier* getBarrier();
     158             : 
     159             :     /**
     160             :      * Release a barrier server by this node.
     161             :      *
     162             :      * @param barrier the barrier.
     163             :      */
     164             :     void releaseBarrier( co::Barrier* barrier );
     165             : 
     166             :     /** Change the latency on all objects (barrier) */
     167             :     void changeLatency( const uint32_t latency );
     168             :     //@}
     169             : 
     170             :     co::ObjectOCommand send( const uint32_t cmd );
     171             :     co::ObjectOCommand send( const uint32_t cmd, const uint128_t& id );
     172             :     EventOCommand sendError( const uint32_t error );
     173             : 
     174             :     void flushSendBuffer();
     175             : 
     176             :     /**
     177             :      * Add a new description how this node can be reached.
     178             :      *
     179             :      * @param desc the connection description.
     180             :      */
     181         312 :     void addConnectionDescription( co::ConnectionDescriptionPtr desc )
     182         312 :     { _connectionDescriptions.push_back( desc ); }
     183             : 
     184             :     /**
     185             :      * Remove a connection description.
     186             :      *
     187             :      * @param cd the connection description.
     188             :      * @return true if the connection description was removed, false otherwise.
     189             :      */
     190             :     EQSERVER_API bool removeConnectionDescription(
     191             :         co::ConnectionDescriptionPtr cd );
     192             : 
     193             :     /** @return the vector of connection descriptions. */
     194         208 :     const co::ConnectionDescriptions& getConnectionDescriptions()
     195         208 :         const { return _connectionDescriptions; }
     196             : 
     197             : 
     198             :     /** @name Attributes */
     199             :     //@{
     200             :     /** String attributes. */
     201             :     enum SAttribute
     202             :     {
     203             :         SATTR_LAUNCH_COMMAND, //!< the command to launch the node
     204             :         SATTR_LAST,
     205             :         SATTR_ALL = SATTR_LAST + 5
     206             :     };
     207             : 
     208             :     /** Character attributes. */
     209             :     enum CAttribute
     210             :     {
     211             :         CATTR_LAUNCH_COMMAND_QUOTE, //!< The character to quote arguments
     212             :         CATTR_LAST,
     213             :         CATTR_ALL = CATTR_LAST + 5
     214             :     };
     215             : 
     216             :     /** @internal Set a string integer attribute. */
     217             :     EQSERVER_API void setSAttribute( const SAttribute attr, const std::string& value );
     218             : 
     219             :     /** @internal Set a character integer attribute. */
     220             :     void setCAttribute( const CAttribute attr, const char value );
     221             : 
     222             :     /** @return the value of a node string attribute. @version 1.0 */
     223             :     const std::string& getSAttribute( const SAttribute attr ) const;
     224             : 
     225             :     /** @return the value of a node string attribute. @version 1.0 */
     226             :     char getCAttribute( const CAttribute attr ) const;
     227             : 
     228             :     /** @internal @return the name of a node string attribute. */
     229             :     static const std::string& getSAttributeString( const SAttribute attr );
     230             :     /** @internal @return the name of a node character attribute. */
     231             :     static const std::string& getCAttributeString( const CAttribute attr );
     232             :     //@}
     233             : 
     234             :     void output( std::ostream& os ) const; //!< @internal
     235             : 
     236             : protected:
     237             : 
     238             :     /** @sa co::Object::attach. */
     239             :     virtual void attach( const uint128_t& id, const uint32_t instanceID );
     240             : 
     241             : private:
     242             :     /** String attributes. */
     243             :     std::string _sAttributes[SATTR_ALL];
     244             : 
     245             :     /** Character attributes. */
     246             :     char _cAttributes[CATTR_ALL];
     247             : 
     248             :     std::string _host; // The host name to launch this node
     249             : 
     250             :     /** Number of activations for this node. */
     251             :     uint32_t _active;
     252             : 
     253             :     /** The network node on which this Equalizer node is running. */
     254             :     co::NodePtr _node;
     255             : 
     256             :     /** The list of descriptions on how this node is reachable. */
     257             :     co::ConnectionDescriptions _connectionDescriptions;
     258             : 
     259             :     typedef stde::hash_map< uint32_t, co::uint128_t > FrameIDHash;
     260             :     /** The frame identifiers non-finished frames. */
     261             :     FrameIDHash _frameIDs;
     262             : 
     263             :     /** The number of the last finished frame. */
     264             :     uint32_t _finishedFrame;
     265             : 
     266             :     /** The number of the last flushed frame (frame finish command sent). */
     267             :     uint32_t _flushedFrame;
     268             : 
     269             :     /** The current state for state change synchronization. */
     270             :     lunchbox::Monitor< State > _state;
     271             : 
     272             :     /** The cached barriers. */
     273             :     std::vector<co::Barrier*> _barriers;
     274             : 
     275             :     /** Task commands for the current operation. */
     276             :     co::BufferConnectionPtr _bufferedTasks;
     277             : 
     278             :     /** The last draw pipe for this entity */
     279             :     const Pipe* _lastDrawPipe;
     280             : 
     281             :     struct Private;
     282             :     Private* _private; // placeholder for binary-compatible changes
     283             : 
     284             :     /**
     285             :      * Compose and execute the launch command by expanding the variables in
     286             :      * the launch command string.
     287             :      *
     288             :      * @param description the connection description.
     289             :      * @return true on success, false otherwise
     290             :      */
     291             :     bool _launch( const std::string& hostname ) const;
     292             :     std::string   _createRemoteCommand() const;
     293             : 
     294             :     uint32_t _getFinishLatency() const;
     295             :     void _finish( const uint32_t currentFrame );
     296             : 
     297             :     /** flush cached barriers. */
     298             :     void _flushBarriers();
     299             : 
     300             :     /** Send the frame finish command for the given frame number. */
     301             :     void _sendFrameFinish( const uint32_t frameNumber );
     302             : 
     303             :     /* ICommand handler functions. */
     304             :     bool _cmdConfigInitReply( co::ICommand& command );
     305             :     bool _cmdConfigExitReply( co::ICommand& command );
     306             :     bool _cmdFrameFinishReply( co::ICommand& command );
     307             : };
     308             : }
     309             : }
     310             : #endif // EQSERVER_NODE_H

Generated by: LCOV version 1.10