22 #include "blackboard_computable.h"
24 #include <bsoncxx/builder/basic/document.hpp>
33 using namespace bsoncxx;
34 using 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");
61 computable = robot_memory_->register_computable(query.extract(),
63 &BlackboardComputable::compute_interfaces,
69 BlackboardComputable::~BlackboardComputable()
71 robot_memory_->remove_computable(computable);
74 std::list<document::value>
75 BlackboardComputable::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();
85 for (
Interface *interface : blackboard_->open_multiple_for_reading(type.c_str(),
id.c_str())) {
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);