Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * net_handler.h - Fawkes configuration network handler 00004 * 00005 * Created: Sat Jan 06 22:53:23 2007 00006 * Copyright 2006-2008 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 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 #include <config/change_handler.h> 00035 00036 #include <cstdlib> 00037 #include <map> 00038 #include <string> 00039 #include <utility> 00040 #include <cstring> 00041 00042 namespace fawkes { 00043 00044 class FawkesNetworkHub; 00045 00046 00047 class ConfigNetworkHandler 00048 : public Thread, 00049 public FawkesNetworkHandler, 00050 public ConfigurationChangeHandler 00051 { 00052 public: 00053 ConfigNetworkHandler(Configuration *config, FawkesNetworkHub *hub); 00054 ~ConfigNetworkHandler(); 00055 00056 /* from FawkesNetworkHandler interface */ 00057 virtual void handle_network_message(FawkesNetworkMessage *msg); 00058 virtual void client_connected(unsigned int clid); 00059 virtual void client_disconnected(unsigned int clid); 00060 virtual void loop(); 00061 00062 /* from ConfigurationChangeHandler interface */ 00063 virtual void config_tag_changed(const char *new_location); 00064 virtual void config_value_changed(const Configuration::ValueIterator *v); 00065 virtual void config_comment_changed(const Configuration::ValueIterator *v); 00066 virtual void config_value_erased(const char *path); 00067 00068 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */ 00069 protected: virtual void run() { Thread::run(); } 00070 00071 private: 00072 void send_value(unsigned int clid, Configuration::ValueIterator *i); 00073 void send_inv_value(unsigned int clid, const char *path); 00074 00075 template <typename T> 00076 T * prepare_msg(const char *path, bool is_default) 00077 { 00078 T * m = (T *)calloc(1, sizeof(T)); 00079 strncpy(m->cp.path, path, CONFIG_MSG_PATH_LENGTH); 00080 m->cp.is_default = is_default; 00081 return m; 00082 } 00083 00084 template <typename T> 00085 T * prepare_string_msg(const char *path, bool is_default, size_t s_length) 00086 { 00087 T * m = (T *)calloc(1, sizeof(T) + s_length); 00088 strncpy(m->cp.path, path, CONFIG_MSG_PATH_LENGTH); 00089 m->cp.is_default = is_default; 00090 m->s_length = s_length; 00091 return m; 00092 } 00093 00094 Configuration *__config; 00095 FawkesNetworkHub *__hub; 00096 LockQueue< FawkesNetworkMessage * > __inbound_queue; 00097 00098 LockList< unsigned int > __subscribers; 00099 LockList< unsigned int >::iterator __sit; 00100 }; 00101 00102 } // end namespace fawkes 00103 00104 #endif