23 #include "log_adapter.h"
25 #include <AdapterConfiguration.hh>
26 #include <AdapterExecInterface.hh>
27 #include <AdapterFactory.hh>
30 #include <plan-utils.hh>
41 : InterfaceAdapter(execInterface)
51 pugi::xml_node
const xml)
52 : InterfaceAdapter(execInterface, xml)
67 logger_ =
reinterpret_cast<fawkes::Logger *
>(m_execInterface.getProperty(
"::Fawkes::Logger"));
69 PLEXIL::g_configuration->registerCommandInterface(
"print",
this);
70 PLEXIL::g_configuration->registerCommandInterface(
"pprint",
this);
71 PLEXIL::g_configuration->registerCommandInterface(
"printToString",
this);
72 PLEXIL::g_configuration->registerCommandInterface(
"pprintToString",
this);
73 PLEXIL::g_configuration->registerCommandInterface(
"to_string",
this);
75 PLEXIL::g_configuration->registerCommandInterface(
"log_debug",
this);
76 PLEXIL::g_configuration->registerCommandInterface(
"log_info",
this);
77 PLEXIL::g_configuration->registerCommandInterface(
"log_warn",
this);
78 PLEXIL::g_configuration->registerCommandInterface(
"log_error",
this);
120 v_tostring(
const std::vector<PLEXIL::Value> &values,
bool pretty)
124 rv = pprintToString(values).valueToString();
126 rv = printToString(values).valueToString();
128 if (rv[rv.size() - 1] ==
'\n') {
129 rv.resize(rv.size() - 1);
135 v_tovalue(
const std::vector<PLEXIL::Value> &values,
bool pretty)
139 rv = pprintToString(values).valueToString();
141 rv = printToString(values).valueToString();
152 std::map<std::string, std::function<void(
const std::vector<PLEXIL::Value> &)>> mapping_norv = {
154 [
this](
const std::vector<PLEXIL::Value> &values) {
155 this->logger_->
log_info(
"Plexil",
"%s", v_tostring(values,
false).c_str());
158 [
this](
const std::vector<PLEXIL::Value> &values) {
159 this->logger_->
log_info(
"Plexil",
"%s", v_tostring(values,
true).c_str());
162 [
this](
const std::vector<PLEXIL::Value> &values) {
163 this->logger_->
log_debug(
"Plexil",
"%s", v_tostring(values,
true).c_str());
166 [
this](
const std::vector<PLEXIL::Value> &values) {
167 this->logger_->
log_info(
"Plexil",
"%s", v_tostring(values,
true).c_str());
170 [
this](
const std::vector<PLEXIL::Value> &values) {
171 this->logger_->
log_warn(
"Plexil",
"%s", v_tostring(values,
true).c_str());
173 {
"log_error", [
this](
const std::vector<PLEXIL::Value> &values) {
174 this->logger_->
log_error(
"Plexil",
"%s", v_tostring(values,
true).c_str());
177 std::map<std::string, std::function<PLEXIL::Value(
const std::vector<PLEXIL::Value> &)>>
180 [](
const std::vector<PLEXIL::Value> &values) {
return v_tovalue(values,
false); }},
182 [](
const std::vector<PLEXIL::Value> &values) {
return v_tovalue(values,
true); }},
184 [](
const std::vector<PLEXIL::Value> &values) {
return v_tovalue(values,
false); }},
187 const auto &entry_norv = mapping_norv.find(cmd->getName());
188 const auto &entry_rv = mapping_rv.find(cmd->getName());
189 if (entry_norv != mapping_norv.end()) {
190 entry_norv->second(cmd->getArgValues());
191 m_execInterface.handleCommandAck(cmd, PLEXIL::COMMAND_SUCCESS);
192 }
else if (entry_rv != mapping_rv.end()) {
193 m_execInterface.handleCommandReturn(cmd, entry_rv->second(cmd->getArgValues()));
194 m_execInterface.handleCommandAck(cmd, PLEXIL::COMMAND_SUCCESS);
196 m_execInterface.handleCommandAck(cmd, PLEXIL::COMMAND_FAILED);
199 m_execInterface.notifyOfExternalEvent();
208 m_execInterface.handleCommandAbortAck(cmd,
false);
209 m_execInterface.notifyOfExternalEvent();
214 initFawkesLoggingAdapter()