Equalizer  1.6.1
object.h
1 
2 /* Copyright (c) 2009-2012, 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 {
39  class Object : public co::Serializable
40  {
41  public:
45  EQFABRIC_API void setName( const std::string& name );
46 
48  EQFABRIC_API const std::string& getName() const;
49 
59  EQFABRIC_API void setUserData( co::Object* userData );
60 
62  co::Object* getUserData() { return _userData; }
63 
65  const co::Object* getUserData() const { return _userData; }
67 
79  EQFABRIC_API void setError( const int32_t error );
80 
82  eq::fabric::Error getError() const { return _error; }
84 
96  uint32_t getTasks() const { return _tasks; }
97 
98  uint32_t getSerial() const { return _serial; }
99 
100 
102  EQFABRIC_API virtual bool isDirty() const;
103 
105  EQFABRIC_API virtual uint128_t commit( const uint32_t incarnation =
106  CO_COMMIT_NEXT );
107 
109  EQFABRIC_API virtual void backup();
110 
112  EQFABRIC_API virtual void restore();
113 
120  {
121  DIRTY_NAME = Serializable::DIRTY_CUSTOM << 0, // 1
122  DIRTY_USERDATA = Serializable::DIRTY_CUSTOM << 1, // 2
123  DIRTY_ERROR = Serializable::DIRTY_CUSTOM << 2, // 4
124  DIRTY_TASKS = Serializable::DIRTY_CUSTOM << 3, // 8
125  DIRTY_REMOVED = Serializable::DIRTY_CUSTOM << 4, // 16
126  DIRTY_SERIAL = Serializable::DIRTY_CUSTOM << 5, // 32
127  // Leave room for binary-compatible patches
128  DIRTY_CUSTOM = Serializable::DIRTY_CUSTOM << 6, // 64
129  DIRTY_OBJECT_BITS = DIRTY_NAME | DIRTY_USERDATA | DIRTY_ERROR
130  };
131 
132  protected:
134  EQFABRIC_API Object();
135 
137  EQFABRIC_API virtual ~Object();
138 
143  virtual bool hasMasterUserData() { return false; }
144 
146  virtual uint32_t getUserDataLatency() const { return 0; }
147 
149  EQFABRIC_API void setTasks( const uint32_t tasks );
150 
151  EQFABRIC_API virtual void notifyDetach();
152 
153  EQFABRIC_API virtual void serialize( co::DataOStream& os,
154  const uint64_t dirtyBits );
155  EQFABRIC_API virtual void deserialize( co::DataIStream& is,
156  const uint64_t dirtyBits );
157 
159  virtual uint64_t getRedistributableBits() const
160  { return DIRTY_OBJECT_BITS; }
161 
167  EQFABRIC_API void postRemove( Object* child );
168 
170  virtual void removeChild( const UUID& ) { LBUNIMPLEMENTED; }
171 
173  template< class C, class S >
174  void commitChild( C* child, S* sender, uint32_t cmd,
175  const uint32_t incarnation );
176 
178  template< class C > inline
179  void commitChild( C* child, const uint32_t incarnation )
180  {
181  LBASSERT( child->isAttached( ));
182  child->commit( incarnation );
183  }
184 
186  template< class C, class S >
187  void commitChildren( const std::vector< C* >& children, S* sender,
188  uint32_t cmd, const uint32_t incarnation );
189 
191  template< class C >
192  void commitChildren( const std::vector< C* >& children, uint32_t cmd,
193  const uint32_t incarnation )
194  { commitChildren< C, Object >( children, this, cmd, incarnation ); }
195 
197  template< class C >
198  void commitChildren( const std::vector< C* >& children,
199  const uint32_t incarnation );
200 
202  template< class C >
203  void syncChildren( const std::vector< C* >& children );
204 
206  template< class P, class C >
207  inline void releaseChildren( const std::vector< C* >& children );
208 
210  EQFABRIC_API bool _cmdSync( co::ICommand& command );
211 
212  private:
213  struct BackupData
214  {
216  std::string name;
217 
219  co::ObjectVersion userData;
220  }
221  _data, _backup;
222 
224  co::Object* _userData;
225 
227  uint32_t _tasks;
228 
230  eq::fabric::Error _error;
231 
233  uint32_t _serial;
234 
236  std::vector< UUID > _removedChildren;
237 
238  struct Private;
239  Private* _private; // placeholder for binary-compatible changes
240  };
241 
242  // Template Implementation
243  template< class C, class S > inline void
244  Object::commitChild( C* child, S* sender, uint32_t cmd,
245  const uint32_t incarnation )
246  {
247  if( !child->isAttached( ))
248  {
249  LBASSERT( !isMaster( ));
250  co::LocalNodePtr localNode = child->getConfig()->getLocalNode();
251  const uint32_t requestID = localNode->registerRequest();
252 
253  co::NodePtr node = child->getServer().get();
254  sender->send( node, cmd ) << requestID;
255 
256  uint128_t identifier;
257  localNode->waitRequest( requestID, identifier );
258  LBCHECK( localNode->mapObject( child,identifier,co::VERSION_NONE ));
259  }
260  child->commit( incarnation );
261  }
262 
263  template< class C, class S > inline void
264  Object::commitChildren( const std::vector< C* >& children, S* sender,
265  uint32_t cmd, const uint32_t incarnation )
266  {
267  // TODO Opt: async register and commit
268  for( typename std::vector< C* >::const_iterator i = children.begin();
269  i != children.end(); ++i )
270  {
271  C* child = *i;
272  commitChild< C, S >( child, sender, cmd, incarnation );
273  }
274  }
275 
276  template< class C >
277  inline void Object::commitChildren( const std::vector< C* >& children,
278  const uint32_t incarnation )
279  {
280  // TODO Opt: async commit
281  for( typename std::vector< C* >::const_iterator i = children.begin();
282  i != children.end(); ++i )
283  {
284  C* child = *i;
285  LBASSERT( child->isAttached( ));
286  child->commit( incarnation );
287  }
288  }
289 
290  template< class C >
291  inline void Object::syncChildren( const std::vector< C* >& children )
292  {
293  for( typename std::vector< C* >::const_iterator i = children.begin();
294  i != children.end(); ++i )
295  {
296  C* child = *i;
297  LBASSERT( child->isMaster( )); // slaves are synced using version
298  child->sync();
299  }
300  }
301 
302  template< class P, class C >
303  inline void Object::releaseChildren( const std::vector< C* >& children )
304  {
305  for( size_t i = children.size(); i > 0; --i )
306  {
307  C* child = children[ i - 1 ];
308 
309  if( child->isAttached( ))
310  {
311  getLocalNode()->releaseObject( child );
312  if( !isMaster( ))
313  {
314  static_cast< P* >( this )->_removeChild( child );
315  static_cast< P* >( this )->release( child );
316  }
317  }
318  else
319  {
320  LBASSERT( isMaster( ));
321  }
322  }
323  }
324 }
325 }
326 #endif // EQFABRIC_OBJECT_H
Internal base class for all distributed, inheritable Equalizer objects.
Definition: object.h:39
uint32_t getTasks() const
Return the set of tasks this channel might execute in the worst case.
Definition: object.h:96
eq::fabric::Error getError() const
Definition: object.h:82
void setName(const std::string &name)
Set the name of the object.
Error
Defines errors produced by Equalizer classes.
virtual uint32_t getUserDataLatency() const
Definition: object.h:146
virtual ~Object()
Destruct the object.
virtual bool isDirty() const
virtual bool hasMasterUserData()
Definition: object.h:143
const co::Object * getUserData() const
Definition: object.h:65
co::Object * getUserData()
Definition: object.h:62
DirtyBits
The changed parts of the object since the last pack().
Definition: object.h:119
void setError(const int32_t error)
Set an error code why the last operation failed.
const std::string & getName() const
Object()
Construct a new Object.
void setUserData(co::Object *userData)
Set user-specific data.