Eris  1.3.19
Response.h
1 #ifndef ERIS_RESPONSE_H
2 #define ERIS_RESPONSE_H
3 
4 #include <Atlas/Objects/ObjectsFwd.h>
5 #include <map>
6 
7 namespace Eris
8 {
9 
11 {
12 public:
13  virtual ~ResponseBase();
14 
19  virtual bool responseReceived(const Atlas::Objects::Operation::RootOperation& op) = 0;
20 };
21 
22 class NullResponse : public ResponseBase
23 {
24 public:
25  virtual bool responseReceived(const Atlas::Objects::Operation::RootOperation&);
26 };
27 
28 void* clearMemberResponse(void*);
29 
30 template <class T>
32 {
33 public:
34  typedef void (T::*T_method)(const Atlas::Objects::Operation::RootOperation& op);
35 
36  MemberResponse(T *obj, void (T::*method)(const Atlas::Objects::Operation::RootOperation& op)) :
37  m_object(obj),
38  m_func(method)
39  {
40  obj->add_destroy_notify_callback(&m_object, &clearMemberResponse);
41  }
42 
43  ~MemberResponse()
44  {
45  if (m_object) m_object->remove_destroy_notify_callback(&m_object);
46  }
47 
48  virtual bool responseReceived(const Atlas::Objects::Operation::RootOperation& op)
49  {
50  if (m_object) (m_object->*m_func)(op);
51  return true;
52  }
53 
54 private:
55  T* m_object;
56  T_method m_func;
57 };
58 
60 {
61 public:
62 
63  ~ResponseTracker();
64 
65  void await(int serialno, ResponseBase*);
66 
67  template <class T>
68  void await(int serial, T* ins, void (T::*method)(const Atlas::Objects::Operation::RootOperation& op) )
69  {
70  await(serial, new MemberResponse<T>(ins, method));
71  }
72 
73  void ignore(int serial)
74  {
75  await(serial, new NullResponse());
76  }
77 
78  bool handleOp(const Atlas::Objects::Operation::RootOperation& op);
79 
80 private:
81  typedef std::map<int, ResponseBase*> RefnoResponseMap;
82  RefnoResponseMap m_pending;
83 };
84 
85 } // of namespace
86 
87 #endif // of ERIS_RESPONSE_H