Line data Source code
1 :
2 : /* Copyright (c) 2010-2014, Stefan Eilemann <eile@eyescale.ch>
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 EQFABRIC_NODE_H
20 : #define EQFABRIC_NODE_H
21 :
22 : #include <eq/fabric/object.h> // base class
23 : #include <eq/fabric/types.h>
24 :
25 : namespace eq
26 : {
27 : namespace fabric
28 : {
29 : /** Base data transport class for nodes. @sa eq::Node */
30 : template< class C, class N, class P, class V > class Node : public Object
31 : {
32 : public:
33 : /** A vector of pointers to pipes. @version 1.0 */
34 : typedef std::vector< P* > Pipes;
35 :
36 : /** @name Data Access */
37 : //@{
38 : /** @return the config of this node. @version 1.0 */
39 2360 : C* getConfig() { return _config; }
40 :
41 : /** @return the config of this node. @version 1.0 */
42 132 : const C* getConfig() const { return _config; }
43 :
44 : /** @return the vector of child pipes. @version 1.0 */
45 12497 : const Pipes& getPipes() const { return _pipes; }
46 :
47 : /**
48 : * @internal
49 : * @return true if all render tasks for this node are executed by the
50 : * application process, false otherwise.
51 : */
52 568 : bool isApplicationNode() const { return _isAppNode; }
53 :
54 : /** @internal */
55 : EQFABRIC_INL void setApplicationNode( const bool isAppNode );
56 :
57 : /** @internal @return the index path to this node. */
58 : EQFABRIC_INL NodePath getPath() const;
59 : P* findPipe( const uint128_t& id ); //!< @internal
60 :
61 : /**
62 : * Perform a depth-first traversal of this node.
63 : *
64 : * @param visitor the visitor.
65 : * @return the result of the visitor traversal.
66 : * @version 1.0
67 : */
68 : EQFABRIC_INL VisitorResult accept( V& visitor );
69 :
70 : /** Const-version of accept(). @version 1.0 */
71 : EQFABRIC_INL VisitorResult accept( V& visitor ) const;
72 : //@}
73 :
74 : /** @name Attributes */
75 : //@{
76 : // Note: also update string array initialization in node.ipp
77 : /** Integer attributes. */
78 : enum IAttribute
79 : {
80 : /** <a href="http://www.equalizergraphics.com/documents/design/threads.html#sync">Threading model</a> */
81 : IATTR_THREAD_MODEL,
82 : IATTR_LAUNCH_TIMEOUT, //!< Timeout when auto-launching the node
83 : IATTR_HINT_AFFINITY,
84 : IATTR_LAST,
85 : IATTR_ALL = IATTR_LAST + 5
86 : };
87 :
88 : /** @internal Set a node integer attribute. */
89 : EQFABRIC_INL void setIAttribute( const IAttribute attr,
90 : const int32_t value );
91 :
92 : /** @return the value of a node integer attribute. @version 1.0 */
93 : EQFABRIC_INL int32_t getIAttribute( const IAttribute attr ) const;
94 :
95 : /** @internal @return the name of a node integer attribute. */
96 : static const std::string& getIAttributeString( const IAttribute attr );
97 : //@}
98 :
99 : /** @internal */
100 : //@{
101 : EQFABRIC_INL virtual void backup(); //!< @internal
102 : EQFABRIC_INL virtual void restore(); //!< @internal
103 : void create( P** pipe ); //!< @internal
104 : void release( P* pipe ); //!< @internal
105 0 : virtual void output( std::ostream& ) const {} //!< @internal
106 : EQFABRIC_INL virtual uint128_t commit( const uint32_t incarnation =
107 : CO_COMMIT_NEXT );
108 : //@}
109 :
110 : protected:
111 : /** @internal Construct a new node. */
112 : Node( C* parent );
113 : /** @internal Destruct the node. */
114 : EQFABRIC_INL virtual ~Node();
115 :
116 : /** @internal */
117 : EQFABRIC_INL virtual void serialize( co::DataOStream& os,
118 : const uint64_t dirtyBits );
119 : /** @internal */
120 : EQFABRIC_INL virtual void deserialize( co::DataIStream& is,
121 : const uint64_t dirtyBits );
122 :
123 : EQFABRIC_INL virtual void notifyDetach(); //!< @internal
124 :
125 : /** @sa Serializable::setDirty() @internal */
126 : EQFABRIC_INL virtual void setDirty( const uint64_t bits );
127 :
128 : /** @internal */
129 23 : virtual ChangeType getChangeType() const { return UNBUFFERED; }
130 :
131 : enum DirtyBits
132 : {
133 : DIRTY_ATTRIBUTES = Object::DIRTY_CUSTOM << 0,
134 : DIRTY_PIPES = Object::DIRTY_CUSTOM << 1,
135 : DIRTY_MEMBER = Object::DIRTY_CUSTOM << 2,
136 : DIRTY_NODE_BITS =
137 : DIRTY_ATTRIBUTES | DIRTY_PIPES | DIRTY_MEMBER |
138 : DIRTY_OBJECT_BITS
139 : };
140 :
141 : /** @internal @return the bits to be re-committed by the master. */
142 8 : virtual uint64_t getRedistributableBits() const
143 8 : { return DIRTY_NODE_BITS; }
144 :
145 : private:
146 : /** Pipe children. */
147 : Pipes _pipes;
148 :
149 : /** The parent config. */
150 : C* const _config;
151 :
152 : struct BackupData
153 : {
154 : BackupData();
155 : /** Integer attributes. */
156 : int32_t iAttributes[IATTR_ALL];
157 : }
158 : _data, _backup;
159 :
160 : bool _isAppNode; //!< execute render tasks in application process
161 :
162 : template< class, class, class, class > friend class Pipe;
163 : void _addPipe( P* pipe );
164 : bool _removePipe( P* pipe );
165 :
166 : /** @internal */
167 176 : bool _mapNodeObjects() { return _config->mapNodeObjects(); }
168 : };
169 :
170 : template< class C, class N, class P, class V > EQFABRIC_INL
171 : std::ostream& operator << ( std::ostream&, const Node< C, N, P, V >& );
172 : }
173 : }
174 :
175 : #endif // EQFABRIC_NODE_H
|