Fawkes API  Fawkes Development Version
net_handler.cpp
1 
2 /***************************************************************************
3  * net_handler.cpp - Fawkes configuration network handler
4  *
5  * Generated: Sat Jan 06 22:55:03 2007
6  * Copyright 2006-2007 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 #include <config/net_handler.h>
25 #include <config/net_messages.h>
26 #include <config/net_list_content.h>
27 #include <logging/liblogger.h>
28 
29 #include <netcomm/fawkes/component_ids.h>
30 #include <netcomm/fawkes/hub.h>
31 #include <config/config.h>
32 
33 #include <algorithm>
34 #include <cstring>
35 
36 namespace fawkes {
37 
38 /** @class ConfigNetworkHandler <config/net_handler.h>
39  * Fawkes Configuration Network Handler.
40  * It provides access to a given config via the network.
41  * This is mainly used to allow modification of config values over the network.
42  *
43  * @author Tim Niemueller
44  */
45 
46 /** Constructor.
47  * @param config configuration, loaded and ready to be used for getting and
48  * setting values
49  * @param hub Fawkes network hub to use for receiving and sending network
50  * messages
51  */
53  FawkesNetworkHub *hub)
54  : Thread("ConfigNetworkHandler", Thread::OPMODE_WAITFORWAKEUP),
55  FawkesNetworkHandler(FAWKES_CID_CONFIGMANAGER),
57 {
58  __config = config;
59  __hub = hub;
60 
61  start();
62 
63  __config->add_change_handler(this);
64  __hub->add_handler( this );
65 }
66 
67 
68 /** Destructor. */
70 {
71  __hub->remove_handler(this);
72  cancel();
73  join();
74  __config->rem_change_handler(this);
75  __inbound_queue.clear();
76 }
77 
78 
79 /** Send invalid value message.
80  * @param clid client ID
81  * @param path path
82  */
83 void
84 ConfigNetworkHandler::send_inv_value(unsigned int clid, const char *path)
85 {
86  config_invval_msg_t *r = prepare_msg<config_invval_msg_t>(path, false);
87  __hub->send(clid, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_INV_VALUE, r, sizeof(config_invval_msg_t));
88 }
89 
90 
91 /** Send value.
92  * @param clid client ID
93  * @param i value
94  */
95 void
96 ConfigNetworkHandler::send_value(unsigned int clid, const Configuration::ValueIterator *i)
97 {
98  if ( i->is_uint() ) {
99  try {
100  uint32_t *values;
101  uint16_t num_values = i->is_list() ? i->get_list_size() : 0;
102  size_t data_size = 0;
103  void *m = prepare_value_msg<uint32_t>(i->path(), i->is_default(), i->is_list(),
104  num_values, data_size, (void**)&values);
105  if (i->is_list()) {
106  std::vector<unsigned int> c_values = i->get_uints();
107  for (uint16_t i = 0; i < num_values; ++i) values[0] = c_values[0];
108  } else {
109  values[0] = i->get_uint();
110  }
111  __hub->send(clid, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_UINT_VALUE, m, data_size);
112  } catch (Exception &e) {
113  LibLogger::log_warn("ConfigNetworkHandler",
114  "send_value: Value %s could not be sent",
115  i->path());
116  LibLogger::log_warn("ConfigNetworkHandler", e);
117  }
118  } else if ( i->is_int() ) {
119  try {
120  int32_t *values;
121  int16_t num_values = i->is_list() ? i->get_list_size() : 0;
122  size_t data_size = 0;
123  void *m = prepare_value_msg<int32_t>(i->path(), i->is_default(), i->is_list(),
124  num_values, data_size, (void**)&values);
125  if (i->is_list()) {
126  std::vector<int> c_values = i->get_ints();
127  for (uint16_t i = 0; i < num_values; ++i) values[0] = c_values[0];
128  } else {
129  values[0] = i->get_int();
130  }
131  __hub->send(clid, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_INT_VALUE, m, data_size);
132  } catch (Exception &e) {
133  LibLogger::log_warn("ConfigNetworkHandler",
134  "send_value: Value %s could not be sent",
135  i->path());
136  LibLogger::log_warn("ConfigNetworkHandler", e);
137  }
138  } else if ( i->is_bool() ) {
139  try {
140  int32_t *values;
141  int16_t num_values = i->is_list() ? i->get_list_size() : 0;
142  size_t data_size = 0;
143  void *m = prepare_value_msg<int32_t>(i->path(), i->is_default(), i->is_list(),
144  num_values, data_size, (void**)&values);
145  if (i->is_list()) {
146  std::vector<bool> c_values = i->get_bools();
147  for (uint16_t i = 0; i < num_values; ++i) values[0] = (c_values[0] ? 1 : 0);
148  } else {
149  values[0] = i->get_bool() ? 1 : 0;
150  }
151  __hub->send(clid, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_BOOL_VALUE, m, data_size);
152  } catch (Exception &e) {
153  LibLogger::log_warn("ConfigNetworkHandler",
154  "send_value: Value %s could not be sent",
155  i->path());
156  LibLogger::log_warn("ConfigNetworkHandler", e);
157  }
158  } else if ( i->is_float() ) {
159  try {
160  float *values;
161  uint16_t num_values = i->is_list() ? i->get_list_size() : 0;
162  size_t data_size = 0;
163  void *m = prepare_value_msg<float>(i->path(), i->is_default(), i->is_list(), num_values,
164  data_size, (void**)&values);
165  if (i->is_list()) {
166  std::vector<float> c_values = i->get_floats();
167  for (uint16_t i = 0; i < num_values; ++i) values[0] = c_values[0];
168  } else {
169  values[0] = i->get_float();
170  }
171  __hub->send(clid, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_FLOAT_VALUE, m, data_size);
172  } catch (Exception &e) {
173  LibLogger::log_warn("ConfigNetworkHandler",
174  "send_value: Value %s could not be sent",
175  i->path());
176  LibLogger::log_warn("ConfigNetworkHandler", e);
177  }
178  } else if ( i->is_string() ) {
179  try {
180  if (i->is_list()) {
181  std::vector<std::string> s = i->get_strings();
182  size_t data_size = sizeof(config_descriptor_t);
183 
184  for (unsigned int j = 0; j < s.size(); ++j) {
185  data_size += sizeof(config_string_value_t) + s[j].length() + 1;
186  }
187  void *m = calloc(1, data_size);
188 
190  strncpy(cd->path, i->path(), CONFIG_MSG_PATH_LENGTH);
191  cd->is_default = i->is_default();
192  cd->num_values = s.size();
193 
194  char *tmp = ((char *)m + sizeof(config_descriptor_t));
195  for (unsigned int i = 0; i < s.size(); ++i) {
197  char *msg_string = tmp + sizeof(config_string_value_t);
198  sv->s_length = s[i].length();
199  strcpy(msg_string, s[i].c_str());
200  tmp += sizeof(config_string_value_t) + sv->s_length + 1;
201  }
202 
203  __hub->send(clid, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_STRING_VALUE, m, data_size);
204  } else {
205  std::string s = i->get_string();
206  size_t data_size =
207  sizeof(config_descriptor_t) + sizeof(config_string_value_t) + s.length() + 1;
208  void *m = calloc(1, data_size);
210  strncpy(cd->path, i->path(), CONFIG_MSG_PATH_LENGTH);
211  cd->is_default = i->is_default();
212  cd->num_values = 0;
213 
214  config_string_value_t *sv =
215  (config_string_value_t *)((char *)m + sizeof(config_descriptor_t));
216  char *msg_string = (char *)sv + sizeof(config_string_value_t);
217 
218  sv->s_length = s.length();
219  strcpy(msg_string, s.c_str());
220 
221  __hub->send(clid, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_STRING_VALUE, m, data_size);
222  }
223  } catch (Exception &e) {
224  LibLogger::log_warn("ConfigNetworkHandler",
225  "send_value: Value %s could not be sent",
226  i->path());
227  LibLogger::log_warn("ConfigNetworkHandler", e);
228  }
229  } else {
230  LibLogger::log_warn("ConfigNetworkHandler",
231  "send_value: unknown type of value %s",
232  i->path());
233  }
234 }
235 
236 
237 /** Process all network messages that have been received. */
238 void
240 {
241  while ( ! __inbound_queue.empty() ) {
242  FawkesNetworkMessage *msg = __inbound_queue.front();
243 
244  // printf("Received message of type %u\n", msg->msgid());
245 
246  if (msg->msgid() == MSG_CONFIG_SUBSCRIBE) {
247 
248  __subscribers.push_back_locked(msg->clid());
249  __subscribers.sort();
250  __subscribers.unique();
251 
252  __config->lock();
253  ConfigListContent *content = new ConfigListContent();
254  Configuration::ValueIterator *i = __config->iterator();
255  while ( i->next() ) {
256  if (i->is_default()) {
257  content->append(i);
258  }
259  }
260  delete i;
261  i = __config->iterator();
262  while ( i->next() ) {
263  if (! i->is_default()) {
264  content->append(i);
265  }
266  }
267  delete i;
268  __hub->send(msg->clid(), FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_LIST, content);
269  __config->unlock();
270 
271  } else if (msg->msgid() == MSG_CONFIG_ERASE_VALUE) {
272  try {
274  char path[CONFIG_MSG_PATH_LENGTH + 1];
275  path[CONFIG_MSG_PATH_LENGTH] = 0;
276  strncpy(path, m->cp.path, CONFIG_MSG_PATH_LENGTH);
277 
278  if ( m->cp.is_default == 1 ) {
279  __config->erase_default(path);
280  } else {
281  __config->erase(path);
282  }
283 
284  config_value_erased_msg_t *r = prepare_msg<config_value_erased_msg_t>(path, (m->cp.is_default == 1));
285  __hub->send(msg->clid(), FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_VALUE_ERASED,
286  r, sizeof(config_value_erased_msg_t));
287 
288  } catch (Exception &e) {
289  send_inv_value(msg->clid(), "?");
290  e.append("Failed to erase value");
291  LibLogger::log_warn("ConfigNetworkHandler", "Failed to erase value");
292  LibLogger::log_warn("ConfigNetworkHandler", e);
293  }
294 
295  } else if ( (msg->msgid() >= MSG_CONFIG_GET_BEGIN) &&
296  (msg->msgid() <= MSG_CONFIG_GET_END) ) {
297 
298  if ( msg->payload_size() != sizeof(config_getval_msg_t) ) {
299  LibLogger::log_warn("ConfigNetworkHandler",
300  "CONFIG_GET_FLOAT: invalid payload size "
301  "(received %zu instead of %zu bytes",
302  msg->payload_size(), sizeof(config_getval_msg_t));
303  } else {
305  char path[CONFIG_MSG_PATH_LENGTH + 1];
306  path[CONFIG_MSG_PATH_LENGTH] = 0;
307  strncpy(path, m->cp.path, CONFIG_MSG_PATH_LENGTH);
308 
309  switch (msg->msgid()) {
310  case MSG_CONFIG_GET_FLOAT:
311  case MSG_CONFIG_GET_UINT:
312  case MSG_CONFIG_GET_INT:
313  case MSG_CONFIG_GET_BOOL:
314  case MSG_CONFIG_GET_STRING:
315  case MSG_CONFIG_GET_VALUE:
316  try {
317  Configuration::ValueIterator *i = __config->get_value(path);
318  if ( i->next() ) {
319  send_value(msg->clid(), i);
320  } else {
321  send_inv_value(msg->clid(), path);
322  }
323  delete i;
324  } catch (ConfigurationException &e) {
325  LibLogger::log_warn("ConfigNetworkHandler",
326  "get value: Value %s could not be found", path);
327  LibLogger::log_warn("ConfigNetworkHandler", e);
328  }
329  break;
330 
331  }
332  }
333  } else if ( (msg->msgid() >= MSG_CONFIG_SET_BEGIN) &&
334  (msg->msgid() <= MSG_CONFIG_SET_END) ) {
335 
336  bool success = false;
337 
338  char path[CONFIG_MSG_PATH_LENGTH + 1];
339  if ( msg->payload_size() < sizeof(config_descriptor_t)) {
340  LibLogger::log_warn("ConfigNetworkHandler",
341  "inbound set: payload is too small"
342  "(%zu is less than %zu bytes",
343  msg->payload_size(), sizeof(config_descriptor_t));
344  send_inv_value(msg->clid(), "?");
345  } else {
347  path[CONFIG_MSG_PATH_LENGTH] = 0;
348  strncpy(path, cd->path, CONFIG_MSG_PATH_LENGTH);
349 
350  switch (msg->msgid()) {
351  case MSG_CONFIG_SET_FLOAT:
352  case MSG_CONFIG_SET_DEFAULT_FLOAT:
353  try {
354  float * vs = (float *)((char *)msg->payload() + sizeof(config_descriptor_t));
355  if (cd->num_values > 0) {
356  std::vector<float> values(cd->num_values);
357  for (unsigned int i = 0; i < cd->num_values; ++i) {
358  values[i] = vs[i];
359  }
360  __config->set_floats(path, values);
361  } else {
362  if ( msg->msgid() == MSG_CONFIG_SET_FLOAT ) {
363  __config->set_float(path, *vs);
364  } else {
365  __config->set_default_float(path, *vs);
366  }
367  }
368  success = true;
369  } catch (Exception &e) {
370  send_inv_value(msg->clid(), path);
371  LibLogger::log_warn("ConfigNetworkHandler",
372  "set float: Value %s could not be set", path);
373  LibLogger::log_warn("ConfigNetworkHandler", e);
374  }
375  break;
376 
377  case MSG_CONFIG_SET_UINT:
378  case MSG_CONFIG_SET_DEFAULT_UINT:
379  try {
380  uint32_t * vs = (uint32_t *)((char *)msg->payload() + sizeof(config_descriptor_t));
381  if (cd->num_values > 0) {
382  std::vector<unsigned int> values(cd->num_values);
383  for (unsigned int i = 0; i < cd->num_values; ++i) {
384  values[i] = vs[i];
385  }
386  __config->set_uints(path, values);
387  } else {
388  if ( msg->msgid() == MSG_CONFIG_SET_UINT ) {
389  __config->set_uint(path, *vs);
390  } else {
391  __config->set_default_uint(path, *vs);
392  }
393  }
394  success = true;
395  } catch (Exception &e) {
396  send_inv_value(msg->clid(), path);
397  LibLogger::log_warn("ConfigNetworkHandler",
398  "set uint: Value %s could not be set", path);
399  LibLogger::log_warn("ConfigNetworkHandler", e);
400  }
401  break;
402 
403  case MSG_CONFIG_SET_INT:
404  case MSG_CONFIG_SET_DEFAULT_INT:
405  try {
406  int32_t * vs = (int32_t *)((char *)msg->payload() + sizeof(config_descriptor_t));
407  if (cd->num_values > 0) {
408  std::vector<int> values(cd->num_values);
409  for (unsigned int i = 0; i < cd->num_values; ++i) {
410  values[i] = vs[i];
411  }
412  __config->set_ints(path, values);
413  } else {
414  if ( msg->msgid() == MSG_CONFIG_SET_INT ) {
415  __config->set_int(path, *vs);
416  } else {
417  __config->set_default_int(path, *vs);
418  }
419  }
420  success = true;
421  } catch (Exception &e) {
422  send_inv_value(msg->clid(), path);
423  LibLogger::log_warn("ConfigNetworkHandler",
424  "set int: Value %s could not be set", path);
425  LibLogger::log_warn("ConfigNetworkHandler", e);
426  }
427  break;
428 
429  case MSG_CONFIG_SET_BOOL:
430  case MSG_CONFIG_SET_DEFAULT_BOOL:
431  try {
432  int32_t * vs = (int32_t *)((char *)msg->payload() + sizeof(config_descriptor_t));
433  if (cd->num_values > 0) {
434  std::vector<bool> values(cd->num_values);
435  for (unsigned int i = 0; i < cd->num_values; ++i) {
436  values[i] = (vs[i] != 0);
437  }
438  __config->set_bools(path, values);
439  } else {
440  if ( msg->msgid() == MSG_CONFIG_SET_INT ) {
441  __config->set_bool(path, (*vs != 0));
442  } else {
443  __config->set_default_bool(path, (*vs != 0));
444  }
445  }
446  success = true;
447  } catch (Exception &e) {
448  send_inv_value(msg->clid(), path);
449  LibLogger::log_warn("ConfigNetworkHandler",
450  "set bool: Value %s could not be set", path);
451  LibLogger::log_warn("ConfigNetworkHandler", e);
452  }
453  break;
454 
455  case MSG_CONFIG_SET_STRING:
456  case MSG_CONFIG_SET_DEFAULT_STRING:
457  try {
458 
459  char *tmp = ((char *)msg->payload() + sizeof(config_descriptor_t));
460 
461  if (cd->num_values > 0) {
462  std::vector<std::string> values(cd->num_values);
463  for (unsigned int i = 0; i < cd->num_values; ++i) {
465  char *msg_string = tmp + sizeof(config_string_value_t);
466  tmp += sizeof(config_string_value_t) + sv->s_length + 1;
467  values[i] = std::string(msg_string, sv->s_length);
468  }
469  __config->set_strings(path, values);
470  } else {
472  char *msg_string = tmp + sizeof(config_string_value_t);
473  std::string value = std::string(msg_string, sv->s_length);
474  if ( msg->msgid() == MSG_CONFIG_SET_INT ) {
475  __config->set_string(path, value);
476  } else {
477  __config->set_default_string(path, value);
478  }
479  }
480  success = true;
481  } catch (Exception &e) {
482  send_inv_value(msg->clid(), path);
483  LibLogger::log_warn("ConfigNetworkHandler",
484  "set string: Value %s could not be set", path);
485  LibLogger::log_warn("ConfigNetworkHandler", e);
486  }
487  break;
488  }
489  }
490 
491  if (success) {
492  try {
493  Configuration::ValueIterator *i = __config->get_value(path);
494  if ( i->next() ) {
495  send_value(msg->clid(), i);
496  } else {
497  send_inv_value(msg->clid(), path);
498  }
499  delete i;
500  } catch (ConfigurationException &e) {
501  LibLogger::log_warn("ConfigNetworkHandler",
502  "get value: Value %s could not be found", path);
503  LibLogger::log_warn("ConfigNetworkHandler", e);
504  }
505  }
506  }
507 
508 
509  msg->unref();
510  __inbound_queue.pop_locked();
511  }
512 }
513 
514 
515 /** Handle network message.
516  * The message is put into the inbound queue and processed in processAfterLoop().
517  * @param msg message
518  */
519 void
521 {
522  msg->ref();
523  __inbound_queue.push_locked(msg);
524  wakeup();
525 }
526 
527 
528 /** Client connected.
529  * Ignored.
530  * @param clid client ID
531  */
532 void
534 {
535 }
536 
537 
538 /** Client disconnected.
539  * If the client was a subscriber it is removed.
540  * @param clid client ID
541  */
542 void
544 {
545  __subscribers.lock();
546  if (find(__subscribers.begin(), __subscribers.end(), clid) != __subscribers.end()) {
547  LibLogger::log_warn("ConfigNetworkHandler",
548  "Client %u disconnected without closing the config, removing from list of subscribers",
549  clid);
550  __subscribers.remove(clid);
551  }
552  __subscribers.unlock();
553 }
554 
555 
556 /** Tag changed.
557  * Ignored.
558  * @param new_tag new tag
559  */
560 void
562 {
563 }
564 
565 
566 void
568 {
569  const char *path = v->path();
570 
571  __subscribers.lock();
572  for (__sit = __subscribers.begin(); __sit != __subscribers.end(); ++__sit) {
573  try {
574  send_value(*__sit, v);
575  } catch (Exception &e) {
576  LibLogger::log_warn("ConfigNetworkHandler",
577  "config_value_changed: Value for %s could not be sent "
578  "to client %u", path, *__sit);
579  LibLogger::log_warn("ConfigNetworkHandler", e);
580  }
581  }
582  __subscribers.unlock();
583 }
584 
585 
586 void
588 {
589 }
590 
591 
592 void
594 {
595  __subscribers.lock();
596  for (__sit = __subscribers.begin(); __sit != __subscribers.end(); ++__sit) {
597  try {
599  prepare_msg<config_value_erased_msg_t>(path, false);
600  __hub->send(*__sit, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_VALUE_ERASED,
601  r, sizeof(config_value_erased_msg_t));
602  } catch (Exception &e) {
603  LibLogger::log_warn("ConfigNetworkHandler",
604  "configValueErased: Value for %s could not be sent "
605  "to client %u", path, *__sit);
606  }
607  }
608  __subscribers.unlock();
609 }
610 
611 } // end namespace fawkes
void * payload() const
Get payload buffer.
Definition: message.cpp:321
virtual ValueIterator * iterator()=0
Iterator for all values.
void clear()
Clear the queue.
Definition: lock_queue.h:158
virtual void set_default_float(const char *path, float f)=0
Set new default value in configuration of type float.
virtual std::vector< bool > get_bools() const =0
Get list of values from configuration which is of type bool.
virtual void set_default_int(const char *path, int i)=0
Set new default value in configuration of type int.
void unref()
Decrement reference count and conditionally delete this instance.
Definition: refcount.cpp:99
void append(Configuration::ValueIterator *i)
Append from iterator.
virtual std::vector< std::string > get_strings() const =0
Get list of values from configuration which is of type string.
virtual void lock() const
Lock list.
Definition: lock_list.h:128
virtual std::vector< float > get_floats() const =0
Get list of values from configuration which is of type float.
virtual bool is_bool() const =0
Check if current value is a bool.
Fawkes library namespace.
unsigned int clid() const
Get client ID.
Definition: message.cpp:281
virtual void config_value_changed(const Configuration::ValueIterator *v)
Called whenever a watched value has changed.
config_descriptor_t cp
value descriptor
Definition: net_messages.h:112
~ConfigNetworkHandler()
Destructor.
Definition: net_handler.cpp:69
Get value message.
Definition: net_messages.h:101
virtual void add_handler(FawkesNetworkHandler *handler)=0
Add a message handler.
Interface for configuration change handling.
char path[CONFIG_MSG_PATH_LENGTH]
path to config value.
Definition: net_messages.h:93
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
Config list content.
virtual bool next()=0
Check if there is another element and advance to this if possible.
virtual std::vector< int > get_ints() const =0
Get list of values from configuration which is of type int.
virtual float get_float() const =0
Get float value.
virtual void set_int(const char *path, int i)=0
Set new value in configuration of type int.
virtual unsigned int get_uint() const =0
Get unsigned int value.
Thread class encapsulation of pthreads.
Definition: thread.h:42
virtual size_t get_list_size() const =0
Get number of elements in list value.
virtual bool is_float() const =0
Check if current value is a float.
void push_back_locked(const Type &x)
Push element to list at back with lock protection.
Definition: lock_list.h:152
virtual void set_bool(const char *path, bool b)=0
Set new value in configuration of type bool.
virtual bool is_int() const =0
Check if current value is a int.
virtual void set_floats(const char *path, std::vector< float > &f)=0
Set new value in configuration of type float.
virtual void set_strings(const char *path, std::vector< std::string > &s)=0
Set new value in configuration of type string.
virtual bool get_bool() const =0
Get bool value.
virtual void set_float(const char *path, float f)=0
Set new value in configuration of type float.
virtual int get_int() const =0
Get int value.
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
virtual bool is_string() const =0
Check if current value is a string.
void wakeup()
Wake up thread.
Definition: thread.cpp:1000
virtual void erase_default(const char *path)=0
Erase the given default value from the configuration.
virtual void erase(const char *path)=0
Erase the given value from the configuration.
virtual void set_default_bool(const char *path, bool b)=0
Set new default value in configuration of type bool.
virtual std::vector< unsigned int > get_uints() const =0
Get list of values from configuration which is of type unsigned int.
uint16_t is_default
1 if value is a default value, 0 otherwise, only for get response
Definition: net_messages.h:94
Base class for exceptions in Fawkes.
Definition: exception.h:36
virtual void send(FawkesNetworkMessage *msg)=0
Method to send a message to a specific client.
String value header indicating the string length.
Definition: net_messages.h:121
virtual void set_default_uint(const char *path, unsigned int uint)=0
Set new default value in configuration of type unsigned int.
virtual void set_bools(const char *path, std::vector< bool > &b)=0
Set new value in configuration of type bool.
virtual void rem_change_handler(ConfigurationChangeHandler *h)
Remove a configuration change handler.
Definition: config.cpp:564
virtual void set_uints(const char *path, std::vector< unsigned int > &uint)=0
Set new value in configuration of type unsigned int.
void ref()
Increment reference count.
Definition: refcount.cpp:70
virtual void unlock() const
Unlock list.
Definition: lock_list.h:144
virtual bool is_uint() const =0
Check if current value is a unsigned int.
virtual bool is_list() const =0
Check if a value is a list.
Basic config descriptor.
Definition: net_messages.h:92
virtual std::string get_string() const =0
Get string value.
Network handler abstract base class.
Definition: handler.h:31
uint16_t num_values
Number of valus in list.
Definition: net_messages.h:97
Generic configuration exception.
Definition: config.h:41
virtual const char * path() const =0
Path of value.
static void log_warn(const char *component, const char *format,...)
Log warning message.
Definition: liblogger.cpp:162
virtual void client_disconnected(unsigned int clid)
Client disconnected.
void cancel()
Cancel a thread.
Definition: thread.cpp:651
void pop_locked()
Pop element from queue with lock protection.
Definition: lock_queue.h:149
virtual void unlock()=0
Unlock the config.
virtual void client_connected(unsigned int clid)
Client connected.
unsigned short int msgid() const
Get message type ID.
Definition: message.cpp:301
Invalid value request message.
Definition: net_messages.h:106
Value erased message.
Definition: net_messages.h:116
virtual ValueIterator * get_value(const char *path)=0
Get value from configuration.
void push_locked(const Type &x)
Push element to queue with lock protection.
Definition: lock_queue.h:139
Iterator interface to iterate over config values.
Definition: config.h:72
void join()
Join the thread.
Definition: thread.cpp:610
virtual bool is_default() const =0
Check if current value was read from the default config.
uint16_t s_length
Length of following string.
Definition: net_messages.h:122
virtual void add_change_handler(ConfigurationChangeHandler *h)
Add a configuration change handler.
Definition: config.cpp:547
config_descriptor_t cp
value descriptor
Definition: net_messages.h:102
virtual void remove_handler(FawkesNetworkHandler *handler)=0
Remove a message handler.
MT * msg() const
Get correctly casted payload.
Definition: message.h:115
virtual void set_default_string(const char *path, std::string &s)=0
Set new default value in configuration of type string.
virtual void set_ints(const char *path, std::vector< int > &i)=0
Set new value in configuration of type int.
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:67
virtual void set_uint(const char *path, unsigned int uint)=0
Set new value in configuration of type unsigned int.
virtual void set_string(const char *path, std::string &s)=0
Set new value in configuration of type string.
void append(const char *format,...)
Append messages to the message list.
Definition: exception.cpp:341
virtual void lock()=0
Lock the config.
virtual void config_tag_changed(const char *new_location)
Tag changed.
void start(bool wait=true)
Call this method to start the thread.
Definition: thread.cpp:511
size_t payload_size() const
Get payload size.
Definition: message.cpp:311