Eris
1.3.21
|
00001 #ifndef ERIS_RESPONSE_H 00002 #define ERIS_RESPONSE_H 00003 00004 #include <Atlas/Objects/ObjectsFwd.h> 00005 #include <map> 00006 00007 namespace Eris 00008 { 00009 00010 class ResponseBase 00011 { 00012 public: 00013 virtual ~ResponseBase(); 00014 00019 virtual bool responseReceived(const Atlas::Objects::Operation::RootOperation& op) = 0; 00020 }; 00021 00022 class NullResponse : public ResponseBase 00023 { 00024 public: 00025 virtual bool responseReceived(const Atlas::Objects::Operation::RootOperation&); 00026 }; 00027 00028 void* clearMemberResponse(void*); 00029 00030 template <class T> 00031 class MemberResponse : public ResponseBase 00032 { 00033 public: 00034 typedef void (T::*T_method)(const Atlas::Objects::Operation::RootOperation& op); 00035 00036 MemberResponse(T *obj, void (T::*method)(const Atlas::Objects::Operation::RootOperation& op)) : 00037 m_object(obj), 00038 m_func(method) 00039 { 00040 obj->add_destroy_notify_callback(&m_object, &clearMemberResponse); 00041 } 00042 00043 ~MemberResponse() 00044 { 00045 if (m_object) m_object->remove_destroy_notify_callback(&m_object); 00046 } 00047 00048 virtual bool responseReceived(const Atlas::Objects::Operation::RootOperation& op) 00049 { 00050 if (m_object) (m_object->*m_func)(op); 00051 return true; 00052 } 00053 00054 private: 00055 T* m_object; 00056 T_method m_func; 00057 }; 00058 00059 class ResponseTracker 00060 { 00061 public: 00062 00063 ~ResponseTracker(); 00064 00065 void await(int serialno, ResponseBase*); 00066 00067 template <class T> 00068 void await(int serial, T* ins, void (T::*method)(const Atlas::Objects::Operation::RootOperation& op) ) 00069 { 00070 await(serial, new MemberResponse<T>(ins, method)); 00071 } 00072 00073 void ignore(int serial) 00074 { 00075 await(serial, new NullResponse()); 00076 } 00077 00078 bool handleOp(const Atlas::Objects::Operation::RootOperation& op); 00079 00080 private: 00081 typedef std::map<int, ResponseBase*> RefnoResponseMap; 00082 RefnoResponseMap m_pending; 00083 }; 00084 00085 } // of namespace 00086 00087 #endif // of ERIS_RESPONSE_H