23 #include "feature_blackboard.h"
25 #include <blackboard/blackboard.h>
26 #include <blackboard/exceptions.h>
27 #include <core/threading/mutex_locker.h>
28 #include <interface/interface_info.h>
29 #include <logging/logger.h>
30 #include <utils/misc/string_conversions.h>
31 #include <utils/misc/string_split.h>
32 #include <utils/time/time.h>
56 blackboard_(blackboard),
57 cfg_retract_early_(retract_early)
64 for (
auto &iface_map : interfaces_) {
65 for (
auto &iface_list : iface_map.second.reading) {
66 for (
auto iface : iface_list.second) {
67 blackboard_->
close(iface);
70 for (
auto &iface_list : iface_map.second.writing) {
71 for (
auto iface : iface_list.second) {
72 blackboard_->
close(iface);
84 envs_[env_name] = clips;
85 clips->evaluate(
"(path-load \"blackboard.clp\")");
87 "blackboard-enable-time-read",
88 sigc::slot<void>(sigc::bind<0>(
89 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_enable_time_read), env_name)));
92 sigc::slot<void, std::string, std::string>(sigc::bind<0>(
93 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_open_interface_reading),
96 "blackboard-open-reading",
97 sigc::slot<void, std::string, std::string>(sigc::bind<0>(
98 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_open_interface_reading),
101 "blackboard-open-writing",
102 sigc::slot<void, std::string, std::string>(sigc::bind<0>(
103 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_open_interface_writing),
107 sigc::slot<void, std::string, std::string>(
108 sigc::bind<0>(sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_close_interface),
110 clips->add_function(
"blackboard-preload",
111 sigc::slot<void, std::string>(sigc::bind<0>(
112 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_preload),
114 clips->add_function(
"blackboard-read",
115 sigc::slot<void>(sigc::bind<0>(
116 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_read),
118 clips->add_function(
"blackboard-write",
119 sigc::slot<void, std::string>(sigc::bind<0>(
120 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_write),
122 clips->add_function(
"blackboard-get-info",
123 sigc::slot<void>(sigc::bind<0>(
124 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_get_info),
126 clips->add_function(
"blackboard-set",
127 sigc::slot<void, std::string, std::string, CLIPS::Value>(sigc::bind<0>(
128 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_set),
131 "blackboard-set-multifield",
132 sigc::slot<void, std::string, std::string, CLIPS::Values>(
133 sigc::bind<0>(sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_set_multifield),
135 clips->add_function(
"blackboard-create-msg",
136 sigc::slot<CLIPS::Value, std::string, std::string>(sigc::bind<0>(
137 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_create_msg),
140 "blackboard-list-msg-fields",
141 sigc::slot<CLIPS::Values, void *>(
142 sigc::bind<0>(sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_list_msg_fields),
145 "blackboard-set-msg-field",
146 sigc::slot<void, void *, std::string, CLIPS::Value>(
147 sigc::bind<0>(sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_set_msg_field),
149 clips->add_function(
"blackboard-set-msg-multifield",
150 sigc::slot<void, void *, std::string, CLIPS::Values>(sigc::bind<0>(
152 &BlackboardCLIPSFeature::clips_blackboard_set_msg_multifield),
154 clips->add_function(
"blackboard-send-msg",
155 sigc::slot<CLIPS::Value, void *>(sigc::bind<0>(
156 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_send_msg),
163 if (interfaces_.find(env_name) != interfaces_.end()) {
164 for (
auto &iface_map : interfaces_[env_name].reading) {
165 for (
auto iface : iface_map.second) {
166 logger_->
log_debug((
"BBCLIPS|" + env_name).c_str(),
167 "Closing reading interface %s",
169 blackboard_->
close(iface);
172 for (
auto &iface_map : interfaces_[env_name].writing) {
173 for (
auto iface : iface_map.second) {
174 logger_->
log_debug((
"BBCLIPS|" + env_name).c_str(),
175 "Closing writing interface %s",
177 blackboard_->
close(iface);
180 interfaces_.erase(env_name);
182 envs_.erase(env_name);
186 BlackboardCLIPSFeature::clips_blackboard_enable_time_read(
const std::string &env_name)
188 if (envs_.find(env_name) == envs_.end()) {
189 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
190 "Cannot enable reading for environment %s "
196 std::string bb_read_defrule =
"(defrule blackboard-read\n"
197 " (declare (salience 1000))\n"
200 " (blackboard-read)\n"
204 envs_[env_name]->build(bb_read_defrule);
208 BlackboardCLIPSFeature::clips_assert_interface_type(
const std::string &env_name,
209 const std::string &log_name,
211 const std::string &type)
213 std::string deftemplate =
"(deftemplate " + type +
"\n" +
" (slot id (type STRING))\n"
214 +
" (multislot time (type INTEGER) (cardinality 2 2))\n";
218 for (f = iface->
fields(); f != f_end; ++f) {
223 deftemplate += std::string() +
" (" + ((f.
get_length() > 1) ?
"multi" :
"") +
"slot "
224 + f.
get_name() +
" (type SYMBOL) (allowed-values TRUE FALSE))\n";
236 deftemplate += std::string() +
" (" + ((f.
get_length() > 1) ?
"multi" :
"") +
"slot "
237 + f.
get_name() +
" (type INTEGER))\n";
242 deftemplate += std::string() +
" (" + ((f.
get_length() > 1) ?
"multi" :
"") +
"slot "
243 + f.
get_name() +
" (type FLOAT))\n";
247 deftemplate += std::string() +
" (slot " + f.
get_name() +
" (type STRING))\n";
251 deftemplate += std::string() +
" (" + ((f.
get_length() > 1) ?
"multi" :
"") +
"slot "
252 + f.
get_name() +
" (type SYMBOL))\n";
262 if (cfg_retract_early_) {
263 retract =
"(defrule " + type +
"-cleanup\n" +
" (declare (salience -10000))\n" +
" ?f <- ("
270 retract =
"(deffunction " + type
271 +
"-cleanup-late (?id)\n"
272 " (delayed-do-for-all-facts ((?f "
279 logstr =
"Deffunction";
282 if (envs_[env_name]->build(deftemplate) && envs_[env_name]->build(retract)) {
283 logger_->
log_debug(log_name.c_str(),
"Deftemplate:\n%s", deftemplate.c_str());
284 logger_->
log_debug(log_name.c_str(),
"%s:\n%s", logstr.c_str(), retract.c_str());
288 "Defining blackboard type for %s in %s failed",
296 BlackboardCLIPSFeature::clips_blackboard_preload(
const std::string &env_name,
297 const std::string &type)
299 std::string name =
"BBCLIPS|" + env_name;
301 if (envs_.find(env_name) == envs_.end()) {
303 "Environment %s has not been registered "
304 "for blackboard feature",
309 if (interfaces_[env_name].reading.find(type) == interfaces_[env_name].reading.end()
310 && interfaces_[env_name].writing.find(type) == interfaces_[env_name].writing.end()) {
314 iface = blackboard_->
open_for_reading(type.c_str(),
"__clips_blackboard_preload__");
315 clips_assert_interface_type(env_name, name, iface, type);
316 blackboard_->
close(iface);
317 interfaces_[env_name].reading.insert(std::make_pair(type, std::list<fawkes::Interface *>()));
320 "Failed to preload interface type %s, "
330 BlackboardCLIPSFeature::clips_blackboard_open_interface(
const std::string &env_name,
331 const std::string &type,
332 const std::string &
id,
335 std::string name =
"BBCLIPS|" + env_name;
336 std::string owner =
"CLIPS:" + env_name;
338 if (envs_.find(env_name) == envs_.end()) {
340 "Environment %s has not been registered "
341 "for blackboard feature",
349 InterfaceMap &iface_map = writing ? interfaces_[env_name].writing : interfaces_[env_name].reading;
351 if (iface_map.find(type) == iface_map.end()) {
355 iface = blackboard_->
open_for_writing(type.c_str(),
id.c_str(), owner.c_str());
357 iface = blackboard_->
open_for_reading(type.c_str(),
id.c_str(), owner.c_str());
361 "Failed to open interface %s:%s, exception follows",
368 if (!clips_assert_interface_type(env_name, name, iface, type)) {
369 blackboard_->
close(iface);
372 "Added interface %s for %s",
374 iface->
is_writer() ?
"writing" :
"reading");
375 iface_map.insert(std::make_pair(type, std::list<fawkes::Interface *>(1, iface)));
377 clips->assert_fact_f(
"(blackboard-interface (id \"%s\") (type \"%s\") (uid \"%s\") "
378 " (hash \"%s\") (serial %u) (writing %s))",
384 writing ?
"TRUE" :
"FALSE");
387 auto &iface_list = iface_map[type];
388 if (std::none_of(iface_list.begin(),
390 [&type, &id](
const Interface *i) ->
bool {
391 return (type == i->type()) && (
id == i->id());
395 iface = blackboard_->
open_for_writing(type.c_str(),
id.c_str(), owner.c_str());
397 iface = blackboard_->
open_for_reading(type.c_str(),
id.c_str(), owner.c_str());
399 iface_map[type].push_back(iface);
401 "Added interface %s for %s",
403 iface->
is_writer() ?
"writing" :
"reading");
405 clips->assert_fact_f(
"(blackboard-interface (id \"%s\") (type \"%s\") (uid \"%s\") "
406 " (hash \"%s\") (serial %u) (writing %s))",
412 writing ?
"TRUE" :
"FALSE");
415 "Failed to open interface %s:%s, exception follows",
426 BlackboardCLIPSFeature::clips_blackboard_open_interface_reading(
const std::string &env_name,
427 const std::string &type,
428 const std::string &
id)
430 clips_blackboard_open_interface(env_name, type,
id,
false);
434 BlackboardCLIPSFeature::clips_blackboard_open_interface_writing(
const std::string &env_name,
435 const std::string &type,
436 const std::string &
id)
438 clips_blackboard_open_interface(env_name, type,
id,
true);
442 BlackboardCLIPSFeature::clips_blackboard_close_interface(
const std::string &env_name,
443 const std::string &type,
444 const std::string &
id)
446 std::string name =
"BBCLIPS|" + env_name;
448 if (envs_.find(env_name) == envs_.end()) {
450 "Environment %s has not been registered "
451 "for blackboard feature",
456 if (interfaces_[env_name].reading.find(type) != interfaces_[env_name].reading.end()) {
457 auto &l = interfaces_[env_name].reading[type];
459 find_if(l.begin(), l.end(), [&id](
const Interface *iface) {
return id == iface->
id(); });
460 if (iface_it != l.end()) {
461 blackboard_->
close(*iface_it);
467 if (interfaces_[env_name].writing.find(type) != interfaces_[env_name].writing.end()) {
468 auto &l = interfaces_[env_name].writing[type];
470 find_if(l.begin(), l.end(), [&id](
const Interface *iface) {
return id == iface->
id(); });
471 if (iface_it != l.end()) {
472 blackboard_->
close(*iface_it);
481 BlackboardCLIPSFeature::clips_blackboard_read(
const std::string &env_name)
484 if (interfaces_.find(env_name) == interfaces_.end())
486 if (envs_.find(env_name) == envs_.end()) {
488 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
489 "Environment %s not registered,"
490 " cannot read interfaces",
496 CLIPS::Environment &env = **(envs_[env_name]);
497 for (
auto &iface_map : interfaces_[env_name].reading) {
498 for (
auto i : iface_map.second) {
501 if (!cfg_retract_early_) {
502 std::string fun = std::string(
"(") + i->type() +
"-cleanup-late \"" + i->id() +
"\")";
505 const Time *t = i->timestamp();
507 std::string fact = std::string(
"(") + i->type() +
" (id \"" + i->id() +
"\")" +
" (time "
508 + StringConversions::to_string(t->
get_sec()) +
" "
509 + StringConversions::to_string(t->
get_usec()) +
")";
512 for (f = i->fields(); f != f_end; ++f) {
516 std::string::size_type pos = 0;
517 while ((pos = value.find(
"\"", pos)) != std::string::npos) {
518 value.replace(pos, 1,
"\\\"");
521 value = std::string(
"\"") + value +
"\"";
523 value = f.get_value_string();
524 std::string::size_type pos;
525 while ((pos = value.find(
",")) != std::string::npos) {
526 value = value.erase(pos, 1);
530 std::string::size_type pos;
531 while ((pos = value.find(
"-inf")) != std::string::npos) {
532 value = value.replace(pos, 4, std::to_string(std::numeric_limits<double>::min()));
534 while ((pos = value.find(
"inf")) != std::string::npos) {
535 value = value.replace(pos, 3, std::to_string(std::numeric_limits<double>::max()));
537 while ((pos = value.find(
"-nan")) != std::string::npos) {
539 value.replace(pos, 4, std::to_string(std::numeric_limits<double>::min() + 1));
541 while ((pos = value.find(
"nan")) != std::string::npos) {
543 value.replace(pos, 3, std::to_string(std::numeric_limits<double>::max() - 1));
545 }
else if (f.get_type() ==
IFT_BOOL) {
546 std::string::size_type pos;
547 while ((pos = value.find(
"false")) != std::string::npos) {
548 value = value.replace(pos, 5,
"FALSE");
550 while ((pos = value.find(
"true")) != std::string::npos) {
551 value = value.replace(pos, 4,
"TRUE");
555 fact += std::string(
" (") + f.get_name() +
" " + value +
")";
558 env.assert_fact(fact);
565 BlackboardCLIPSFeature::clips_blackboard_write(
const std::string &env_name,
const std::string &uid)
568 if (interfaces_.find(env_name) == interfaces_.end())
570 if (envs_.find(env_name) == envs_.end()) {
572 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
573 "Environment %s not registered,"
574 " cannot write interface %s",
579 std::string type, id;
580 Interface::parse_uid(uid.c_str(), type, id);
581 if (interfaces_[env_name].writing.find(type) != interfaces_[env_name].writing.end()) {
582 auto i = std::find_if(interfaces_[env_name].writing[type].begin(),
583 interfaces_[env_name].writing[type].end(),
584 [&uid](
const Interface *iface) ->
bool {
return uid == iface->
uid(); });
585 if (i != interfaces_[env_name].writing[type].end()) {
588 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
589 "Interface %s not opened for writing,"
590 " in environment %s",
596 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
597 "No interface of type %s opened for,"
598 " writing in environment %s",
606 BlackboardCLIPSFeature::clips_blackboard_get_info(
const std::string &env_name)
608 if (envs_.find(env_name) == envs_.end()) {
610 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
611 "Environment %s not registered,"
612 " cannot read interfaces",
622 for (
auto ii : *iil) {
623 const Time * timestamp = ii.timestamp();
624 std::list<std::string> quoted_readers;
625 std::list<std::string> readers = ii.readers();
626 std::for_each(readers.begin(), readers.end(), ["ed_readers](
const std::string &r) {
627 quoted_readers.push_back(std::string(
"\"") + r +
"\"");
629 std::string quoted_readers_s =
str_join(quoted_readers,
' ');
630 clips->assert_fact_f(
"(blackboard-interface-info (id \"%s\") (type \"%s\") "
631 "(hash \"%s\") (has-writer %s) (num-readers %u) "
632 "(writer \"%s\") (readers %s) (timestamp %u %u))",
635 ii.hash_printable().c_str(),
636 ii.has_writer() ?
"TRUE" :
"FALSE",
639 quoted_readers_s.c_str(),
648 BlackboardCLIPSFeature::clips_blackboard_set(
const std::string &env_name,
649 const std::string &uid,
650 const std::string &field,
654 if (interfaces_.find(env_name) == interfaces_.end())
656 if (envs_.find(env_name) == envs_.end()) {
658 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
659 "Environment %s not registered,"
660 " cannot set %s on interface %s",
666 std::string type, id;
667 Interface::parse_uid(uid.c_str(), type, id);
668 if (interfaces_[env_name].writing.find(type) != interfaces_[env_name].writing.end()) {
669 auto i = std::find_if(interfaces_[env_name].writing[type].begin(),
670 interfaces_[env_name].writing[type].end(),
671 [&uid](
const Interface *iface) ->
bool {
return uid == iface->
uid(); });
672 if (i != interfaces_[env_name].writing[type].end()) {
673 set_field((*i)->fields(), (*i)->fields_end(), env_name, field, value);
675 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
676 "Interface %s not opened for writing,"
677 " in environment %s",
683 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
684 "No interface of type %s opened for,"
685 " writing in environment %s",
693 BlackboardCLIPSFeature::clips_blackboard_set_multifield(
const std::string &env_name,
694 const std::string &uid,
695 const std::string &field,
696 CLIPS::Values values)
699 if (interfaces_.find(env_name) == interfaces_.end())
701 if (envs_.find(env_name) == envs_.end()) {
703 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
704 "Environment %s not registered,"
705 " cannot set %s on interface %s",
711 std::string type, id;
712 Interface::parse_uid(uid.c_str(), type, id);
713 if (interfaces_[env_name].writing.find(type) != interfaces_[env_name].writing.end()) {
714 auto i = std::find_if(interfaces_[env_name].writing[type].begin(),
715 interfaces_[env_name].writing[type].end(),
716 [&uid](
const Interface *iface) ->
bool {
return uid == iface->
uid(); });
717 if (i != interfaces_[env_name].writing[type].end()) {
718 set_multifield((*i)->fields(), (*i)->fields_end(), env_name, field, values);
720 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
721 "Interface %s not opened for writing,"
722 " in environment %s",
728 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
729 "No interface of type %s opened for,"
730 " writing in environment %s",
738 BlackboardCLIPSFeature::clips_blackboard_create_msg(
const std::string &env_name,
739 const std::string &uid,
740 const std::string &msg_type)
743 if (interfaces_.find(env_name) == interfaces_.end()) {
744 return CLIPS::Value(
new std::shared_ptr<Message>());
746 if (envs_.find(env_name) == envs_.end()) {
748 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
749 "Environment %s not registered,"
750 " cannot read interfaces",
752 return CLIPS::Value(
new std::shared_ptr<Message>());
756 std::string if_type, id;
757 Interface::parse_uid(uid.c_str(), if_type, id);
760 if (interfaces_[env_name].reading.find(if_type) == interfaces_[env_name].reading.end()) {
762 (
"BBCLIPS|" + env_name).c_str(),
763 "Can't create message for interface %s, because there is no opened interface with this type",
765 return CLIPS::Value(
new std::shared_ptr<Message>());
767 auto i = std::find_if(interfaces_[env_name].reading[if_type].begin(),
768 interfaces_[env_name].reading[if_type].end(),
769 [&uid](
const Interface *iface) ->
bool {
return uid == iface->
uid(); });
770 if (i == interfaces_[env_name].reading[if_type].end()) {
772 (
"BBCLIPS|" + env_name).c_str(),
773 "Can't create message for interface %s, because there is no opened interface with that uid",
775 return CLIPS::Value(
new std::shared_ptr<Message>());
779 std::list<const char *> available_types = (*i)->get_message_types();
780 bool type_exists =
false;
781 for (std::list<const char *>::iterator it = available_types.begin();
782 it != available_types.end() && !type_exists;
784 if (std::string(*it).compare(msg_type) == 0) {
789 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
790 "Can't create message for interface %s, because there is no message type %s",
793 return CLIPS::Value(
new std::shared_ptr<Message>());
797 Message *m = (*i)->create_message(msg_type.c_str());
800 interface_of_msg_[m] = (*i);
803 return CLIPS::Value(
new std::shared_ptr<Message>(m));
807 BlackboardCLIPSFeature::clips_blackboard_list_msg_fields(
const std::string &env_name,
void *msgptr)
809 std::shared_ptr<Message> *m =
static_cast<std::shared_ptr<Message> *
>(msgptr);
811 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
812 "Can't list message fields, the pointer is wrong.");
813 return CLIPS::Values();
816 const int field_count = (*m)->num_fields();
817 CLIPS::Values field_names(field_count);
820 field_names[i].set(it.get_name(),
true);
821 logger_->
log_info((
"BBCLIPS|" + env_name).c_str(),
"Message has field %s", it.get_name());
828 BlackboardCLIPSFeature::clips_blackboard_set_msg_field(
const std::string &env_name,
830 const std::string &field_name,
833 std::shared_ptr<Message> *m =
static_cast<std::shared_ptr<Message> *
>(msgptr);
835 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
836 "Can't set message field, the pointer is wrong.");
840 bool set_success = set_field((*m)->fields(), (*m)->fields_end(), env_name, field_name, value);
842 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Can't set message field.");
847 BlackboardCLIPSFeature::clips_blackboard_set_msg_multifield(
const std::string &env_name,
849 const std::string &field_name,
850 CLIPS::Values values)
852 std::shared_ptr<Message> *m =
static_cast<std::shared_ptr<Message> *
>(msgptr);
854 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
855 "Can't set message field, the pointer is wrong.");
860 set_multifield((*m)->fields(), (*m)->fields_end(), env_name, field_name, values);
862 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Can't set message field.");
867 BlackboardCLIPSFeature::clips_blackboard_send_msg(
const std::string &env_name,
void *msgptr)
869 std::shared_ptr<Message> *m =
static_cast<std::shared_ptr<Message> *
>(msgptr);
871 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
872 "Can't set message field, the pointer is wrong.");
873 return CLIPS::Value(0);
875 if (!interface_of_msg_[m->get()]) {
876 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Can't send message, was it already sent?");
877 return CLIPS::Value(0);
883 unsigned int message_id = 0;
887 interface_of_msg_[m->get()]->msgq_enqueue(m->get());
888 message_id = m->get()->
id();
893 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
894 "Failed to send message: %s",
899 interface_of_msg_.erase(m->get());
904 return CLIPS::Value(message_id);
915 const std::string & env_name,
916 const std::string & field,
917 CLIPS::Values values)
921 for (fit = fit_begin; fit != fit_end; ++fit) {
924 if (values.size() < min_length) {
925 min_length = values.size();
928 for (
size_t i = 0; i < min_length; i++) {
929 bool success = set_field(fit, fit_end, env_name, field, values[i], i);
938 if (fit == fit_end) {
939 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
"Can't find field %s", field.c_str());
953 const std::string & env_name,
954 const std::string & field,
959 for (fit = fit_begin; fit != fit_end; ++fit) {
963 if (value.type() != CLIPS::TYPE_SYMBOL && value.type() != CLIPS::TYPE_STRING) {
964 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
965 "Cannot set field %s: invalid value (not a symbol)",
969 std::string val_s = value.as_string();
970 if (value ==
"TRUE") {
972 }
else if (value ==
"FALSE") {
975 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
976 "Cannot set field %s: invalid value %s (not a bool)",
985 if (value.type() != CLIPS::TYPE_INTEGER) {
986 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
987 "Cannot set field %s: invalid value (not an integer)",
991 long long int val = value.as_integer();
997 if (value.type() != CLIPS::TYPE_INTEGER) {
998 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
999 "Cannot set field %s: invalid value (not an integer)",
1003 long long int val = value.as_integer();
1009 if (value.type() != CLIPS::TYPE_INTEGER) {
1010 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1011 "Cannot set field %s: invalid value (not an integer)",
1015 long long int val = value.as_integer();
1021 if (value.type() != CLIPS::TYPE_INTEGER) {
1022 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1023 "Cannot set field %s: invalid value (not an integer)",
1027 long long int val = value.as_integer();
1033 if (value.type() != CLIPS::TYPE_INTEGER) {
1034 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1035 "Cannot set field %s: invalid value (not an integer)",
1039 long long int val = value.as_integer();
1045 if (value.type() != CLIPS::TYPE_INTEGER) {
1046 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1047 "Cannot set field %s: invalid value (not an integer)",
1051 long long int val = value.as_integer();
1057 if (value.type() != CLIPS::TYPE_INTEGER) {
1058 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1059 "Cannot set field %s: invalid value (not an integer)",
1063 long long int val = value.as_integer();
1069 if (value.type() != CLIPS::TYPE_INTEGER) {
1070 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1071 "Cannot set field %s: invalid value (not an integer)",
1075 long long int val = value.as_integer();
1081 if (value.type() != CLIPS::TYPE_FLOAT && value.type() != CLIPS::TYPE_INTEGER) {
1082 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1083 "Cannot set field %s: invalid value "
1084 "(neither float nor integer)",
1088 if (value.type() == CLIPS::TYPE_FLOAT) {
1089 double val = value.as_float();
1092 long long int val = value.as_integer();
1099 if (value.type() != CLIPS::TYPE_FLOAT && value.type() != CLIPS::TYPE_INTEGER) {
1100 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1101 "Cannot set field %s: invalid value "
1102 "(neither double nor integer)",
1106 if (value.type() == CLIPS::TYPE_FLOAT) {
1107 double val = value.as_float();
1110 long long int val = value.as_integer();
1117 if (value.type() != CLIPS::TYPE_SYMBOL && value.type() != CLIPS::TYPE_STRING) {
1118 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1119 "Cannot set field %s: invalid value "
1120 "(neither symbol nor string)",
1124 std::string val = value.as_string();
1127 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1128 "Cannot set field %s[%d]: "
1129 "there are no string arrays in interfaces",
1137 if (value.type() != CLIPS::TYPE_SYMBOL) {
1138 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1139 "Cannot set field %s: invalid value "
1144 std::string val = value.as_string();
1147 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1148 "Failed to set enum field %s to %s, exception follows",
1150 value.as_string().c_str());
1151 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(), e);
1158 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1159 "Setting of field type %s for %s not supported",
1169 if (fit == fit_end) {
1170 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
"Can't find field %s", field.c_str());