22#include "blackboard_computable.h"
24#include <bsoncxx/builder/basic/document.hpp>
33using namespace bsoncxx;
34using namespace mongocxx;
48 robot_memory_ = robot_memory;
49 blackboard_ = blackboard;
53 using namespace bsoncxx::builder;
54 basic::document query;
55 query.append(basic::kvp(
"interface", [](basic::sub_document subdoc) {
56 subdoc.append(basic::kvp(
"$exists",
true));
58 int priority = config->
get_int(
"plugins/robot-memory/computables/blackboard/priority");
60 config->
get_float(
"plugins/robot-memory/computables/blackboard/caching-time");
63 &BlackboardComputable::compute_interfaces,
69BlackboardComputable::~BlackboardComputable()
74std::list<document::value>
75BlackboardComputable::compute_interfaces(
const document::view &query,
const std::string &collection)
77 std::list<document::value> res;
78 std::string type = query[
"interface"].get_utf8().value.to_string();
80 auto id_it = query.find(
"id");
81 if (id_it != query.end()) {
82 id = query[
"id"].get_utf8().value.to_string();
88 using namespace bsoncxx::builder;
90 doc.append(basic::kvp(
"interface", interface->type()));
91 doc.append(basic::kvp(
"id", interface->id()));
93 if (it.get_length() > 1 && it.get_type() != IFT_STRING) {
94 doc.append(basic::kvp(std::string(it.get_name()), [it](basic::sub_array array) {
95 for (unsigned int i = 0; i < it.get_length(); i++) {
96 switch (it.get_type()) {
97 case IFT_BOOL: array.append(it.get_bool(i)); break;
98 case IFT_INT8: array.append(it.get_int8(i)); break;
99 case IFT_UINT8: array.append(it.get_uint8(i)); break;
100 case IFT_INT16: array.append(it.get_int16(i)); break;
101 case IFT_UINT16: array.append(it.get_uint16(i)); break;
102 case IFT_INT32: array.append(it.get_int32(i)); break;
103 case IFT_UINT32: array.append(static_cast<int64_t>(it.get_uint32(i))); break;
104 case IFT_INT64: array.append(static_cast<int64_t>(it.get_int64(i))); break;
105 case IFT_UINT64: array.append(static_cast<int64_t>(it.get_uint64(i))); break;
106 case IFT_FLOAT: array.append(it.get_float(i)); break;
107 case IFT_DOUBLE: array.append(it.get_double(i)); break;
108 case IFT_STRING: array.append(it.get_string()); break;
109 case IFT_BYTE: array.append(it.get_byte(i)); break;
110 case IFT_ENUM: array.append(it.get_enum_string(i)); break;
115 std::string key{it.get_name()};
116 switch (it.get_type()) {
117 case IFT_BOOL: doc.append(basic::kvp(key, it.get_bool()));
break;
118 case IFT_INT8: doc.append(basic::kvp(key, it.get_int8()));
break;
119 case IFT_UINT8: doc.append(basic::kvp(key, it.get_uint8()));
break;
120 case IFT_INT16: doc.append(basic::kvp(key, it.get_int16()));
break;
121 case IFT_UINT16: doc.append(basic::kvp(key, it.get_uint16()));
break;
122 case IFT_INT32: doc.append(basic::kvp(key, it.get_int32()));
break;
123 case IFT_UINT32: doc.append(basic::kvp(key,
static_cast<int64_t
>(it.get_uint32())));
break;
124 case IFT_INT64: doc.append(basic::kvp(key,
static_cast<int64_t
>(it.get_int64())));
break;
125 case IFT_UINT64: doc.append(basic::kvp(key,
static_cast<int64_t
>(it.get_uint64())));
break;
126 case IFT_FLOAT: doc.append(basic::kvp(key, it.get_float()));
break;
127 case IFT_DOUBLE: doc.append(basic::kvp(key, it.get_double()));
break;
128 case IFT_STRING: doc.append(basic::kvp(key, it.get_string()));
break;
129 case IFT_BYTE: doc.append(basic::kvp(key, it.get_byte()));
break;
130 case IFT_ENUM: doc.append(basic::kvp(key, it.get_enum_string()));
break;
134 res.push_back(doc.extract());
135 blackboard_->
close(interface);
BlackboardComputable(RobotMemory *robot_memory, fawkes::BlackBoard *blackboard, fawkes::Logger *logger, fawkes::Configuration *config)
Constructor with references to objects of the plugin.
Access to the robot memory based on mongodb.
Computable * register_computable(bsoncxx::document::value &&query_to_compute, const std::string &collection, std::list< bsoncxx::document::value >(T::*compute_func)(const bsoncxx::document::view &, const std::string &), T *obj, double caching_time=0.0, int priority=0)
Registers a Computable which provides information in the robot memory that is computed on demand.
void remove_computable(Computable *computable)
Remove previously registered computable.
The BlackBoard abstract class.
virtual std::list< Interface * > open_multiple_for_reading(const char *type_pattern, const char *id_pattern="*", const char *owner=NULL)=0
Open multiple interfaces for reading.
virtual void close(Interface *interface)=0
Close interface.
Interface for configuration handling.
virtual float get_float(const char *path)=0
Get value from configuration which is of type float.
virtual int get_int(const char *path)=0
Get value from configuration which is of type int.
Interface field iterator.
Base class for all Fawkes BlackBoard interfaces.
Fawkes library namespace.
@ IFT_INT8
8 bit integer field
@ IFT_UINT32
32 bit unsigned integer field
@ IFT_BYTE
byte field, alias for uint8
@ IFT_UINT64
64 bit unsigned integer field
@ IFT_UINT16
16 bit unsigned integer field
@ IFT_INT32
32 bit integer field
@ IFT_INT64
64 bit integer field
@ IFT_INT16
16 bit integer field
@ IFT_ENUM
field with interface specific enum type
@ IFT_UINT8
8 bit unsigned integer field