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