22 #include "skiller-rest-api.h"
24 #include <core/threading/mutex_locker.h>
25 #include <interfaces/SkillerDebugInterface.h>
26 #include <interfaces/SkillerInterface.h>
27 #include <utils/time/wait.h>
28 #include <webview/rest_api_manager.h>
55 WebRequest::METHOD_GET,
"/skills", std::bind(&SkillerRestApi::cb_list_skills,
this));
56 rest_api_->add_handler<
Skill>(WebRequest::METHOD_GET,
58 std::bind(&SkillerRestApi::cb_get_skill,
60 std::placeholders::_1));
61 rest_api_->add_handler(WebRequest::METHOD_DELETE,
63 std::bind(&SkillerRestApi::cb_stop_skill,
this, std::placeholders::_1));
66 std::bind(&SkillerRestApi::cb_exec_skill,
68 std::placeholders::_1));
85 SkillerRestApi::set_and_wait_graph(
const char *graph)
87 if (strcmp(skdb_if_->
graph_fsm(), graph) != 0) {
97 }
while (strcmp(skdb_if_->
graph_fsm(), graph) != 0 && (now - &
start) <= 5.0);
100 if (strcmp(skdb_if_->
graph_fsm(), graph) != 0) {
102 "Did not receive '%s' in time from skiller",
108 SkillerRestApi::cb_list_skills()
115 "Behavior Engine plugin is not loaded");
118 std::string prev_fsm = skdb_if_->
graph_fsm();
120 set_and_wait_graph(
"LIST");
122 std::stringstream ss(skdb_if_->
graph());
123 std::string skill_name;
124 while (std::getline(ss, skill_name,
'\n')) {
142 std::string skill_name{params.
path_arg(
"id")};
144 if (skill_name ==
"active") {
145 skill_name =
"ACTIVE";
152 "Behavior Engine plugin is not loaded");
155 set_and_wait_graph(skill_name.c_str());
161 s.set_graph(skdb_if_->
graph());
163 if (skill_name ==
"ACTIVE") {
166 s.set_error(skiller_if_->
error());
167 s.set_msg_id(skiller_if_->
msgid());
169 switch (skiller_if_->
status()) {
170 case SkillerInterface::S_RUNNING: s.set_status(
"RUNNING");
break;
171 case SkillerInterface::S_FINAL: s.set_status(
"FINAL");
break;
172 case SkillerInterface::S_FAILED: s.set_status(
"FAILED");
break;
173 default: s.set_status(
"INACTIVE");
break;
181 SkillerRestApi::cb_exec_skill(
const SkillCall &call)
190 "Behavior Engine plugin is not loaded");
206 "Failed to execute skill: %s",
219 std::unique_ptr<fawkes::WebviewRestReply>
222 std::string skill_name{params.
path_arg(
"id")};
224 if (skill_name !=
"active") {
226 "Only the 'active' skill can be stopped");
232 "Behavior Engine plugin is not loaded");
244 "Failed to execute skill: %s",
248 return std::make_unique<WebviewRestReply>(WebReply::HTTP_OK,
"OK",
"text/plain");