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 16 : ConfigUpdateVisitor( const uint128_t& initID, const uint32_t frameNumber )
34 16 : : _initID( initID ), _frameNumber( frameNumber ) {}
35 16 : virtual ~ConfigUpdateVisitor() {}
36 :
37 26 : virtual VisitorResult visitPre( Node* node )
38 26 : { return _updateDown( node ); }
39 16 : virtual VisitorResult visitPost( Node* node )
40 : {
41 16 : const VisitorResult result = _updateUp( node );
42 16 : if( result == TRAVERSE_CONTINUE )
43 16 : node->flushSendBuffer();
44 16 : return result;
45 : }
46 :
47 30 : virtual VisitorResult visitPre( Pipe* pipe )
48 30 : { return _updateDown( pipe ); }
49 30 : virtual VisitorResult visitPost( Pipe* pipe )
50 30 : { return _updateUp( pipe ); }
51 :
52 30 : virtual VisitorResult visitPre( Window* window )
53 30 : { return _updateDown( window ); }
54 30 : virtual VisitorResult visitPost( Window* window )
55 30 : { return _updateUp( window ); }
56 :
57 140 : virtual VisitorResult visit( Channel* channel )
58 : {
59 140 : if( _updateDown( channel ) == TRAVERSE_CONTINUE )
60 30 : return _updateUp( channel );
61 110 : return TRAVERSE_CONTINUE;
62 : }
63 :
64 : private:
65 : const uint128_t _initID;
66 : const uint32_t _frameNumber;
67 :
68 226 : template< class T > VisitorResult _updateDown( T* entity ) const
69 : {
70 226 : const uint32_t state = entity->getState() & ~STATE_DELETE;
71 :
72 226 : switch( state )
73 : {
74 : case STATE_STOPPED:
75 173 : if( entity->isActive( ))
76 : {
77 53 : entity->configInit( _initID, _frameNumber );
78 53 : return TRAVERSE_CONTINUE;
79 : }
80 120 : return TRAVERSE_PRUNE;
81 :
82 : case STATE_RUNNING:
83 53 : return TRAVERSE_CONTINUE;
84 : case STATE_FAILED:
85 0 : if( entity->isActive( ))
86 0 : return TRAVERSE_PRUNE;
87 0 : return TRAVERSE_CONTINUE;
88 : }
89 0 : LBUNREACHABLE;
90 0 : return TRAVERSE_PRUNE;
91 : }
92 :
93 106 : template< class T > VisitorResult _updateUp( T* entity ) const
94 : {
95 106 : const uint32_t state = entity->getState() & ~STATE_DELETE;
96 106 : switch( state )
97 : {
98 : case STATE_INITIALIZING:
99 : case STATE_INIT_FAILED:
100 : case STATE_INIT_SUCCESS:
101 53 : return TRAVERSE_CONTINUE;
102 :
103 : case STATE_RUNNING:
104 53 : if( !entity->isActive( ))
105 53 : entity->configExit();
106 53 : return TRAVERSE_CONTINUE;
107 :
108 : case STATE_FAILED:
109 0 : LBASSERT( !entity->isActive( ));
110 0 : if( !entity->isActive( ))
111 : {
112 0 : entity->setState( STATE_STOPPED );
113 0 : 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
|