00001 #ifndef _DHT_CLIENT_H_ 00002 #define _DHT_CLIENT_H_ 00003 00004 #include "common.h" 00005 #include "key.h" 00006 #include "value.h" 00007 #include "name_value_map.h" 00008 #include "notify_handler.h" 00009 #include "search_handler.h" 00010 #include "event_observer_notifier.h" 00011 00075 namespace dht { 00123 class client { 00124 event_observer_notifier *_obs_notifier; 00125 protected: 00126 inline event_observer_notifier *observer_notifier() { 00127 return _obs_notifier; 00128 } 00129 00130 public: 00131 enum { 00132 disconnected = 1, 00133 connecting, 00134 connected, 00135 disconnecting, 00136 }; 00137 00138 client(); 00146 virtual ~client(); 00147 00151 virtual int in_state() const; 00155 virtual const char *in_state_str() const; 00162 virtual const char *state_str(int state) const; 00163 00171 virtual void init(const dht::name_value_map &opts) = 0; 00172 00181 virtual void observer_attach(dht::event_observer *h, 00182 int event_mask); 00189 virtual void observer_remove(dht::event_observer *h); 00197 virtual void observer_remove(dht::event_observer *h, int event_mask); 00198 00210 virtual void connect(dht::notify_handler *handler = NULL) = 0; 00211 00223 virtual void disconnect(dht::notify_handler *handler = NULL) = 0; 00224 00236 virtual void find(const dht::key &fkey, 00237 dht::search_handler *handler) = 0; 00238 00250 virtual void store(const dht::key &skey, 00251 const dht::value &svalue, 00252 dht::notify_handler *handler = NULL) = 0; 00253 00263 virtual const addr_inet_type &external_addr() = 0; 00264 00286 virtual int process(time_value_type &max_wait) = 0; 00287 00309 virtual int process(time_value_type *max_wait = NULL) = 0; 00310 00328 virtual reactor_type *reactor() = 0; 00329 00347 virtual void reactor(reactor_type *reactor) = 0; 00348 00349 00359 virtual int handler_cancel(dht::notify_handler *handler) = 0; 00360 00361 }; 00362 } 00363 00364 #endif //_DHT_CLIENT_H_