00001 #ifndef _DHT_EVENT_OBSERVER_NOTIFIER_H_
00002 #define _DHT_EVENT_OBSERVER_NOTIFIER_H_
00003
00004 #include <map>
00005 #include <list>
00006
00007 #include "event_observer.h"
00008 #include "key.h"
00009 #include "value.h"
00010
00011 namespace dht {
00012 class event_observer_notifier {
00013
00014 typedef std::map<int, event_observer *> _observer_map_type;
00015 _observer_map_type _container;
00016
00017 int _last_received_state;
00018
00019 inline event_observer *_find_obs(int ev_type);
00020 public:
00021 event_observer_notifier();
00022 virtual ~event_observer_notifier();
00023
00024 void observer_attach(event_observer *h, int event_mask);
00025 void observer_remove(event_observer *h);
00026 void observer_remove(event_observer *h, int event_mask);
00027
00028
00029 inline int state_changed(int state);
00030 inline int search_result(const key &k, const value &v);
00031 inline int last_received_state() const;
00032 };
00033
00034 inline event_observer *
00035 event_observer_notifier::_find_obs(int ev_type) {
00036 _observer_map_type::iterator i = _container.find(ev_type);
00037 if (i != _container.end()) return i->second;
00038 return NULL;
00039 }
00040
00041 inline int
00042 event_observer_notifier::state_changed(int state) {
00043 _last_received_state = state;
00044 event_observer *o = _find_obs(event_observer::mask_state_changed);
00045 return (o ? o->state_changed(state) : 0);
00046 }
00047
00048 inline int
00049 event_observer_notifier::search_result(const key &k, const value &v) {
00050 event_observer *o = _find_obs(event_observer::mask_search_result);
00051 return (o ? o->search_result(k, v) : 0);
00052 }
00053
00054 inline int
00055 event_observer_notifier::last_received_state() const {
00056 return _last_received_state;
00057 }
00058 }
00059
00060 #endif // _DHT_EVENT_OBSERVER_NOTIFIER_H_