Equalizer  2.0.0
Parallel Rendering Framework
object.h
1 
2 /* Copyright (c) 2009-2016, Stefan Eilemann <eile@equalizergraphics.com>
3  * 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 bool isDirty() const override;
88 
90  EQFABRIC_API uint128_t commit( const uint32_t incarnation =
91  CO_COMMIT_NEXT ) override;
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 void notifyDetach() override;
142 
143  EQFABRIC_API void serialize( co::DataOStream& os,
144  const uint64_t dirtyBits ) override;
145  EQFABRIC_API void deserialize( co::DataIStream& is,
146  const uint64_t dirtyBits ) override;
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  EQFABRIC_API void updateEvent( Event& event, int64_t time );
203 
204 private:
205  detail::Object* const _impl;
206 };
207 
208 // Template Implementation
209 template< class C, class S > inline void
210 Object::commitChild( C* child, S* sender, uint32_t cmd,
211  const uint32_t incarnation )
212 {
213  if( !child->isAttached( ))
214  {
215  LBASSERT( !isMaster( ));
216  co::LocalNodePtr localNode = child->getConfig()->getLocalNode();
217  lunchbox::Request< uint128_t > request =
218  localNode->registerRequest< uint128_t >();
219  co::NodePtr node = child->getServer().get();
220  sender->send( node, cmd ) << request;
221 
222  LBCHECK( localNode->mapObject( child, request.wait(),
223  co::VERSION_NONE ));
224  }
225  child->commit( incarnation );
226 }
227 
228 template< class C, class S > inline void
229 Object::commitChildren( const std::vector< C* >& children, S* sender,
230  uint32_t cmd, const uint32_t incarnation )
231 {
232  // TODO Opt: async register and commit
233  for( typename std::vector< C* >::const_iterator i = children.begin();
234  i != children.end(); ++i )
235  {
236  C* child = *i;
237  commitChild< C, S >( child, sender, cmd, incarnation );
238  }
239 }
240 
241 template< class C >
242 inline void Object::commitChildren( const std::vector< C* >& children,
243  const uint32_t incarnation )
244 {
245  // TODO Opt: async commit
246  for( typename std::vector< C* >::const_iterator i = children.begin();
247  i != children.end(); ++i )
248  {
249  C* child = *i;
250  LBASSERT( child->isAttached( ));
251  child->commit( incarnation );
252  }
253 }
254 
255 template< class C >
256 inline void Object::syncChildren( const std::vector< C* >& children )
257 {
258  for( typename std::vector< C* >::const_iterator i = children.begin();
259  i != children.end(); ++i )
260  {
261  C* child = *i;
262  LBASSERT( child->isMaster( )); // slaves are synced using version
263  child->sync();
264  }
265 }
266 
267 template< class P, class C >
268 inline void Object::releaseChildren( const std::vector< C* >& children )
269 {
270  for( size_t i = children.size(); i > 0; --i )
271  {
272  C* child = children[ i - 1 ];
273 
274  if( child->isAttached( ))
275  {
276  getLocalNode()->releaseObject( child );
277  if( !isMaster( ))
278  {
279  static_cast< P* >( this )->_removeChild( child );
280  static_cast< P* >( this )->release( child );
281  }
282  }
283  else
284  {
285  LBASSERT( isMaster( ));
286  }
287  }
288 }
289 }
290 }
291 #endif // EQFABRIC_OBJECT_H
Base event structure to report window system and other events.
Definition: event.h:36
Defines export visibility macros for library EqualizerFabric.
virtual uint32_t getUserDataLatency() const
Definition: object.h:136
DirtyBits
The changed parts of the object since the last pack().
Definition: object.h:104
The Equalizer client library.
Definition: eq/agl/types.h:23
Internal base class for all distributed, inheritable Equalizer objects.
Definition: object.h:41
virtual bool hasMasterUserData()
Definition: object.h:133