Equalizer  2.1.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 <co/objectOCommand.h> // used inline send()
23 #include <co/objectVersion.h> // member
24 #include <co/serializable.h> // base class
25 #include <eq/fabric/api.h>
26 #include <eq/fabric/error.h> // enum
27 #include <eq/fabric/types.h>
28 
29 namespace eq
30 {
31 namespace fabric
32 {
33 namespace detail
34 {
35 class Object;
36 }
37 
44 class Object : public co::Serializable
45 {
46 public:
50  EQFABRIC_API virtual void setName(const std::string& name);
51 
53  EQFABRIC_API const std::string& getName() const;
54 
64  EQFABRIC_API void setUserData(co::Object* userData);
65 
67  EQFABRIC_API co::Object* getUserData();
68 
70  EQFABRIC_API const co::Object* getUserData() const;
72 
84  EQFABRIC_API uint32_t getTasks() const;
85 
86  EQFABRIC_API uint32_t getSerial() const;
87 
88 
90  EQFABRIC_API bool isDirty() const override;
91 
93  EQFABRIC_API uint128_t
94  commit(const uint32_t incarnation = CO_COMMIT_NEXT) override;
95 
97  EQFABRIC_API virtual void backup();
98 
100  EQFABRIC_API virtual void restore();
101 
108  {
109  DIRTY_NAME = Serializable::DIRTY_CUSTOM << 0, // 1
110  DIRTY_USERDATA = Serializable::DIRTY_CUSTOM << 1, // 2
111  DIRTY_TASKS = Serializable::DIRTY_CUSTOM << 2, // 4
112  DIRTY_REMOVED = Serializable::DIRTY_CUSTOM << 3, // 8
113  DIRTY_SERIAL = Serializable::DIRTY_CUSTOM << 4, // 16
114  // Leave room for binary-compatible patches
115  DIRTY_CUSTOM = Serializable::DIRTY_CUSTOM << 6, // 64
116  DIRTY_OBJECT_BITS = DIRTY_NAME | DIRTY_USERDATA
117  };
118 
119 protected:
121  EQFABRIC_API Object();
122 
124  EQFABRIC_API Object(const Object&);
125 
127  EQFABRIC_API virtual ~Object();
128 
130  EQFABRIC_API Object& operator=(const Object& from);
131 
136  virtual bool hasMasterUserData() { return false; }
138  virtual uint32_t getUserDataLatency() const { return 0; }
140  EQFABRIC_API void setTasks(const uint32_t tasks);
141 
142  EQFABRIC_API void notifyDetach() override;
143 
144  EQFABRIC_API void serialize(co::DataOStream& os,
145  const uint64_t dirtyBits) override;
146  EQFABRIC_API void deserialize(co::DataIStream& is,
147  const uint64_t dirtyBits) override;
148 
150  virtual uint64_t getRedistributableBits() const
151  {
152  return DIRTY_OBJECT_BITS;
153  }
154 
160  EQFABRIC_API void postRemove(Object* child);
161 
163  virtual void removeChild(const uint128_t&) { LBUNIMPLEMENTED; }
165  template <class C, class S>
166  void commitChild(C* child, S* sender, uint32_t cmd,
167  const uint32_t incarnation);
168 
170  template <class C>
171  inline void commitChild(C* child, const uint32_t incarnation)
172  {
173  LBASSERT(child->isAttached());
174  child->commit(incarnation);
175  }
176 
178  template <class C, class S>
179  void commitChildren(const std::vector<C*>& children, S* sender,
180  uint32_t cmd, const uint32_t incarnation);
181 
183  template <class C>
184  void commitChildren(const std::vector<C*>& children, uint32_t cmd,
185  const uint32_t incarnation)
186  {
187  commitChildren<C, Object>(children, this, cmd, incarnation);
188  }
189 
191  template <class C>
192  void commitChildren(const std::vector<C*>& children,
193  const uint32_t incarnation);
194 
196  template <class C>
197  void syncChildren(const std::vector<C*>& children);
198 
200  template <class P, class C>
201  inline void releaseChildren(const std::vector<C*>& children);
202 
204  EQFABRIC_API bool _cmdSync(co::ICommand& command);
205 
206  EQFABRIC_API void updateEvent(Event& event, int64_t time);
207 
208 private:
209  detail::Object* const _impl;
210 };
211 
212 // Template Implementation
213 template <class C, class S>
214 inline void Object::commitChild(C* child, S* sender, uint32_t cmd,
215  const uint32_t incarnation)
216 {
217  if (!child->isAttached())
218  {
219  LBASSERT(!isMaster());
220  co::LocalNodePtr localNode = child->getConfig()->getLocalNode();
221  lunchbox::Request<uint128_t> request =
222  localNode->registerRequest<uint128_t>();
223  co::NodePtr node = child->getServer().get();
224  sender->send(node, cmd) << request;
225 
226  LBCHECK(localNode->mapObject(child, request.wait(), co::VERSION_NONE));
227  }
228  child->commit(incarnation);
229 }
230 
231 template <class C, class S>
232 inline void Object::commitChildren(const std::vector<C*>& children, S* sender,
233  uint32_t cmd, const uint32_t incarnation)
234 {
235  // TODO Opt: async register and commit
236  for (typename std::vector<C*>::const_iterator i = children.begin();
237  i != children.end(); ++i)
238  {
239  C* child = *i;
240  commitChild<C, S>(child, sender, cmd, incarnation);
241  }
242 }
243 
244 template <class C>
245 inline void Object::commitChildren(const std::vector<C*>& children,
246  const uint32_t incarnation)
247 {
248  // TODO Opt: async commit
249  for (typename std::vector<C*>::const_iterator i = children.begin();
250  i != children.end(); ++i)
251  {
252  C* child = *i;
253  LBASSERT(child->isAttached());
254  child->commit(incarnation);
255  }
256 }
257 
258 template <class C>
259 inline void Object::syncChildren(const std::vector<C*>& children)
260 {
261  for (typename std::vector<C*>::const_iterator i = children.begin();
262  i != children.end(); ++i)
263  {
264  C* child = *i;
265  LBASSERT(child->isMaster()); // slaves are synced using version
266  child->sync();
267  }
268 }
269 
270 template <class P, class C>
271 inline void Object::releaseChildren(const std::vector<C*>& children)
272 {
273  for (size_t i = children.size(); i > 0; --i)
274  {
275  C* child = children[i - 1];
276 
277  if (child->isAttached())
278  {
279  getLocalNode()->releaseObject(child);
280  if (!isMaster())
281  {
282  static_cast<P*>(this)->_removeChild(child);
283  static_cast<P*>(this)->release(child);
284  }
285  }
286  else
287  {
288  LBASSERT(isMaster());
289  }
290  }
291 }
292 }
293 }
294 #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:138
DirtyBits
The changed parts of the object since the last pack().
Definition: object.h:107
The Equalizer client library.
Definition: eq/agl/types.h:23
Internal base class for all distributed, inheritable Equalizer objects.
Definition: object.h:44
virtual bool hasMasterUserData()
Definition: object.h:136