Line data Source code
1 :
2 : /* Copyright (c) 2005-2015, Stefan Eilemann <eile@equalizergraphics.com>
3 : * Cedric Stalder <cedric Stalder@gmail.com>
4 : * Daniel Nachbaur <danielnachbaur@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 EQFABRIC_CONFIG_H
21 : #define EQFABRIC_CONFIG_H
22 :
23 : #include <eq/fabric/api.h>
24 : #include <eq/fabric/object.h> // DIRTY_CUSTOM enum
25 : #include <eq/fabric/types.h> // typedefs
26 :
27 : namespace eq
28 : {
29 : namespace fabric
30 : {
31 : /** Base data class for a configuration. @sa eq::Config */
32 : template <class S, class C, class O, class L, class CV, class N, class V>
33 : // cppcheck-suppress noConstructor
34 : class Config : public Object
35 : {
36 : public:
37 : typedef std::vector<O*> Observers; //!< A vector of observers
38 : typedef std::vector<L*> Layouts; //!< A vector of layouts
39 : typedef std::vector<CV*> Canvases; //!< A vector of canvases
40 : typedef std::vector<N*> Nodes; //!< A vector of nodes
41 :
42 : /** @name Data Access */
43 : //@{
44 : /** @return the local server proxy. @version 1.0 */
45 : EQFABRIC_INL lunchbox::RefPtr<S> getServer();
46 :
47 : /** @return the local server proxy. @version 1.0 */
48 : EQFABRIC_INL lunchbox::RefPtr<const S> getServer() const;
49 :
50 : /** @return the vector of observers, app-node only. @version 1.0 */
51 6042 : const Observers& getObservers() const { return _observers; }
52 : /** @return the vector of layouts, app-node only. @version 1.0 */
53 6025 : const Layouts& getLayouts() const { return _layouts; }
54 : /** @return the vector of canvases, app-node only. @version 1.0 */
55 5729 : const Canvases& getCanvases() const { return _canvases; }
56 :
57 : /**
58 : * @internal
59 : * @return the timeout in ms or LB_TIMEOUT_INDEFINITE for failures.
60 : */
61 : EQFABRIC_INL uint32_t getTimeout() const;
62 :
63 : /**
64 : * @return the vector of nodes instantiated in this process.
65 : * @version 1.0
66 : */
67 11668 : const Nodes& getNodes() const { return _nodes; }
68 : EQFABRIC_INL N* findAppNode(); //!< @internal
69 : EQFABRIC_INL const N* findAppNode() const; //!< @internal
70 :
71 : /**
72 : * Perform a depth-first traversal of this config.
73 : *
74 : * @param visitor the visitor.
75 : * @return the result of the visitor traversal.
76 : * @version 1.0
77 : */
78 : EQFABRIC_INL VisitorResult accept(V& visitor);
79 :
80 : /** Const-version of accept(). @version 1.0 */
81 : EQFABRIC_INL VisitorResult accept(V& visitor) const;
82 :
83 : /** @return the entity of the given identifier, or 0. @version 1.0 */
84 : template <typename T>
85 : EQFABRIC_INL T* find(const uint128_t& id);
86 :
87 : /** @return the entity of the given identifier, or 0. @version 1.0 */
88 : template <typename T>
89 : EQFABRIC_INL const T* find(const uint128_t& id) const;
90 :
91 : /** @return the first entity of the given name, or 0. @version 1.0 */
92 : template <typename T>
93 : EQFABRIC_INL T* find(const std::string& name);
94 :
95 : /** @return the first entity of the given name, or 0. @version 1.0 */
96 : template <typename T>
97 : EQFABRIC_INL const T* find(const std::string& name) const;
98 :
99 : /** @internal @return the observer at the given path. */
100 : O* getObserver(const ObserverPath& path);
101 :
102 : /** @internal @return the layout at the given path. */
103 : L* getLayout(const LayoutPath& path);
104 :
105 : /** @internal @return the canvas at the given path. */
106 : CV* getCanvas(const CanvasPath& path);
107 :
108 : /** @internal */
109 : template <typename T>
110 : void find(const uint128_t& id, T** result);
111 :
112 : /** @internal */
113 : template <typename T>
114 : void find(const std::string& name, const T** result) const;
115 :
116 : /** @internal Update or init the given canvas in a running config. */
117 1 : virtual void updateCanvas(CV*) { /* NOP */}
118 :
119 : /** @internal Init the given canvas in a running config. */
120 0 : virtual void exitCanvas(CV*) { /* NOP */}
121 : //@}
122 :
123 : /** @name Attributes */
124 : //@{
125 : // Note: also update string array initialization in config.ipp
126 :
127 : /** Floating-point attributes */
128 : enum FAttribute
129 : {
130 : FATTR_EYE_BASE, //!< The default interocular distance in meters
131 : FATTR_VERSION, //!< The version of the file loaded
132 : FATTR_LAST,
133 : FATTR_ALL = FATTR_LAST + 5
134 : };
135 :
136 : /** Integer attributes. */
137 : enum IAttribute
138 : {
139 : IATTR_ROBUSTNESS, //!< Tolerate resource failures
140 : IATTR_LAST,
141 : IATTR_ALL = IATTR_LAST + 5
142 : };
143 :
144 : /** @internal */
145 3206 : void setFAttribute(const FAttribute attr, const float value)
146 : {
147 3206 : _fAttributes[attr] = value;
148 3206 : }
149 : /** @internal */
150 2626 : void setIAttribute(const IAttribute attr, const int32_t value)
151 : {
152 2626 : _iAttributes[attr] = value;
153 2626 : }
154 :
155 : /** @return the given floating-point attribute. */
156 1013 : float getFAttribute(const FAttribute attr) const
157 : {
158 1013 : return _fAttributes[attr];
159 : }
160 :
161 : /** @return the given integer attribute. */
162 208 : int32_t getIAttribute(const IAttribute attr) const
163 : {
164 208 : return _iAttributes[attr];
165 : }
166 :
167 : /** @internal */
168 : static const std::string& getFAttributeString(const FAttribute attr);
169 : /** @internal */
170 : static const std::string& getIAttributeString(const IAttribute attr);
171 : //@}
172 :
173 : /** @name Operations */
174 : //@{
175 : /**
176 : * Set the maximum accepted latency for this config.
177 : *
178 : * The latency is defined as the maximum number of frames between the
179 : * start of a frame and the finish of the last rendering task for that
180 : * frame. Setting the latency of a running config finishes all pending
181 : * frames.
182 : *
183 : * @param latency the latency.
184 : * @version 1.0
185 : */
186 : virtual void setLatency(const uint32_t latency);
187 :
188 : /** @return the latency of this config. @version 1.0 */
189 405 : uint32_t getLatency() const { return _data.latency; }
190 : /** @internal Restore the last backup. */
191 : EQFABRIC_INL virtual void restore();
192 : //@}
193 :
194 0 : virtual void output(std::ostream&) const {} //!< @internal
195 : void create(O** observer); //!< @internal
196 : void release(O* observer); //!< @internal
197 : void create(L** layout); //!< @internal
198 : void release(L* layout); //!< @internal
199 : void create(CV** canvas); //!< @internal
200 : void release(CV* canvas); //!< @internal
201 : void create(N** node); //!< @internal
202 : void release(N* node); //!< @internal
203 :
204 : protected:
205 : /** @internal Construct a new config. */
206 : EQFABRIC_INL explicit Config(lunchbox::RefPtr<S> parent);
207 :
208 : /** @internal Destruct a config. */
209 : EQFABRIC_INL virtual ~Config();
210 :
211 : /** @internal */
212 : EQFABRIC_INL virtual void attach(const uint128_t& id,
213 : const uint32_t instanceID);
214 :
215 : /** @internal */
216 : EQFABRIC_INL virtual void serialize(co::DataOStream& os,
217 : const uint64_t dirtyBits);
218 : EQFABRIC_INL virtual void deserialize(co::DataIStream& is,
219 : const uint64_t dirtyBits);
220 : EQFABRIC_INL virtual void notifyDetach();
221 :
222 : /** @internal Execute the slave remove request. */
223 0 : virtual void _removeChild(const uint128_t&) { LBUNIMPLEMENTED; }
224 : template <class, class, class, class, class, class>
225 : friend class Server;
226 :
227 : void setAppNodeID(const co::NodeID& nodeID); //!< @internal
228 : /** @internal */
229 33 : const co::NodeID& getAppNodeID() const { return _appNodeID; }
230 : /** @internal */
231 : EQFABRIC_INL EventOCommand sendError(co::NodePtr node, const uint32_t event,
232 : const Error& error);
233 :
234 0 : virtual void changeLatency(const uint32_t) { /* NOP */} //!< @internal
235 0 : virtual bool mapViewObjects() const { return false; } //!< @internal
236 18 : virtual bool mapNodeObjects() const { return false; } //!< @internal
237 : /** @internal */
238 795 : virtual VisitorResult _acceptCompounds(V&) { return TRAVERSE_CONTINUE; }
239 : /** @internal */
240 0 : virtual VisitorResult _acceptCompounds(V&) const
241 : {
242 0 : return TRAVERSE_CONTINUE;
243 : }
244 : template <class C2, class V2>
245 : friend VisitorResult _acceptImpl(C2*, V2&);
246 :
247 : N* _findNode(const uint128_t& id); //!< @internal
248 :
249 : /** @internal */
250 : EQFABRIC_INL virtual uint128_t commit(
251 : const uint32_t incarnation = CO_COMMIT_NEXT);
252 : //@}
253 :
254 : private:
255 : /** The parent server. */
256 : lunchbox::RefPtr<S> _server;
257 :
258 : /** Float attributes. */
259 : float _fAttributes[FATTR_ALL];
260 :
261 : /** Integer attributes. */
262 : int32_t _iAttributes[IATTR_ALL];
263 :
264 : /** The list of observers. */
265 : Observers _observers;
266 :
267 : /** The list of layouts. */
268 : Layouts _layouts;
269 :
270 : /** The list of canvases. */
271 : Canvases _canvases;
272 :
273 : /** The list of nodes. */
274 : Nodes _nodes;
275 :
276 : /** The node identifier of the node running the application thread. */
277 : co::NodeID _appNodeID;
278 :
279 : struct BackupData
280 : {
281 810 : BackupData()
282 810 : : latency(1)
283 : {
284 810 : }
285 :
286 : /** The latency between frame start and end frame, in frames. */
287 : uint32_t latency;
288 : } _data, _backup;
289 :
290 : struct Private;
291 : Private* _private; // placeholder for binary-compatible changes
292 :
293 : enum DirtyBits
294 : {
295 : DIRTY_MEMBER = Object::DIRTY_CUSTOM << 0,
296 : DIRTY_LATENCY = Object::DIRTY_CUSTOM << 1,
297 : DIRTY_ATTRIBUTES = Object::DIRTY_CUSTOM << 2,
298 : DIRTY_NODES = Object::DIRTY_CUSTOM << 3,
299 : DIRTY_OBSERVERS = Object::DIRTY_CUSTOM << 4,
300 : DIRTY_LAYOUTS = Object::DIRTY_CUSTOM << 5,
301 : DIRTY_CANVASES = Object::DIRTY_CUSTOM << 6,
302 : DIRTY_CONFIG_BITS = DIRTY_MEMBER | DIRTY_ATTRIBUTES | DIRTY_OBSERVERS |
303 : DIRTY_LAYOUTS | DIRTY_CANVASES | DIRTY_NODES |
304 : DIRTY_LATENCY
305 : };
306 :
307 : /** @internal @return the bits to be re-committed by the master. */
308 4 : virtual uint64_t getRedistributableBits() const
309 : {
310 4 : return DIRTY_CONFIG_BITS;
311 : }
312 :
313 : template <class, class>
314 : friend class Observer;
315 : void _addObserver(O* observer);
316 : bool _removeObserver(O* observer);
317 :
318 : template <class, class, class>
319 : friend class Layout;
320 : void _addLayout(L* layout);
321 : bool _removeLayout(L* layout);
322 :
323 : template <class, class, class, class>
324 : friend class Canvas;
325 : void _addCanvas(CV* canvas);
326 : bool _removeCanvas(CV* canvas);
327 :
328 : template <class, class, class, class>
329 : friend class Node;
330 : void _addNode(N* node);
331 : EQFABRIC_INL bool _removeNode(N* node);
332 :
333 : typedef co::CommandFunc<Config<S, C, O, L, CV, N, V>> CmdFunc;
334 : bool _cmdNewLayout(co::ICommand& command);
335 : bool _cmdNewCanvas(co::ICommand& command);
336 : bool _cmdNewObserver(co::ICommand& command);
337 : bool _cmdNewEntityReply(co::ICommand& command);
338 : };
339 :
340 : template <class S, class C, class O, class L, class CV, class N, class V>
341 : EQFABRIC_INL std::ostream& operator<<(
342 : std::ostream& os, const Config<S, C, O, L, CV, N, V>& config);
343 : }
344 : }
345 : #endif // EQFABRIC_CONFIG_H
|