28 #ifndef EQ_ADMIN_REMOVE_WINDOW_H
29 #define EQ_ADMIN_REMOVE_WINDOW_H
33 #include <eq/admin/base.h>
39 class FindChannelSegments :
public eq::admin::ConfigVisitor
42 FindChannelSegments( eq::admin::Channel* channel ) : _channel( channel ) {}
43 virtual ~FindChannelSegments() {}
45 virtual eq::admin::VisitorResult visit( eq::admin::Segment* segment )
47 if( segment->getChannel() == _channel )
48 _segments.push_back( segment );
49 return eq::admin::TRAVERSE_CONTINUE;
52 const eq::admin::Segments& getResult()
const {
return _segments; }
55 eq::admin::Channel*
const _channel;
56 eq::admin::Segments _segments;
59 class FindCanvasLayouts :
public eq::admin::ConfigVisitor
62 FindCanvasLayouts(
const eq::admin::Canvas* canvas )
63 : _canvas( canvas ), _layout( 0 ) {}
64 virtual ~FindCanvasLayouts() {}
66 virtual eq::admin::VisitorResult visitPre( eq::admin::Canvas* canvas )
68 if( canvas == _canvas && !_layout )
70 const eq::admin::Layouts& layouts = canvas->getLayouts();
71 eq::admin::Config* config = canvas->getConfig();
72 for( eq::admin::Layouts::const_iterator i = layouts.begin();
73 i != layouts.end(); ++i )
77 config->accept(*
this) == eq::admin::TRAVERSE_CONTINUE )
79 _layouts.push_back( _layout );
83 return eq::admin::TRAVERSE_TERMINATE;
85 else if( canvas != _canvas && _layout )
87 const eq::admin::Layouts& layouts = canvas->getLayouts();
88 if( lunchbox::find( layouts, _layout ) != layouts.end( ))
89 return eq::admin::TRAVERSE_TERMINATE;
91 return eq::admin::TRAVERSE_CONTINUE;
94 const eq::admin::Layouts& getResult()
const {
return _layouts; }
97 const eq::admin::Canvas*
const _canvas;
98 eq::admin::Layout* _layout;
99 eq::admin::Layouts _layouts;
102 class FindLayoutObservers :
public eq::admin::ConfigVisitor
105 FindLayoutObservers(
const eq::admin::Layout* layout )
106 : _layout( layout ), _observer( 0 ) {}
107 virtual ~FindLayoutObservers() {}
109 virtual eq::admin::VisitorResult visit( eq::admin::View* view )
111 if( view->getLayout() == _layout && !_observer )
113 eq::admin::Config* config = view->getConfig();
114 _observer = view->getObserver();
116 config->accept(*
this) == eq::admin::TRAVERSE_CONTINUE )
118 _observers.push_back( _observer );
119 view->setObserver( 0 );
122 return eq::admin::TRAVERSE_TERMINATE;
124 else if( view->getLayout() != _layout && _observer )
126 if( _observer == view->getObserver( ))
127 return eq::admin::TRAVERSE_TERMINATE;
129 return eq::admin::TRAVERSE_CONTINUE;
132 const eq::admin::Observers& getResult()
const {
return _observers; }
135 const eq::admin::Layout*
const _layout;
136 eq::admin::Observer* _observer;
137 eq::admin::Observers _observers;
142 inline bool removeWindow( eq::admin::ServerPtr server )
148 eq::admin::Pipe* pipe = findPipe( server );
152 const eq::admin::Windows& windows = pipe->getWindows();
153 if( windows.size() < 2 )
157 eq::admin::Window* window = windows.back();
158 eq::admin::Config* config = pipe->getConfig();
160 const eq::admin::Channels& channels = window->getChannels();
161 for( eq::admin::Channels::const_iterator i = channels.begin();
162 i != channels.end(); ++i )
165 eq::admin::Channel* channel = *i;
166 FindChannelSegments channelSegments( channel );
167 config->accept( channelSegments );
168 const eq::admin::Segments& segments = channelSegments.getResult();
170 for( eq::admin::Segments::const_iterator j = segments.begin();
171 j != segments.end(); ++j )
173 eq::admin::Segment* segment = *j;
174 eq::admin::Canvas* canvas = segment->getCanvas();
178 if( !canvas->getSegments().empty( ))
182 FindCanvasLayouts canvasLayouts( canvas );
183 config->accept( canvasLayouts );
184 const eq::admin::Layouts& layouts = canvasLayouts.getResult();
185 for( eq::admin::Layouts::const_iterator k = layouts.begin();
186 k != layouts.end(); ++k )
188 eq::admin::Layout* layout = *k;
189 FindLayoutObservers layoutObservers( layout );
190 config->accept( layoutObservers );
191 eq::admin::Observers observers = layoutObservers.getResult();
192 lunchbox::usort( observers );
194 for( eq::admin::Observers::const_iterator l = observers.begin();
195 l != observers.end(); ++l )
211 #endif // EQ_ADMIN_REMOVE_WINDOW_H