21 #include "message_action_executor.h"
25 #include <blackboard/blackboard.h>
26 #include <config/config.h>
27 #include <golog++/model/activity.h>
28 #include <logging/logger.h>
50 const std::string &cfg_prefix)
51 :
ActionExecutor(logger), blackboard_(blackboard), config_(config), cfg_prefix_(cfg_prefix)
60 for (
auto interface : open_interfaces_) {
61 blackboard_->
close(interface.second);
68 return activity->mapped_name() ==
"send_message";
75 throw Exception(
"Cannot execute activity '%s' with BBMessageActionExecutor",
76 activity->mapped_name().c_str());
78 activity->update(gologpp::Transition::Hook::START);
79 std::string interface_type =
80 static_cast<std::string
>(activity->mapped_arg_value(
"interface_type"));
81 std::string interface_id =
static_cast<std::string
>(activity->mapped_arg_value(
"interface_id"));
82 std::string message_type =
static_cast<std::string
>(activity->mapped_arg_value(
"message_type"));
83 if (open_interfaces_.find(interface_id) == open_interfaces_.end()) {
84 open_interfaces_[interface_id] =
87 Interface *
interface = open_interfaces_[interface_id];
88 auto msg = interface->create_message(message_type.c_str());
91 if (activity->target()->mapping().is_mapped(field.get_name())) {
92 auto value = activity->mapped_arg_value(field.get_name());
94 value_to_field(value, &field);
95 }
catch (boost::bad_get &e) {
97 "Failed to convert value '%s' of field '%s' with type '%s': '%s'",
98 value.string_representation().c_str(),
100 field.get_typename(),
102 activity->update(gologpp::Transition::Hook::FAIL);
107 interface->msgq_enqueue(msg);
108 activity->update(gologpp::Transition::Hook::FINISH);
116 "Cannot stop a message that has already been sent!");