Equalizer  1.12.0
Parallel Rendering Framework
object.h
1 
2 /* Copyright (c) 2009-2014, Stefan Eilemann <eile@equalizergraphics.com>
3  * 2012, Daniel Nachbaur <danielnachbaur@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_OBJECT_H
20 #define EQFABRIC_OBJECT_H
21 
22 #include <eq/fabric/api.h>
23 #include <eq/fabric/error.h> // enum
24 #include <eq/fabric/types.h>
25 #include <co/objectOCommand.h> // used inline send()
26 #include <co/objectVersion.h> // member
27 #include <co/serializable.h> // base class
28 
29 namespace eq
30 {
31 namespace fabric
32 {
33 namespace detail { class Object; }
34 
41 class Object : public co::Serializable
42 {
43 public:
47  EQFABRIC_API virtual void setName( const std::string& name );
48 
50  EQFABRIC_API const std::string& getName() const;
51 
61  EQFABRIC_API void setUserData( co::Object* userData );
62 
64  EQFABRIC_API co::Object* getUserData();
65 
67  EQFABRIC_API const co::Object* getUserData() const;
69 
81  EQFABRIC_API uint32_t getTasks() const;
82 
83  EQFABRIC_API uint32_t getSerial() const;
84 
85 
87  EQFABRIC_API virtual bool isDirty() const;
88 
90  EQFABRIC_API virtual uint128_t commit( const uint32_t incarnation =
91  CO_COMMIT_NEXT );
92 
94  EQFABRIC_API virtual void backup();
95 
97  EQFABRIC_API virtual void restore();
98 
105  {
106  DIRTY_NAME = Serializable::DIRTY_CUSTOM << 0, // 1
107  DIRTY_USERDATA = Serializable::DIRTY_CUSTOM << 1, // 2
108  DIRTY_TASKS = Serializable::DIRTY_CUSTOM << 2, // 4
109  DIRTY_REMOVED = Serializable::DIRTY_CUSTOM << 3, // 8
110  DIRTY_SERIAL = Serializable::DIRTY_CUSTOM << 4, // 16
111  // Leave room for binary-compatible patches
112  DIRTY_CUSTOM = Serializable::DIRTY_CUSTOM << 6, // 64
113  DIRTY_OBJECT_BITS = DIRTY_NAME | DIRTY_USERDATA
114  };
115 
116 protected:
118  EQFABRIC_API Object();
119 
121  EQFABRIC_API Object( const Object& );
122 
124  EQFABRIC_API virtual ~Object();
125 
127  EQFABRIC_API Object& operator = ( const Object& from );
128 
133  virtual bool hasMasterUserData() { return false; }
134 
136  virtual uint32_t getUserDataLatency() const { return 0; }
137 
139  EQFABRIC_API void setTasks( const uint32_t tasks );
140 
141  EQFABRIC_API virtual void notifyDetach();
142 
143  EQFABRIC_API virtual void serialize( co::DataOStream& os,
144  const uint64_t dirtyBits );
145  EQFABRIC_API virtual void deserialize( co::DataIStream& is,
146  const uint64_t dirtyBits );
147 
149  virtual uint64_t getRedistributableBits() const
150  { return DIRTY_OBJECT_BITS; }
151 
157  EQFABRIC_API void postRemove( Object* child );
158 
160  virtual void removeChild( const uint128_t& ) { LBUNIMPLEMENTED; }
161 
163  template< class C, class S >
164  void commitChild( C* child, S* sender, uint32_t cmd,
165  const uint32_t incarnation );
166 
168  template< class C > inline
169  void commitChild( C* child, const uint32_t incarnation )
170  {
171  LBASSERT( child->isAttached( ));
172  child->commit( incarnation );
173  }
174 
176  template< class C, class S >
177  void commitChildren( const std::vector< C* >& children, S* sender,
178  uint32_t cmd, const uint32_t incarnation );
179 
181  template< class C >
182  void commitChildren( const std::vector< C* >& children, uint32_t cmd,
183  const uint32_t incarnation )
184  { commitChildren< C, Object >( children, this, cmd, incarnation ); }
185 
187  template< class C >
188  void commitChildren( const std::vector< C* >& children,
189  const uint32_t incarnation );
190 
192  template< class C >
193  void syncChildren( const std::vector< C* >& children );
194 
196  template< class P, class C >
197  inline void releaseChildren( const std::vector< C* >& children );
198 
200  EQFABRIC_API bool _cmdSync( co::ICommand& command );
201 
202 private:
203  detail::Object* const _impl;
204 };
205 
206 // Template Implementation
207 template< class C, class S > inline void
208 Object::commitChild( C* child, S* sender, uint32_t cmd,
209  const uint32_t incarnation )
210 {
211  if( !child->isAttached( ))
212  {
213  LBASSERT( !isMaster( ));
214  co::LocalNodePtr localNode = child->getConfig()->getLocalNode();
215  lunchbox::Request< uint128_t > request =
216  localNode->registerRequest< uint128_t >();
217  co::NodePtr node = child->getServer().get();
218  sender->send( node, cmd ) << request;
219 
220  LBCHECK( localNode->mapObject( child, request.wait(),
221  co::VERSION_NONE ));
222  }
223  child->commit( incarnation );
224 }
225 
226 template< class C, class S > inline void
227 Object::commitChildren( const std::vector< C* >& children, S* sender,
228  uint32_t cmd, const uint32_t incarnation )
229 {
230  // TODO Opt: async register and commit
231  for( typename std::vector< C* >::const_iterator i = children.begin();
232  i != children.end(); ++i )
233  {
234  C* child = *i;
235  commitChild< C, S >( child, sender, cmd, incarnation );
236  }
237 }
238 
239 template< class C >
240 inline void Object::commitChildren( const std::vector< C* >& children,
241  const uint32_t incarnation )
242 {
243  // TODO Opt: async commit
244  for( typename std::vector< C* >::const_iterator i = children.begin();
245  i != children.end(); ++i )
246  {
247  C* child = *i;
248  LBASSERT( child->isAttached( ));
249  child->commit( incarnation );
250  }
251 }
252 
253 template< class C >
254 inline void Object::syncChildren( const std::vector< C* >& children )
255 {
256  for( typename std::vector< C* >::const_iterator i = children.begin();
257  i != children.end(); ++i )
258  {
259  C* child = *i;
260  LBASSERT( child->isMaster( )); // slaves are synced using version
261  child->sync();
262  }
263 }
264 
265 template< class P, class C >
266 inline void Object::releaseChildren( const std::vector< C* >& children )
267 {
268  for( size_t i = children.size(); i > 0; --i )
269  {
270  C* child = children[ i - 1 ];
271 
272  if( child->isAttached( ))
273  {
274  getLocalNode()->releaseObject( child );
275  if( !isMaster( ))
276  {
277  static_cast< P* >( this )->_removeChild( child );
278  static_cast< P* >( this )->release( child );
279  }
280  }
281  else
282  {
283  LBASSERT( isMaster( ));
284  }
285  }
286 }
287 }
288 }
289 #endif // EQFABRIC_OBJECT_H
Defines export visibility macros for library EqualizerFabric.
EQFABRIC_API Object & operator=(const Object &from)
NOP assignment operator.
virtual uint32_t getUserDataLatency() const
Definition: object.h:136
DirtyBits
The changed parts of the object since the last pack().
Definition: object.h:104
EQFABRIC_API void setUserData(co::Object *userData)
Set user-specific data.
EQFABRIC_API const std::string & getName() const
virtual EQFABRIC_API ~Object()
Destruct the object.
virtual EQFABRIC_API void setName(const std::string &name)
Set the name of the object.
EQFABRIC_API uint32_t getTasks() const
Return the set of tasks this channel might execute in the worst case.
The Equalizer client library.
Definition: eq/agl/types.h:23
EQFABRIC_API co::Object * getUserData()
virtual EQFABRIC_API bool isDirty() const
Internal base class for all distributed, inheritable Equalizer objects.
Definition: object.h:41
EQFABRIC_API Object()
Construct a new Object.
virtual bool hasMasterUserData()
Definition: object.h:133