00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __CONFIG_NET_HANDLER_H_
00025 #define __CONFIG_NET_HANDLER_H_
00026
00027 #include <core/threading/thread.h>
00028 #include <netcomm/fawkes/handler.h>
00029 #include <core/utils/lock_queue.h>
00030 #include <core/utils/lock_list.h>
00031
00032 #include <config/net_messages.h>
00033 #include <config/config.h>
00034
00035 #include <cstdlib>
00036 #include <map>
00037 #include <string>
00038 #include <utility>
00039
00040 namespace fawkes {
00041
00042 class FawkesNetworkHub;
00043
00044
00045 class ConfigNetworkHandler
00046 : public Thread,
00047 public FawkesNetworkHandler,
00048 public ConfigurationChangeHandler
00049 {
00050 public:
00051 ConfigNetworkHandler(Configuration *config, FawkesNetworkHub *hub);
00052 ~ConfigNetworkHandler();
00053
00054
00055 virtual void handle_network_message(FawkesNetworkMessage *msg);
00056 virtual void client_connected(unsigned int clid);
00057 virtual void client_disconnected(unsigned int clid);
00058 virtual void loop();
00059
00060
00061 virtual void config_tag_changed(const char *new_location);
00062 virtual void config_value_changed(const char *path, bool is_default, int value);
00063 virtual void config_value_changed(const char *path, bool is_default, unsigned int value);
00064 virtual void config_value_changed(const char *path, bool is_default, float value);
00065 virtual void config_value_changed(const char *path, bool is_default, bool value);
00066 virtual void config_value_changed(const char *path, bool is_default, const char *value);
00067 virtual void config_comment_changed(const char *path, bool is_default, const char *comment);
00068 virtual void config_value_erased(const char *path, bool is_default);
00069
00070
00071 protected: virtual void run() { Thread::run(); }
00072
00073 private:
00074 void send_value(unsigned int clid, Configuration::ValueIterator *i);
00075 void send_inv_value(unsigned int clid, const char *path);
00076
00077 template <typename T>
00078 T * prepare_msg(const char *path, bool is_default)
00079 {
00080 T * m = (T *)calloc(1, sizeof(T));
00081 strncpy(m->cp.path, path, CONFIG_MSG_PATH_LENGTH);
00082 m->cp.is_default = is_default;
00083 return m;
00084 }
00085
00086 template <typename T>
00087 T * prepare_string_msg(const char *path, bool is_default, size_t s_length)
00088 {
00089 T * m = (T *)calloc(1, sizeof(T) + s_length);
00090 strncpy(m->cp.path, path, CONFIG_MSG_PATH_LENGTH);
00091 m->cp.is_default = is_default;
00092 m->s_length = s_length;
00093 return m;
00094 }
00095
00096 Configuration *__config;
00097 FawkesNetworkHub *__hub;
00098 LockQueue< FawkesNetworkMessage * > __inbound_queue;
00099
00100 LockList< unsigned int > __subscribers;
00101 LockList< unsigned int >::iterator __sit;
00102 };
00103
00104 }
00105
00106 #endif