Line data Source code
1 :
2 : /* Copyright (c) 2005-2016, Stefan Eilemann <eile@equalizergraphics.com>
3 : * Daniel Nachbaur <danielnachbaur@gmail.com>
4 : * Cedric Stalder <cedric Stalder@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_CONFIG_H
21 : #define EQSERVER_CONFIG_H
22 :
23 : #include <eq/server/api.h>
24 : #include "types.h"
25 : #include "server.h" // used in inline method
26 : #include "state.h" // enum
27 : #include "visitorResult.h" // enum
28 :
29 : #include <eq/fabric/config.h> // base class
30 : #include <lunchbox/monitor.h> // member
31 :
32 : #include <iostream>
33 : #include <vector>
34 :
35 : namespace eq
36 : {
37 : namespace server
38 : {
39 : /** The config. */
40 : class Config : public fabric::Config< Server, Config, Observer, Layout,
41 : Canvas, Node, ConfigVisitor >
42 : {
43 : public:
44 : typedef fabric::Config< Server, Config, Observer, Layout, Canvas, Node,
45 : ConfigVisitor > Super;
46 :
47 : /** Construct a new config. */
48 : EQSERVER_API explicit Config( ServerPtr parent );
49 : virtual ~Config();
50 :
51 : /**
52 : * @name Data Access.
53 : */
54 : //@{
55 : Channel* getChannel( const ChannelPath& path );
56 : Segment* getSegment( const SegmentPath& path );
57 : View* getView( const ViewPath& path );
58 :
59 4 : bool isRunning() const { return ( _state == STATE_RUNNING ); }
60 8 : bool isUsed() const { return _state != STATE_UNUSED; }
61 4 : bool isAutoConfig() const
62 4 : { return getName().find( " autoconfig" ) != std::string::npos; }
63 :
64 28 : co::CommandQueue* getMainThreadQueue()
65 28 : { return getServer()->getMainThreadQueue(); }
66 24 : co::CommandQueue* getCommandThreadQueue()
67 24 : { return getServer()->getCommandThreadQueue(); }
68 :
69 : /**
70 : * Adds a new compound to this config.
71 : *
72 : * @param compound the compound.
73 : */
74 : EQSERVER_API void addCompound( Compound* compound );
75 :
76 : /**
77 : * Removes a compound from this config.
78 : *
79 : * @param compound the compound
80 : * @return <code>true</code> if the compound was removed,
81 : * <code>false</code> otherwise.
82 : */
83 : EQSERVER_API bool removeCompound( Compound* compound );
84 :
85 : /** @return the vector of compounds. */
86 2214 : const Compounds& getCompounds() const { return _compounds; }
87 :
88 : /**
89 : * Find the first channel of a given name.
90 : *
91 : * @param name the name of the channel to find
92 : * @return the first channel with the name, or <code>0</code> if no
93 : * channel with the name exists.
94 : */
95 : const Channel* findChannel( const std::string& name ) const;
96 :
97 : /**
98 : * Find the channel for the given view/segment intersection.
99 : *
100 : * @param segment the segment.
101 : * @param view the view.
102 : * @return the channel for updating the view/segment intersection.
103 : */
104 : EQSERVER_API Channel* findChannel( const Segment* segment,
105 : const View* view );
106 :
107 : /** @return the application node, or 0. */
108 : EQSERVER_API Node* findApplicationNode();
109 : //@}
110 :
111 : /** @sa fabric::Config::changeLatency() */
112 : virtual void changeLatency( const uint32_t latency );
113 :
114 : /**
115 : * Set the network node running the application thread.
116 : *
117 : * @param node the application node.
118 : */
119 : void setApplicationNetNode( co::NodePtr node );
120 :
121 : /** @return network node running the application thread. */
122 : co::NodePtr findApplicationNetNode();
123 :
124 : /** @internal set auto-configured server connections */
125 0 : void setServerConnections( const co::Connections& connections )
126 0 : { _connections = connections; }
127 :
128 : /** @internal @return the auto-configured server connections */
129 0 : const co::Connections& getServerConnections() const
130 0 : { return _connections; }
131 :
132 : /**
133 : * Set the name of the render client executable.
134 : *
135 : * @param rc the name of the render client executable.
136 : */
137 4 : void setRenderClient( const std::string& rc ){ _renderClient = rc; }
138 :
139 : /** @return the name of the render client executable. */
140 0 : const std::string& getRenderClient() const { return _renderClient; }
141 :
142 : /** Set the render client command line options. */
143 4 : void setRenderClientArgs( const Strings& args ){ _renderClientArgs = args; }
144 :
145 : /** @return the render client command line options. */
146 0 : const Strings& getRenderClientArgs() const { return _renderClientArgs; }
147 :
148 : /** Set the prefixes of the environmental variables to pass on clients. */
149 4 : void setRenderClientEnvPrefixes( const Strings& prefixes )
150 4 : { _renderClientEnvPrefixes = prefixes; }
151 :
152 : /** @return prefixes of the environmental variables to pass on clients. */
153 0 : const Strings& getRenderClientEnvPrefixes() const
154 0 : { return _renderClientEnvPrefixes; }
155 :
156 : /**
157 : * Set the working directory for render client.
158 : *
159 : * @param workDir the working directory for the render client.
160 : */
161 4 : void setWorkDir( const std::string& workDir ){ _workDir = workDir; }
162 :
163 : /** @return the working directory for the render client. */
164 0 : const std::string& getWorkDir() const { return _workDir; }
165 :
166 : /** Notify that a node of this config has finished a frame. */
167 : void notifyNodeFrameFinished( const uint32_t frameNumber );
168 :
169 : // Used by Server::releaseConfig() to make sure config is exited
170 : bool exit();
171 :
172 : /** Register the config and all shared object children. */
173 : void register_();
174 :
175 : /** Deregister all shared objects and the config. */
176 : void deregister();
177 :
178 : /** Commit the config for the current frame. */
179 : uint128_t commit();
180 :
181 : virtual void restore();
182 :
183 : EventOCommand sendError( const uint32_t type, const Error& error );
184 :
185 : /** Return the initID, used for late initialization */
186 : uint128_t getInitID(){ return _initID; }
187 :
188 : /** Activate the given canvas after it is complete (dest channels). */
189 : virtual void activateCanvas( Canvas* canvas );
190 :
191 : /** Initialize the given canvas in a running configuration */
192 : virtual void updateCanvas( Canvas* canvas );
193 :
194 : /** Request a finish of outstanding frames on next frame */
195 4 : void postNeedsFinish() { _needsFinish = true; }
196 :
197 : /** @internal @return the last finished frame */
198 4 : uint32_t getFinishedFrame() const { return _finishedFrame.get(); }
199 :
200 : /** @internal */
201 : virtual VisitorResult _acceptCompounds( ConfigVisitor& visitor );
202 : /** @internal */
203 : virtual VisitorResult _acceptCompounds( ConfigVisitor& visitor ) const;
204 :
205 : void output( std::ostream& os ) const; //!< @internal
206 0 : virtual bool mapViewObjects() const { return true; } //!< @internal
207 6 : virtual bool mapNodeObjects() const { return true; } //!< @internal
208 :
209 : protected:
210 : /** @internal */
211 : virtual void attach( const uint128_t& id, const uint32_t instanceID );
212 :
213 : /** @internal Execute the slave remove request. */
214 : virtual void removeChild( const uint128_t& id );
215 :
216 : private:
217 : Config( const Config& from );
218 :
219 : /** The initID for late initialization. */
220 : uint128_t _initID;
221 :
222 : /** The list of compounds. */
223 : Compounds _compounds;
224 :
225 : /** Auto-configured server connections. */
226 : co::Connections _connections;
227 :
228 : /** The name of the render client executable. */
229 : std::string _renderClient;
230 :
231 : /** The render client command line options. */
232 : Strings _renderClientArgs;
233 :
234 : /** The prefixes of environmental variables to pass on to render clients. */
235 : Strings _renderClientEnvPrefixes;
236 :
237 : /** The working directory of the render client. */
238 : std::string _workDir;
239 :
240 : /** The last started frame, or 0. */
241 : uint32_t _currentFrame;
242 :
243 : /** The eternal frame commit counter, starting at 1 (#66). */
244 : uint32_t _incarnation;
245 :
246 : /** The last finished frame, or 0. */
247 : lunchbox::Monitor< uint32_t > _finishedFrame;
248 :
249 : State _state;
250 :
251 : bool _needsFinish; //!< true after runtime changes
252 :
253 : int64_t _lastCheck;
254 :
255 : struct Private;
256 : Private* _private; // placeholder for binary-compatible changes
257 :
258 : /**
259 : * @name Operations
260 : */
261 : //@{
262 : /** @return true on success, false on error */
263 : bool _updateRunning( const bool canFail );
264 :
265 : void _updateCanvases();
266 : bool _connectNodes();
267 : bool _connectNode( Node* node );
268 : bool _syncConnectNode( Node* node, const lunchbox::Clock& clock );
269 : void _startNodes();
270 : lunchbox::Request< void > _createConfig( Node* node );
271 : bool _updateNodes( const bool canFail );
272 : void _stopNodes();
273 : template< class T >
274 : void _deleteEntities( const std::vector< T* >& entities );
275 : void _syncClock();
276 : void _verifyFrameFinished( const uint32_t frameNumber );
277 : bool _init( const uint128_t& initID );
278 :
279 : void _startFrame( const uint128_t& frameID );
280 : void _flushAllFrames();
281 : //@}
282 :
283 : virtual Observer* createObserver();
284 : virtual void releaseObserver( Observer* observer );
285 : virtual Layout* createLayout();
286 : virtual void releaseLayout( Layout* layout );
287 : virtual Canvas* createCanvas();
288 : virtual void releaseCanvas( Canvas* canvas );
289 :
290 : /** @internal Post deletion for the given child, returns true if found*/
291 : template< class T > bool _postDelete( const uint128_t& id );
292 :
293 : /** The command functions. */
294 : bool _cmdInit( co::ICommand& command );
295 : bool _cmdExit( co::ICommand& command );
296 : bool _cmdUpdate( co::ICommand& command );
297 : bool _cmdStartFrame( co::ICommand& command );
298 : bool _cmdStopFrames( co::ICommand& command );
299 : bool _cmdFinishAllFrames( co::ICommand& command );
300 : bool _cmdCreateReply( co::ICommand& command );
301 : bool _cmdFreezeLoadBalancing( co::ICommand& command );
302 : bool _cmdCheckFrame( co::ICommand& command );
303 :
304 850 : LB_TS_VAR( _cmdThread );
305 850 : LB_TS_VAR( _mainThread );
306 : };
307 : }
308 : }
309 : #endif // EQSERVER_CONFIG_H
|