LCOV - code coverage report
Current view: top level - eq/server - configUpdateSyncVisitor.h (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 39 52 75.0 %
Date: 2014-06-18 Functions: 19 20 95.0 %

          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_CONFIGUPDATESYNCVISITOR_H
      19             : #define EQSERVER_CONFIGUPDATESYNCVISITOR_H
      20             : 
      21             : #include "configVisitor.h" // base class
      22             : 
      23             : namespace eq
      24             : {
      25             : namespace server
      26             : {
      27             : namespace
      28             : {
      29             : 
      30             : class ConfigUpdateSyncVisitor : public ConfigVisitor
      31             : {
      32             : public:
      33          16 :     ConfigUpdateSyncVisitor() : _result( true ), _sync( false ) {}
      34          16 :     virtual ~ConfigUpdateSyncVisitor() {}
      35             : 
      36          16 :     VisitorResult visitPre( Config* )
      37             :     {
      38          16 :         _result = true;
      39          16 :         _sync = false;
      40          16 :         return TRAVERSE_CONTINUE;
      41             :     }
      42             : 
      43          26 :     VisitorResult visitPre( Node* node ) override
      44          26 :         { return _updateDown( node ); }
      45          16 :     VisitorResult visitPost( Node* node ) override
      46             :     {
      47          16 :         const VisitorResult& result = _updateUp( node );
      48          16 :         node->flushSendBuffer();
      49          16 :         return result;
      50             :     }
      51             : 
      52          30 :     VisitorResult visitPre( Pipe* pipe ) override
      53          30 :         { return _updateDown( pipe ); }
      54          30 :     VisitorResult visitPost( Pipe* pipe ) override
      55          30 :         { return _updateUp( pipe ); }
      56             : 
      57          30 :     VisitorResult visitPre( Window* window ) override
      58          30 :         { return _updateDown( window ); }
      59          30 :     VisitorResult visitPost( Window* window ) override
      60          30 :         { return _updateUp( window ); }
      61             : 
      62         140 :     VisitorResult visit( Channel* channel ) override
      63         140 :         { return _updateUp( channel ); }
      64             : 
      65          16 :     bool getResult() const { return _result; }
      66          16 :     bool needsSync() const { return _sync; }
      67             : 
      68             : private:
      69             :     bool _result; // success or failure
      70             :     bool _sync;   // call again after init failure
      71             : 
      72          86 :     template< class T > VisitorResult _updateDown( T* entity ) const
      73             :     {
      74          86 :         const uint32_t state = entity->getState() & ~STATE_DELETE;
      75          86 :         switch( state )
      76             :         {
      77             :             case STATE_INITIALIZING:
      78             :             case STATE_INIT_FAILED:
      79             :             case STATE_INIT_SUCCESS:
      80             :             case STATE_EXITING:
      81             :             case STATE_EXIT_FAILED:
      82             :             case STATE_EXIT_SUCCESS:
      83             :             case STATE_RUNNING:
      84          76 :                 return TRAVERSE_CONTINUE;
      85             : 
      86             :             case STATE_STOPPED:
      87             :             case STATE_FAILED:
      88          10 :                 return TRAVERSE_PRUNE;
      89             :         }
      90           0 :         LBUNREACHABLE;
      91           0 :         return TRAVERSE_PRUNE;
      92             :     }
      93             : 
      94         216 :     template< class T > VisitorResult _updateUp( T* entity )
      95             :     {
      96         216 :         const uint32_t state = entity->getState() & ~STATE_DELETE;
      97         216 :         switch( state )
      98             :         {
      99             :             case STATE_INITIALIZING:
     100             :             case STATE_INIT_FAILED:
     101             :             case STATE_INIT_SUCCESS:
     102          53 :                 if( !entity->syncConfigInit( ))
     103             :                 {
     104           0 :                     entity->sync();
     105           0 :                     _result = false;
     106           0 :                     _sync = true;
     107           0 :                     LBWARN << lunchbox::className( entity ) << " init failed"
     108           0 :                            << std::endl;
     109             :                 }
     110             :                 else
     111          53 :                     entity->sync();
     112          53 :                 return TRAVERSE_CONTINUE;
     113             : 
     114             :             case STATE_EXITING:
     115             :             case STATE_EXIT_FAILED:
     116             :             case STATE_EXIT_SUCCESS:
     117          53 :                 if( !entity->syncConfigExit( ))
     118             :                 {
     119           0 :                     entity->sync();
     120           0 :                     _result = false;
     121           0 :                     LBWARN << lunchbox::className( entity ) << " exit failed"
     122           0 :                            << std::endl;
     123             :                 }
     124             :                 else
     125          53 :                     entity->sync();
     126          53 :                 return TRAVERSE_CONTINUE;
     127             : 
     128             :             case STATE_RUNNING:
     129             :             case STATE_STOPPED:
     130             :             case STATE_FAILED:
     131         110 :                 return TRAVERSE_CONTINUE;
     132             :         }
     133           0 :         LBUNREACHABLE;
     134           0 :         return TRAVERSE_PRUNE;
     135             :     }
     136             : };
     137             : 
     138             : }
     139             : }
     140             : }
     141             : 
     142             : #endif // EQSERVER_CONFIGUPDATESYNCVISITOR_H

Generated by: LCOV version 1.10