Fawkes API  Fawkes Development Version
netconf.cpp
1 
2 /***************************************************************************
3  * netconf.cpp - Fawkes remote configuration access via Fawkes net
4  *
5  * Created: Sun Jan 07 15:04:41 2007
6  * Copyright 2006-2009 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/netconf.h>
25 #include <config/net_messages.h>
26 #include <config/memory.h>
27 #include <config/net_list_content.h>
28 
29 #include <core/threading/mutex.h>
30 #include <core/threading/interruptible_barrier.h>
31 #include <netcomm/fawkes/client.h>
32 #include <netcomm/fawkes/message.h>
33 #include <netcomm/utils/exceptions.h>
34 
35 #include <logging/liblogger.h>
36 #include <utils/misc/string_conversions.h>
37 
38 #ifndef _GNU_SOURCE
39 #define _GNU_SOURCE
40 #endif
41 #include <cstring>
42 #include <cstdlib>
43 
44 namespace fawkes {
45 
46 /** @class CannotEnableMirroringException <config/netconf.h>
47  * Thrown if enabling mirror mode failed.
48  */
49 
50 /** Constructor.
51  * @param msg message describing the problem
52  */
54  : Exception("Could not enable mirroring: %s", msg)
55 {
56 }
57 
58 
59 /** @class NetworkConfiguration <config/netconf.h>
60  * Remote configuration via Fawkes net.
61  * This implementation of the Configuration interface allows for remote access
62  * to a Fawkes process implemented using the ConfigurationManager.
63  *
64  * The network configuration can operator in two modes. In mirror and in non-mirror
65  * mode. The non-mirror mode is recommended if only a few operations have to be
66  * carried out like getting only a very few values or setting a single value.
67  * The mirror mode is for longer usage periods and on-the-fly updates. In mirror
68  * mode the complete configuration is copied once from the Fawkes process and then
69  * all updates are incorporated into the local database. You can register change
70  * handlers to be notified as soon as someone modifies a value.
71  *
72  */
73 
74 /** Constructor.
75  * @param c Fawkes network client (thread).
76  * @param mirror_timeout_sec timeout in seconds for initiating mirroring
77  */
79  unsigned int mirror_timeout_sec)
80 {
81  __mirror_timeout_sec = mirror_timeout_sec;
82  mutex = new Mutex();
83  msg = NULL;
84  __mirror_mode = false;
85  __mirror_mode_before_connection_dead = false;
86  __mirror_init_waiting = false;
87  __mirror_init_barrier = new InterruptibleBarrier(2);
88 
89  __connected = c->connected();
90  this->c = c;
91  try {
92  c->register_handler(this, FAWKES_CID_CONFIGMANAGER);
93  } catch (Exception &e) {
94  e.append("Failed to register for config manager component on network client");
95  throw;
96  }
97 }
98 
99 
100 /** Destructor. */
102 {
103  set_mirror_mode(false);
104  c->deregister_handler(FAWKES_CID_CONFIGMANAGER);
105  if (msg != NULL) {
106  msg->unref();
107  }
108  delete __mirror_init_barrier;
109  delete mutex;
110 }
111 
112 
113 void
114 NetworkConfiguration::load(const char *file_path)
115 {
116 }
117 
118 
119 /** Copy all values from the given configuration.
120  * All values from the given configuration are copied. Old values are not erased
121  * so that the copied values will overwrite existing values, new values are
122  * created, but values existent in current config but not in the copie config
123  * will remain unchanged.
124  * @param copyconf configuration to copy
125  */
126 void
128 {
129  copyconf->lock();
130  Configuration::ValueIterator *i = copyconf->iterator();
131  while ( i->next() ) {
132  if ( i->is_float() ) {
133  set_float(i->path(), i->get_float());
134  } else if ( i->is_int() ) {
135  set_int(i->path(), i->get_int());
136  } else if ( i->is_uint() ) {
137  set_uint(i->path(), i->get_uint());
138  } else if ( i->is_bool() ) {
139  set_bool(i->path(), i->get_bool());
140  } else if ( i->is_string() ) {
141  std::string s = i->get_string();
142  set_string(i->path(), s);
143  }
144  }
145  delete i;
146  copyconf->unlock();
147 }
148 
149 bool
151 {
152  ValueIterator *i = get_value(path);
153  bool rv = i->valid();
154  delete i;
155  return rv;
156 }
157 
158 
159 bool
161 {
162  ValueIterator *i = get_value(path);
163  bool rv = i->is_default();
164  delete i;
165  return rv;
166 }
167 
168 
169 /** Get type of field.
170  * @param path path
171  * @return string of type
172  */
173 std::string
175 {
176  std::string s = "";
177  mutex->lock();
178  if ( __mirror_mode ) {
179  s = mirror_config->get_type(path);
180  mutex->unlock();
181  } else {
182  mutex->unlock();
183  Configuration::ValueIterator *i = get_value(path);
184  s = i->type();
185  delete i;
186  }
187  return s;
188 }
189 
190 
191 bool
193 {
194  return (get_type(path) == "float");
195 }
196 
197 
198 bool
200 {
201  return (get_type(path) == "unsigned int");
202 }
203 
204 
205 bool
207 {
208  return (get_type(path) == "int");
209 }
210 
211 
212 bool
214 {
215  return (get_type(path) == "bool");
216 }
217 
218 
219 bool
221 {
222  return (get_type(path) == "string");
223 }
224 
225 bool
227 {
228  return false;
229 }
230 
231 void
232 NetworkConfiguration::send_get(const char *path, unsigned int msgid, unsigned int expected_reply)
233 {
234  if ( ! __connected ) {
235  throw ConnectionDiedException("NetworkConfiguration: Cannot send get, "
236  "client connection is not alive");
237  }
239  strncpy(g->cp.path, path, CONFIG_MSG_PATH_LENGTH);
240  FawkesNetworkMessage *omsg = new FawkesNetworkMessage(FAWKES_CID_CONFIGMANAGER,
241  msgid,
242  g, sizeof(config_getval_msg_t));
243  c->enqueue_and_wait(omsg);
244 
245  if ( ! msg ) {
246  mutex->unlock();
247  throw NullPointerException("NetworkConfiguration::send_get: msg == NULL");
248  }
249 
250  if ( msg->msgid() != expected_reply ) {
251  unsigned int msg_msgid = msg->msgid();
252  msg->unref();
253  msg = NULL;
254  mutex->unlock();
255  throw Exception("NetworkConfiguration::send_get: expected %u, but got %u",
256  expected_reply, msg_msgid);
257  }
258 }
259 
260 
261 float
263 {
264  if ( strlen(path) > CONFIG_MSG_PATH_LENGTH ) {
265  throw OutOfBoundsException("NetworkConfiguration::get_float: "
266  "Maximum length for path exceeded");
267  }
268  if ( ! __connected ) {
269  throw ConnectionDiedException("NetworkConfiguration: Cannot send get, "
270  "client connection is not alive");
271  }
272 
273  float f;
274  mutex->lock();
275 
276  if ( __mirror_mode ) {
277  try {
278  f = mirror_config->get_float(path);
279  } catch (Exception &e) {
280  e.append("NetworkConfiguration[mirroring]::get_float: exception in mirror database");
281  mutex->unlock();
282  throw;
283  }
284  } else {
285  try {
286  send_get(path, MSG_CONFIG_GET_FLOAT, MSG_CONFIG_FLOAT_VALUE);
287 
288  config_descriptor_t *d = msg->msgge<config_descriptor_t>();
289  if (d->num_values > 0) {
290  msg->unref();
291  msg = NULL;
292  throw Exception("NetworkConfiguration: received list of and not a single value");
293  }
294  f = *(float *)((char *)msg->payload() + sizeof(config_descriptor_t));
295 
296  msg->unref();
297  msg = NULL;
298 
299  } catch (Exception &e) {
300  e.append("NetworkConfiguration::get_float: Fetching float failed");
301  if ( msg != NULL ) {
302  msg->unref();
303  msg = NULL;
304  }
305  mutex->unlock();
306  throw;
307  }
308  }
309 
310  mutex->unlock();
311 
312  return f;
313 }
314 
315 
316 unsigned int
318 {
319  if ( strlen(path) > CONFIG_MSG_PATH_LENGTH ) {
320  throw OutOfBoundsException("NetworkConfiguration::get_uint: "
321  "Maximum length for path exceeded");
322  }
323  if ( ! __connected ) {
324  throw ConnectionDiedException("NetworkConfiguration: Cannot send get, "
325  "client connection is not alive");
326  }
327 
328  unsigned int u;
329  mutex->lock();
330 
331  if ( __mirror_mode ) {
332  try {
333  u = mirror_config->get_uint(path);
334  } catch (Exception &e) {
335  e.append("NetworkConfiguration[mirroring]::get_uint: exception in mirror database");
336  mutex->unlock();
337  throw;
338  }
339  } else {
340  try {
341  send_get(path, MSG_CONFIG_GET_UINT, MSG_CONFIG_UINT_VALUE);
342 
343  config_descriptor_t *d = msg->msgge<config_descriptor_t>();
344  if (d->num_values > 0) {
345  msg->unref();
346  msg = NULL;
347  throw Exception("NetworkConfiguration: received list of and not a single value");
348  }
349  u = *(uint32_t *)((char *)msg->payload() + sizeof(config_descriptor_t));
350 
351  msg->unref();
352  msg = NULL;
353 
354  } catch (Exception &e) {
355  e.append("NetworkConfiguration::get_uint: Fetching unsigned int failed");
356  if ( msg != NULL ) {
357  msg->unref();
358  msg = NULL;
359  }
360  mutex->unlock();
361  throw;
362  }
363  }
364 
365  mutex->unlock();
366 
367  return u;
368 }
369 
370 
371 int
373 {
374  if ( strlen(path) > CONFIG_MSG_PATH_LENGTH ) {
375  throw OutOfBoundsException("NetworkConfiguration::get_int: "
376  "Maximum length for path exceeded");
377  }
378  if ( ! __connected ) {
379  throw ConnectionDiedException("NetworkConfiguration: Cannot send get, "
380  "client connection is not alive");
381  }
382 
383  int i;
384  mutex->lock();
385 
386  if ( __mirror_mode ) {
387  try {
388  i = mirror_config->get_int(path);
389  } catch (Exception &e) {
390  e.append("NetworkConfiguration[mirroring]::get_int: exception in mirror database");
391  mutex->unlock();
392  throw;
393  }
394  } else {
395  try {
396  send_get(path, MSG_CONFIG_GET_INT, MSG_CONFIG_INT_VALUE);
397 
398  config_descriptor_t *d = msg->msgge<config_descriptor_t>();
399  if (d->num_values > 0) {
400  msg->unref();
401  msg = NULL;
402  throw Exception("NetworkConfiguration: received list of and not a single value");
403  }
404  i = *(int32_t *)((char *)msg->payload() + sizeof(config_descriptor_t));
405 
406  msg->unref();
407  msg = NULL;
408 
409  } catch (Exception &e) {
410  e.append("NetworkConfiguration::get_int: Fetching int failed");
411  if ( msg != NULL ) {
412  msg->unref();
413  msg = NULL;
414  }
415  mutex->unlock();
416  throw;
417  }
418  }
419 
420  mutex->unlock();
421 
422  return i;
423 }
424 
425 
426 bool
428 {
429  if ( strlen(path) > CONFIG_MSG_PATH_LENGTH ) {
430  throw OutOfBoundsException("NetworkConfiguration::get_bool: "
431  "Maximum length for path exceeded");
432  }
433  if ( ! __connected ) {
434  throw ConnectionDiedException("NetworkConfiguration: Cannot send get, "
435  "client connection is not alive");
436  }
437 
438  bool b;
439  mutex->lock();
440 
441  if ( __mirror_mode ) {
442  try {
443  b = mirror_config->get_bool(path);
444  } catch (Exception &e) {
445  e.append("NetworkConfiguration[mirroring]::get_bool: exception in mirror database");
446  mutex->unlock();
447  throw;
448  }
449  } else {
450  try {
451  send_get(path, MSG_CONFIG_GET_BOOL, MSG_CONFIG_BOOL_VALUE);
452 
453  config_descriptor_t *d = msg->msgge<config_descriptor_t>();
454  if (d->num_values > 0) {
455  msg->unref();
456  msg = NULL;
457  throw Exception("NetworkConfiguration: received list of and not a single value");
458  }
459  b = (*(int32_t *)((char *)msg->payload() + sizeof(config_descriptor_t)) != 0);
460 
461  msg->unref();
462  msg = NULL;
463 
464  } catch (Exception &e) {
465  e.append("NetworkConfiguration::get_bool: Fetching bool failed");
466  if ( msg != NULL ) {
467  msg->unref();
468  msg = NULL;
469  }
470  mutex->unlock();
471  throw;
472  }
473  }
474 
475  mutex->unlock();
476 
477  return b;
478 }
479 
480 
481 std::string
483 {
484  if ( strlen(path) > CONFIG_MSG_PATH_LENGTH ) {
485  throw OutOfBoundsException("NetworkConfiguration::get_string: "
486  "Maximum length for path exceeded");
487  }
488  if ( ! __connected ) {
489  throw ConnectionDiedException("NetworkConfiguration: Cannot send get, "
490  "client connection is not alive");
491  }
492 
493  std::string s;
494  mutex->lock();
495 
496  if ( __mirror_mode ) {
497  try {
498  s = mirror_config->get_string(path);
499  } catch (Exception &e) {
500  e.append("NetworkConfiguration[mirroring]::get_string: exception in mirror database");
501  mutex->unlock();
502  throw;
503  }
504  } else {
505  try {
506  send_get(path, MSG_CONFIG_GET_STRING, MSG_CONFIG_STRING_VALUE);
507 
508  config_descriptor_t *d = msg->msgge<config_descriptor_t>();
509  if (d->num_values > 0) {
510  msg->unref();
511  msg = NULL;
512  throw Exception("NetworkConfiguration: received list of and not a single value");
513  }
515  (config_string_value_t *)((char *)msg->payload() + sizeof(config_descriptor_t));
516  s = std::string((char *)sv + sizeof(config_string_value_t), sv->s_length);
517 
518  msg->unref();
519  msg = NULL;
520 
521  } catch (Exception &e) {
522  e.append("NetworkConfiguration::get_string: Fetching string failed");
523  if ( msg != NULL ) {
524  msg->unref();
525  msg = NULL;
526  }
527  mutex->unlock();
528  throw;
529  }
530  }
531 
532  mutex->unlock();
533 
534  return s;
535 }
536 
537 std::vector<float>
539 {
540  throw NotImplementedException("NetworkConf: list values are not supported");
541 }
542 
543 std::vector<unsigned int>
545 {
546  throw NotImplementedException("NetworkConf: list values are not supported");
547 }
548 
549 std::vector<int>
551 {
552  throw NotImplementedException("NetworkConf: list values are not supported");
553 }
554 
555 std::vector<bool>
557 {
558  throw NotImplementedException("NetworkConf: list values are not supported");
559 }
560 
561 std::vector<std::string>
563 {
564  throw NotImplementedException("NetworkConf: list values are not supported");
565 }
566 
567 
568 std::string
570 {
571  if ( strlen(path) > CONFIG_MSG_PATH_LENGTH ) {
572  throw OutOfBoundsException("NetworkConfiguration::get_comment: "
573  "Maximum length for path exceeded");
574  }
575  if ( ! __connected ) {
576  throw ConnectionDiedException("NetworkConfiguration: Cannot send get, "
577  "client connection is not alive");
578  }
579 
580  std::string s;
581  mutex->lock();
582 
583  if ( __mirror_mode ) {
584  try {
585  s = mirror_config->get_comment(path);
586  } catch (Exception &e) {
587  e.append("NetworkConfiguration[mirroring]::get_comment: exception in mirror database");
588  mutex->unlock();
589  throw;
590  }
591  } else {
592  try {
593  send_get(path, MSG_CONFIG_GET_COMMENT, MSG_CONFIG_COMMENT_VALUE);
594 
595  config_comment_msg_t *sm = msg->msgge<config_comment_msg_t>();
596  s = sm->s;
597 
598  msg->unref();
599  msg = NULL;
600 
601  } catch (Exception &e) {
602  e.append("NetworkConfiguration::get_comment: Fetching int failed");
603  if ( msg != NULL ) {
604  msg->unref();
605  msg = NULL;
606  }
607  mutex->unlock();
608  throw;
609  }
610  }
611 
612  mutex->unlock();
613 
614  return s;
615 }
616 
617 
618 std::string
620 {
621  if ( strlen(path) > CONFIG_MSG_PATH_LENGTH ) {
622  throw OutOfBoundsException("NetworkConfiguration::get_default_comment: "
623  "Maximum length for path exceeded");
624  }
625  if ( ! __connected ) {
626  throw ConnectionDiedException("NetworkConfiguration: Cannot send get, "
627  "client connection is not alive");
628  }
629 
630  std::string s;
631  mutex->lock();
632 
633  if ( __mirror_mode ) {
634  try {
635  s = mirror_config->get_default_comment(path);
636  } catch (Exception &e) {
637  e.append("NetworkConfiguration[mirroring]::get_default_comment: "
638  "exception in mirror database");
639  mutex->unlock();
640  throw;
641  }
642  } else {
643  try {
644  send_get(path, MSG_CONFIG_GET_DEFAULT_COMMENT, MSG_CONFIG_COMMENT_VALUE);
645 
646  config_comment_msg_t *sm = msg->msgge<config_comment_msg_t>();
647  s = sm->s;
648 
649  msg->unref();
650  msg = NULL;
651 
652  } catch (Exception &e) {
653  e.append("NetworkConfiguration::get_comment: Fetching int failed");
654  if ( msg != NULL ) {
655  msg->unref();
656  msg = NULL;
657  }
658  mutex->unlock();
659  throw;
660  }
661  }
662 
663  mutex->unlock();
664 
665  return s;
666 }
667 
668 
671 {
672  if ( strlen(path) > CONFIG_MSG_PATH_LENGTH ) {
673  throw OutOfBoundsException("NetworkConfiguration::get_value: "
674  "Maximum length for path exceeded");
675  }
676  if ( ! __connected ) {
677  throw ConnectionDiedException("NetworkConfiguration: Cannot send get, "
678  "client connection is not alive");
679  }
680 
682  mutex->lock();
683 
684  if ( __mirror_mode ) {
685  try {
686  i = mirror_config->get_value(path);
687  } catch (Exception &e) {
688  e.append("NetworkConfiguration[mirroring]::get_float: exception in mirror database");
689  mutex->unlock();
690  throw;
691  }
692  } else {
694  strncpy(g->cp.path, path, CONFIG_MSG_PATH_LENGTH);
695  FawkesNetworkMessage *omsg = new FawkesNetworkMessage(FAWKES_CID_CONFIGMANAGER,
696  MSG_CONFIG_GET_VALUE,
697  g, sizeof(config_getval_msg_t));
698  c->enqueue_and_wait(omsg);
699 
700  if ( msg == NULL ) {
701  mutex->unlock();
702  throw NullPointerException("NetworkConfiguration::get_value: msg == NULL");
703  }
704 
705  i = new NetConfValueIterator(msg);
706 
707  msg->unref();
708  msg = NULL;
709  }
710 
711  mutex->unlock();
712 
713  return i;
714 }
715 
716 
717 void
718 NetworkConfiguration::set_value_internal(unsigned int msg_type,
719  const char *path, uint16_t num_values,
720  size_t data_size, void *data)
721 {
722  if ( strlen(path) > CONFIG_MSG_PATH_LENGTH ) {
723  throw OutOfBoundsException("NetworkConfiguration::set_float: "
724  "Maximum length for path exceeded");
725  }
726  if ( ! __connected ) {
727  throw ConnectionDiedException("NetworkConfiguration: Cannot set value, "
728  "client connection is not alive");
729  }
730 
731  mutex->lock();
732  size_t msg_size = sizeof(config_descriptor_t) + data_size;
733  FawkesNetworkMessage *omsg = new FawkesNetworkMessage(FAWKES_CID_CONFIGMANAGER,
734  msg_type, msg_size);
736  strncpy(cd->path, path, CONFIG_MSG_PATH_LENGTH);
737  cd->num_values = num_values;
738 
739  void *mdata = ((char *)omsg->payload() + sizeof(config_descriptor_t));
740  memcpy(mdata, data, data_size);
741 
742  c->enqueue_and_wait(omsg);
743  if ( ! __mirror_mode && (msg != NULL) ) {
744  msg->unref();
745  msg = NULL;
746  }
747  mutex->unlock();
748 }
749 
750 void
751 NetworkConfiguration::set_float(const char *path, float f)
752 {
753  set_value_internal(MSG_CONFIG_SET_FLOAT, path, 0, sizeof(float), &f);
754 }
755 
756 
757 void
758 NetworkConfiguration::set_default_float(const char *path, float f)
759 {
760  set_value_internal(MSG_CONFIG_SET_DEFAULT_FLOAT, path, 0, sizeof(float), &f);
761 }
762 
763 
764 void
765 NetworkConfiguration::set_uint(const char *path, unsigned int uint)
766 {
767  set_value_internal(MSG_CONFIG_SET_UINT, path, 0, sizeof(uint32_t), &uint);
768 }
769 
770 
771 void
772 NetworkConfiguration::set_default_uint(const char *path, unsigned int uint)
773 {
774  set_value_internal(MSG_CONFIG_SET_DEFAULT_UINT, path, 0, sizeof(uint32_t), &uint);
775 }
776 
777 
778 void
779 NetworkConfiguration::set_int(const char *path, int i)
780 {
781  set_value_internal(MSG_CONFIG_SET_INT, path, 0, sizeof(int32_t), &i);
782 }
783 
784 
785 void
787 {
788  set_value_internal(MSG_CONFIG_SET_DEFAULT_INT, path, 0, sizeof(int32_t), &i);
789 }
790 
791 
792 void
793 NetworkConfiguration::set_bool(const char *path, bool b)
794 {
795  int32_t bs[1] = { b ? 1 : 0 };
796  set_value_internal(MSG_CONFIG_SET_BOOL, path, 0, sizeof(int32_t), bs);
797 }
798 
799 
800 void
801 NetworkConfiguration::set_default_bool(const char *path, bool b)
802 {
803  int32_t bs[1] = { b ? 1 : 0 };
804  set_value_internal(MSG_CONFIG_SET_DEFAULT_BOOL, path, 0, sizeof(int32_t), bs);
805 }
806 
807 
808 void
809 NetworkConfiguration::set_string(const char *path, const char *s)
810 {
811  size_t s_length = strlen(s);
812  size_t data_size = sizeof(config_string_value_t) + s_length;
813  void *data = malloc(data_size);
815  sv->s_length = s_length;
816  strncpy((char *)sv + sizeof(config_string_value_t), s, s_length);
817  set_value_internal(MSG_CONFIG_SET_STRING, path, 0, data_size, data);
818  free(data);
819 }
820 
821 
822 void
823 NetworkConfiguration::set_default_string(const char *path, const char *s)
824 {
825  size_t s_length = strlen(s);
826  size_t data_size = sizeof(config_string_value_t) + s_length;
827  void *data = malloc(data_size);
829  sv->s_length = s_length;
830  strncpy((char *)sv + sizeof(config_string_value_t), s, s_length);
831  set_value_internal(MSG_CONFIG_SET_DEFAULT_STRING, path, 0, data_size, data);
832  free(data);
833 }
834 
835 
836 void
837 NetworkConfiguration::set_string(const char *path, std::string &s)
838 {
839  set_string(path, s.c_str());
840 }
841 
842 
843 void
844 NetworkConfiguration::set_default_string(const char *path, std::string &s)
845 {
846  set_default_string(path, s.c_str());
847 }
848 
849 
850 void
851 NetworkConfiguration::set_floats(const char *path, std::vector<float> &f)
852 {
853  throw NotImplementedException("NetworkConf: list values are not supported");
854 }
855 
856 void
857 NetworkConfiguration::set_uints(const char *path, std::vector<unsigned int> &u)
858 {
859  throw NotImplementedException("NetworkConf: list values are not supported");
860 }
861 
862 void
863 NetworkConfiguration::set_ints(const char *path, std::vector<int> &i)
864 {
865  throw NotImplementedException("NetworkConf: list values are not supported");
866 }
867 
868 void
869 NetworkConfiguration::set_bools(const char *path, std::vector<bool> &b)
870 {
871  throw NotImplementedException("NetworkConf: list values are not supported");
872 }
873 
874 void
875 NetworkConfiguration::set_strings(const char *path, std::vector<std::string> &s)
876 {
877  throw NotImplementedException("NetworkConf: list values are not supported");
878 }
879 
880 void
881 NetworkConfiguration::set_strings(const char *path, std::vector<const char *> &s)
882 {
883  throw NotImplementedException("NetworkConf: list values are not supported");
884 }
885 
886 
887 
888 void
889 NetworkConfiguration::set_comment(const char *path, const char *comment)
890 {
891 }
892 
893 
894 void
895 NetworkConfiguration::set_default_comment(const char *path, const char *comment)
896 {
897 }
898 
899 
900 void
901 NetworkConfiguration::set_comment(const char *path, std::string &comment)
902 {
903 }
904 
905 
906 void
907 NetworkConfiguration::set_default_comment(const char *path, std::string &comment)
908 {
909 }
910 
911 
912 void
913 NetworkConfiguration::erase_internal(const char *path, bool is_default)
914 {
915  if ( strlen(path) > CONFIG_MSG_PATH_LENGTH ) {
916  throw OutOfBoundsException("NetworkConfiguration::erase: "
917  "Maximum length for path exceeded");
918  }
919  if ( ! __connected ) {
920  throw ConnectionDiedException("NetworkConfiguration: Cannot set value, "
921  "client connection is not alive");
922  }
923 
924  mutex->lock();
925  FawkesNetworkMessage *omsg = new FawkesNetworkMessage(FAWKES_CID_CONFIGMANAGER,
926  MSG_CONFIG_ERASE_VALUE,
927  sizeof(config_erase_value_msg_t));
929  m->cp.is_default = is_default ? 1 : 0;
930  strncpy(m->cp.path, path, CONFIG_MSG_PATH_LENGTH);
931  c->enqueue_and_wait(omsg);
932  if ( ! __mirror_mode && (msg != NULL) ) {
933  msg->unref();
934  msg = NULL;
935  }
936  mutex->unlock();
937 }
938 
939 
940 void
942 {
943  erase_internal(path, /*default */ false);
944 }
945 
946 
947 void
949 {
950  erase_internal(path, /*default */ true);
951 }
952 
953 
954 /** We are no longer registered in Fawkes network client.
955  * Ignored.
956  * @param id the id of the calling client
957  */
958 void
959 NetworkConfiguration::deregistered(unsigned int id) throw()
960 {
961 }
962 
963 
964 void
966  unsigned int id) throw()
967 {
968  if ( m->cid() == FAWKES_CID_CONFIGMANAGER ) {
969 
970  if ( __mirror_mode ) {
971  switch (m->msgid()) {
972  case MSG_CONFIG_LIST:
973  // put all values into mirror database
974  {
975  //mirror_config->transaction_begin();
976  ConfigListContent *clc = m->msgc<ConfigListContent>();
977  while ( clc->has_next() ) {
978  size_t cle_size = 0;
979  config_list_entity_header_t *cle = clc->next(&cle_size);
980  switch ( cle->type ) {
981  case MSG_CONFIG_FLOAT_VALUE:
982  {
983  float *msg_values =
984  (float *)((char *)cle + sizeof(config_list_entity_header_t));
985  if (cle->cp.num_values > 0) {
986  std::vector<float> values(cle->cp.num_values, 0);
987  for (volatile unsigned int j = 0; j < cle->cp.num_values; ++j) {
988  values[j] = msg_values[j];
989  }
990  mirror_config->set_floats(cle->cp.path, values);
991  } else {
992  if ( cle->cp.is_default ) {
993  mirror_config->set_default_float(cle->cp.path, *msg_values);
994  } else {
995  mirror_config->set_float(cle->cp.path, *msg_values);
996  }
997  }
998  }
999  break;
1000 
1001  case MSG_CONFIG_INT_VALUE:
1002  {
1003  int32_t *msg_values =
1004  (int32_t *)((char *)cle + sizeof(config_list_entity_header_t));
1005  if (cle->cp.num_values > 0) {
1006  std::vector<int32_t> values(cle->cp.num_values, 0);
1007  for (volatile unsigned int j = 0; j < cle->cp.num_values; ++j) {
1008  values[j] = msg_values[j];
1009  }
1010  mirror_config->set_ints(cle->cp.path, values);
1011  } else {
1012  if ( cle->cp.is_default ) {
1013  mirror_config->set_default_int(cle->cp.path, *msg_values);
1014  } else {
1015  mirror_config->set_int(cle->cp.path, *msg_values);
1016  }
1017  }
1018  }
1019  break;
1020 
1021  case MSG_CONFIG_UINT_VALUE:
1022  {
1023  uint32_t *msg_values =
1024  (uint32_t *)((char *)cle + sizeof(config_list_entity_header_t));
1025  if (cle->cp.num_values > 0) {
1026  std::vector<uint32_t> values(cle->cp.num_values, 0);
1027  for (volatile unsigned int j = 0; j < cle->cp.num_values; ++j) {
1028  values[j] = msg_values[j];
1029  }
1030  mirror_config->set_uints(cle->cp.path, values);
1031  } else {
1032  if ( cle->cp.is_default ) {
1033  mirror_config->set_default_uint(cle->cp.path, *msg_values);
1034  } else {
1035  mirror_config->set_uint(cle->cp.path, *msg_values);
1036  }
1037  }
1038  }
1039  break;
1040 
1041  case MSG_CONFIG_BOOL_VALUE:
1042  {
1043  int32_t *msg_values =
1044  (int32_t *)((char *)cle + sizeof(config_list_entity_header_t));
1045  if (cle->cp.num_values > 0) {
1046  std::vector<bool> values(cle->cp.num_values, 0);
1047  for (volatile unsigned int j = 0; j < cle->cp.num_values; ++j) {
1048  values[j] = (msg_values[j] != 0);
1049  }
1050  mirror_config->set_bools(cle->cp.path, values);
1051  } else {
1052  if ( cle->cp.is_default ) {
1053  mirror_config->set_default_bool(cle->cp.path, (*msg_values != 0));
1054  } else {
1055  mirror_config->set_bool(cle->cp.path, (*msg_values != 0));
1056  }
1057  }
1058  }
1059  break;
1060 
1061  case MSG_CONFIG_STRING_VALUE:
1062  {
1063  char *tmpdata = (char *)cle + sizeof(config_list_entity_header_t);
1064  if (cle->cp.num_values > 0) {
1065  std::vector<std::string> values(cle->cp.num_values, "");
1066  for (volatile unsigned int j = 0; j < cle->cp.num_values; ++j) {
1067  config_string_value_t *csv = (config_string_value_t *)tmpdata;
1068  char *msg_string = tmpdata + sizeof(config_string_value_t);
1069  values[j] = std::string(msg_string, csv->s_length);
1070  tmpdata += sizeof(config_string_value_t) + csv->s_length + 1;
1071  }
1072  mirror_config->set_strings(cle->cp.path, values);
1073  } else {
1074  config_string_value_t *csv = (config_string_value_t *)tmpdata;
1075  char *msg_string = tmpdata + sizeof(config_string_value_t);
1076  if ( cle->cp.is_default ) {
1077  mirror_config->set_default_string(cle->cp.path,
1078  std::string(msg_string, csv->s_length).c_str());
1079  } else {
1080  mirror_config->set_string(cle->cp.path,
1081  std::string(msg_string, csv->s_length).c_str());
1082  }
1083  }
1084  }
1085  break;
1086 
1087  case MSG_CONFIG_COMMENT_VALUE:
1088  // ignored
1089  break;
1090  }
1091  }
1092  //mirror_config->transaction_commit();
1093  delete clc;
1094  }
1095 
1096  // add all change handlers
1097  for (ChangeHandlerMultimap::const_iterator j = _change_handlers.begin(); j != _change_handlers.end(); ++j) {
1098  _ch_range = _change_handlers.equal_range((*j).first);
1099  for (ChangeHandlerMultimap::const_iterator i = _ch_range.first; i != _ch_range.second; ++i) {
1100  mirror_config->add_change_handler((*i).second);
1101  }
1102  }
1103  // initial answer received -> wake up set_mirror_mode()
1104  if (__mirror_init_waiting) {
1105  __mirror_init_barrier->wait();
1106  }
1107  break;
1108 
1109  case MSG_CONFIG_VALUE_ERASED:
1110  try {
1112  if (em->cp.is_default == 1) {
1113  mirror_config->erase_default(em->cp.path);
1114  } else {
1115  mirror_config->erase(em->cp.path);
1116  }
1117  } catch (Exception &e) {
1118  // Just ignore silently
1119  LibLogger::log_warn("NetworkConfiguration", "[mirroring]::inboundReceived: erasing failed");
1120  }
1121  break;
1122 
1123  case MSG_CONFIG_FLOAT_VALUE:
1124  try {
1125  config_descriptor_t *cd = m->msgge<config_descriptor_t>();
1126  if (cd->num_values > 0) {
1127  float *fs = (float *)((char *)msg->payload() + sizeof(config_descriptor_t));
1128  std::vector<float> floats(cd->num_values, 0.0);
1129  for (unsigned int i = 0; i < cd->num_values; ++i) {
1130  floats[i] = fs[i];
1131  }
1132  mirror_config->set_floats(cd->path, floats);
1133  } else {
1134  float f = *(float *)((char *)msg->payload() + sizeof(config_descriptor_t));
1135  if (cd->is_default == 1) {
1136  mirror_config->set_default_float(cd->path, f);
1137  } else {
1138  mirror_config->set_float(cd->path, f);
1139  }
1140  }
1141  } catch (TypeMismatchException &e) {
1142  // Just ignore silently
1143  LibLogger::log_warn("NetworkConfiguration", "[mirroring]::inboundReceived: invalid float received");
1144  }
1145  break;
1146 
1147  case MSG_CONFIG_UINT_VALUE:
1148  try {
1149  config_descriptor_t *cd = m->msgge<config_descriptor_t>();
1150  if (cd->num_values > 0) {
1151  uint32_t *vs = (uint32_t *)((char *)msg->payload() + sizeof(config_descriptor_t));
1152  std::vector<unsigned int> values(cd->num_values, 0);
1153  for (unsigned int i = 0; i < cd->num_values; ++i) {
1154  values[i] = vs[i];
1155  }
1156  mirror_config->set_uints(cd->path, values);
1157  } else {
1158  unsigned int u =
1159  *(uint32_t *)((char *)msg->payload() + sizeof(config_descriptor_t));
1160 
1161  if (cd->is_default == 1) {
1162  mirror_config->set_default_uint(cd->path, u);
1163  } else {
1164  mirror_config->set_uint(cd->path, u);
1165  }
1166  }
1167  } catch (TypeMismatchException &e) {
1168  // Just ignore silently
1169  LibLogger::log_warn("NetworkConfiguration", "[mirroring]::inboundReceived: invalid uint received");
1170  }
1171  break;
1172 
1173  case MSG_CONFIG_INT_VALUE:
1174  try {
1175  config_descriptor_t *cd = m->msgge<config_descriptor_t>();
1176  if (cd->num_values > 0) {
1177  int32_t *vs = (int32_t *)((char *)msg->payload() + sizeof(config_descriptor_t));
1178  std::vector<int> values(cd->num_values, 0);
1179  for (unsigned int i = 0; i < cd->num_values; ++i) {
1180  values[i] = vs[i];
1181  }
1182  mirror_config->set_ints(cd->path, values);
1183  } else {
1184  unsigned int i =
1185  *(int32_t *)((char *)msg->payload() + sizeof(config_descriptor_t));
1186 
1187  if (cd->is_default == 1) {
1188  mirror_config->set_default_int(cd->path, i);
1189  } else {
1190  mirror_config->set_int(cd->path, i);
1191  }
1192  }
1193  } catch (TypeMismatchException &e) {
1194  // Just ignore silently
1195  LibLogger::log_warn("NetworkConfiguration", "[mirroring]::inboundReceived: invalid int received");
1196  }
1197  break;
1198 
1199  case MSG_CONFIG_BOOL_VALUE:
1200  try {
1201  config_descriptor_t *cd = m->msgge<config_descriptor_t>();
1202  if (cd->num_values > 0) {
1203  int32_t *vs = (int32_t *)((char *)msg->payload() + sizeof(config_descriptor_t));
1204  std::vector<bool> values(cd->num_values, 0);
1205  for (unsigned int i = 0; i < cd->num_values; ++i) {
1206  values[i] = (vs[i] != 0);
1207  }
1208  mirror_config->set_bools(cd->path, values);
1209  } else {
1210  unsigned int i =
1211  *(int32_t *)((char *)msg->payload() + sizeof(config_descriptor_t));
1212 
1213  if (cd->is_default == 1) {
1214  mirror_config->set_default_bool(cd->path, (i != 0));
1215  } else {
1216  mirror_config->set_bool(cd->path, (i != 0));
1217  }
1218  }
1219  } catch (TypeMismatchException &e) {
1220  // Just ignore silently
1221  LibLogger::log_warn("NetworkConfiguration", "[mirroring]::inboundReceived: invalid bool received");
1222  }
1223  break;
1224 
1225  case MSG_CONFIG_STRING_VALUE:
1226  try {
1227  config_descriptor_t *cd = m->msgge<config_descriptor_t>();
1228  if (cd->num_values > 0) {
1229  std::vector<std::string> values(cd->num_values, "");
1230  size_t pos = sizeof(config_descriptor_t);
1231  for (unsigned int i = 0; i < cd->num_values; ++i) {
1232  config_string_value_t *vs =
1233  (config_string_value_t *)((char *)msg->payload() + pos);
1234  char *msg_string =
1235  ((char *)msg->payload() + pos) + sizeof(config_string_value_t);
1236  values[i] = std::string(msg_string, vs->s_length);
1237  pos += sizeof(config_string_value_t) + vs->s_length + 1;
1238  }
1239  mirror_config->set_strings(cd->path, values);
1240  } else {
1241  config_string_value_t *sv =
1242  (config_string_value_t *)((char *)msg->payload() + sizeof(config_descriptor_t));
1243  char *msg_string =
1244  (char *)msg->payload() + sizeof(config_string_value_t);
1245 
1246  std::string value = std::string(msg_string, sv->s_length);
1247  if (cd->is_default == 1) {
1248  mirror_config->set_default_string(cd->path, value);
1249  } else {
1250  mirror_config->set_string(cd->path, value);
1251  }
1252  }
1253  } catch (TypeMismatchException &e) {
1254  // Just ignore silently
1255  LibLogger::log_warn("NetworkConfiguration", "[mirroring]::inboundReceived: invalid string received");
1256  }
1257  break;
1258 
1259  case MSG_CONFIG_COMMENT_VALUE:
1260  try {
1261  config_comment_msg_t *cm = m->msgge<config_comment_msg_t>();
1262  if (cm->cp.is_default == 1) {
1263  mirror_config->set_default_comment(cm->cp.path, cm->s);
1264  } else {
1265  mirror_config->set_comment(cm->cp.path, cm->s);
1266  }
1267  } catch (TypeMismatchException &e) {
1268  // Just ignore silently
1269  LibLogger::log_warn("NetworkConfiguration", "[mirroring]::inboundReceived: invalid string received");
1270  }
1271  break;
1272  }
1273  } else {
1274  msg = m;
1275  msg->ref();
1276  }
1277  }
1278 }
1279 
1280 
1281 void
1283 {
1284  __connected = false;
1285  __mirror_mode_before_connection_dead = __mirror_mode;
1286  set_mirror_mode(false);
1287  mutex->unlock(); //Just in case...
1288 }
1289 
1290 
1291 void
1293 {
1294  __connected = true;
1295  set_mirror_mode(__mirror_mode_before_connection_dead);
1296 }
1297 
1298 
1299 void
1301 {
1303 
1304  if ( __mirror_mode ) {
1305  mirror_config->add_change_handler(h);
1306  }
1307 }
1308 
1309 
1310 void
1312 {
1314  if ( __mirror_mode ) {
1315  mirror_config->rem_change_handler(h);
1316  }
1317 }
1318 
1319 
1320 /** Enable or disable mirror mode.
1321  * @param mirror true to enable mirror mode, false to disable
1322  */
1323 void
1325 {
1326  if ( mirror ) {
1327  if ( ! __mirror_mode ) {
1328 
1329  if ( ! __connected ) {
1330  throw CannotEnableMirroringException("Client connection is dead");
1331  }
1332 
1333  mirror_config = new MemoryConfiguration();
1334 
1335  __mirror_init_waiting = true;
1336  mutex->lock();
1337 
1338  __mirror_mode = true;
1339 
1340  // subscribe
1341  FawkesNetworkMessage *omsg = new FawkesNetworkMessage(FAWKES_CID_CONFIGMANAGER,
1342  MSG_CONFIG_SUBSCRIBE);
1343  c->enqueue(omsg);
1344 
1345  // wait until all data has been received (or timeout)
1346  if (! __mirror_init_barrier->wait(__mirror_timeout_sec, 0)) {
1347  // timeout
1348  __mirror_init_waiting = false;
1349  delete mirror_config;
1350  mutex->unlock();
1351  throw CannotEnableMirroringException("Didn't receive data in time");
1352  }
1353  __mirror_init_waiting = false;
1354  mutex->unlock();
1355  }
1356  } else {
1357  if ( __mirror_mode ) {
1358  __mirror_mode = false;
1359  // unsubscribe
1360  if ( __connected ) {
1361  FawkesNetworkMessage *omsg = new FawkesNetworkMessage(FAWKES_CID_CONFIGMANAGER,
1362  MSG_CONFIG_UNSUBSCRIBE);
1363  c->enqueue(omsg);
1364  }
1365 
1366  // delete local temporary mirror database
1367  delete mirror_config;
1368  }
1369  }
1370 }
1371 
1372 
1373 void
1375 {
1376  mutex->lock();
1377 }
1378 
1379 
1380 bool
1382 {
1383  return mutex->try_lock();
1384 }
1385 
1386 
1387 void
1389 {
1390  mutex->unlock();
1391 }
1392 
1393 
1394 void
1396 {
1397 }
1398 
1399 
1402 {
1403  if ( __mirror_mode ) {
1404  return mirror_config->iterator();
1405  } else {
1406  throw Exception("NetworkConfiguration: Iterating only supported in mirror mode");
1407  }
1408 }
1409 
1410 
1411 /** Iterator for all default values.
1412  * Returns an iterator that can be used to iterate over all default values in
1413  * the current default configuration. Note that this might return less paths than
1414  * available, because the values for which no default entry exists are not
1415  * returned.
1416  * @return iterator over all default values
1417  */
1420 {
1421  if ( __mirror_mode ) {
1422  return mirror_config->iterator_default();
1423  } else {
1424  throw Exception("NetworkConfiguration: Iterating only supported in mirror mode");
1425  }
1426 }
1427 
1428 
1429 /** Iterator for all host-specific values.
1430  * Returns an iterator that can be used to iterate over all host-specific values
1431  * in the current configuration. Note that this might return less paths than
1432  * available, because the default values for which no host-specific entry exists
1433  * are not returned.
1434  * @return iterator over all host-specific values
1435  */
1438 {
1439  if ( __mirror_mode ) {
1440  return mirror_config->iterator_hostspecific();
1441  } else {
1442  throw Exception("NetworkConfiguration: Iterating only supported in mirror mode");
1443  }
1444 }
1445 
1446 
1449 {
1450  if ( __mirror_mode ) {
1451  return mirror_config->search(path);
1452  } else {
1453  throw Exception("NetworkConfiguration: Searching only supported in mirror mode");
1454  }
1455 }
1456 
1457 
1458 /** @class NetworkConfiguration::NetConfValueIterator <config/netconf.h>
1459  * Network configuration value iterator.
1460  * @author Tim Niemueller
1461  */
1462 
1463 
1464 /** Constructor.
1465  * @param i internal other iterator, for instance form local mirrored database.
1466  */
1468 {
1469  // not interesting in this case, but anyway...
1470  iterated_once = false;
1471  this->i = i;
1472  msg = NULL;
1473  _path = NULL;
1474 }
1475 
1476 
1477 /** Constructor.
1478  * Returns invalid iterator.
1479  */
1481 {
1482  // not interesting in this case, but anyway...
1483  iterated_once = false;
1484  i = NULL;
1485  msg = NULL;
1486  _path = NULL;
1487 }
1488 
1489 
1490 /** Constructor.
1491  * Internally holds a message. Only this one value is accessible.
1492  * @param m message
1493  */
1495 {
1496  i = NULL;
1497  msg = NULL;
1498  iterated_once = false;
1499  _path = NULL;
1500 
1501  if ( (m->cid() == FAWKES_CID_CONFIGMANAGER) &&
1502  (m->msgid() >= MSG_CONFIG_VALUE_BEGIN) &&
1503  (m->msgid() <= MSG_CONFIG_VALUE_END) &&
1504  (m->payload_size() > sizeof(config_descriptor_t)) ) {
1505  msg = m;
1506  msg->ref();
1507  // extract path
1508  // all messages start with config_descriptor!
1509  _path = (char *)malloc(CONFIG_MSG_PATH_LENGTH + 1);
1510  _path[CONFIG_MSG_PATH_LENGTH] = 0;
1511  config_descriptor_t *cd = (config_descriptor_t *)msg->payload();
1512  strncpy(_path, cd->path, CONFIG_MSG_PATH_LENGTH);
1513  } else {
1514  // invalid value, maybe path does not exist!
1515  }
1516 }
1517 
1518 
1519 /** Destructor. */
1521 {
1522  delete i;
1523  if ( msg != NULL ) msg->unref();
1524  if ( _path != NULL) free(_path);
1525 }
1526 
1527 
1528 bool
1530 {
1531  if ( i == NULL) {
1532  if ( (msg == NULL) || iterated_once ) {
1533  return false;
1534  } else {
1535  iterated_once = true;
1536  return true;
1537  }
1538  } else {
1539  return i->next();
1540  }
1541 }
1542 
1543 
1544 bool
1546 {
1547  return ( (i != NULL) || (msg != NULL) );
1548 }
1549 
1550 
1551 const char *
1553 {
1554  if ( i == NULL ) {
1555  if ( msg == NULL ) {
1556  throw NullPointerException("You may not access path on invalid iterator");
1557  } else {
1558  return _path;
1559  }
1560  } else {
1561  return i->path();
1562  }
1563 }
1564 
1565 
1566 const char *
1568 {
1569  if ( i == NULL ) {
1570  if ( msg == NULL ) {
1571  throw NullPointerException("You may not access path on invalid iterator");
1572  }
1573 
1574  switch (msg->msgid()) {
1575  case MSG_CONFIG_FLOAT_VALUE: return "float";
1576  case MSG_CONFIG_UINT_VALUE: return "unsigned int";
1577  case MSG_CONFIG_INT_VALUE: return "int";
1578  case MSG_CONFIG_BOOL_VALUE: return "bool";
1579  case MSG_CONFIG_STRING_VALUE: return "string";
1580  default:
1581  throw NullPointerException("Unknown type in NetConfValueIterator");
1582  }
1583  } else {
1584  return i->type();
1585  }
1586 }
1587 
1588 
1589 bool
1591 {
1592  if ( i == NULL ) {
1593  if ( msg == NULL ) {
1594  throw NullPointerException("You may not access value methods on invalid iterator");
1595  }
1596  return (msg->msgid() == MSG_CONFIG_FLOAT_VALUE);
1597  } else {
1598  return i->is_float();
1599  }
1600 }
1601 
1602 
1603 bool
1605 {
1606  if ( i == NULL ) {
1607  if ( msg == NULL ) {
1608  throw NullPointerException("You may not access value methods on invalid iterator");
1609  }
1610  return (msg->msgid() == MSG_CONFIG_UINT_VALUE);
1611  } else {
1612  return i->is_float();
1613  }
1614 }
1615 
1616 
1617 bool
1619 {
1620  if ( i == NULL ) {
1621  if ( msg == NULL ) {
1622  throw NullPointerException("You may not access value methods on invalid iterator");
1623  }
1624  return (msg->msgid() == MSG_CONFIG_INT_VALUE);
1625  } else {
1626  return i->is_int();
1627  }
1628 }
1629 
1630 
1631 bool
1633 {
1634  if ( i == NULL ) {
1635  if ( msg == NULL ) {
1636  throw NullPointerException("You may not access value methods on invalid iterator");
1637  }
1638  return (msg->msgid() == MSG_CONFIG_BOOL_VALUE);
1639  } else {
1640  return i->is_bool();
1641  }
1642 }
1643 
1644 
1645 bool
1647 {
1648  if ( i == NULL ) {
1649  if ( msg == NULL ) {
1650  throw NullPointerException("You may not access value methods on invalid iterator");
1651  }
1652  return (msg->msgid() == MSG_CONFIG_STRING_VALUE);
1653  } else {
1654  return i->is_string();
1655  }
1656 }
1657 
1658 
1659 bool
1661 {
1662  if ( i == NULL ) {
1663  if ( msg == NULL ) {
1664  throw NullPointerException("You may not access value methods on invalid iterator");
1665  }
1666  config_descriptor_t *cd = msg->msgge<config_descriptor_t>();
1667  return cd->num_values > 0;
1668  } else {
1669  return i->is_list();
1670  }
1671 }
1672 
1673 
1674 size_t
1676 {
1677  if ( i == NULL ) {
1678  if ( msg == NULL ) {
1679  throw NullPointerException("You may not access value methods on invalid iterator");
1680  }
1681  config_descriptor_t *cd = msg->msgge<config_descriptor_t>();
1682  return cd->num_values;
1683  } else {
1684  return i->get_list_size();
1685  }
1686 }
1687 
1688 
1689 bool
1691 {
1692  if ( i == NULL ) {
1693  if ( msg == NULL ) {
1694  throw NullPointerException("You may not access value methods on invalid iterator");
1695  } else {
1696  unsigned int msgid = msg->msgid();
1697  switch (msgid) {
1698  case MSG_CONFIG_FLOAT_VALUE:
1699  case MSG_CONFIG_UINT_VALUE:
1700  case MSG_CONFIG_INT_VALUE:
1701  case MSG_CONFIG_BOOL_VALUE:
1702  case MSG_CONFIG_STRING_VALUE:
1703  {
1704  config_descriptor_t *cd = msg->msgge<config_descriptor_t>();
1705  return cd->is_default;
1706  }
1707  }
1708 
1709  throw TypeMismatchException("NetworkConfiguration: Neither in mirror mode nor "
1710  "iterator to value message");
1711  }
1712  } else {
1713  return i->is_default();
1714  }
1715 }
1716 
1717 
1718 float
1720 {
1721  if ( i == NULL ) {
1722  if ( msg == NULL ) {
1723  throw NullPointerException("You may not access value methods on invalid iterator");
1724  }
1725  if (msg->msgid() == MSG_CONFIG_FLOAT_VALUE) {
1726  config_descriptor_t *cd = msg->msgge<config_descriptor_t>();
1727  if (cd->num_values > 0) {
1728  throw TypeMismatchException("NetConfValueIterator::get_float: list received");
1729  }
1730  return *(float *)((char *)msg->payload() + sizeof(config_descriptor_t));
1731  } else {
1732  throw TypeMismatchException("NetConfValueIterator::get_float: type mismatch");
1733  }
1734  } else {
1735  return i->get_float();
1736  }
1737 }
1738 
1739 
1740 unsigned int
1742 {
1743  if ( i == NULL ) {
1744  if ( msg == NULL ) {
1745  throw NullPointerException("You may not access value methods on invalid iterator");
1746  }
1747  if (msg->msgid() == MSG_CONFIG_UINT_VALUE) {
1748  config_descriptor_t *cd = msg->msgge<config_descriptor_t>();
1749  if (cd->num_values > 0) {
1750  throw TypeMismatchException("NetConfValueIterator::get_uint: list received");
1751  }
1752  return *(uint32_t *)((char *)msg->payload() + sizeof(config_descriptor_t));
1753  } else {
1754  throw TypeMismatchException("NetConfValueIterator::get_uint: type mismatch");
1755  }
1756  } else {
1757  return i->get_int();
1758  }
1759 }
1760 
1761 
1762 int
1764 {
1765  if ( i == NULL ) {
1766  if ( msg == NULL ) {
1767  throw NullPointerException("You may not access value methods on invalid iterator");
1768  }
1769  if (msg->msgid() == MSG_CONFIG_INT_VALUE) {
1770  config_descriptor_t *cd = msg->msgge<config_descriptor_t>();
1771  if (cd->num_values > 0) {
1772  throw TypeMismatchException("NetConfValueIterator::get_int: list received");
1773  }
1774  return *(int32_t *)((char *)msg->payload() + sizeof(config_descriptor_t));
1775  } else {
1776  throw TypeMismatchException("NetConfValueIterator::get_int: type mismatch");
1777  }
1778  } else {
1779  return i->get_int();
1780  }
1781 }
1782 
1783 
1784 bool
1786 {
1787  if ( i == NULL ) {
1788  if ( msg == NULL ) {
1789  throw NullPointerException("You may not access value methods on invalid iterator");
1790  }
1791  if (msg->msgid() == MSG_CONFIG_BOOL_VALUE) {
1792  config_descriptor_t *cd = msg->msgge<config_descriptor_t>();
1793  if (cd->num_values > 0) {
1794  throw TypeMismatchException("NetConfValueIterator::get_int: list received");
1795  }
1796  return (*(int32_t *)((char *)msg->payload() + sizeof(config_descriptor_t)) != 0);
1797  } else {
1798  throw TypeMismatchException("NetConfValueIterator::get_bool: type mismatch");
1799  }
1800  } else {
1801  return i->get_bool();
1802  }
1803 }
1804 
1805 
1806 std::string
1808 {
1809  if ( i == NULL ) {
1810  if ( msg == NULL ) {
1811  throw NullPointerException("You may not access value methods on invalid iterator");
1812  }
1813  if (msg->msgid() == MSG_CONFIG_STRING_VALUE) {
1814  config_descriptor_t *cd = msg->msgge<config_descriptor_t>();
1815  if (cd->num_values > 0) {
1816  throw TypeMismatchException("NetConfValueIterator::get_int: list received");
1817  }
1818  config_string_value_t *sv =
1819  (config_string_value_t *)((char *)msg->payload() + sizeof(config_descriptor_t));
1820  char *msg_string =
1821  (char *)msg->payload() + sizeof(config_descriptor_t) + sizeof(config_string_value_t);
1822  return std::string(msg_string, sv->s_length);
1823  } else {
1824  throw TypeMismatchException("NetConfValueIterator::get_string: type mismatch, expected %u, got %u",
1825  MSG_CONFIG_STRING_VALUE, msg->msgid());
1826  }
1827  } else {
1828  return i->get_string();
1829  }
1830 }
1831 
1832 
1833 std::vector<float>
1835 {
1836  if ( i == NULL ) {
1837  if ( msg == NULL ) {
1838  throw NullPointerException("You may not access value methods on invalid iterator");
1839  }
1840  if (msg->msgid() == MSG_CONFIG_FLOAT_VALUE) {
1841  config_descriptor_t *cd = msg->msgge<config_descriptor_t>();
1842  if (cd->num_values <= 1) {
1843  throw TypeMismatchException("NetConfValueIterator::get_floats: not a list");
1844  }
1845  float *data = (float *)((char *)cd + sizeof(config_descriptor_t));
1846  std::vector<float> rv(cd->num_values, 0);
1847 
1848  for (unsigned int j = 0; j < cd->num_values; ++j) {
1849  rv[j] = data[j];
1850  }
1851  return rv;
1852  } else {
1853  throw TypeMismatchException("NetConfValueIterator::get_string: type mismatch, expected %u, got %u",
1854  MSG_CONFIG_STRING_VALUE, msg->msgid());
1855  }
1856  } else {
1857  return i->get_floats();
1858  }
1859 }
1860 
1861 std::vector<unsigned int>
1863 {
1864  if ( i == NULL ) {
1865  if ( msg == NULL ) {
1866  throw NullPointerException("You may not access value methods on invalid iterator");
1867  }
1868  if (msg->msgid() == MSG_CONFIG_UINT_VALUE) {
1869  config_descriptor_t *cd = msg->msgge<config_descriptor_t>();
1870  if (cd->num_values <= 1) {
1871  throw TypeMismatchException("NetConfValueIterator::get_uints: not a list");
1872  }
1873  uint32_t *data = (uint32_t *)((char *)cd + sizeof(config_descriptor_t));
1874  std::vector<unsigned int> rv(cd->num_values, 0);
1875 
1876  for (unsigned int j = 0; j < cd->num_values; ++j) {
1877  rv[j] = data[j];
1878  }
1879  return rv;
1880  } else {
1881  throw TypeMismatchException("NetConfValueIterator::get_string: type mismatch, expected %u, got %u",
1882  MSG_CONFIG_STRING_VALUE, msg->msgid());
1883  }
1884  } else {
1885  return i->get_uints();
1886  }
1887 }
1888 
1889 std::vector<int>
1891 {
1892  if ( i == NULL ) {
1893  if ( msg == NULL ) {
1894  throw NullPointerException("You may not access value methods on invalid iterator");
1895  }
1896  if (msg->msgid() == MSG_CONFIG_INT_VALUE) {
1897  config_descriptor_t *cd = msg->msgge<config_descriptor_t>();
1898  if (cd->num_values <= 1) {
1899  throw TypeMismatchException("NetConfValueIterator::get_ints: not a list");
1900  }
1901  int32_t *data = (int32_t *)((char *)cd + sizeof(config_descriptor_t));
1902  std::vector<int> rv(cd->num_values, 0);
1903 
1904  for (unsigned int j = 0; j < cd->num_values; ++j) {
1905  rv[j] = data[j];
1906  }
1907  return rv;
1908  } else {
1909  throw TypeMismatchException("NetConfValueIterator::get_string: type mismatch, expected %u, got %u",
1910  MSG_CONFIG_STRING_VALUE, msg->msgid());
1911  }
1912  } else {
1913  return i->get_ints();
1914  }
1915 }
1916 
1917 std::vector<bool>
1919 {
1920  if ( i == NULL ) {
1921  if ( msg == NULL ) {
1922  throw NullPointerException("You may not access value methods on invalid iterator");
1923  }
1924  if (msg->msgid() == MSG_CONFIG_INT_VALUE) {
1925  config_descriptor_t *cd = msg->msgge<config_descriptor_t>();
1926  if (cd->num_values <= 1) {
1927  throw TypeMismatchException("NetConfValueIterator::get_ints: not a list");
1928  }
1929  int32_t *data = (int32_t *)((char *)cd + sizeof(config_descriptor_t));
1930  std::vector<bool> rv(cd->num_values, 0);
1931 
1932  for (unsigned int j = 0; j < cd->num_values; ++j) {
1933  rv[j] = (data[j] != 0);
1934  }
1935  return rv;
1936  } else {
1937  throw TypeMismatchException("NetConfValueIterator::get_string: type mismatch, expected %u, got %u",
1938  MSG_CONFIG_STRING_VALUE, msg->msgid());
1939  }
1940  } else {
1941  return i->get_bools();
1942  }
1943 }
1944 
1945 std::vector<std::string>
1947 {
1948  if ( i == NULL ) {
1949  if ( msg == NULL ) {
1950  throw NullPointerException("You may not access value methods on invalid iterator");
1951  }
1952  if (msg->msgid() == MSG_CONFIG_STRING_VALUE) {
1953  config_descriptor_t *cd = msg->msgge<config_descriptor_t>();
1954  if (cd->num_values <= 1) {
1955  throw TypeMismatchException("NetConfValueIterator::get_strings: not a list");
1956  }
1957  std::vector<std::string> rv(cd->num_values, "");
1958  char *tmpdata = (char *)cd + sizeof(config_descriptor_t);
1959 
1960  for (unsigned int j = 0; j < cd->num_values; ++j) {
1962  char *msg_string = tmpdata + sizeof(config_string_value_t);
1963  rv[j] = std::string(msg_string, sv->s_length);
1964  tmpdata += sizeof(config_string_value_t) + sv->s_length + 1;
1965  }
1966  return rv;
1967  } else {
1968  throw TypeMismatchException("NetConfValueIterator::get_string: type mismatch, expected %u, got %u",
1969  MSG_CONFIG_STRING_VALUE, msg->msgid());
1970  }
1971  } else {
1972  return i->get_strings();
1973  }
1974 }
1975 
1976 
1977 std::string
1979 {
1980  if ( i == NULL ) {
1981  if ( msg == NULL ) {
1982  throw NullPointerException("You may not access value methods on "
1983  "invalid iterator");
1984  }
1985  if (msg->msgid() == MSG_CONFIG_STRING_VALUE) {
1986  return get_string();
1987  } else if (msg->msgid() == MSG_CONFIG_BOOL_VALUE) {
1988  return get_bool() ? "true" : "false";
1989  } else if (msg->msgid() == MSG_CONFIG_INT_VALUE) {
1990  return StringConversions::to_string(get_int());
1991  } else if (msg->msgid() == MSG_CONFIG_UINT_VALUE) {
1992  return StringConversions::to_string(get_uint());
1993  } else if (msg->msgid() == MSG_CONFIG_FLOAT_VALUE) {
1994  return StringConversions::to_string(get_float());
1995  } else {
1996  throw Exception("NetConfValueIterator::get_as_string: unknown type");
1997  }
1998  } else {
1999  return i->get_as_string();
2000  }
2001 }
2002 
2003 
2004 std::string
2006 {
2007  if ( i == NULL ) {
2008  if ( msg == NULL ) {
2009  throw NullPointerException("You may not access value methods on invalid iterator");
2010  }
2011  if (msg->msgid() == MSG_CONFIG_COMMENT_VALUE) {
2012  config_comment_msg_t *cm = msg->msgge<config_comment_msg_t>();
2013  return cm->s;
2014  } else {
2015  throw TypeMismatchException("NetConfValueIterator::get_comment: type mismatch");
2016  }
2017  } else {
2018  return i->get_comment();
2019  }
2020 }
2021 
2022 } // end namespace fawkes
virtual void set_ints(const char *path, std::vector< int > &i)
Set new value in configuration of type int.
Definition: netconf.cpp:863
virtual std::vector< int > get_ints() const
Get list of values from configuration which is of type int.
Definition: netconf.cpp:1890
virtual std::string get_as_string() const
Get value as string.
Definition: netconf.cpp:1978
virtual void connection_died(unsigned int id)
Client connection died.
Definition: netconf.cpp:1282
void * payload() const
Get payload buffer.
Definition: message.cpp:321
virtual void try_dump()
Try to dump configuration.
Definition: netconf.cpp:1395
NetworkConfiguration(FawkesNetworkClient *c, unsigned int mirror_timeout_sec=15)
Constructor.
Definition: netconf.cpp:78
virtual void add_change_handler(ConfigurationChangeHandler *h)
Add a configuration change handler.
Definition: netconf.cpp:1300
virtual bool exists(const char *path)
Check if a given value exists.
Definition: netconf.cpp:150
virtual std::vector< unsigned int > get_uints() const
Get list of values from configuration which is of type unsigned int.
Definition: netconf.cpp:1862
virtual std::vector< std::string > get_strings(const char *path)
Get list of values from configuration which is of type string.
Definition: netconf.cpp:562
virtual ValueIterator * iterator()=0
Iterator for all values.
virtual bool is_uint() const
Check if current value is a unsigned int.
Definition: netconf.cpp:1604
virtual bool is_default(const char *path)
Check if a value was read from the default config.
Definition: netconf.cpp:160
virtual bool is_string(const char *path)
Check if a value is of type string.
Definition: netconf.cpp:220
virtual bool get_bool() const
Get bool value.
Definition: netconf.cpp:1785
virtual void load(const char *file_path)
Load configuration.
Definition: netconf.cpp:114
virtual std::vector< float > get_floats() const
Get list of values from configuration which is of type float.
Definition: netconf.cpp:1834
Simple Fawkes network client.
Definition: client.h:52
virtual bool is_list() const
Check if a value is a list.
Definition: netconf.cpp:1660
virtual ~NetworkConfiguration()
Destructor.
Definition: netconf.cpp:101
virtual void set_float(const char *path, float f)
Set new value in configuration of type float.
Definition: netconf.cpp:751
unsigned short int cid() const
Get component ID.
Definition: message.cpp:291
virtual ValueIterator * get_value(const char *path)
Get value from configuration.
Definition: netconf.cpp:670
virtual bool is_uint(const char *path)
Check if a value is of type unsigned int.
Definition: netconf.cpp:199
virtual bool is_int() const
Check if current value is a int.
Definition: netconf.cpp:1618
virtual const char * type() const =0
Type of value.
MT * msgge() const
Get correctly casted payload.
Definition: message.h:134
virtual void inbound_received(FawkesNetworkMessage *msg, unsigned int id)
Called for incoming messages.
Definition: netconf.cpp:965
virtual bool next()
Check if there is another element and advance to this if possible.
Definition: netconf.cpp:1529
virtual bool is_bool() const =0
Check if current value is a bool.
config_descriptor_t cp
value descriptor
Definition: net_messages.h:129
Fawkes library namespace.
config_list_entity_header_t * next(size_t *size)
Get next plugin from list.
virtual size_t get_list_size() const
Get number of elements in list value.
Definition: netconf.cpp:1675
virtual std::vector< unsigned int > get_uints(const char *path)
Get list of values from configuration which is of type unsigned int.
Definition: netconf.cpp:544
Exception()
Constructor for subclasses.
Definition: exception.cpp:257
Called method has not been implemented.
Definition: software.h:107
config_descriptor_t cp
value descriptor
Definition: net_messages.h:112
virtual void set_default_bool(const char *path, bool b)
Set new default value in configuration of type bool.
Definition: netconf.cpp:801
Get value message.
Definition: net_messages.h:101
void register_handler(FawkesNetworkClientHandler *handler, unsigned int component_id)
Register handler.
Definition: client.cpp:646
Interface for configuration change handling.
void lock()
Lock the config.
Definition: netconf.cpp:1374
char path[CONFIG_MSG_PATH_LENGTH]
path to config value.
Definition: net_messages.h:93
virtual std::string get_comment() const
Get comment of value.
Definition: netconf.cpp:2005
Representation of a message that is sent over the network.
Definition: message.h:75
ValueIterator * iterator()
Iterator for all values.
Definition: netconf.cpp:1401
Config list content.
virtual bool next()=0
Check if there is another element and advance to this if possible.
virtual float get_float() const =0
Get float value.
virtual unsigned int get_uint() const =0
Get unsigned int value.
A NULL pointer was supplied where not allowed.
Definition: software.h:34
void unlock()
Unlock the config.
Definition: netconf.cpp:1388
virtual unsigned int get_uint() const
Get unsigned int value.
Definition: netconf.cpp:1741
virtual float get_float(const char *path)
Get value from configuration which is of type float.
Definition: netconf.cpp:262
virtual std::string get_string(const char *path)
Get value from configuration which is of type string.
Definition: netconf.cpp:482
virtual bool is_float() const =0
Check if current value is a float.
virtual bool is_float(const char *path)
Check if a value is of type float.
Definition: netconf.cpp:192
virtual int get_int(const char *path)
Get value from configuration which is of type int.
Definition: netconf.cpp:372
virtual const char * path() const
Path of value.
Definition: netconf.cpp:1552
virtual std::string get_string() const
Get string value.
Definition: netconf.cpp:1807
virtual std::string get_type(const char *path)
Get type of field.
Definition: netconf.cpp:174
virtual std::vector< bool > get_bools() const
Get list of values from configuration which is of type bool.
Definition: netconf.cpp:1918
virtual bool is_int() const =0
Check if current value is a int.
A barrier is a synchronization tool which blocks until a given number of threads have reached the bar...
virtual bool get_bool(const char *path)
Get value from configuration which is of type bool.
Definition: netconf.cpp:427
virtual void rem_change_handler(ConfigurationChangeHandler *h)
Remove a configuration change handler.
Definition: netconf.cpp:1311
ValueIterator * iterator_default()
Iterator for all default values.
Definition: netconf.cpp:1419
virtual bool get_bool() const =0
Get bool value.
virtual bool is_bool() const
Check if current value is a bool.
Definition: netconf.cpp:1632
virtual bool is_int(const char *path)
Check if a value is of type int.
Definition: netconf.cpp:206
uint32_t type
type of entity, uses MSG_CONFIG_*_VALUE message IDs
Definition: net_messages.h:149
virtual int get_int() const
Get int value.
Definition: netconf.cpp:1763
virtual const char * type() const
Type of value.
Definition: netconf.cpp:1567
virtual int get_int() const =0
Get int value.
bool has_next()
Check if more list elements are available.
virtual bool is_string() const
Check if current value is a string.
Definition: netconf.cpp:1646
virtual std::string get_comment(const char *path)
Get comment of value at given path.
Definition: netconf.cpp:569
virtual void set_bools(const char *path, std::vector< bool > &b)
Set new value in configuration of type bool.
Definition: netconf.cpp:869
virtual void set_default_uint(const char *path, unsigned int uint)
Set new default value in configuration of type unsigned int.
Definition: netconf.cpp:772
virtual bool is_string() const =0
Check if current value is a string.
uint16_t is_default
1 if value is a default value, 0 otherwise, only for get response
Definition: net_messages.h:94
virtual void set_comment(const char *path, std::string &comment)
Set new comment for existing value.
Definition: netconf.cpp:901
Base class for exceptions in Fawkes.
Definition: exception.h:36
String value header indicating the string length.
Definition: net_messages.h:121
virtual void rem_change_handler(ConfigurationChangeHandler *h)
Remove a configuration change handler.
Definition: config.cpp:564
virtual bool valid() const
Check if the current element is valid.
Definition: netconf.cpp:1545
virtual std::vector< int > get_ints(const char *path)
Get list of values from configuration which is of type int.
Definition: netconf.cpp:550
void ref()
Increment reference count.
Definition: refcount.cpp:70
virtual void set_floats(const char *path, std::vector< float > &f)
Set new value in configuration of type float.
Definition: netconf.cpp:851
virtual void set_strings(const char *path, std::vector< std::string > &s)
Set new value in configuration of type string.
Definition: netconf.cpp:875
config_descriptor_t cp
value descriptor
Definition: net_messages.h:117
virtual bool is_uint() const =0
Check if current value is a unsigned int.
virtual std::vector< std::string > get_strings() const
Get list of values from configuration which is of type string.
Definition: netconf.cpp:1946
virtual void erase(const char *path)
Erase the given value from the configuration.
Definition: netconf.cpp:941
Basic config descriptor.
Definition: net_messages.h:92
virtual std::string get_string() const =0
Get string value.
virtual void set_uints(const char *path, std::vector< unsigned int > &uint)
Set new value in configuration of type unsigned int.
Definition: netconf.cpp:857
ValueIterator * iterator_hostspecific()
Iterator for all host-specific values.
Definition: netconf.cpp:1437
virtual void set_default_float(const char *path, float f)
Set new default value in configuration of type float.
Definition: netconf.cpp:758
uint16_t num_values
Number of valus in list.
Definition: net_messages.h:97
virtual void set_mirror_mode(bool mirror)
Enable or disable mirror mode.
Definition: netconf.cpp:1324
virtual void set_bool(const char *path, bool b)
Set new value in configuration of type bool.
Definition: netconf.cpp:793
virtual const char * path() const =0
Path of value.
virtual bool valid() const =0
Check if the current element is valid.
static void log_warn(const char *component, const char *format,...)
Log warning message.
Definition: liblogger.cpp:162
virtual void copy(Configuration *copyconf)
Copy all values from the given configuration.
Definition: netconf.cpp:127
config_descriptor_t cp
Config descriptor.
Definition: net_messages.h:148
virtual unsigned int get_uint(const char *path)
Get value from configuration which is of type unsigned int.
Definition: netconf.cpp:317
Thrown if the connection died during an operation.
Definition: exceptions.h:31
virtual bool is_list(const char *path)
Check if a value is a list.
Definition: netconf.cpp:226
virtual void unlock()=0
Unlock the config.
virtual void connection_established(unsigned int id)
Client has established a connection.
Definition: netconf.cpp:1292
unsigned short int msgid() const
Get message type ID.
Definition: message.cpp:301
virtual bool is_default() const
Check if current value was read from the default config.
Definition: netconf.cpp:1690
Value erased message.
Definition: net_messages.h:116
Config list entity header.
Definition: net_messages.h:147
virtual void set_default_int(const char *path, int i)
Set new default value in configuration of type int.
Definition: netconf.cpp:786
virtual std::string get_default_comment(const char *path)
Get comment of value at given path.
Definition: netconf.cpp:619
virtual std::vector< bool > get_bools(const char *path)
Get list of values from configuration which is of type bool.
Definition: netconf.cpp:556
In-memory configuration store.
Definition: memory.h:38
Iterator interface to iterate over config values.
Definition: config.h:72
Network configuration value iterator.
Definition: netconf.h:123
virtual float get_float() const
Get float value.
Definition: netconf.cpp:1719
virtual void set_int(const char *path, int i)
Set new value in configuration of type int.
Definition: netconf.cpp:779
char s[2]
comment, 0-terminated
Definition: net_messages.h:131
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
virtual std::vector< float > get_floats(const char *path)
Get list of values from configuration which is of type float.
Definition: netconf.cpp:538
bool try_lock()
Try to lock the config.
Definition: netconf.cpp:1381
config_descriptor_t cp
value descriptor
Definition: net_messages.h:102
virtual bool is_bool(const char *path)
Check if a value is of type bool.
Definition: netconf.cpp:213
bool connected() const
Check if connection is alive.
Definition: client.cpp:823
MT * msg() const
Get correctly casted payload.
Definition: message.h:115
Mutex mutual exclusion lock.
Definition: mutex.h:32
virtual void set_default_comment(const char *path, std::string &comment)
Set new default comment for existing default configuration value.
Definition: netconf.cpp:907
Index out of bounds.
Definition: software.h:88
virtual void deregistered(unsigned int id)
We are no longer registered in Fawkes network client.
Definition: netconf.cpp:959
Interface for configuration handling.
Definition: config.h:67
virtual void set_default_string(const char *path, std::string &s)
Set new default value in configuration of type string.
Definition: netconf.cpp:844
ValueIterator * search(const char *path)
Iterator with search results.
Definition: netconf.cpp:1448
virtual void set_uint(const char *path, unsigned int uint)
Set new value in configuration of type unsigned int.
Definition: netconf.cpp:765
static std::string to_string(unsigned int i)
Convert unsigned int value to a string.
CannotEnableMirroringException(const char *msg)
Constructor.
Definition: netconf.cpp:53
virtual bool is_float() const
Check if current value is a float.
Definition: netconf.cpp:1590
void append(const char *format,...)
Append messages to the message list.
Definition: exception.cpp:341
virtual void lock()=0
Lock the config.
size_t payload_size() const
Get payload size.
Definition: message.cpp:311
virtual void set_string(const char *path, std::string &s)
Set new value in configuration of type string.
Definition: netconf.cpp:837
virtual void erase_default(const char *path)
Erase the given default value from the configuration.
Definition: netconf.cpp:948