23 #include "feature_config.h" 25 #include <config/config.h> 26 #include <core/threading/mutex_locker.h> 27 #include <logging/logger.h> 28 #include <utils/misc/string_split.h> 46 :
CLIPSFeature(
"config"), logger_(logger), config_(config)
60 envs_[env_name] = clips;
61 clips->evaluate(
"(path-load \"ff-config.clp\")");
62 clips->add_function(
"config-load",
63 sigc::slot<void, std::string>(
64 sigc::bind<0>(sigc::mem_fun(*
this, &ConfigCLIPSFeature::clips_config_load),
71 envs_.erase(env_name);
75 ConfigCLIPSFeature::clips_config_load(std::string env_name, std::string cfg_prefix)
77 std::string name =
"ClipsConfig|" + env_name;
79 if (envs_.find(env_name) == envs_.end()) {
81 "Environment %s has not been registered " 88 #if __cplusplus >= 201103L 89 std::unique_ptr<Configuration::ValueIterator> v(config_->
search(cfg_prefix.c_str()));
91 std::auto_ptr<Configuration::ValueIterator> v(config_->
search(cfg_prefix.c_str()));
95 std::string type =
"";
96 std::string value = v->get_as_string();
100 else if (v->is_int())
102 else if (v->is_float())
104 else if (v->is_bool()) {
106 value = v->get_bool() ?
"TRUE" :
"FALSE";
107 }
else if (v->is_string()) {
110 std::stringstream escaped_quotes_value;
111 escaped_quotes_value << std::quoted(value);
112 value = escaped_quotes_value.str();
114 std::vector<std::string> strings = v->get_strings();
115 if (!strings.empty()) {
116 for (std::string &s : strings) {
117 std::stringstream escaped_quotes_value;
118 escaped_quotes_value << std::quoted(s);
119 s = escaped_quotes_value.str();
126 "Config value at '%s' of unknown type '%s'",
132 envs_[env_name]->assert_fact_f(
"(confval (path \"%s\") (type %s) " 133 "(is-list TRUE) (list-value %s))",
138 envs_[env_name]->assert_fact_f(
"(confval (path \"%s\") (type %s) (value %s))",
Fawkes library namespace.
std::string str_join(const InputIterator &first, const InputIterator &last, char delim='/')
Join list of strings string using given delimiter.
virtual ValueIterator * search(const char *path)=0
Iterator with search results.
virtual void clips_context_destroyed(const std::string &env_name)
Notification that a CLIPS environment has been destroyed.
virtual ~ConfigCLIPSFeature()
Destructor.
ConfigCLIPSFeature(fawkes::Logger *logger, fawkes::Configuration *config)
Constructor.
CLIPS feature maintainer.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
Interface for configuration handling.
virtual void clips_context_init(const std::string &env_name, fawkes::LockPtr< CLIPS::Environment > &clips)
Initialize a CLIPS context to use the provided feature.