23 #include "feature_config.h" 24 #include <core/threading/mutex_locker.h> 25 #include <config/config.h> 26 #include <logging/logger.h> 43 :
CLIPSFeature(
"config"), logger_(logger), config_(config)
59 envs_[env_name] = clips;
60 clips->evaluate(
"(path-load \"ff-config.clp\")");
61 clips->add_function(
"config-load",
62 sigc::slot<void, std::string>(
64 sigc::mem_fun(*
this, &ConfigCLIPSFeature::clips_config_load),
73 envs_.erase(env_name);
78 ConfigCLIPSFeature::clips_config_load(std::string env_name, std::string cfg_prefix)
80 std::string name =
"ClipsConfig|" + env_name;
82 if (envs_.find(env_name) == envs_.end()) {
83 logger_->
log_warn(name.c_str(),
"Environment %s has not been registered " 84 "for config feature", env_name.c_str());
89 #if __cplusplus >= 201103L 90 std::unique_ptr<Configuration::ValueIterator> v(config_->
search(cfg_prefix.c_str()));
92 std::auto_ptr<Configuration::ValueIterator> v(config_->
search(cfg_prefix.c_str()));
96 std::string type =
"";
99 if (v->
is_uint()) type =
"UINT";
100 else if (v->
is_int()) type =
"INT";
101 else if (v->
is_float()) type =
"FLOAT";
104 value = v->
get_bool() ?
"TRUE" :
"FALSE";
108 value = std::string(
"\"") + value +
"\"";
111 logger_->
log_warn(name.c_str(),
"Config value at '%s' of unknown type '%s'",
116 envs_[env_name]->assert_fact_f(
"(confval (path \"%s\") (type %s) " 117 "(is-list TRUE) (list-value %s))",
118 v->
path(), type.c_str(), value.c_str());
120 envs_[env_name]->assert_fact_f(
"(confval (path \"%s\") (type %s) (value %s))",
121 v->
path(), type.c_str(), value.c_str());
virtual const char * type() const =0
Type of value.
virtual bool is_bool() const =0
Check if current value is a bool.
Fawkes library namespace.
virtual ValueIterator * search(const char *path)=0
Iterator with search results.
virtual bool next()=0
Check if there is another element and advance to this if possible.
virtual bool is_float() const =0
Check if current value is a float.
virtual bool is_int() const =0
Check if current value is a int.
virtual bool get_bool() const =0
Get bool value.
virtual void clips_context_destroyed(const std::string &env_name)
Notification that a CLIPS environment has been destroyed.
virtual std::string get_as_string() const =0
Get value as string.
virtual bool is_string() const =0
Check if current value is a string.
virtual ~ConfigCLIPSFeature()
Destructor.
ConfigCLIPSFeature(fawkes::Logger *logger, fawkes::Configuration *config)
Constructor.
virtual bool is_uint() const =0
Check if current value is a unsigned int.
virtual bool is_list() const =0
Check if a value is a list.
CLIPS feature maintainer.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
virtual const char * path() const =0
Path of value.
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.