24 #include <config/yaml.h> 26 #include "yaml_node.h" 28 #include <core/threading/mutex.h> 29 #include <core/threading/mutex_locker.h> 30 #include <core/exceptions/software.h> 31 #include <logging/liblogger.h> 32 #include <utils/system/fam_thread.h> 33 #include <utils/misc/string_split.h> 43 #include <sys/socket.h> 44 #include <netinet/in.h> 45 #include <arpa/inet.h> 47 #include <yaml-cpp/exceptions.h> 54 #define PATH_REGEX "^[a-zA-Z0-9_-]+$" 55 #define YAML_REGEX "^[a-zA-Z0-9_-]+\\.yaml$" 57 #define URL_REGEX "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?" 58 #define FRAME_REGEX "^([a-zA-Z_][a-zA-Z0-9_/-]*)+$" 75 current_ = nodes_.end();
83 : first_(true), nodes_(nodes)
85 current_ = nodes_.end();
93 current_ = nodes_.begin();
97 return (current_ != nodes_.end());
103 return (current_ != nodes_.end());
109 if (current_ == nodes_.end()) {
110 throw Exception(
"YamlValueIterator: cannot get path of invalid iterator");
112 return current_->first.c_str();
118 if (current_ == nodes_.end()) {
119 throw Exception(
"YamlValueIterator: cannot get type of invalid iterator");
121 return YamlConfigurationNode::Type::to_string(current_->second->get_type());
127 if (current_ == nodes_.end()) {
128 throw Exception(
"YamlValueIterator: cannot check type on invalid iterator");
130 return (current_->second->is_type<
float>());
136 if (current_ == nodes_.end()) {
137 throw Exception(
"YamlValueIterator: cannot check type on invalid iterator");
139 return (current_->second->is_type<
unsigned int>());
145 if (current_ == nodes_.end()) {
146 throw Exception(
"YamlValueIterator: cannot check type on invalid iterator");
148 return (current_->second->is_type<
int>());
154 if (current_ == nodes_.end()) {
155 throw Exception(
"YamlValueIterator: cannot check type on invalid iterator");
157 return (current_->second->is_type<
bool>());
163 if (current_ == nodes_.end()) {
164 throw Exception(
"YamlValueIterator: cannot check type on invalid iterator");
166 return (current_->second->is_type<std::string>());
172 if (current_ == nodes_.end()) {
173 throw Exception(
"YamlValueIterator: cannot check type on invalid iterator");
175 return current_->second->get_type() == YamlConfigurationNode::Type::SEQUENCE;
182 if (current_ == nodes_.end()) {
183 throw Exception(
"YamlValueIterator: cannot check type on invalid iterator");
185 if (current_->second->get_type() != YamlConfigurationNode::Type::SEQUENCE) {
186 throw Exception(
"YamlValueIterator: cannot get list size of non-list value");
188 return current_->second->get_list_size();
194 if (current_ == nodes_.end()) {
195 throw Exception(
"YamlValueIterator: cannot get value of invalid iterator");
197 return current_->second->get_value<
float>();
203 if (current_ == nodes_.end()) {
204 throw Exception(
"YamlValueIterator: cannot get value of invalid iterator");
206 return current_->second->get_value<
unsigned int>();
212 if (current_ == nodes_.end()) {
213 throw Exception(
"YamlValueIterator: cannot get value of invalid iterator");
215 return current_->second->get_value<
int>();
221 if (current_ == nodes_.end()) {
222 throw Exception(
"YamlValueIterator: cannot get value of invalid iterator");
224 return current_->second->get_value<
bool>();
230 if (current_ == nodes_.end()) {
231 throw Exception(
"YamlValueIterator: cannot get value of invalid iterator");
233 return current_->second->get_value<std::string>();
239 if (current_ == nodes_.end()) {
240 throw Exception(
"YamlValueIterator: cannot get value of invalid iterator");
242 if (current_->second->get_type() == YamlConfigurationNode::Type::SEQUENCE) {
243 return current_->second->get_list_as_string();
245 return current_->second->get_value<std::string>();
252 if (current_ == nodes_.end()) {
253 throw Exception(
"YamlValueIterator: cannot get value of invalid iterator");
255 return current_->second->get_list<
float>();
258 std::vector<unsigned int>
261 if (current_ == nodes_.end()) {
262 throw Exception(
"YamlValueIterator: cannot get value of invalid iterator");
264 return current_->second->get_list<
unsigned int>();
270 if (current_ == nodes_.end()) {
271 throw Exception(
"YamlValueIterator: cannot get value of invalid iterator");
273 return current_->second->get_list<
int>();
279 if (current_ == nodes_.end()) {
280 throw Exception(
"YamlValueIterator: cannot get value of invalid iterator");
282 return current_->second->get_list<
bool>();
285 std::vector<std::string>
288 if (current_ == nodes_.end()) {
289 throw Exception(
"YamlValueIterator: cannot get value of invalid iterator");
291 return current_->second->get_list<std::string>();
304 if (current_ == nodes_.end()) {
305 throw Exception(
"YamlValueIterator: cannot get value of invalid iterator");
307 return current_->second->is_default();
321 root_ = host_root_ = NULL;
324 write_pending_ =
false;
325 write_pending_mutex_ =
new Mutex();
328 __userconfdir = NULL;
331 __yaml_regex = std::regex(YAML_REGEX, std::regex_constants::extended);
332 __url_regex = std::regex(URL_REGEX, std::regex_constants::extended);
333 __frame_regex = std::regex(FRAME_REGEX, std::regex_constants::extended);
335 if (regcomp(&__yaml_regex, YAML_REGEX, REG_EXTENDED) != 0) {
336 throw Exception(
"Failed to compile YAML regex");
338 if (regcomp(&__url_regex, URL_REGEX, REG_EXTENDED) != 0) {
339 throw Exception(
"Failed to compile URL regex");
341 if (regcomp(&__frame_regex, FRAME_REGEX, REG_EXTENDED) != 0) {
342 throw Exception(
"Failed to compile frame regex");
357 const char *userconfdir)
359 root_ = host_root_ = NULL;
362 write_pending_ =
false;
363 write_pending_mutex_ =
new Mutex();
365 __sysconfdir = strdup(sysconfdir);
368 __yaml_regex = std::regex(YAML_REGEX, std::regex_constants::extended);
369 __url_regex = std::regex(URL_REGEX, std::regex_constants::extended);
370 __frame_regex = std::regex(FRAME_REGEX, std::regex_constants::extended);
372 if (regcomp(&__yaml_regex, YAML_REGEX, REG_EXTENDED) != 0) {
373 throw Exception(
"Failed to compile YAML regex");
375 if (regcomp(&__url_regex, URL_REGEX, REG_EXTENDED) != 0) {
376 throw Exception(
"Failed to compile URL regex");
378 if (regcomp(&__frame_regex, FRAME_REGEX, REG_EXTENDED) != 0) {
379 throw Exception(
"Failed to compile frame regex");
383 if (userconfdir != NULL) {
384 __userconfdir = strdup(userconfdir);
386 const char *homedir = getenv(
"HOME");
387 if (homedir == NULL) {
388 __userconfdir = strdup(sysconfdir);
390 if (asprintf(&__userconfdir,
"%s/%s", homedir, USERDIR) == -1) {
391 __userconfdir = strdup(sysconfdir);
400 if (write_pending_) {
406 root_ = host_root_ = NULL;
409 fam_thread_->cancel();
414 if (__sysconfdir) free(__sysconfdir);
415 if (__userconfdir) free(__userconfdir);
416 #ifndef USE_REGEX_CPP 417 regfree(&__yaml_regex);
418 regfree(&__url_regex);
419 regfree(&__frame_regex);
422 delete write_pending_mutex_;
430 if (file_path == NULL) {
431 file_path =
"config.yaml";
434 std::string filename;
435 if (file_path[0] ==
'/') {
436 filename = file_path;
439 const char *try_paths[] = {__userconfdir, __sysconfdir};
440 int try_paths_len = 2;
443 for (
int i = 0; i < try_paths_len; ++i) {
445 if (asprintf(&path,
"%s/%s", try_paths[i], file_path) != -1) {
446 if (access(path, R_OK) == 0) {
454 if (filename ==
"") {
455 throw Exception(
"YamlConfig: cannot find configuration file %s/%s or %s/%s",
456 __userconfdir, file_path, __sysconfdir, file_path);
460 config_file_ = filename;
463 std::list<std::string> files, dirs;
464 read_yaml_config(filename, host_file_, root_, host_root_, files, dirs);
469 fam->add_filter(
"^[^.].*\\.yaml$");
470 std::list<std::string>::iterator f;
471 for (f = files.begin(); f != files.end(); ++f) {
473 fam->watch_file(f->c_str());
475 for (f = dirs.begin(); f != dirs.end(); ++f) {
477 fam->watch_dir(f->c_str());
479 fam->add_listener(
this);
480 fam_thread_->start();
487 YamlConfigurationNode *
488 YamlConfiguration::read_yaml_file(std::string filename,
bool ignore_missing,
489 std::queue<LoadQueueEntry> &load_queue,
490 std::string &host_file)
492 if (access(filename.c_str(), R_OK) == -1) {
493 if (ignore_missing) {
496 throw Exception(errno,
"YamlConfig: cannot access file %s", filename.c_str());
499 #ifdef HAVE_YAMLCPP_0_5 500 std::vector<YAML::Node> docs;
502 std::ifstream fin(filename.c_str());
504 YAML::Node doc1, doc2;
506 bool have_doc1 =
false, have_doc2 =
false;
509 #ifdef HAVE_YAMLCPP_0_5 510 docs = YAML::LoadAllFromFile(filename);
511 have_doc1 = docs.size() > 0;
512 have_doc2 = docs.size() > 1;
515 have_doc1 = parser.GetNextDocument(doc1);
516 have_doc2 = parser.GetNextDocument(doc2);
518 }
catch (YAML::ParserException &e) {
520 filename.c_str(), e.mark.line, e.mark.column,
524 YamlConfigurationNode *sub_root = NULL;
529 }
else if (have_doc1 && have_doc2) {
531 #ifdef HAVE_YAMLCPP_0_5 532 read_meta_doc(docs[0], load_queue, host_file);
533 read_config_doc(docs[1], sub_root);
535 read_meta_doc(doc1, load_queue, host_file);
536 read_config_doc(doc2, sub_root);
541 #ifdef HAVE_YAMLCPP_0_5 542 read_config_doc(docs[0], sub_root);
544 read_config_doc(doc1, sub_root);
553 YamlConfiguration::read_yaml_config(std::string filename, std::string &host_file,
554 YamlConfigurationNode *& root, YamlConfigurationNode *& host_root,
555 std::list<std::string> &files, std::list<std::string> &dirs)
557 root =
new YamlConfigurationNode();
559 std::queue<LoadQueueEntry> load_queue;
560 load_queue.push(LoadQueueEntry(filename,
false));
562 while (! load_queue.empty()) {
563 LoadQueueEntry &qe = load_queue.front();
566 dirs.push_back(qe.filename);
572 YamlConfigurationNode *sub_root = read_yaml_file(qe.filename, qe.ignore_missing, load_queue, host_file);
575 files.push_back(qe.filename);
584 if (host_file !=
"") {
587 std::queue<LoadQueueEntry> host_load_queue;
588 host_root = read_yaml_file(host_file,
true, host_load_queue, host_file);
589 if (! host_load_queue.empty()) {
595 files.push_back(host_file);
596 }
else host_root =
new YamlConfigurationNode();
598 host_root =
new YamlConfigurationNode();
607 std::string host_file =
"";
608 std::list<std::string> files, dirs;
609 YamlConfigurationNode *root, *host_root;
610 read_yaml_config(config_file_, host_file, root, host_root, files, dirs);
612 std::list<std::string> changes = YamlConfigurationNode::diff(root_, root);
614 if (! changes.empty()) {
615 YamlConfigurationNode *old_root = root_;
616 YamlConfigurationNode *old_host_root = host_root_;
618 host_root_ = host_root;
619 host_file_ = host_file;
621 delete old_host_root;
623 std::list<std::string>::iterator c;
624 for (c = changes.begin(); c != changes.end(); ++c) {
635 std::list<std::string>::iterator f;
636 for (f = files.begin(); f != files.end(); ++f) {
637 fam->watch_file(f->c_str());
639 for (f = dirs.begin(); f != dirs.end(); ++f) {
640 fam->watch_dir(f->c_str());
645 "Failed to reload changed config, exception follows");
658 if (path[0] ==
'/') {
661 return std::string(CONFDIR) +
"/" +
path;
667 YamlConfiguration::read_meta_doc(YAML::Node &doc, std::queue<LoadQueueEntry> &load_queue,
668 std::string &host_file)
671 const YAML::Node &includes = doc[
"include"];
672 #ifdef HAVE_YAMLCPP_0_5 673 for (YAML::const_iterator it = includes.begin(); it != includes.end(); ++it) {
674 std::string include = it->as<std::string>();
676 for (YAML::Iterator it = includes.begin(); it != includes.end(); ++it) {
680 bool ignore_missing =
false;
681 if (it->Tag() ==
"tag:fawkesrobotics.org,cfg/ignore-missing") {
682 ignore_missing =
true;
685 if (it->Tag() ==
"tag:fawkesrobotics.org,cfg/host-specific") {
686 if (host_file !=
"") {
687 throw Exception(
"YamlConfig: Only one host-specific file can be specified");
689 #ifdef HAVE_YAMLCPP_0_5 692 it->GetScalar(host_file);
698 if (include.empty()) {
699 throw Exception(
"YamlConfig: invalid empty include");
702 if (include[include.size() - 1] ==
'/') {
705 struct stat dir_stat;
706 if ((stat(dirname.c_str(), &dir_stat) != 0)) {
707 if (ignore_missing)
continue;
708 throw Exception(errno,
"YamlConfig: Failed to stat directory %s", dirname.c_str());
711 if (! S_ISDIR(dir_stat.st_mode)) {
712 throw Exception(
"YamlConfig: %s is not a directory", dirname.c_str());
715 DIR *d = opendir(dirname.c_str());
717 throw Exception(errno,
"YamlConfig: failed to open directory %s",
721 load_queue.push(LoadQueueEntry(dirname, ignore_missing,
true));
723 std::list<std::string> files;
726 while ((dent = readdir(d)) != NULL) {
728 if (regex_search(dent->d_name, __yaml_regex)) {
734 if (regexec(&__yaml_regex, dent->d_name, 0, NULL, 0) != REG_NOMATCH) {
736 std::string dn = dent->d_name;
737 files.push_back(dirname + dn);
743 for (std::list<std::string>::iterator f = files.begin(); f != files.end(); ++f) {
744 load_queue.push(LoadQueueEntry(*f, ignore_missing));
748 load_queue.push(LoadQueueEntry(
abs_cfg_path(include), ignore_missing));
751 }
catch (YAML::KeyNotFound &e) {
758 YamlConfiguration::read_config_doc(
const YAML::Node &doc, YamlConfigurationNode *&node, std::string
path)
761 node =
new YamlConfigurationNode(
"root");
764 if (*path.rbegin() !=
'/')
766 if (node->name() !=
"root")
767 path += node->name();
769 if (doc.Type() == YAML::NodeType::Map) {
770 #ifdef HAVE_YAMLCPP_0_5 771 for (YAML::const_iterator it = doc.begin(); it != doc.end(); ++it) {
772 std::string key = it->first.as<std::string>();
774 for (YAML::Iterator it = doc.begin(); it != doc.end(); ++it) {
778 YamlConfigurationNode *in = node;
779 if (key.find(
"/") != std::string::npos) {
781 std::vector<std::string> pel =
str_split(key);
782 for (
size_t i = 0; i < pel.size() - 1; ++i) {
783 YamlConfigurationNode *n = (*in)[pel[i]];
785 n =
new YamlConfigurationNode(pel[i]);
786 in->add_child(pel[i], n);
794 YamlConfigurationNode *tmp = (*in)[key];
796 #ifdef HAVE_YAMLCPP_0_5 797 if (tmp->is_scalar() && it->second.Type() != YAML::NodeType::Scalar)
799 if (tmp->is_scalar() && it.second().Type() != YAML::NodeType::Scalar)
802 throw Exception(
"YamlConfig: %s: scalar %s cannot be overwritten by non-scalar",
803 path.c_str(), tmp->name().c_str());
805 #ifdef HAVE_YAMLCPP_0_5 806 tmp->set_scalar(it->second.Scalar());
809 if (it.second().GetScalar(s)) {
814 #ifdef HAVE_YAMLCPP_0_5 815 YamlConfigurationNode *tmp =
new YamlConfigurationNode(key, it->second);
816 in->add_child(key, tmp);
817 read_config_doc(it->second, tmp, path);
819 YamlConfigurationNode *tmp =
new YamlConfigurationNode(key, it.second());
820 in->add_child(key, tmp);
821 read_config_doc(it.second(), tmp,
path);
826 }
else if (doc.Type() == YAML::NodeType::Scalar) {
827 if (doc.Tag() ==
"tag:fawkesrobotics.org,cfg/ipv4" ||
828 doc.Tag() ==
"tag:fawkesrobotics.org,cfg/ipv6")
832 addr_s = node->get_string();
834 e.
prepend(
"YamlConfig: %s: Invalid IPv4 or IPv6 address (not a string)", path.c_str());
838 if (doc.Tag() ==
"tag:fawkesrobotics.org,cfg/ipv4") {
840 if (inet_pton(AF_INET, addr_s.c_str(), &addr) != 1) {
841 throw Exception(
"YamlConfig: %s is not a valid IPv4 address", addr_s.c_str());
844 if (doc.Tag() ==
"tag:fawkesrobotics.org,cfg/ipv6") {
845 struct in6_addr addr;
846 if (inet_pton(AF_INET6, addr_s.c_str(), &addr) != 1) {
847 throw Exception(
"YamlConfig: %s is not a valid IPv6 address", addr_s.c_str());
851 }
else if (doc.Tag() ==
"tag:fawkesrobotics.org,cfg/tcp-port" ||
852 doc.Tag() ==
"tag:fawkesrobotics.org,cfg/udp-port")
856 p = node->get_uint();
858 e.
prepend(
"YamlConfig: %s: Invalid TCP/UDP port number (not an unsigned int)", path.c_str());
861 if (p <= 0 || p >= 65535) {
862 throw Exception(
"YamlConfig: Invalid TCP/UDP port number " 863 "(%u out of allowed range)", p);
865 }
else if (doc.Tag() ==
"tag:fawkesrobotics.org,cfg/url") {
866 #ifdef HAVE_YAMLCPP_0_5 867 std::string scalar = doc.Scalar();
870 doc.GetScalar(scalar);
873 if (regex_search(scalar, __url_regex)) {
879 if (regexec(&__url_regex, scalar.c_str(), 0, NULL, 0) == REG_NOMATCH) {
880 throw Exception(
"YamlConfig: %s: %s is not a valid URL", path.c_str(), scalar.c_str());
883 }
else if (doc.Tag() ==
"tag:fawkesrobotics.org,cfg/frame") {
884 #ifdef HAVE_YAMLCPP_0_5 885 std::string scalar = doc.Scalar();
888 doc.GetScalar(scalar);
891 if (regex_search(scalar, __frame_regex)) {
897 if (regexec(&__frame_regex, scalar.c_str(), 0, NULL, 0) == REG_NOMATCH) {
898 throw Exception(
"YamlConfig: %s: %s is not a valid frame ID", path.c_str(), scalar.c_str());
907 YamlConfiguration::write_host_file()
909 if (host_file_ ==
"") {
910 throw Exception(
"YamlConfig: no host config file specified");
912 if (mutex->try_lock()) {
914 host_root_->emit(host_file_);
917 write_pending_mutex_->unlock();
922 write_pending_mutex_->lock();
923 write_pending_ =
true;
924 write_pending_mutex_->unlock();
939 YamlConfigurationNode *n = root_->find(path);
940 return ! n->has_children();
950 YamlConfigurationNode *n = root_->find(path);
951 if (n->has_children()) {
955 return YamlConfigurationNode::Type::to_string(n->get_type());
976 YamlConfigurationNode *n = root->find(path);
977 if (n->has_children()) {
980 return n->get_value<T>();
991 static inline std::vector<T>
992 get_list(YamlConfigurationNode *root,
const char *path)
994 YamlConfigurationNode *n = root->find(path);
995 if (n->has_children()) {
998 return n->get_list<T>();
1005 return get_value_as<float>(root_,
path);
1011 return get_value_as<unsigned int>(root_,
path);
1017 return get_value_as<int>(root_,
path);
1023 return get_value_as<bool>(root_,
path);
1029 return get_value_as<std::string>(root_,
path);
1036 return get_list<float>(root_,
path);
1040 std::vector<unsigned int>
1043 return get_list<unsigned int>(root_,
path);
1050 return get_list<int>(root_,
path);
1056 return get_list<bool>(root_,
path);
1059 std::vector<std::string>
1062 return get_list<std::string>(root_,
path);
1071 template<
typename T>
1073 is_type(YamlConfigurationNode *root,
const char *path)
1075 YamlConfigurationNode *n = root->find(path);
1076 if (n->has_children()) {
1079 return n->is_type<T>();
1086 return is_type<float>(root_,
path);
1092 YamlConfigurationNode *n = root_->find(path);
1093 if (n->has_children()) {
1097 if (! n->is_type<
unsigned int>())
return false;
1099 int v = n->get_value<
int>();
1106 return is_type<int>(root_,
path);
1112 return is_type<bool>(root_,
path);
1118 return is_type<std::string>(root_,
path);
1125 YamlConfigurationNode *n = root_->find(path);
1126 if (n->has_children()) {
1129 return (n->get_type() == YamlConfigurationNode::Type::SEQUENCE);
1150 YamlConfigurationNode *n = root_->find(path);
1151 if (n->has_children()) {
1154 std::map<std::string, YamlConfigurationNode *> nodes;
1166 root_->set_value(path, f);
1167 host_root_->set_value(path, f);
1174 root_->set_value(path, uint);
1175 host_root_->set_value(path, uint);
1182 root_->set_value(path, i);
1183 host_root_->set_value(path, i);
1190 root_->set_value(path, b);
1191 host_root_->set_value(path, b);
1198 root_->set_value(path, std::string(s));
1199 host_root_->set_value(path, std::string(s));
1213 root_->set_list(path, f);
1214 host_root_->set_list(path, f);
1221 root_->set_list(path, u);
1222 host_root_->set_list(path, u);
1229 root_->set_list(path, i);
1230 host_root_->set_list(path, i);
1237 root_->set_list(path, b);
1238 host_root_->set_list(path, b);
1245 root_->set_list(path, s);
1246 host_root_->set_list(path, s);
1253 root_->set_list(path, s);
1254 host_root_->set_list(path, s);
1271 host_root_->erase(path);
1350 return mutex->try_lock();
1359 write_pending_mutex_->lock();
1360 if (write_pending_) {
1361 host_root_->emit(host_file_);
1362 write_pending_ =
false;
1364 write_pending_mutex_->unlock();
1378 std::map<std::string, YamlConfigurationNode *> nodes;
1379 root_->enum_leafs(nodes);
1386 std::string tmp_path =
path;
1387 std::string::size_type tl = tmp_path.length();
1388 if ((tl > 0) && (tmp_path[tl - 1] ==
'/')) {
1389 tmp_path.resize(tl - 1);
1392 YamlConfigurationNode *n = root_->find(tmp_path.c_str());
1393 std::map<std::string, YamlConfigurationNode *> nodes;
1394 n->enum_leafs(nodes, tmp_path);
1407 YamlConfigurationNode *
1408 YamlConfiguration::query(
const char *path)
const 1411 return root_->find(pel_q);
virtual void set_int(const char *path, int i)
Set new value in configuration of type int.
virtual std::vector< int > get_ints() const
Get list of values from configuration which is of type int.
virtual bool is_float() const
Check if current value is a float.
virtual bool is_list() const
Check if a value is a list.
virtual std::string get_string() const
Get string value.
ValueIterator * search(const char *path)
Iterator with search results.
virtual bool is_uint(const char *path)
Check if a value is of type unsigned int.
virtual int get_int() const
Get int value.
virtual float get_float() const
Get float value.
ValueIterator * iterator()
Iterator for all values.
virtual void set_comment(const char *path, std::string &comment)
Set new comment for existing value.
virtual std::vector< float > get_floats() const
Get list of values from configuration which is of type float.
YamlConfiguration()
Constructor.
virtual void erase_default(const char *path)
Erase the given default value from the configuration.
virtual void set_uint(const char *path, unsigned int uint)
Set new value in configuration of type unsigned int.
virtual bool is_list(const char *path)
Check if a value is a list.
virtual std::vector< unsigned int > get_uints(const char *path)
Get list of values from configuration which is of type unsigned int.
Fawkes library namespace.
virtual void set_strings(const char *path, std::vector< std::string > &s)
Set new value in configuration of type string.
Called method has not been implemented.
Thrown if config could not be opened.
Thrown if a config entry could not be found.
virtual bool valid() const
Check if the current element is valid.
virtual void set_string(const char *path, std::string &s)
Set new value in configuration of type string.
void lock()
Lock the config.
virtual bool is_bool(const char *path)
Check if a value is of type bool.
virtual bool is_uint() const
Check if current value is a unsigned int.
virtual void set_default_comment(const char *path, const char *comment)
Set new default comment for existing default configuration value.
virtual bool is_int(const char *path)
Check if a value is of type int.
virtual std::vector< std::string > get_strings(const char *path)
Get list of values from configuration which is of type string.
virtual bool is_default(const char *path)
Check if a value was read from the default config.
virtual bool is_float(const char *path)
Check if a value is of type float.
virtual bool is_bool() const
Check if current value is a bool.
virtual std::vector< unsigned int > get_uints() const
Get list of values from configuration which is of type unsigned int.
static std::queue< std::string > str_split_to_queue(const std::string &s, char delim='/')
Split string by delimiter.
virtual std::string get_comment() const
Get comment of value.
virtual ValueIterator * get_value(const char *path)
Get value from configuration.
virtual int get_int(const char *path)
Get value from configuration which is of type int.
virtual void load(const char *file_path)
Load configuration.
virtual std::vector< int > get_ints(const char *path)
Get list of values from configuration which is of type int.
static std::string abs_cfg_path(const std::string &path)
Create absolute config path.
YamlValueIterator()
Constructor.
void reset()
Reset pointer.
virtual std::vector< bool > get_bools() const
Get list of values from configuration which is of type bool.
static std::vector< T > get_list(YamlConfigurationNode *root, const char *path)
Retrieve value casted to given type T.
virtual std::string get_string(const char *path)
Get value from configuration which is of type string.
virtual unsigned int get_uint(const char *path)
Get value from configuration which is of type unsigned int.
virtual const char * path() const
Path of value.
virtual std::string get_type(const char *path)
Get type of value at given path.
Base class for exceptions in Fawkes.
virtual std::string get_as_string() const
Get value as string.
virtual size_t get_list_size() const
Get number of elements in list value.
virtual void set_bool(const char *path, bool b)
Set new value in configuration of type bool.
void prepend(const char *format,...)
Prepend messages to the message list.
virtual void set_default_uint(const char *path, unsigned int uint)
Set new default value in configuration of type unsigned int.
void unlock()
Unlock the config.
virtual bool get_bool() const
Get bool value.
virtual void set_bools(const char *path, std::vector< bool > &b)
Set new value in configuration of type bool.
virtual ~YamlConfiguration()
Destructor.
static void log_warn(const char *component, const char *format,...)
Log warning message.
virtual void set_float(const char *path, float f)
Set new value in configuration of type float.
virtual unsigned int get_uint() const
Get unsigned int value.
virtual void try_dump()
Try to dump configuration.
bool try_lock()
Try to lock the config.
virtual void set_floats(const char *path, std::vector< float > &f)
Set new value in configuration of type float.
virtual bool next()
Check if there is another element and advance to this if possible.
void notify_handlers(const char *path, bool comment_changed=false)
Notify handlers for given path.
RefPtr<> is a reference-counting shared smartpointer.
virtual std::string get_comment(const char *path)
Get comment of value at given path.
virtual bool is_string(const char *path)
Check if a value is of type string.
virtual bool is_default() const
Check if current value was read from the default config.
static T get_value_as(YamlConfigurationNode *root, const char *path)
Retrieve value casted to given type T.
virtual bool exists(const char *path)
Check if a given value exists.
virtual void set_default_string(const char *path, std::string &s)
Set new default value in configuration of type string.
virtual void set_ints(const char *path, std::vector< int > &i)
Set new value in configuration of type int.
static std::vector< std::string > str_split(const std::string &s, char delim='/')
Split string by delimiter.
Iterator interface to iterate over config values.
virtual std::vector< std::string > get_strings() const
Get list of values from configuration which is of type string.
virtual bool get_bool(const char *path)
Get value from configuration which is of type bool.
virtual void set_uints(const char *path, std::vector< unsigned int > &uint)
Set new value in configuration of type unsigned int.
virtual void erase(const char *path)
Erase the given value from the configuration.
virtual void set_default_bool(const char *path, bool b)
Set new default value in configuration of type bool.
virtual void set_default_float(const char *path, float f)
Set new default value in configuration of type float.
virtual void set_default_int(const char *path, int i)
Set new default value in configuration of type int.
virtual std::string get_default_comment(const char *path)
Get comment of value at given path.
virtual std::vector< float > get_floats(const char *path)
Get list of values from configuration which is of type float.
FileAlterationMonitor thread wrapper.
virtual bool is_string() const
Check if current value is a string.
virtual void fam_event(const char *filename, unsigned int mask)
Event has been raised.
virtual float get_float(const char *path)
Get value from configuration which is of type float.
virtual bool is_int() const
Check if current value is a int.
Mutex mutual exclusion lock.
virtual void copy(Configuration *copyconf)
Copies all values from the given configuration.
static bool is_type(YamlConfigurationNode *root, const char *path)
Check if value is of given type T.
virtual std::vector< bool > get_bools(const char *path)
Get list of values from configuration which is of type bool.
Interface for configuration handling.
virtual const char * type() const
Type of value.