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  cancel();
72  join();
73  __config->rem_change_handler(this);
74  __inbound_queue.clear();
75 }
76 
77 
78 /** Send invalid value message.
79  * @param clid client ID
80  * @param path path
81  */
82 void
83 ConfigNetworkHandler::send_inv_value(unsigned int clid, const char *path)
84 {
85  config_invval_msg_t *r = prepare_msg<config_invval_msg_t>(path, false);
86  __hub->send(clid, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_INV_VALUE, r, sizeof(config_invval_msg_t));
87 }
88 
89 
90 /** Send value.
91  * @param clid client ID
92  * @param i value
93  */
94 void
95 ConfigNetworkHandler::send_value(unsigned int clid, Configuration::ValueIterator *i)
96 {
97  if ( i->is_float() ) {
98  try {
99  config_float_value_msg_t *r = prepare_msg<config_float_value_msg_t>(i->path(), i->is_default());
100  r->f = i->get_float();
101  __hub->send(clid, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_FLOAT_VALUE, r, sizeof(config_float_value_msg_t));
102  } catch (Exception &e) {
103  LibLogger::log_warn("ConfigNetworkHandler",
104  "send_value: Value %s could not be sent",
105  i->path());
106  LibLogger::log_warn("ConfigNetworkHandler", e);
107  }
108  } else if ( i->is_uint() ) {
109  try {
110  config_uint_value_msg_t *r = prepare_msg<config_uint_value_msg_t>(i->path(), i->is_default());
111  r->u = i->get_uint();
112  __hub->send(clid, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_UINT_VALUE, r, sizeof(config_uint_value_msg_t));
113  } catch (Exception &e) {
114  LibLogger::log_warn("ConfigNetworkHandler",
115  "send_value: Value %s could not be sent",
116  i->path());
117  LibLogger::log_warn("ConfigNetworkHandler", e);
118  }
119  } else if ( i->is_int() ) {
120  try {
121  config_int_value_msg_t *r = prepare_msg<config_int_value_msg_t>(i->path(), i->is_default());
122  r->i = i->get_int();
123  __hub->send(clid, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_INT_VALUE, r, sizeof(config_int_value_msg_t));
124  } catch (Exception &e) {
125  LibLogger::log_warn("ConfigNetworkHandler",
126  "send_value: Value %s could not be sent",
127  i->path());
128  LibLogger::log_warn("ConfigNetworkHandler", e);
129  }
130  } else if ( i->is_bool() ) {
131  try {
132  config_bool_value_msg_t *r = prepare_msg<config_bool_value_msg_t>(i->path(), i->is_default());
133  r->b = (i->get_bool() ? 1 : 0);
134  __hub->send(clid, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_BOOL_VALUE, r, sizeof(config_bool_value_msg_t));
135  } catch (Exception &e) {
136  LibLogger::log_warn("ConfigNetworkHandler",
137  "send_value: Value %s could not be sent",
138  i->path());
139  LibLogger::log_warn("ConfigNetworkHandler", e);
140  }
141  } else if ( i->is_string() ) {
142  try {
143  size_t sl = sizeof(config_string_value_msg_t) + i->get_string().length();
145  strncpy(m->cp.path, i->path(), CONFIG_MSG_PATH_LENGTH);
146  m->cp.is_default = i->is_default() ? 1 : 0;
147  m->s_length = i->get_string().length();
148  strcpy(m->s, i->get_string().c_str());
149  __hub->send(clid, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_STRING_VALUE, m, sl);
150  } catch (Exception &e) {
151  LibLogger::log_warn("ConfigNetworkHandler",
152  "send_value: Value %s could not be sent",
153  i->path());
154  LibLogger::log_warn("ConfigNetworkHandler", e);
155  }
156  }
157 }
158 
159 
160 /** Process all network messages that have been received. */
161 void
163 {
164  while ( ! __inbound_queue.empty() ) {
165  FawkesNetworkMessage *msg = __inbound_queue.front();
166 
167  // printf("Received message of type %u\n", msg->msgid());
168 
169  if (msg->msgid() == MSG_CONFIG_SUBSCRIBE) {
170 
171  __subscribers.push_back_locked(msg->clid());
172  __subscribers.sort();
173  __subscribers.unique();
174 
175  __config->lock();
176  ConfigListContent *content = new ConfigListContent();
178  while ( i->next() ) {
179  content->append(i);
180  }
181  delete i;
182  i = __config->iterator_hostspecific();
183  while ( i->next() ) {
184  content->append(i);
185  }
186  delete i;
187  __hub->send(msg->clid(), FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_LIST, content);
188  __config->unlock();
189 
190  } else if (msg->msgid() == MSG_CONFIG_ERASE_VALUE) {
191  try {
193  char path[CONFIG_MSG_PATH_LENGTH + 1];
194  path[CONFIG_MSG_PATH_LENGTH] = 0;
195  strncpy(path, m->cp.path, CONFIG_MSG_PATH_LENGTH);
196 
197  if ( m->cp.is_default == 1 ) {
198  __config->erase_default(path);
199  } else {
200  __config->erase(path);
201  }
202 
203  config_value_erased_msg_t *r = prepare_msg<config_value_erased_msg_t>(path, (m->cp.is_default == 1));
204  __hub->send(msg->clid(), FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_VALUE_ERASED,
205  r, sizeof(config_value_erased_msg_t));
206 
207  } catch (Exception &e) {
208  send_inv_value(msg->clid(), "?");
209  e.append("Failed to erase value");
210  LibLogger::log_warn("ConfigNetworkHandler", "Failed to erase value");
211  LibLogger::log_warn("ConfigNetworkHandler", e);
212  }
213 
214  } else if ( (msg->msgid() >= MSG_CONFIG_GET_BEGIN) &&
215  (msg->msgid() <= MSG_CONFIG_GET_END) ) {
216 
217  if ( msg->payload_size() != sizeof(config_getval_msg_t) ) {
218  LibLogger::log_warn("ConfigNetworkHandler",
219  "CONFIG_GET_FLOAT: invalid payload size "
220  "(received %zu instead of %zu bytes",
221  msg->payload_size(), sizeof(config_getval_msg_t));
222  } else {
224  char path[CONFIG_MSG_PATH_LENGTH + 1];
225  path[CONFIG_MSG_PATH_LENGTH] = 0;
226  strncpy(path, m->cp.path, CONFIG_MSG_PATH_LENGTH);
227 
228  switch (msg->msgid()) {
229  case MSG_CONFIG_GET_FLOAT:
230  try {
231  float f = __config->get_float(path);
232  bool d = __config->is_default(path);
233  config_float_value_msg_t *r = prepare_msg<config_float_value_msg_t>(path, d);
234  r->f = f;
235  __hub->send(msg->clid(), FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_FLOAT_VALUE,
236  r, sizeof(config_float_value_msg_t));
237  } catch (Exception &e) {
238  send_inv_value(msg->clid(), path);
239  LibLogger::log_warn("ConfigNetworkHandler",
240  "get float: Value %s could not be found", path);
241  LibLogger::log_warn("ConfigNetworkHandler", e);
242  }
243  break;
244 
245  case MSG_CONFIG_GET_UINT:
246  try {
247  unsigned int u = __config->get_uint(path);
248  bool d = __config->is_default(path);
249  config_uint_value_msg_t *r = prepare_msg<config_uint_value_msg_t>(path, d);
250  r->u = u;
251  __hub->send(msg->clid(), FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_UINT_VALUE,
252  r, sizeof(config_uint_value_msg_t));
253  } catch (Exception &e) {
254  send_inv_value(msg->clid(), path);
255  LibLogger::log_warn("ConfigNetworkHandler",
256  "get uint: Value %s could not be found", path);
257  LibLogger::log_warn("ConfigNetworkHandler", e);
258  }
259  break;
260 
261  case MSG_CONFIG_GET_INT:
262  try {
263  int i = __config->get_int(path);
264  bool d = __config->is_default(path);
265  config_int_value_msg_t *r = prepare_msg<config_int_value_msg_t>(path, d);
266  r->i = i;
267  __hub->send(msg->clid(), FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_INT_VALUE,
268  r, sizeof(config_int_value_msg_t));
269  } catch (Exception &e) {
270  send_inv_value(msg->clid(), path);
271  LibLogger::log_warn("ConfigNetworkHandler",
272  "get int: Value %s could not be found", path);
273  LibLogger::log_warn("ConfigNetworkHandler", e);
274  }
275  break;
276 
277  case MSG_CONFIG_GET_BOOL:
278  try {
279  bool b = __config->get_bool(path);
280  bool d = __config->is_default(path);
281  config_bool_value_msg_t *r = prepare_msg<config_bool_value_msg_t>(path, d);
282  r->b = b;
283  __hub->send(msg->clid(), FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_BOOL_VALUE,
284  r, sizeof(config_bool_value_msg_t));
285  } catch (Exception &e) {
286  send_inv_value(msg->clid(), path);
287  LibLogger::log_warn("ConfigNetworkHandler",
288  "get bool: Value %s could not be found", path);
289  LibLogger::log_warn("ConfigNetworkHandler", e);
290  }
291  break;
292 
293  case MSG_CONFIG_GET_STRING:
294  try {
295  std::string s = __config->get_string(path);
296  bool d = __config->is_default(path);
297  config_string_value_msg_t *r = prepare_string_msg<config_string_value_msg_t>(path, d, s.length());
298  strcpy(r->s, s.c_str());
299  __hub->send(msg->clid(), FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_STRING_VALUE,
300  r, sizeof(config_string_value_msg_t));
301  } catch (Exception &e) {
302  send_inv_value(msg->clid(), path);
303  LibLogger::log_warn("ConfigNetworkHandler",
304  "get string: Value %s could not be found", path);
305  LibLogger::log_warn("ConfigNetworkHandler", e);
306  }
307  break;
308 
309  case MSG_CONFIG_GET_VALUE:
310  try {
311  Configuration::ValueIterator *i = __config->get_value(path);
312  if ( i->next() ) {
313  send_value(msg->clid(), i);
314  } else {
315  send_inv_value(msg->clid(), path);
316  }
317  delete i;
318  } catch (ConfigurationException &e) {
319  LibLogger::log_warn("ConfigNetworkHandler",
320  "get value: Value %s could not be found", path);
321  LibLogger::log_warn("ConfigNetworkHandler", e);
322  }
323  break;
324 
325  }
326  }
327  } else if ( (msg->msgid() >= MSG_CONFIG_SET_BEGIN) &&
328  (msg->msgid() <= MSG_CONFIG_SET_END) ) {
329 
330  char path[CONFIG_MSG_PATH_LENGTH + 1];
331  if ( msg->payload_size() < sizeof(config_descriptor_t)) {
332  LibLogger::log_warn("ConfigNetworkHandler",
333  "inbound set: payload is too small"
334  "(%zu is less than %zu bytes",
335  msg->payload_size(), sizeof(config_descriptor_t));
336  send_inv_value(msg->clid(), "?");
337  } else {
339  path[CONFIG_MSG_PATH_LENGTH] = 0;
340  strncpy(path, d->path, CONFIG_MSG_PATH_LENGTH);
341 
342  switch (msg->msgid()) {
343  case MSG_CONFIG_SET_FLOAT:
344  case MSG_CONFIG_SET_DEFAULT_FLOAT:
345  try {
347  if ( msg->msgid() == MSG_CONFIG_SET_FLOAT ) {
348  __config->set_float(path, m->f);
349  } else {
350  __config->set_default_float(path, m->f);
351  }
352  float f = __config->get_float(path);
353  config_float_value_msg_t *r = prepare_msg<config_float_value_msg_t>(path, (msg->msgid() == MSG_CONFIG_SET_DEFAULT_FLOAT));
354  r->f = f;
355  __hub->send(msg->clid(), FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_FLOAT_VALUE,
356  r, sizeof(config_float_value_msg_t));
357  } catch (Exception &e) {
358  send_inv_value(msg->clid(), path);
359  LibLogger::log_warn("ConfigNetworkHandler",
360  "set float: Value %s could not be set", path);
361  LibLogger::log_warn("ConfigNetworkHandler", e);
362  }
363  break;
364 
365  case MSG_CONFIG_SET_UINT:
366  case MSG_CONFIG_SET_DEFAULT_UINT:
367  try {
369  if ( msg->msgid() == MSG_CONFIG_SET_UINT ) {
370  __config->set_uint(path, m->u);
371  } else {
372  __config->set_default_uint(path, m->u);
373  }
374  unsigned int u = __config->get_uint(path);
375  config_uint_value_msg_t *r = prepare_msg<config_uint_value_msg_t>(path, (msg->msgid() == MSG_CONFIG_SET_DEFAULT_UINT));
376  r->u = u;
377  __hub->send(msg->clid(), FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_UINT_VALUE,
378  r, sizeof(config_uint_value_msg_t));
379  } catch (Exception &e) {
380  send_inv_value(msg->clid(), path);
381  LibLogger::log_warn("ConfigNetworkHandler",
382  "set uint: Value %s could not be set", path);
383  LibLogger::log_warn("ConfigNetworkHandler", e);
384  }
385  break;
386 
387  case MSG_CONFIG_SET_INT:
388  case MSG_CONFIG_SET_DEFAULT_INT:
389  try {
391  if ( msg->msgid() == MSG_CONFIG_SET_INT ) {
392  __config->set_int(path, m->i);
393  } else {
394  __config->set_default_int(path, m->i);
395  }
396  int i = __config->get_int(path);
397  config_int_value_msg_t *r = prepare_msg<config_int_value_msg_t>(path, (msg->msgid() == MSG_CONFIG_SET_DEFAULT_INT));
398  r->i = i;
399  __hub->send(msg->clid(), FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_INT_VALUE,
400  r, sizeof(config_int_value_msg_t));
401  } catch (Exception &e) {
402  send_inv_value(msg->clid(), path);
403  LibLogger::log_warn("ConfigNetworkHandler",
404  "set int: Value %s could not be set", path);
405  LibLogger::log_warn("ConfigNetworkHandler", e);
406  }
407  break;
408 
409  case MSG_CONFIG_SET_BOOL:
410  case MSG_CONFIG_SET_DEFAULT_BOOL:
411  try {
413  if ( msg->msgid() == MSG_CONFIG_SET_BOOL ) {
414  __config->set_bool(path, (m->b != 0));
415  } else {
416  __config->set_default_bool(path, (m->b != 0));
417  }
418  bool b = __config->get_bool(path);
419  config_bool_value_msg_t *r = prepare_msg<config_bool_value_msg_t>(path, (msg->msgid() == MSG_CONFIG_SET_DEFAULT_BOOL));
420  r->b = (b ? 1 : 0);
421  __hub->send(msg->clid(), FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_BOOL_VALUE,
422  r, sizeof(config_bool_value_msg_t));
423  } catch (Exception &e) {
424  send_inv_value(msg->clid(), path);
425  LibLogger::log_warn("ConfigNetworkHandler",
426  "set bool: Value %s could not be set", path);
427  LibLogger::log_warn("ConfigNetworkHandler", e);
428  }
429  break;
430 
431  case MSG_CONFIG_SET_STRING:
432  case MSG_CONFIG_SET_DEFAULT_STRING:
433  try {
435  if ( msg->msgid() == MSG_CONFIG_SET_STRING ) {
436  __config->set_string(path, m->s);
437  } else {
438  __config->set_default_string(path, m->s);
439  }
440  std::string s = __config->get_string(path);
441  size_t s_length = s.length();
442  config_string_value_msg_t *r = prepare_string_msg<config_string_value_msg_t>(path, (msg->msgid() == MSG_CONFIG_SET_DEFAULT_STRING), s_length);
443  strcpy(r->s, s.c_str());
444  __hub->send(msg->clid(), FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_STRING_VALUE,
445  r, sizeof(config_string_value_msg_t) + s_length);
446  } catch (Exception &e) {
447  send_inv_value(msg->clid(), path);
448  LibLogger::log_warn("ConfigNetworkHandler",
449  "set string: Value %s could not be set", path);
450  LibLogger::log_warn("ConfigNetworkHandler", e);
451  }
452  break;
453 
454  case MSG_CONFIG_SET_COMMENT:
455  case MSG_CONFIG_SET_DEFAULT_COMMENT:
456  try {
458  std::string s = "";
459  if ( msg->msgid() == MSG_CONFIG_SET_COMMENT ) {
460  __config->set_comment(path, m->s);
461  s = __config->get_comment(path);
462  } else {
463  __config->set_default_comment(path, m->s);
464  s = __config->get_default_comment(path);
465  }
466  size_t s_length = s.length();
467  config_comment_msg_t *r = prepare_string_msg<config_comment_msg_t>(path, (msg->msgid() == MSG_CONFIG_SET_DEFAULT_COMMENT), s_length);
468  strcpy(r->s, s.c_str());
469  __hub->send(msg->clid(), FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_COMMENT_VALUE,
470  r, sizeof(config_comment_msg_t) + s_length);
471  } catch (Exception &e) {
472  send_inv_value(msg->clid(), path);
473  LibLogger::log_warn("ConfigNetworkHandler",
474  "set comment: Value %s could not be set", path);
475  LibLogger::log_warn("ConfigNetworkHandler", e);
476  }
477  break;
478 
479  }
480  }
481  }
482 
483 
484  msg->unref();
485  __inbound_queue.pop_locked();
486  }
487 }
488 
489 
490 /** Handle network message.
491  * The message is put into the inbound queue and processed in processAfterLoop().
492  * @param msg message
493  */
494 void
496 {
497  msg->ref();
498  __inbound_queue.push_locked(msg);
499  wakeup();
500 }
501 
502 
503 /** Client connected.
504  * Ignored.
505  * @param clid client ID
506  */
507 void
509 {
510 }
511 
512 
513 /** Client disconnected.
514  * If the client was a subscriber it is removed.
515  * @param clid client ID
516  */
517 void
519 {
520  __subscribers.lock();
521  if (find(__subscribers.begin(), __subscribers.end(), clid) != __subscribers.end()) {
522  LibLogger::log_warn("ConfigNetworkHandler",
523  "Client %u disconnected without closing the config, removing from list of subscribers",
524  clid);
525  __subscribers.remove(clid);
526  }
527  __subscribers.unlock();
528 }
529 
530 
531 /** Tag changed.
532  * Ignored.
533  * @param new_tag new tag
534  */
535 void
537 {
538 }
539 
540 
541 void
543 {
544  const char *path = v->path();
545  bool is_default = v->is_default();
546 
547  __subscribers.lock();
548  for (__sit = __subscribers.begin(); __sit != __subscribers.end(); ++__sit) {
549  try {
550  if (v->is_string()) {
551  std::string value = v->get_string();
552  size_t s_length = value.length();
554  prepare_string_msg<config_string_value_msg_t>(path, is_default,
555  s_length);
556  strcpy(r->s, value.c_str());
557  __hub->send(*__sit, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_STRING_VALUE,
558  r, sizeof(config_string_value_msg_t) + s_length);
559  } else if (v->is_bool()) {
560  bool value = v->get_bool();
562  prepare_msg<config_bool_value_msg_t>(path, is_default);
563  r->b = (value ? 1 : 0);
564  __hub->send(*__sit, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_BOOL_VALUE,
565  r, sizeof(config_bool_value_msg_t));
566  } else if (v->is_int()) {
567  int value = v->get_int();
569  prepare_msg<config_int_value_msg_t>(path, is_default);
570  r->i = value;
571  __hub->send(*__sit, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_INT_VALUE,
572  r, sizeof(config_int_value_msg_t));
573  } else if (v->is_uint()) {
574  unsigned int value = v->get_uint();
576  prepare_msg<config_uint_value_msg_t>(path, is_default);
577  r->u = value;
578  __hub->send(*__sit, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_UINT_VALUE,
579  r, sizeof(config_uint_value_msg_t));
580  } else if (v->is_float()) {
581  float value = v->get_float();
583  prepare_msg<config_float_value_msg_t>(path, is_default);
584  r->f = value;
585  __hub->send(*__sit, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_FLOAT_VALUE,
586  r, sizeof(config_float_value_msg_t));
587  }
588 
589  } catch (Exception &e) {
590  LibLogger::log_warn("ConfigNetworkHandler",
591  "config_value_changed: Value for %s could not be sent "
592  "to client %u", path, *__sit);
593  LibLogger::log_warn("ConfigNetworkHandler", e);
594  }
595  }
596  __subscribers.unlock();
597 }
598 
599 
600 void
602 {
603  const char *path = v->path();
604  bool is_default = v->is_default();
605  std::string comment = v->get_comment();
606  __subscribers.lock();
607  for (__sit = __subscribers.begin(); __sit != __subscribers.end(); ++__sit) {
608  try {
609  size_t s_length = comment.length();
611  prepare_string_msg<config_comment_msg_t>(path, is_default, s_length);
612  strcpy(r->s, comment.c_str());
613 
614  __hub->send(*__sit, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_COMMENT_VALUE,
615  r, sizeof(config_comment_msg_t) + s_length);
616  } catch (Exception &e) {
617  LibLogger::log_warn("ConfigNetworkHandler",
618  "config_comment_changed[string]: Value for %s could "
619  "not be sent to client %u", path, *__sit);
620  LibLogger::log_warn("ConfigNetworkHandler", e);
621  }
622  }
623  __subscribers.unlock();
624 }
625 
626 
627 void
629 {
630  __subscribers.lock();
631  for (__sit = __subscribers.begin(); __sit != __subscribers.end(); ++__sit) {
632  try {
634  prepare_msg<config_value_erased_msg_t>(path, false);
635  __hub->send(*__sit, FAWKES_CID_CONFIGMANAGER, MSG_CONFIG_VALUE_ERASED,
636  r, sizeof(config_value_erased_msg_t));
637  } catch (Exception &e) {
638  LibLogger::log_warn("ConfigNetworkHandler",
639  "configValueErased: Value for %s could not be sent "
640  "to client %u", path, *__sit);
641  }
642  }
643  __subscribers.unlock();
644 }
645 
646 } // end namespace fawkes
virtual std::string get_default_comment(const char *path)=0
Get comment of value at given path.
virtual bool is_float() const =0
Check if current value is a float.
uint32_t is_default
1 if value is a default value, 0 otherwise, only for get response
Definition: net_messages.h:94
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 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 void set_default_comment(const char *path, const char *comment)=0
Set new default comment for existing default configuration value.
virtual bool is_bool() const =0
Check if current value is a bool.
virtual bool is_default(const char *path)=0
Check if a value was read from the default config.
Fawkes library namespace.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
virtual void config_value_changed(const Configuration::ValueIterator *v)
Called whenever a watched value has changed.
virtual void unlock() const
Unlock list.
Definition: lock_list.h:144
void * payload() const
Get payload buffer.
Definition: message.cpp:321
config_descriptor_t cp
value descriptor
Definition: net_messages.h:111
~ConfigNetworkHandler()
Destructor.
Definition: net_handler.cpp:69
Get value message.
Definition: net_messages.h:100
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 std::string get_string() const =0
Get string value.
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
virtual bool is_string() const =0
Check if current value is a string.
virtual bool is_uint() const =0
Check if current value is a unsigned int.
unsigned short int msgid() const
Get message type ID.
Definition: message.cpp:301
Config list content.
virtual bool next()=0
Check if there is another element and advance to this if possible.
virtual void set_int(const char *path, int i)=0
Set new value in configuration of type int.
virtual float get_float() const =0
Get float value.
Thread class encapsulation of pthreads.
Definition: thread.h:42
uint16_t s_length
Length of following string.
Definition: net_messages.h:146
virtual void lock() const
Lock list.
Definition: lock_list.h:128
virtual ValueIterator * iterator_hostspecific()=0
Iterator for all host-specific values.
virtual const char * path() const =0
Path of value.
virtual int get_int(const char *path)=0
Get value from configuration which is of type int.
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 void set_float(const char *path, float f)=0
Set new value in configuration of type float.
config_descriptor_t cp
value descriptor
Definition: net_messages.h:145
virtual void loop()
Process all network messages that have been received.
Fawkes Network Hub.
Definition: hub.h:33
virtual unsigned int get_uint() const =0
Get unsigned int value.
size_t payload_size() const
Get payload size.
Definition: message.cpp:311
String value message.
Definition: net_messages.h:144
ConfigNetworkHandler(Configuration *config, FawkesNetworkHub *hub)
Constructor.
Definition: net_handler.cpp:52
char s[2]
string value, 0-terminated
Definition: net_messages.h:147
MT * msgge() const
Get correctly casted payload.
Definition: message.h:134
void wakeup()
Wake up thread.
Definition: thread.cpp:979
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.
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.
virtual void set_default_uint(const char *path, unsigned int uint)=0
Set new default value in configuration of type unsigned int.
virtual bool is_int() const =0
Check if current value is a int.
virtual std::string get_comment() const =0
Get comment of value.
virtual void rem_change_handler(ConfigurationChangeHandler *h)
Remove a configuration change handler.
Definition: config.cpp:496
void ref()
Increment reference count.
Definition: refcount.cpp:70
Basic config descriptor.
Definition: net_messages.h:92
Unsigned int value message.
Definition: net_messages.h:126
virtual bool get_bool() const =0
Get bool value.
Network handler abstract base class.
Definition: handler.h:31
Generic configuration exception.
Definition: config.h:37
static void log_warn(const char *component, const char *format,...)
Log warning message.
Definition: liblogger.cpp:160
virtual void client_disconnected(unsigned int clid)
Client disconnected.
void cancel()
Cancel a thread.
Definition: thread.cpp:640
void pop_locked()
Pop element from queue with lock protection.
Definition: lock_queue.h:149
virtual void unlock()=0
Unlock the config.
virtual ValueIterator * iterator_default()=0
Iterator for all default values.
virtual void client_connected(unsigned int clid)
Client connected.
MT * msg() const
Get correctly casted payload.
Definition: message.h:115
Invalid value request message.
Definition: net_messages.h:105
Integer value message.
Definition: net_messages.h:132
Value erased message.
Definition: net_messages.h:115
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:68
void join()
Join the thread.
Definition: thread.cpp:599
char s[2]
comment, 0-terminated
Definition: net_messages.h:155
virtual void add_change_handler(ConfigurationChangeHandler *h)
Add a configuration change handler.
Definition: config.cpp:479
config_descriptor_t cp
value descriptor
Definition: net_messages.h:101
virtual unsigned int get_uint(const char *path)=0
Get value from configuration which is of type unsigned int.
virtual void set_default_string(const char *path, std::string &s)=0
Set new default value in configuration of type string.
virtual void config_comment_changed(const Configuration::ValueIterator *v)
Called whenever a comment of a watched value has changed.
virtual std::string get_comment(const char *path)=0
Get comment of value at given path.
Interface for configuration handling.
Definition: config.h:63
virtual void set_comment(const char *path, const char *comment)=0
Set new comment for existing value.
virtual float get_float(const char *path)=0
Get value from configuration which is of type float.
virtual bool is_default() const =0
Check if current value was read from the default config.
Boolean value message.
Definition: net_messages.h:138
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 std::string get_string(const char *path)=0
Get value from configuration which is of type string.
virtual void lock()=0
Lock the config.
unsigned int clid() const
Get client ID.
Definition: message.cpp:281
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:507
virtual int get_int() const =0
Get int value.