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!");
The BlackBoard abstract class.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
virtual void close(Interface *interface)=0
Close interface.
Interface for configuration handling.
Base class for exceptions in Fawkes.
Base class for all Fawkes BlackBoard interfaces.
InterfaceFieldIterator fields_end()
Invalid iterator.
InterfaceFieldIterator fields()
Get iterator over all fields of this interface instance.
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
Abstract class to execute a Golog++ activity.
Logger * logger_
The logger to use for logging messages.
bool can_execute_activity(std::shared_ptr< gologpp::Activity > activity) const override
Determine if this executor can execute the given activity.
BBMessageActionExecutor(Logger *logger, BlackBoard *blackboard, Configuration *config, const std::string &cfg_prefix)
Constructor.
virtual ~BBMessageActionExecutor()
Destructor.
void start(std::shared_ptr< gologpp::Activity > activity) override
Start the given activity.
void stop(std::shared_ptr< gologpp::Grounding< gologpp::Action >> activity) override
Stop the given activity.
Fawkes library namespace.