LCOV - code coverage report
Current view: top level - eq/server - configUpdateVisitor.h (source / functions) Hit Total Coverage
Test: Equalizer Lines: 43 49 87.8 %
Date: 2016-09-29 05:02:09 Functions: 17 18 94.4 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2010-2013, Stefan Eilemann <eile@eyescale.ch>
       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 EQSERVER_CONFIGUPDATEVISITOR_H
      19             : #define EQSERVER_CONFIGUPDATEVISITOR_H
      20             : 
      21             : #include "configVisitor.h" // base class
      22             : 
      23             : namespace eq
      24             : {
      25             : namespace server
      26             : {
      27             : namespace
      28             : {
      29             : 
      30             : class ConfigUpdateVisitor : public ConfigVisitor
      31             : {
      32             : public:
      33           4 :     ConfigUpdateVisitor( const uint128_t& initID, const uint32_t frameNumber )
      34           4 :             : _initID( initID ), _frameNumber( frameNumber ) {}
      35           4 :     virtual ~ConfigUpdateVisitor() {}
      36             : 
      37           4 :     virtual VisitorResult visitPre( Node* node )
      38           4 :         { return _updateDown( node ); }
      39           4 :     virtual VisitorResult visitPost( Node* node )
      40             :         {
      41           4 :             const VisitorResult result = _updateUp( node );
      42           4 :             if( result == TRAVERSE_CONTINUE )
      43           4 :                 node->flushSendBuffer();
      44           4 :             return result;
      45             :         }
      46             : 
      47           4 :     virtual VisitorResult visitPre( Pipe* pipe )
      48           4 :         { return _updateDown( pipe ); }
      49           4 :     virtual VisitorResult visitPost( Pipe* pipe )
      50           4 :         { return _updateUp( pipe ); }
      51             : 
      52           4 :     virtual VisitorResult visitPre( Window* window )
      53           4 :         { return _updateDown( window ); }
      54           4 :     virtual VisitorResult visitPost( Window* window )
      55           4 :         { return _updateUp( window ); }
      56             : 
      57           8 :     virtual VisitorResult visit( Channel* channel )
      58             :         {
      59           8 :             if( _updateDown( channel ) == TRAVERSE_CONTINUE )
      60           4 :                 return _updateUp( channel );
      61           4 :             return TRAVERSE_CONTINUE;
      62             :         }
      63             : 
      64             : private:
      65             :     const uint128_t _initID;
      66             :     const uint32_t  _frameNumber;
      67             : 
      68          20 :     template< class T > VisitorResult _updateDown( T* entity ) const
      69             :         {
      70          20 :             const uint32_t state = entity->getState() & ~STATE_DELETE;
      71             : 
      72          20 :             switch( state )
      73             :             {
      74             :                 case STATE_STOPPED:
      75          12 :                     if( entity->isActive( ))
      76             :                     {
      77           8 :                         entity->configInit( _initID, _frameNumber );
      78           8 :                         return TRAVERSE_CONTINUE;
      79             :                     }
      80           4 :                     return TRAVERSE_PRUNE;
      81             : 
      82             :                 case STATE_RUNNING:
      83           2 :                     return TRAVERSE_CONTINUE;
      84             :                 case STATE_FAILED:
      85           6 :                     if( entity->isActive( ))
      86           0 :                         return TRAVERSE_PRUNE;
      87           6 :                     return TRAVERSE_CONTINUE;
      88             :             }
      89           0 :             LBUNREACHABLE;
      90           0 :             return TRAVERSE_PRUNE;
      91             :         }
      92             : 
      93          16 :     template< class T > VisitorResult _updateUp( T* entity ) const
      94             :         {
      95          16 :             const uint32_t state = entity->getState() & ~STATE_DELETE;
      96          16 :             switch( state )
      97             :             {
      98             :                 case STATE_INITIALIZING:
      99             :                 case STATE_INIT_FAILED:
     100             :                 case STATE_INIT_SUCCESS:
     101           8 :                     return TRAVERSE_CONTINUE;
     102             : 
     103             :                 case STATE_RUNNING:
     104           2 :                     if( !entity->isActive( ))
     105           2 :                         entity->configExit();
     106           2 :                     return TRAVERSE_CONTINUE;
     107             : 
     108             :                 case STATE_FAILED:
     109           6 :                     LBASSERT( !entity->isActive( ));
     110           6 :                     if( !entity->isActive( ))
     111             :                     {
     112           6 :                         entity->setState( STATE_STOPPED );
     113           6 :                         return TRAVERSE_PRUNE;
     114             :                     }
     115           0 :                     return TRAVERSE_CONTINUE;
     116             :             }
     117           0 :             LBASSERTINFO( false, State( state ));
     118           0 :             return TRAVERSE_PRUNE;
     119             :         }
     120             : };
     121             : 
     122             : }
     123             : }
     124             : }
     125             : 
     126             : #endif // EQSERVER_CONFIGUPDATEVISITOR_H

Generated by: LCOV version 1.11