net_handler.h

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 
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   /* from FawkesNetworkHandler interface */
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   /* from ConfigurationChangeHandler interface */
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  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
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 } // end namespace fawkes
00105 
00106 #endif

Generated on Tue Feb 22 13:31:25 2011 for Fawkes API by  doxygen 1.4.7