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");
char * skill_string() const
Get skill_string value.
SkillerDebugInterface Fawkes BlackBoard Interface.
Webview REST API component.
SkillCall representation for JSON transfer.
unsigned int id() const
Get message ID.
void unref()
Decrement reference count and conditionally delete this instance.
SkillInfo representation for JSON transfer.
REST processing exception.
Fawkes library namespace.
StopExecMessage Fawkes BlackBoard Interface Message.
Skill representation for JSON transfer.
char * error() const
Get error value.
std::optional< std::string > skill_string() const
Get skill_string value.
A class for handling time.
void set_kind(const std::string &kind)
Set kind value.
uint32_t exclusive_controller() const
Get exclusive_controller value.
Thread class encapsulation of pthreads.
SetGraphMessage Fawkes BlackBoard Interface Message.
void unregister_api(WebviewRestApi *api)
Remove a request processor.
void set_apiVersion(const std::string &apiVersion)
Set apiVersion value.
SkillerRestApi()
Constructor.
Logger * logger
This is the Logger member used to access the logger.
void register_api(WebviewRestApi *api)
Add a REST API.
static std::string api_version()
Get version of implemented API.
void wait_systime()
Wait until minimum loop time has been reached in real time.
static std::string api_version()
Get version of implemented API.
void set_kind(const std::string &kind)
Set kind value.
Clock * clock
By means of this member access to the clock is given.
void set_apiVersion(const std::string &apiVersion)
Set apiVersion value.
virtual void finalize()
Finalize the thread.
Base class for exceptions in Fawkes.
REST parameters to pass to handlers.
void read()
Read from BlackBoard into local copy.
void push_back(M &m)
Add item at the back of the container.
void ref()
Increment reference count.
bool has_writer() const
Check if there is a writer for the interface.
SkillStatusEnum status() const
Get status value.
ExecSkillMessage Fawkes BlackBoard Interface Message.
const char * name() const
Get name of thread.
virtual const char * what_no_backtrace() const
Get primary string (does not implicitly print the back trace).
~SkillerRestApi()
Destructor.
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
virtual void loop()
Code to execute in the thread.
unsigned int msgq_enqueue(Message *message)
Enqueue message at end of queue.
virtual void init()
Initialize the thread.
Container to return array via REST.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
WebviewRestApiManager * webview_rest_api_manager
Webview REST API manager.
uint32_t msgid() const
Get msgid value.
SkillerInterface Fawkes BlackBoard Interface.
char * graph() const
Get graph value.
std::string path_arg(const std::string &what)
Get a path argument.
char * graph_fsm() const
Get graph_fsm value.
void set_name(const std::string &name)
Set name value.
void set_name(const std::string &name)
Set name value.
void set_msg_id(const int64_t &msg_id)
Set msg_id value.
void start(bool wait=true)
Call this method to start the thread.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.