23 #include "feature_blackboard.h" 24 #include <core/threading/mutex_locker.h> 25 #include <blackboard/blackboard.h> 26 #include <logging/logger.h> 27 #include <utils/misc/string_conversions.h> 28 #include <utils/time/time.h> 29 #include <utils/misc/string_split.h> 30 #include <interface/interface_info.h> 47 :
CLIPSFeature(
"blackboard"), logger_(logger), blackboard_(blackboard)
55 for (
auto &iface_map : interfaces_) {
56 for (
auto &iface_list : iface_map.second.reading) {
57 for (
auto iface : iface_list.second) {
58 blackboard_->
close(iface);
61 for (
auto &iface_list : iface_map.second.writing) {
62 for (
auto iface : iface_list.second) {
63 blackboard_->
close(iface);
76 envs_[env_name] = clips;
77 clips->evaluate(
"(path-load \"blackboard.clp\")");
78 clips->add_function(
"blackboard-enable-time-read",
81 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_enable_time_read),
85 clips->add_function(
"blackboard-open",
86 sigc::slot<void, std::string, std::string>(
88 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_open_interface_reading),
92 clips->add_function(
"blackboard-open-reading",
93 sigc::slot<void, std::string, std::string>(
95 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_open_interface_reading),
99 clips->add_function(
"blackboard-open-writing",
100 sigc::slot<void, std::string, std::string>(
102 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_open_interface_writing),
106 clips->add_function(
"blackboard-close",
107 sigc::slot<void, std::string, std::string>(
109 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_close_interface),
113 clips->add_function(
"blackboard-preload",
114 sigc::slot<void, std::string>(
116 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_preload),
120 clips->add_function(
"blackboard-read",
123 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_read),
127 clips->add_function(
"blackboard-write",
128 sigc::slot<void, std::string>(
130 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_write),
134 clips->add_function(
"blackboard-get-info",
137 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_get_info),
141 clips->add_function(
"blackboard-set",
142 sigc::slot<void, std::string, std::string, CLIPS::Value>(
144 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_set),
148 clips->add_function(
"blackboard-set-multifield",
149 sigc::slot<void, std::string, std::string, CLIPS::Values>(
151 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_set_multifield),
155 clips->add_function(
"blackboard-create-msg",
156 sigc::slot<CLIPS::Value, std::string, std::string>(
158 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_create_msg),
162 clips->add_function(
"blackboard-list-msg-fields",
163 sigc::slot<CLIPS::Values, void *>(
165 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_list_msg_fields),
169 clips->add_function(
"blackboard-set-msg-field",
170 sigc::slot<void, void *, std::string, CLIPS::Value>(
172 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_set_msg_field),
176 clips->add_function(
"blackboard-set-msg-multifield",
177 sigc::slot<void, void *, std::string, CLIPS::Values>(
179 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_set_msg_multifield),
183 clips->add_function(
"blackboard-send-msg",
184 sigc::slot<CLIPS::Value, void *>(
186 sigc::mem_fun(*
this, &BlackboardCLIPSFeature::clips_blackboard_send_msg),
195 if (interfaces_.find(env_name) != interfaces_.end()) {
196 for (
auto &iface_map : interfaces_[env_name].reading) {
197 for (
auto iface : iface_map.second) {
198 logger_->
log_debug((
"BBCLIPS|" + env_name).c_str(),
"Closing reading interface %s",
200 blackboard_->
close(iface);
203 for (
auto &iface_map : interfaces_[env_name].writing) {
204 for (
auto iface : iface_map.second) {
205 logger_->
log_debug((
"BBCLIPS|" + env_name).c_str(),
"Closing writing interface %s",
207 blackboard_->
close(iface);
210 interfaces_.erase(env_name);
212 envs_.erase(env_name);
217 BlackboardCLIPSFeature::clips_blackboard_enable_time_read(std::string env_name)
219 if (envs_.find(env_name) == envs_.end()) {
220 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
221 "Cannot enable reading for environment %s " 222 "(not defined)", env_name.c_str());
226 std::string bb_read_defrule =
227 "(defrule blackboard-read\n" 228 " (declare (salience 1000))\n" 231 " (blackboard-read)\n" 235 envs_[env_name]->build(bb_read_defrule);
240 BlackboardCLIPSFeature::clips_assert_interface_type(std::string &env_name, std::string &log_name,
243 std::string deftemplate =
244 "(deftemplate " + type +
"\n" +
245 " (slot id (type STRING))\n" +
246 " (multislot time (type INTEGER) (cardinality 2 2))\n";
250 for (f = iface->
fields(); f != f_end; ++f) {
255 deftemplate += std::string() +
257 " (type SYMBOL) (allowed-values TRUE FALSE))\n";
269 deftemplate += std::string() +
271 " (type INTEGER))\n";
276 deftemplate += std::string() +
282 deftemplate += std::string() +
288 deftemplate += std::string() +
297 std::string defrule =
298 "(defrule " + type +
"-cleanup\n" +
299 " (declare (salience -10000))\n" +
300 " ?f <- (" + type +
")\n" +
306 if (envs_[env_name]->build(deftemplate) && envs_[env_name]->build(defrule)) {
307 logger_->
log_info(log_name.c_str(),
"Deftemplate:\n%s", deftemplate.c_str());
308 logger_->
log_info(log_name.c_str(),
"Defrule:\n%s", defrule.c_str());
311 logger_->
log_warn(log_name.c_str(),
"Defining blackboard type for %s in %s failed",
312 type.c_str(), env_name.c_str());
319 BlackboardCLIPSFeature::clips_blackboard_preload(std::string env_name, std::string type)
321 std::string name =
"BBCLIPS|" + env_name;
323 if (envs_.find(env_name) == envs_.end()) {
324 logger_->
log_warn(name.c_str(),
"Environment %s has not been registered " 325 "for blackboard feature", env_name.c_str());
329 if (interfaces_[env_name].reading.find(type) == interfaces_[env_name].reading.end() &&
330 interfaces_[env_name].writing.find(type) == interfaces_[env_name].writing.end())
335 iface = blackboard_->
open_for_reading(type.c_str(),
"__clips_blackboard_preload__");
336 clips_assert_interface_type(env_name, name, iface, type);
337 blackboard_->
close(iface);
338 interfaces_[env_name].reading.insert(std::make_pair(type, std::list<fawkes::Interface *>()));
340 logger_->
log_warn(name.c_str(),
"Failed to preload interface type %s, " 341 "exception follows", type.c_str());
350 BlackboardCLIPSFeature::clips_blackboard_open_interface(std::string env_name,
351 std::string type, std::string
id,
354 std::string name =
"BBCLIPS|" + env_name;
355 std::string owner =
"CLIPS:" + env_name;
357 if (envs_.find(env_name) == envs_.end()) {
358 logger_->
log_warn(name.c_str(),
"Environment %s has not been registered " 359 "for blackboard feature", env_name.c_str());
364 InterfaceMap &iface_map =
365 writing ? interfaces_[env_name].writing : interfaces_[env_name].reading;
367 if (iface_map.find(type) == iface_map.end()) {
371 iface = blackboard_->
open_for_writing(type.c_str(),
id.c_str(), owner.c_str());
373 iface = blackboard_->
open_for_reading(type.c_str(),
id.c_str(), owner.c_str());
376 logger_->
log_warn(name.c_str(),
"Failed to open interface %s:%s, exception follows",
377 type.c_str(),
id.c_str());
382 if (! clips_assert_interface_type(env_name, name, iface, type)) {
383 blackboard_->
close(iface);
385 logger_->
log_info(name.c_str(),
"Added interface %s for %s", iface->
uid(),
386 iface->
is_writer() ?
"writing" :
"reading");
387 iface_map.insert(std::make_pair(type, std::list<fawkes::Interface *>(1, iface)));
390 auto &iface_list = iface_map[type];
391 if (std::none_of(iface_list.begin(), iface_list.end(),
393 return (type == i->type()) && (
id == i->id());
398 iface = blackboard_->
open_for_writing(type.c_str(),
id.c_str(), owner.c_str());
400 iface = blackboard_->
open_for_reading(type.c_str(),
id.c_str(), owner.c_str());
402 iface_map[type].push_back(iface);
403 logger_->
log_info(name.c_str(),
"Added interface %s for %s", iface->
uid(),
404 iface->
is_writer() ?
"writing" :
"reading");
406 logger_->
log_warn(name.c_str(),
"Failed to open interface %s:%s, exception follows",
407 type.c_str(),
id.c_str());
417 BlackboardCLIPSFeature::clips_blackboard_open_interface_reading(std::string env_name,
418 std::string type, std::string
id)
420 clips_blackboard_open_interface(env_name, type,
id,
false);
424 BlackboardCLIPSFeature::clips_blackboard_open_interface_writing(std::string env_name,
425 std::string type, std::string
id)
427 clips_blackboard_open_interface(env_name, type,
id,
true);
432 BlackboardCLIPSFeature::clips_blackboard_close_interface(std::string env_name,
433 std::string type, std::string
id)
435 std::string name =
"BBCLIPS|" + env_name;
437 if (envs_.find(env_name) == envs_.end()) {
438 logger_->
log_warn(name.c_str(),
"Environment %s has not been registered " 439 "for blackboard feature", env_name.c_str());
443 if (interfaces_[env_name].reading.find(type) != interfaces_[env_name].reading.end()) {
444 auto &l = interfaces_[env_name].reading[type];
445 auto iface_it = find_if(l.begin(), l.end(),
446 [&id] (
const Interface *iface) {
return id == iface->
id(); });
447 if (iface_it != l.end()) {
448 blackboard_->
close(*iface_it);
454 if (interfaces_[env_name].writing.find(type) != interfaces_[env_name].writing.end()) {
455 auto &l = interfaces_[env_name].writing[type];
456 auto iface_it = find_if(l.begin(), l.end(),
457 [&id] (
const Interface *iface) {
return id == iface->
id(); });
458 if (iface_it != l.end()) {
459 blackboard_->
close(*iface_it);
468 BlackboardCLIPSFeature::clips_blackboard_read(std::string env_name)
471 if (interfaces_.find(env_name) == interfaces_.end())
return;
472 if (envs_.find(env_name) == envs_.end()) {
474 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Environment %s not registered," 475 " cannot read interfaces", env_name.c_str());
480 for (
auto &iface_map : interfaces_[env_name].reading) {
481 for (
auto i : iface_map.second) {
484 const Time *t = i->timestamp();
485 std::string fact = std::string(
"(") + i->type() +
486 " (id \"" + i->id() +
"\")" +
487 " (time " + StringConversions::to_string(t->
get_sec()) +
" " 488 + StringConversions::to_string(t->
get_usec()) +
")";
491 for (f = i->fields(); f != f_end; ++f) {
494 value = f.
get_bool() ?
"TRUE" :
"FALSE";
496 value = f.get_value_string();
497 std::string::size_type pos = 0;
498 while ((pos = value.find(
"\"", pos)) != std::string::npos) {
499 value.replace(pos, 1,
"\\\"");
502 value = std::string(
"\"") + value +
"\"";
504 value = f.get_value_string();
505 std::string::size_type pos;
506 while ((pos = value.find(
",")) != std::string::npos) {
507 value = value.erase(pos, 1);
511 std::string::size_type pos;
512 while ((pos = value.find(
"-inf")) != std::string::npos) {
513 value = value.replace(pos, 4, std::to_string(std::numeric_limits<double>::min()));
515 while ((pos = value.find(
"inf")) != std::string::npos) {
516 value = value.replace(pos, 3, std::to_string(std::numeric_limits<double>::max()));
521 fact += std::string(
" (") + f.get_name() +
" " + value +
")";
524 envs_[env_name]->assert_fact(fact);
532 BlackboardCLIPSFeature::clips_blackboard_write(std::string env_name, std::string uid)
535 if (interfaces_.find(env_name) == interfaces_.end())
return;
536 if (envs_.find(env_name) == envs_.end()) {
538 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Environment %s not registered," 539 " cannot write interface %s", env_name.c_str(), uid.c_str());
542 std::string type, id;
543 Interface::parse_uid(uid.c_str(), type, id);
544 if (interfaces_[env_name].writing.find(type) != interfaces_[env_name].writing.end()) {
545 auto i = std::find_if(interfaces_[env_name].writing[type].begin(),
546 interfaces_[env_name].writing[type].end(),
548 return uid == iface->
uid();
550 if (i != interfaces_[env_name].writing[type].end()) {
553 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Interface %s not opened for writing," 554 " in environment %s", uid.c_str(), env_name.c_str());
558 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"No interface of type %s opened for," 559 " writing in environment %s", type.c_str(), env_name.c_str());
565 BlackboardCLIPSFeature::clips_blackboard_get_info(std::string env_name)
567 if (envs_.find(env_name) == envs_.end()) {
569 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Environment %s not registered," 570 " cannot read interfaces", env_name.c_str());
579 for (
auto ii : *iil) {
580 const Time *timestamp = ii.timestamp();
581 std::list<std::string> quoted_readers;
582 std::list<std::string> readers = ii.readers();
583 std::for_each(readers.begin(), readers.end(),
584 ["ed_readers](
const std::string &r) {
585 quoted_readers.push_back(std::string(
"\"")+r+
"\"");
587 std::string quoted_readers_s =
str_join(quoted_readers,
' ');
588 clips->assert_fact_f(
"(blackboard-interface-info (id \"%s\") (type \"%s\") " 589 "(hash \"%s\") (has-writer %s) (num-readers %u) " 590 "(writer \"%s\") (readers %s) (timestamp %u %u))",
591 ii.id(), ii.type(), ii.hash_printable().c_str(),
592 ii.has_writer() ?
"TRUE" :
"FALSE", ii.num_readers(),
593 ii.writer().c_str(), quoted_readers_s.c_str(),
602 BlackboardCLIPSFeature::clips_blackboard_set(std::string env_name, std::string uid,
603 std::string field, CLIPS::Value value)
606 if (interfaces_.find(env_name) == interfaces_.end())
return;
607 if (envs_.find(env_name) == envs_.end()) {
609 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Environment %s not registered," 610 " cannot set %s on interface %s", env_name.c_str(),
611 field.c_str(), uid.c_str());
614 std::string type, id;
615 Interface::parse_uid(uid.c_str(), type, id);
616 if (interfaces_[env_name].writing.find(type) != interfaces_[env_name].writing.end()) {
617 auto i = std::find_if(interfaces_[env_name].writing[type].begin(),
618 interfaces_[env_name].writing[type].end(),
620 return uid == iface->
uid();
622 if (i != interfaces_[env_name].writing[type].end()) {
623 set_field((*i)->fields(), (*i)->fields_end(), env_name, field, value);
625 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
"Interface %s not opened for writing," 626 " in environment %s", uid.c_str(), env_name.c_str());
630 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
"No interface of type %s opened for," 631 " writing in environment %s", type.c_str(), env_name.c_str());
637 BlackboardCLIPSFeature::clips_blackboard_set_multifield(std::string env_name,
640 CLIPS::Values values)
643 if (interfaces_.find(env_name) == interfaces_.end())
return;
644 if (envs_.find(env_name) == envs_.end()) {
646 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Environment %s not registered," 647 " cannot set %s on interface %s", env_name.c_str(),
648 field.c_str(), uid.c_str());
651 std::string type, id;
652 Interface::parse_uid(uid.c_str(), type, id);
653 if (interfaces_[env_name].writing.find(type) != interfaces_[env_name].writing.end()) {
654 auto i = std::find_if(interfaces_[env_name].writing[type].begin(),
655 interfaces_[env_name].writing[type].end(),
657 return uid == iface->
uid();
659 if (i != interfaces_[env_name].writing[type].end()) {
660 set_multifield((*i)->fields(), (*i)->fields_end(), env_name, field, values);
662 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
"Interface %s not opened for writing," 663 " in environment %s", uid.c_str(), env_name.c_str());
667 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
"No interface of type %s opened for," 668 " writing in environment %s", type.c_str(), env_name.c_str());
674 BlackboardCLIPSFeature::clips_blackboard_create_msg(std::string env_name, std::string uid,
675 std::string msg_type)
678 if (interfaces_.find(env_name) == interfaces_.end()){
679 return CLIPS::Value(
new std::shared_ptr<Message>());
681 if (envs_.find(env_name) == envs_.end()) {
683 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Environment %s not registered," 684 " cannot read interfaces", env_name.c_str());
685 return CLIPS::Value(
new std::shared_ptr<Message>());
689 std::string if_type, id;
690 Interface::parse_uid(uid.c_str(), if_type, id);
693 if (interfaces_[env_name].reading.find(if_type) == interfaces_[env_name].reading.end()){
694 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Can't create message for interface %s, because there is no opened interface with this type", uid.c_str());
695 return CLIPS::Value(
new std::shared_ptr<Message>());
697 auto i = std::find_if(interfaces_[env_name].reading[if_type].begin(),
698 interfaces_[env_name].reading[if_type].end(),
700 return uid == iface->
uid();
702 if (i == interfaces_[env_name].reading[if_type].end()){
703 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Can't create message for interface %s, because there is no opened interface with that uid", uid.c_str());
704 return CLIPS::Value(
new std::shared_ptr<Message>());
708 std::list<const char *> available_types = (*i)->get_message_types();
709 bool type_exists =
false;
710 for(std::list<const char *>::iterator it = available_types.begin(); it != available_types.end() && !type_exists; it++){
711 if(std::string(*it).compare(msg_type) == 0){
716 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Can't create message for interface %s, because there is no message type %s", uid.c_str(), msg_type.c_str());
717 return CLIPS::Value(
new std::shared_ptr<Message>());
721 Message* m = (*i)->create_message(msg_type.c_str());
724 interface_of_msg_[m] = (*i);
727 return CLIPS::Value(
new std::shared_ptr<Message>(m));
731 BlackboardCLIPSFeature::clips_blackboard_list_msg_fields(std::string env_name,
void *msgptr)
733 std::shared_ptr<Message> *m =
734 static_cast<std::shared_ptr<Message> *
>(msgptr);
736 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Can't list message fields, the pointer is wrong.");
737 return CLIPS::Values();
740 const int field_count = (*m)->num_fields();
741 CLIPS::Values field_names(field_count);
744 field_names[i].set(it.get_name(),
true);
745 logger_->
log_info((
"BBCLIPS|" + env_name).c_str(),
"Message has field %s", it.get_name());
753 BlackboardCLIPSFeature::clips_blackboard_set_msg_field(std::string env_name,
void *msgptr, std::string field_name, CLIPS::Value value)
755 std::shared_ptr<Message> *m =
756 static_cast<std::shared_ptr<Message> *
>(msgptr);
758 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Can't set message field, the pointer is wrong.");
762 bool set_success = set_field((*m)->fields(), (*m)->fields_end(),
763 env_name, field_name, value);
765 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Can't set message field.");
771 BlackboardCLIPSFeature::clips_blackboard_set_msg_multifield(std::string env_name,
void *msgptr, std::string field_name, CLIPS::Values values)
773 std::shared_ptr<Message> *m =
774 static_cast<std::shared_ptr<Message> *
>(msgptr);
776 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Can't set message field, the pointer is wrong.");
780 bool set_success = set_multifield((*m)->fields(), (*m)->fields_end(),
781 env_name, field_name, values);
783 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Can't set message field.");
789 BlackboardCLIPSFeature::clips_blackboard_send_msg(std::string env_name,
void *msgptr)
791 std::shared_ptr<Message> *m =
792 static_cast<std::shared_ptr<Message> *
>(msgptr);
794 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Can't set message field, the pointer is wrong.");
795 return CLIPS::Value(0);
797 if (!interface_of_msg_[m->get()]) {
798 logger_->
log_warn((
"BBCLIPS|" + env_name).c_str(),
"Can't send message, was it already sent?");
799 return CLIPS::Value(0);
806 interface_of_msg_[m->get()]->msgq_enqueue(m->get());
808 unsigned int message_id = m->get()->id();
811 interface_of_msg_.erase(m->get());
816 return CLIPS::Value(message_id);
827 std::string env_name, std::string field,
828 CLIPS::Values values)
832 for (fit = fit_begin; fit != fit_end; ++fit) {
835 if (values.size() < min_length){
836 min_length = values.size();
839 for (
size_t i = 0; i < min_length; i++){
840 bool success = set_field(fit, fit_end, env_name, field, values[i], i);
849 if (fit == fit_end) {
850 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
"Can't find field %s",
866 std::string env_name, std::string field,
867 CLIPS::Value value,
int index)
870 for (fit = fit_begin; fit != fit_end; ++fit) {
874 if (value.type() != CLIPS::TYPE_SYMBOL && value.type() != CLIPS::TYPE_STRING) {
875 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
876 "Cannot set field %s: invalid value (not a symbol)",
880 std::string val_s = value.as_string();
881 if (value ==
"TRUE") {
883 }
else if (value ==
"FALSE") {
886 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
887 "Cannot set field %s: invalid value %s (not a bool)",
888 field.c_str(), val_s.c_str());
895 if (value.type() != CLIPS::TYPE_INTEGER) {
896 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
897 "Cannot set field %s: invalid value (not an integer)",
901 long long int val = value.as_integer();
907 if (value.type() != CLIPS::TYPE_INTEGER) {
908 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
909 "Cannot set field %s: invalid value (not an integer)",
913 long long int val = value.as_integer();
919 if (value.type() != CLIPS::TYPE_INTEGER) {
920 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
921 "Cannot set field %s: invalid value (not an integer)",
925 long long int val = value.as_integer();
931 if (value.type() != CLIPS::TYPE_INTEGER) {
932 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
933 "Cannot set field %s: invalid value (not an integer)",
937 long long int val = value.as_integer();
943 if (value.type() != CLIPS::TYPE_INTEGER) {
944 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
945 "Cannot set field %s: invalid value (not an integer)",
949 long long int val = value.as_integer();
955 if (value.type() != CLIPS::TYPE_INTEGER) {
956 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
957 "Cannot set field %s: invalid value (not an integer)",
961 long long int val = value.as_integer();
967 if (value.type() != CLIPS::TYPE_INTEGER) {
968 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
969 "Cannot set field %s: invalid value (not an integer)",
973 long long int val = value.as_integer();
979 if (value.type() != CLIPS::TYPE_INTEGER) {
980 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
981 "Cannot set field %s: invalid value (not an integer)",
985 long long int val = value.as_integer();
991 if (value.type() != CLIPS::TYPE_FLOAT && value.type() != CLIPS::TYPE_INTEGER) {
992 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
993 "Cannot set field %s: invalid value " 994 "(neither float nor integer)",
998 if (value.type() == CLIPS::TYPE_FLOAT) {
999 double val = value.as_float();
1002 long long int val = value.as_integer();
1009 if (value.type() != CLIPS::TYPE_FLOAT && value.type() != CLIPS::TYPE_INTEGER) {
1010 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1011 "Cannot set field %s: invalid value " 1012 "(neither double nor integer)",
1016 if (value.type() == CLIPS::TYPE_FLOAT) {
1017 double val = value.as_float();
1020 long long int val = value.as_integer();
1027 if (value.type() != CLIPS::TYPE_SYMBOL && value.type() != CLIPS::TYPE_STRING) {
1028 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1029 "Cannot set field %s: invalid value " 1030 "(neither symbol nor string)",
1034 std::string val = value.as_string();
1037 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1038 "Cannot set field %s[%d]: " 1039 "there are no string arrays in interfaces",
1040 field.c_str(), index);
1046 if (value.type() != CLIPS::TYPE_SYMBOL) {
1047 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1048 "Cannot set field %s: invalid value " 1053 std::string val = value.as_string();
1056 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1057 "Failed to set enum field %s to %s, exception follows",
1058 field.c_str(), value.as_string().c_str());
1059 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(), e);
1066 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
1067 "Setting of field type %s for %s not supported",
1076 if (fit == fit_end) {
1077 logger_->
log_error((
"BBCLIPS|" + env_name).c_str(),
"Can't find field %s",
Interface field iterator.
void set_int64(int64_t i, unsigned int index=0)
Set value of current field as integer.
virtual void clips_context_init(const std::string &env_name, fawkes::LockPtr< CLIPS::Environment > &clips)
Initialize a CLIPS context to use the provided feature.
BlackboardCLIPSFeature(fawkes::Logger *logger, fawkes::BlackBoard *blackboard)
Constructor.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
void set_float(float f, unsigned int index=0)
Set value of current field as float.
const char * get_typename() const
Get type of current field as string.
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
void set_bool(bool b, unsigned int index=0)
Set value of current field as bool.
void set_int16(int16_t i, unsigned int index=0)
Set value of current field as integer.
virtual ~BlackboardCLIPSFeature()
Destructor.
Fawkes library namespace.
bool get_bool(unsigned int index=0) const
Get value of current field as bool.
8 bit unsigned integer field
void set_uint16(uint16_t i, unsigned int index=0)
Set value of current field as unsigned integer.
16 bit unsigned integer field
std::string str_join(const InputIterator &first, const InputIterator &last, char delim='/')
Join list of strings string using given delimiter.
const char * id() const
Get identifier of interface.
void set_int8(int8_t i, unsigned int index=0)
Set value of current field as integer.
interface_fieldtype_t get_type() const
Get type of current field.
void set_uint8(uint8_t i, unsigned int index=0)
Set value of current field as unsigned integer.
A class for handling time.
byte field, alias for uint8
Base class for all Fawkes BlackBoard interfaces.
void set_int32(int32_t i, unsigned int index=0)
Set value of current field as integer.
void set_double(double f, unsigned int index=0)
Set value of current field as double.
Interface information list.
Base class for exceptions in Fawkes.
Mutex * objmutex_ptr() const
Get object mutex.
const char * get_name() const
Get name of current field.
CLIPS feature maintainer.
const char * uid() const
Get unique identifier of interface.
void set_string(const char *s)
Set value of current field as string.
64 bit unsigned integer field
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
void set_uint32(uint32_t i, unsigned int index=0)
Set value of current field as unsigned integer.
size_t get_length() const
Get length of current field.
bool is_writer() const
Check if this is a writing instance.
long get_sec() const
Get seconds.
InterfaceFieldIterator fields_end()
Invalid iterator.
long get_usec() const
Get microseconds.
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
virtual InterfaceInfoList * list_all()=0
Get list of all currently existing interfaces.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
void set_enum_string(const char *e, unsigned int index=0)
Set value of current field as enum (from an integer).
void set_uint64(uint64_t i, unsigned int index=0)
Set value of current field as unsigned integer.
The BlackBoard abstract class.
InterfaceFieldIterator fields()
Get iterator over all fields of this interface instance.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
32 bit unsigned integer field
field with interface specific enum type
virtual void clips_context_destroyed(const std::string &env_name)
Notification that a CLIPS environment has been destroyed.
virtual void close(Interface *interface)=0
Close interface.