Fawkes API  Fawkes Development Version
net_handler.h
1 
2 /***************************************************************************
3  * net_handler.h - Fawkes configuration network handler
4  *
5  * Created: Sat Jan 06 22:53:23 2007
6  * Copyright 2006-2008 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __CONFIG_NET_HANDLER_H_
25 #define __CONFIG_NET_HANDLER_H_
26 
27 #include <core/threading/thread.h>
28 #include <netcomm/fawkes/handler.h>
29 #include <core/utils/lock_queue.h>
30 #include <core/utils/lock_list.h>
31 
32 #include <config/net_messages.h>
33 #include <config/config.h>
34 #include <config/change_handler.h>
35 
36 #include <cstdlib>
37 #include <map>
38 #include <string>
39 #include <utility>
40 #include <cstring>
41 
42 namespace fawkes {
43 
44 class FawkesNetworkHub;
45 
46 
48 : public Thread,
49  public FawkesNetworkHandler,
51 {
52  public:
55 
56  /* from FawkesNetworkHandler interface */
58  virtual void client_connected(unsigned int clid);
59  virtual void client_disconnected(unsigned int clid);
60  virtual void loop();
61 
62  /* from ConfigurationChangeHandler interface */
63  virtual void config_tag_changed(const char *new_location);
66  virtual void config_value_erased(const char *path);
67 
68  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
69  protected: virtual void run() { Thread::run(); }
70 
71  private:
72  void send_value(unsigned int clid, Configuration::ValueIterator *i);
73  void send_inv_value(unsigned int clid, const char *path);
74 
75  template <typename T>
76  T * prepare_msg(const char *path, bool is_default)
77  {
78  T * m = (T *)calloc(1, sizeof(T));
79  strncpy(m->cp.path, path, CONFIG_MSG_PATH_LENGTH);
80  m->cp.is_default = is_default;
81  return m;
82  }
83 
84  template <typename T>
85  T * prepare_string_msg(const char *path, bool is_default, size_t s_length)
86  {
87  T * m = (T *)calloc(1, sizeof(T) + s_length);
88  strncpy(m->cp.path, path, CONFIG_MSG_PATH_LENGTH);
89  m->cp.is_default = is_default;
90  m->s_length = s_length;
91  return m;
92  }
93 
94  Configuration *__config;
95  FawkesNetworkHub *__hub;
97 
98  LockList< unsigned int > __subscribers;
100 };
101 
102 } // end namespace fawkes
103 
104 #endif
Fawkes library namespace.
virtual void config_value_changed(const Configuration::ValueIterator *v)
Called whenever a watched value has changed.
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:918
~ConfigNetworkHandler()
Destructor.
Definition: net_handler.cpp:69
Interface for configuration change handling.
virtual void handle_network_message(FawkesNetworkMessage *msg)
Handle network message.
virtual void config_value_erased(const char *path)
Called whenever a value has been erased from the config.
Representation of a message that is sent over the network.
Definition: message.h:75
Thread class encapsulation of pthreads.
Definition: thread.h:42
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: net_handler.h:69
virtual void loop()
Process all network messages that have been received.
Fawkes Network Hub.
Definition: hub.h:33
ConfigNetworkHandler(Configuration *config, FawkesNetworkHub *hub)
Constructor.
Definition: net_handler.cpp:52
Fawkes Configuration Network Handler.
Definition: net_handler.h:47
Network handler abstract base class.
Definition: handler.h:31
virtual void client_disconnected(unsigned int clid)
Client disconnected.
virtual void client_connected(unsigned int clid)
Client connected.
Iterator interface to iterate over config values.
Definition: config.h:68
virtual void config_comment_changed(const Configuration::ValueIterator *v)
Called whenever a comment of a watched value has changed.
Interface for configuration handling.
Definition: config.h:63
virtual void config_tag_changed(const char *new_location)
Tag changed.