Eris 1.3.16
|
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 void await(int serialno, ResponseBase*); 00063 00064 template <class T> 00065 void await(int serial, T* ins, void (T::*method)(const Atlas::Objects::Operation::RootOperation& op) ) 00066 { 00067 await(serial, new MemberResponse<T>(ins, method)); 00068 } 00069 00070 void ignore(int serial) 00071 { 00072 await(serial, new NullResponse()); 00073 } 00074 00075 bool handleOp(const Atlas::Objects::Operation::RootOperation& op); 00076 00077 private: 00078 typedef std::map<int, ResponseBase*> RefnoResponseMap; 00079 RefnoResponseMap m_pending; 00080 }; 00081 00082 } // of namespace 00083 00084 #endif // of ERIS_RESPONSE_H