Line data Source code
1 :
2 : /* Copyright (c) 2005-2013, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 2010, Cedric Stalder<cedric.stalder@gmail.com>
4 : *
5 : * This library is free software; you can redistribute it and/or modify it under
6 : * the terms of the GNU Lesser General Public License version 2.1 as published
7 : * by the Free Software Foundation .
8 : *
9 : * This library is distributed in the hope that it will be useful, but WITHOUT
10 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 : * details.
13 : *
14 : * You should have received a copy of the GNU Lesser General Public License
15 : * along with this library; if not, write to the Free Software Foundation, Inc.,
16 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 : */
18 :
19 : #ifndef EQ_NODE_H
20 : #define EQ_NODE_H
21 :
22 : #include <eq/client/api.h>
23 : #include <eq/client/types.h>
24 : #include <eq/client/visitorResult.h> // enum
25 : #include <eq/fabric/node.h> // base class
26 :
27 : #include <co/types.h>
28 :
29 : namespace eq
30 : {
31 : namespace detail { class Node; }
32 :
33 : /**
34 : * A Node represents a single computer in the cluster.
35 : *
36 : * Each node is executed in a separate process. Each process has only its local
37 : * node instantiated, that is, it has at most instance of a Node and does not
38 : * see other node instances. The application process may not have a node, which
39 : * is the case when it does not contribute to the rendering.
40 : *
41 : * The eq::Node is not to be confused with the co::Node which represents the
42 : * process in the underlying peer-to-peer network layer. The eq::Client and
43 : * eq::Server are co::Nodes representing the local client and Equalizer server,
44 : * respectively.
45 : *
46 : * @sa fabric::Node
47 : */
48 : class Node : public fabric::Node< Config, Node, Pipe, NodeVisitor >
49 : {
50 : public:
51 : /** Construct a new node. @version 1.0 */
52 : EQ_API Node( Config* parent );
53 :
54 : /** Destruct the node. @version 1.0 */
55 : EQ_API virtual ~Node();
56 :
57 : /** @return the parent client node. @version 1.0 */
58 : EQ_API ClientPtr getClient();
59 :
60 : /** @return the parent server node. @version 1.0 */
61 : EQ_API ServerPtr getServer();
62 :
63 : EQ_API co::CommandQueue* getMainThreadQueue(); //!< @internal
64 : EQ_API co::CommandQueue* getCommandThreadQueue(); //!< @internal
65 : co::CommandQueue* getTransmitterQueue(); //!< @internal
66 :
67 : /** @internal node thread only. */
68 : uint32_t getCurrentFrame() const;
69 :
70 : /**
71 : * @internal
72 : * Get a network barrier.
73 : *
74 : * @param barrier the barrier identifier and version.
75 : * @return the barrier.
76 : */
77 : co::Barrier* getBarrier( const co::ObjectVersion& barrier );
78 :
79 : /**
80 : * @internal
81 : * Get a frame data instance.
82 : *
83 : * @param frameDataVersion the frame data identifier and version.
84 : * @return the frame.
85 : */
86 : FrameDataPtr getFrameData( const co::ObjectVersion& frameDataVersion );
87 :
88 : /** @internal Release the frame data instance. */
89 : void releaseFrameData( FrameDataPtr data );
90 :
91 : /** @internal Wait for the node to be initialized. */
92 : EQ_API void waitInitialized() const;
93 :
94 : /**
95 : * @return true if this node is running, false otherwise.
96 : * @version 1.0
97 : */
98 : EQ_API bool isRunning() const;
99 :
100 : /**
101 : * @return true if this node is stopped, false otherwise.
102 : * @version 1.0
103 : */
104 : EQ_API bool isStopped() const;
105 :
106 : /**
107 : * Wait for a frame to be started.
108 : *
109 : * Used by the pipe task methods to implement the current thread
110 : * synchronization model.
111 : *
112 : * @param frameNumber the frame number.
113 : * @sa releaseFrame()
114 : * @version 1.0
115 : */
116 : EQ_API void waitFrameStarted( const uint32_t frameNumber ) const;
117 :
118 : /** @internal @return the number of the last finished frame. */
119 : uint32_t getFinishedFrame() const;
120 :
121 : /**
122 : * Send an error event to the application node.
123 : *
124 : * @param error the error code.
125 : * @version 1.7.1
126 : */
127 : EQ_API EventOCommand sendError( const uint32_t error );
128 :
129 : /**
130 : * Process a received event.
131 : *
132 : * The task of this method is to update the node as necessary, and transform
133 : * the event into a config event to be send to the application using
134 : * Config::sendEvent().
135 : *
136 : * @param event the received event.
137 : * @return true when the event was handled, false if not.
138 : * @version 1.5.2
139 : */
140 : EQ_API virtual bool processEvent( const Event& event );
141 :
142 : /** @internal @sa Serializable::setDirty() */
143 : EQ_API virtual void setDirty( const uint64_t bits );
144 :
145 : /** @internal */
146 : EQ_API void dirtyClientExit();
147 :
148 : protected:
149 : /** @internal */
150 : EQ_API virtual void attach( const uint128_t& id, const uint32_t instanceID );
151 :
152 : /** @name Actions */
153 : //@{
154 : /**
155 : * Start a frame by unlocking all child resources.
156 : *
157 : * @param frameNumber the frame to start.
158 : * @version 1.0
159 : */
160 : EQ_API void startFrame( const uint32_t frameNumber );
161 :
162 : /**
163 : * Signal the completion of a frame to the parent.
164 : *
165 : * @param frameNumber the frame to end.
166 : * @version 1.0
167 : */
168 : EQ_API void releaseFrame( const uint32_t frameNumber );
169 :
170 : /**
171 : * Release the local synchronization of the parent for a frame.
172 : *
173 : * @param frameNumber the frame to release.
174 : * @version 1.0
175 : */
176 : EQ_API void releaseFrameLocal( const uint32_t frameNumber );
177 : //@}
178 :
179 : /**
180 : * @name Callbacks
181 : *
182 : * The callbacks are called by Equalizer during rendering to execute
183 : * various actions.
184 : */
185 : //@{
186 :
187 : /**
188 : * Initialize this node.
189 : *
190 : * @param initID the init identifier.
191 : * @version 1.0
192 : */
193 : EQ_API virtual bool configInit( const uint128_t& initID );
194 :
195 : /** Exit this node. @version 1.0 */
196 : EQ_API virtual bool configExit();
197 :
198 : /**
199 : * Start rendering a frame.
200 : *
201 : * Called once at the beginning of each frame, to start the node's frame
202 : * and to do per-frame updates of node-specific data. This method has to
203 : * call startFrame(). Immediately releases local synchronization if the
204 : * thread model is async.
205 : *
206 : * @param frameID the per-frame identifier.
207 : * @param frameNumber the frame to start.
208 : * @sa startFrame(), Config::beginFrame()
209 : * @version 1.0
210 : */
211 : EQ_API virtual void frameStart( const uint128_t& frameID,
212 : const uint32_t frameNumber );
213 :
214 : /**
215 : * Finish rendering a frame.
216 : *
217 : * Called once at the end of each frame, to end the frame and to do
218 : * per-frame updates of node-specific data. This method has to call
219 : * releaseFrame().
220 : *
221 : * @param frameID the per-frame identifier.
222 : * @param frameNumber the frame to finish.
223 : * @sa endFrame(), Config::finishFrame()
224 : * @version 1.0
225 : */
226 : EQ_API virtual void frameFinish( const uint128_t& frameID,
227 : const uint32_t frameNumber );
228 :
229 : /**
230 : * Finish drawing.
231 : *
232 : * Called once per frame after the last draw operation. Waits for the
233 : * pipes to release the local synchonization and releases the node's
234 : * local synchronization if the thread model is draw_sync (the default).
235 : *
236 : * @param frameID the per-frame identifier.
237 : * @param frameNumber the frame finished with draw.
238 : * @sa Pipe::waitFrameLocal(), releaseFrameLocal()
239 : * @version 1.0
240 : */
241 : EQ_API virtual void frameDrawFinish( const uint128_t& frameID,
242 : const uint32_t frameNumber );
243 :
244 : /**
245 : * Finish all rendering tasks.
246 : *
247 : * Called once per frame after all frame tasks. Waits for the pipes to
248 : * release the local synchonization and releases the node's local
249 : * synchronization if the thread model is local_sync.
250 : *
251 : * Note that frameFinish is called after the latency is exhausted and
252 : * synchronizes pipe thread execution.
253 : *
254 : * @param frameID the per-frame identifier.
255 : * @param frameNumber the frame finished with draw.
256 : * @sa Pipe::waitFrameLocal(), releaseFrameLocal()
257 : * @version 1.0
258 : */
259 : EQ_API virtual void frameTasksFinish( const uint128_t& frameID,
260 : const uint32_t frameNumber );
261 : //@}
262 :
263 : private:
264 : detail::Node* const _impl;
265 :
266 : void _setAffinity();
267 :
268 : void _finishFrame( const uint32_t frameNumber ) const;
269 : void _frameFinish( const uint128_t& frameID,
270 : const uint32_t frameNumber );
271 :
272 : void _flushObjects();
273 :
274 : /** The command functions. */
275 : bool _cmdCreatePipe( co::ICommand& command );
276 : bool _cmdDestroyPipe( co::ICommand& command );
277 : bool _cmdConfigInit( co::ICommand& command );
278 : bool _cmdConfigExit( co::ICommand& command );
279 : bool _cmdFrameStart( co::ICommand& command );
280 : bool _cmdFrameFinish( co::ICommand& command );
281 : bool _cmdFrameDrawFinish( co::ICommand& command );
282 : bool _cmdFrameTasksFinish( co::ICommand& command );
283 : bool _cmdFrameDataTransmit( co::ICommand& command );
284 : bool _cmdFrameDataReady( co::ICommand& command );
285 : bool _cmdSetAffinity( co::ICommand& command );
286 :
287 46 : LB_TS_VAR( _nodeThread );
288 : };
289 : }
290 :
291 : #endif // EQ_NODE_H
|