Fawkes API  Fawkes Development Version
clips-executive-rest-api.cpp
1 
2 /***************************************************************************
3  * clips-executive-rest-api.cpp - CLIPS Executive REST API
4  *
5  * Created: Fri Mar 16 17:17:17 2018
6  * Copyright 2006-2018 Tim Niemueller [www.niemueller.de]
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #include "clips-executive-rest-api.h"
23 
24 #include <core/threading/mutex_locker.h>
25 #include <webview/rest_api_manager.h>
26 
27 using namespace fawkes;
28 
29 /** @class ClipsExecutiveRestApi "clips-executive-rest-api.h"
30  * REST API backend for the CLIPS executive.
31  * @author Tim Niemueller
32  */
33 
34 /** Constructor. */
36 : Thread("ClipsWebviewThread", Thread::OPMODE_WAITFORWAKEUP)
37 {
38 }
39 
40 /** Destructor. */
42 {
43 }
44 
45 void
47 {
48  {
49  std::map<std::string, LockPtr<CLIPS::Environment>> envs = clips_env_mgr->environments();
50  if (envs.find("executive") == envs.end()) {
51  throw Exception("No CLIPS environment named 'executive' found");
52  }
53  clips_ = envs["executive"];
54  }
55 
56  rest_api_ = new WebviewRestApi("clips-executive", logger);
58  WebRequest::METHOD_GET, "/goals", std::bind(&ClipsExecutiveRestApi::cb_list_goals, this));
59  rest_api_->add_handler<Goal>(WebRequest::METHOD_GET,
60  "/goals/{id}",
61  std::bind(&ClipsExecutiveRestApi::cb_get_goal,
62  this,
63  std::placeholders::_1));
65  WebRequest::METHOD_GET,
66  "/domain-operators",
67  std::bind(&ClipsExecutiveRestApi::cb_list_domain_operators, this));
69  WebRequest::METHOD_GET,
70  "/domain-objects",
71  std::bind(&ClipsExecutiveRestApi::cb_list_domain_objects, this));
73  WebRequest::METHOD_GET,
74  "/domain-predicates",
75  std::bind(&ClipsExecutiveRestApi::cb_list_domain_predicates, this));
77  WebRequest::METHOD_GET,
78  "/domain-facts",
79  std::bind(&ClipsExecutiveRestApi::cb_list_domain_facts, this));
81  WebRequest::METHOD_GET, "/plans", std::bind(&ClipsExecutiveRestApi::cb_list_plans, this));
82  rest_api_->add_handler<Plan>(WebRequest::METHOD_GET,
83  "/plans/{goal-id}/{id}",
84  std::bind(&ClipsExecutiveRestApi::cb_get_plan,
85  this,
86  std::placeholders::_1));
88 }
89 
90 void
92 {
94  delete rest_api_;
95 }
96 
97 void
99 {
100 }
101 
102 /** Get a value from a fact.
103  * @param fact pointer to CLIPS fact
104  * @param slot_name name of field to retrieve
105  * @return template-specific return value
106  */
107 template <typename T>
108 T
109 get_value(const CLIPS::Fact::pointer &fact, const std::string &slot_name)
110 {
111  CLIPS::Values v = fact->slot_value(slot_name);
112  if (v.empty()) {
113  throw Exception("No value for slot '%s'", slot_name.c_str());
114  }
115  if (v[0].type() == CLIPS::TYPE_SYMBOL && v[0].as_string() == "nil") {
116  return T();
117  }
118  return v[0];
119 }
120 
121 /** Specialization for bool.
122  * @param fact pointer to CLIPS fact
123  * @param slot_name name of field to retrieve
124  * @return boolean value
125  */
126 template <>
127 bool
128 get_value(const CLIPS::Fact::pointer &fact, const std::string &slot_name)
129 {
130  CLIPS::Values v = fact->slot_value(slot_name);
131  if (v.empty()) {
132  throw Exception("No value for slot '%s'", slot_name.c_str());
133  }
134  if (v[0].type() != CLIPS::TYPE_SYMBOL) {
135  throw Exception("Value for slot '%s' is not a boolean", slot_name.c_str());
136  }
137  return (v[0].as_string() == "TRUE");
138 }
139 
140 /** Get value array.
141  * This is not a template because the overly verbose operator API
142  * of CLIPS::Value can lead to ambiguous overloads, e.g., resolving
143  * std::string to std::string or const char * operators.
144  * @param fact pointer to CLIPS fact
145  * @param slot_name name of field to retrieve
146  * @return vector of strings from multislot
147  */
148 static std::vector<std::string>
149 get_values(const CLIPS::Fact::pointer &fact, const std::string &slot_name)
150 {
151  CLIPS::Values v = fact->slot_value(slot_name);
152  std::vector<std::string> rv(v.size());
153  for (size_t i = 0; i < v.size(); ++i) {
154  switch (v[i].type()) {
155  case CLIPS::TYPE_FLOAT: rv[i] = std::to_string(static_cast<double>(v[i])); break;
156  case CLIPS::TYPE_INTEGER: rv[i] = std::to_string(static_cast<long long int>(v[i])); break;
157  case CLIPS::TYPE_SYMBOL:
158  case CLIPS::TYPE_STRING:
159  case CLIPS::TYPE_INSTANCE_NAME: rv[i] = static_cast<std::string &>(v[i]); break;
160  default: rv[i] = "CANNOT-REPRESENT"; break;
161  }
162  }
163  return rv;
164 }
165 
166 Goal
167 ClipsExecutiveRestApi::generate_goal(CLIPS::Fact::pointer fact)
168 {
169  Goal g;
170  g.set_kind("Goal");
172  g.set_id(get_value<std::string>(fact, "id"));
173  g.set__class(get_value<std::string>(fact, "class"));
174  g.set_type(get_value<std::string>(fact, "type"));
175  g.set_sub_type(get_value<std::string>(fact, "sub-type"));
176  g.set_mode(get_value<std::string>(fact, "mode"));
177  g.set_parent(get_value<std::string>(fact, "parent"));
178  g.set_outcome(get_value<std::string>(fact, "outcome"));
179  g.set_error(get_values(fact, "error"));
180  g.set_message(get_value<std::string>(fact, "message"));
181  g.set_priority(get_value<long int>(fact, "priority"));
182  g.set_parameters(get_values(fact, "params"));
183  g.set_meta(get_values(fact, "meta"));
184  g.set_required_resources(get_values(fact, "required-resources"));
185  g.set_acquired_resources(get_values(fact, "acquired-resources"));
186 
187  CLIPS::Fact::pointer pfact = clips_->get_facts();
188  while (pfact) {
189  CLIPS::Template::pointer tmpl = pfact->get_template();
190  if (tmpl->name() == "plan") {
191  try {
192  if (get_value<std::string>(pfact, "goal-id") == *g.id()) {
193  g.addto_plans(std::move(get_value<std::string>(pfact, "id")));
194  }
195  } catch (Exception &e) {
196  }
197  }
198  pfact = pfact->next();
199  }
200 
201  return g;
202 }
203 
205 ClipsExecutiveRestApi::cb_list_goals()
206 {
207  MutexLocker lock(clips_.objmutex_ptr());
209 
210  CLIPS::Fact::pointer fact = clips_->get_facts();
211  while (fact) {
212  CLIPS::Template::pointer tmpl = fact->get_template();
213  if (tmpl->name() == "goal") {
214  try {
215  rv.push_back(std::move(generate_goal(fact)));
216  } catch (Exception &e) {
217  logger->log_warn(name(), "Failed to add goal: %s", e.what_no_backtrace());
218  }
219  }
220 
221  fact = fact->next();
222  }
223 
224  return rv;
225 }
226 
227 Goal
228 ClipsExecutiveRestApi::cb_get_goal(WebviewRestParams &params)
229 {
230  const std::string id = params.path_arg("id");
231 
232  MutexLocker lock(clips_.objmutex_ptr());
233  CLIPS::Fact::pointer fact = clips_->get_facts();
234  while (fact) {
235  CLIPS::Template::pointer tmpl = fact->get_template();
236  if (tmpl->name() == "goal") {
237  try {
238  if (get_value<std::string>(fact, "id") == id) {
239  return generate_goal(fact);
240  }
241  } catch (Exception &e) {
242  logger->log_warn(name(), "Failed to add goal: %s", e.what_no_backtrace());
243  }
244  }
245 
246  fact = fact->next();
247  }
248 
249  throw WebviewRestException(WebReply::HTTP_BAD_REQUEST, "Goal '%s' is unknown", id.c_str());
250 }
251 
253 ClipsExecutiveRestApi::cb_list_domain_operators()
254 {
255  MutexLocker lock(clips_.objmutex_ptr());
257 
258  std::map<std::string, std::list<std::pair<std::string, std::string>>> op_params;
259 
260  CLIPS::Fact::pointer fact = clips_->get_facts();
261  while (fact) {
262  CLIPS::Template::pointer tmpl = fact->get_template();
263  if (tmpl->name() == "domain-operator-parameter") {
264  std::string operator_name = get_value<std::string>(fact, "operator");
265  if (op_params.find(operator_name) == op_params.end()) {
266  op_params[operator_name] = {};
267  }
268  op_params[operator_name].push_back(
269  std::make_pair(get_value<std::string>(fact, "name"), get_value<std::string>(fact, "type")));
270  }
271  fact = fact->next();
272  }
273 
274  fact = clips_->get_facts();
275  while (fact) {
276  CLIPS::Template::pointer tmpl = fact->get_template();
277  if (tmpl->name() == "domain-operator") {
278  try {
279  DomainOperator o;
280  o.set_kind("DomainOperator");
282  o.set_name(get_value<std::string>(fact, "name"));
283  o.set_wait_sensed(get_value<bool>(fact, "wait-sensed"));
284  if (op_params.find(*o.name()) != op_params.end()) {
285  for (const auto &p : op_params[*o.name()]) {
287  param.set_name(p.first);
288  param.set_type(p.second);
289  o.addto_parameters(std::move(param));
290  }
291  }
292 
293  rv.push_back(std::move(o));
294  } catch (Exception &e) {
295  logger->log_warn(name(), "Failed to add goal: %s", e.what_no_backtrace());
296  }
297  }
298 
299  fact = fact->next();
300  }
301 
302  return rv;
303 }
304 
306 ClipsExecutiveRestApi::cb_list_domain_objects()
307 {
308  MutexLocker lock(clips_.objmutex_ptr());
310 
311  CLIPS::Fact::pointer fact = clips_->get_facts();
312  while (fact) {
313  CLIPS::Template::pointer tmpl = fact->get_template();
314  if (tmpl->name() == "domain-object") {
315  DomainObject o;
316  o.set_kind("DomainObject");
318  o.set_name(get_value<std::string>(fact, "name"));
319  o.set_type(get_value<std::string>(fact, "type"));
320  rv.push_back(std::move(o));
321  }
322  fact = fact->next();
323  }
324 
325  return rv;
326 }
327 
329 ClipsExecutiveRestApi::cb_list_domain_predicates()
330 {
331  MutexLocker lock(clips_.objmutex_ptr());
333 
334  CLIPS::Fact::pointer fact = clips_->get_facts();
335  while (fact) {
336  CLIPS::Template::pointer tmpl = fact->get_template();
337  if (tmpl->name() == "domain-predicate") {
338  DomainPredicate p;
339  p.set_kind("DomainPredicate");
341  p.set_name(get_value<std::string>(fact, "name"));
342  p.set_sensed(get_value<bool>(fact, "sensed"));
343  p.set_param_names(get_values(fact, "param-names"));
344  p.set_param_types(get_values(fact, "param-types"));
345  rv.push_back(std::move(p));
346  }
347  fact = fact->next();
348  }
349 
350  return rv;
351 }
352 
354 ClipsExecutiveRestApi::cb_list_domain_facts()
355 {
356  MutexLocker lock(clips_.objmutex_ptr());
358 
359  CLIPS::Fact::pointer fact = clips_->get_facts();
360  while (fact) {
361  CLIPS::Template::pointer tmpl = fact->get_template();
362  if (tmpl->name() == "domain-fact") {
363  DomainFact f;
364  f.set_kind("DomainFact");
366  f.set_name(get_value<std::string>(fact, "name"));
367  f.set_param_values(get_values(fact, "param-values"));
368  rv.push_back(std::move(f));
369  }
370  fact = fact->next();
371  }
372 
373  return rv;
374 }
375 
376 std::shared_ptr<DomainPreconditionAtom>
377 ClipsExecutiveRestApi::gen_domain_precondition_atom(const CLIPS::Fact::pointer fact)
378 {
379  auto pre_atom = std::make_shared<DomainPreconditionAtom>();
380  pre_atom->set_kind("DomainPreconditionAtom");
381  pre_atom->set_apiVersion(DomainPreconditionAtom::api_version());
382  pre_atom->set_name(get_value<std::string>(fact, "name"));
383  pre_atom->set_type("atom");
384  pre_atom->set_grounded(get_value<bool>(fact, "grounded"));
385  pre_atom->set_is_satisfied(get_value<bool>(fact, "is-satisfied"));
386  pre_atom->set_predicate(get_value<std::string>(fact, "predicate"));
387  for (const auto &s : get_values(fact, "param-names")) {
388  pre_atom->addto_param_names(std::move(s));
389  }
390  for (const auto &s : get_values(fact, "param-values")) {
391  pre_atom->addto_param_values(std::move(s));
392  }
393  for (const auto &s : get_values(fact, "param-constants")) {
394  pre_atom->addto_param_constants(std::move(s));
395  }
396  return pre_atom;
397 }
398 
399 std::shared_ptr<DomainPreconditionCompound>
400 ClipsExecutiveRestApi::gen_domain_precondition_compound(const CLIPS::Fact::pointer fact,
401  const PlanActionKey & plan_action_key,
402  PreCompoundMap & prec,
403  PreAtomMap & prea)
404 {
405  std::string prec_name = get_value<std::string>(fact, "name");
406 
407  auto pre_comp = std::make_shared<DomainPreconditionCompound>();
408  pre_comp->set_kind("DomainPreconditionCompound");
409  pre_comp->set_apiVersion(DomainPreconditionCompound::api_version());
410  pre_comp->set_name(prec_name);
411  pre_comp->set_type(get_value<std::string>(fact, "type"));
412  pre_comp->set_grounded(get_value<bool>(fact, "grounded"));
413  pre_comp->set_is_satisfied(get_value<bool>(fact, "is-satisfied"));
414 
415  // elements of pre_compondition compound
416  for (const auto &prea_fact : prea[plan_action_key]) {
417  std::string part_of = get_value<std::string>(prea_fact, "part-of");
418  if (part_of == prec_name) {
419  pre_comp->addto_elements(gen_domain_precondition_atom(prea_fact));
420  }
421  }
422  for (const auto &prec_fact : prec[plan_action_key]) {
423  std::string part_of = get_value<std::string>(prec_fact, "part-of");
424  if (part_of == prec_name) {
425  pre_comp->addto_elements(
426  gen_domain_precondition_compound(prec_fact, plan_action_key, prec, prea));
427  }
428  }
429 
430  return pre_comp;
431 }
432 
433 void
434 ClipsExecutiveRestApi::gen_plan_precompute(PlanMap & plans,
435  PlanActionMap & plan_actions,
436  PreCompoundMap &prec,
437  PreAtomMap & prea)
438 {
439  CLIPS::Fact::pointer fact = clips_->get_facts();
440  while (fact) {
441  CLIPS::Template::pointer tmpl = fact->get_template();
442  if (tmpl->name() == "plan") {
443  plans[std::make_pair(get_value<std::string>(fact, "goal-id"),
444  get_value<std::string>(fact, "id"))] = fact;
445  } else if (tmpl->name() == "plan-action") {
446  plan_actions[std::make_pair(get_value<std::string>(fact, "goal-id"),
447  get_value<std::string>(fact, "plan-id"))]
448  .push_back(fact);
449  } else if (tmpl->name() == "domain-precondition"
450  || tmpl->name() == "domain-atomic-precondition") {
451  std::string goal_id = get_value<std::string>(fact, "goal-id");
452  std::string plan_id = get_value<std::string>(fact, "plan-id");
453  int64_t action_id = get_value<int64_t>(fact, "grounded-with");
454  if (action_id != 0) {
455  if (tmpl->name() == "domain-precondition") {
456  prec[std::make_tuple(goal_id, plan_id, action_id)].push_back(fact);
457  } else {
458  prea[std::make_tuple(goal_id, plan_id, action_id)].push_back(fact);
459  }
460  }
461  }
462  fact = fact->next();
463  }
464 }
465 
466 Plan
467 ClipsExecutiveRestApi::gen_plan(const PlanKey & plan_key,
468  const CLIPS::Fact::pointer fact,
469  PlanActionMap & plan_actions,
470  PreCompoundMap & prec,
471  PreAtomMap & prea)
472 {
473  const std::string &goal_id = get_value<std::string>(fact, "goal-id");
474  const std::string &plan_id = get_value<std::string>(fact, "id");
475 
476  Plan p;
477  p.set_kind("Plan");
479  p.set_goal_id(goal_id);
480  p.set_id(plan_id);
481  p.set_cost(get_value<double>(fact, "cost"));
482  if (plan_actions.find(plan_key) != plan_actions.end()) {
483  std::vector<std::shared_ptr<PlanAction>> actions;
484 
485  for (auto &pai : plan_actions[plan_key]) {
486  auto pa = std::make_shared<PlanAction>();
487 
488  int64_t action_id = get_value<int64_t>(pai, "id");
489  std::string operator_name = get_value<std::string>(pai, "action-name");
490 
491  // general info
492  pa->set_kind("PlanAction");
493  pa->set_apiVersion(PlanAction::api_version());
494  pa->set_id(action_id);
495  pa->set_operator_name(operator_name);
496  for (const auto &pv : get_values(pai, "param-values")) {
497  pa->addto_param_values(std::move(pv));
498  }
499  pa->set_state(get_value<std::string>(pai, "state"));
500  pa->set_executable(get_value<bool>(pai, "executable"));
501  pa->set_duration(get_value<double>(pai, "duration"));
502  pa->set_dispatch_time(get_value<double>(pai, "dispatch-time"));
503 
504  // preconditions
505  const PlanActionKey plan_action_key{std::make_tuple(goal_id, plan_id, action_id)};
506  if (prec.find(plan_action_key) != prec.end()) {
507  for (auto &prec_fact : prec[plan_action_key]) {
508  std::string part_of = get_value<std::string>(prec_fact, "part-of");
509  int64_t grounded_with = get_value<int64_t>(prec_fact, "grounded-with");
510  if (part_of == operator_name && grounded_with == action_id) {
511  pa->addto_preconditions(
512  gen_domain_precondition_compound(prec_fact, plan_action_key, prec, prea));
513  }
514  }
515  }
516  actions.push_back(std::move(pa));
517  }
518 
519  std::sort(actions.begin(),
520  actions.end(),
521  [](std::shared_ptr<PlanAction> &a, std::shared_ptr<PlanAction> &b) {
522  return *a->id() < *b->id();
523  });
524  p.set_actions(actions);
525  }
526 
527  return p;
528 }
529 
531 ClipsExecutiveRestApi::cb_list_plans()
532 {
533  MutexLocker lock(clips_.objmutex_ptr());
535 
536  std::map<PlanKey, CLIPS::Fact::pointer> plans;
537  std::map<PlanKey, ClipsFactList> plan_actions;
538  PreCompoundMap prec;
539  PreAtomMap prea;
540  gen_plan_precompute(plans, plan_actions, prec, prea);
541 
542  for (auto &pi : plans) {
543  rv.push_back(std::move(gen_plan(pi.first, pi.second, plan_actions, prec, prea)));
544  }
545 
546  return rv;
547 }
548 
549 Plan
550 ClipsExecutiveRestApi::cb_get_plan(WebviewRestParams &params)
551 {
552  std::string goal_id = params.path_arg("goal-id");
553  std::string id = params.path_arg("id");
554 
555  MutexLocker lock(clips_.objmutex_ptr());
557 
558  std::map<PlanKey, CLIPS::Fact::pointer> plans;
559  std::map<PlanKey, ClipsFactList> plan_actions;
560  PreCompoundMap prec;
561  PreAtomMap prea;
562 
563  gen_plan_precompute(plans, plan_actions, prec, prea);
564 
565  const PlanKey plan_key{goal_id, id};
566  if (plans.find(plan_key) == plans.end()) {
567  throw WebviewRestException(WebReply::HTTP_BAD_REQUEST,
568  "No plan for goal '%s' with ID '%s' found",
569  goal_id.c_str(),
570  id.c_str());
571  }
572 
573  return gen_plan(plan_key, plans[plan_key], plan_actions, prec, prea);
574 }
virtual void finalize()
Finalize the thread.
virtual void init()
Initialize the thread.
virtual void loop()
Code to execute in the thread.
DomainFact representation for JSON transfer.
Definition: DomainFact.h:28
void set_apiVersion(const std::string &apiVersion)
Set apiVersion value.
Definition: DomainFact.h:118
void set_kind(const std::string &kind)
Set kind value.
Definition: DomainFact.h:101
static std::string api_version()
Get version of implemented API.
Definition: DomainFact.h:48
void set_name(const std::string &name)
Set name value.
Definition: DomainFact.h:135
void set_param_values(const std::vector< std::string > &param_values)
Set param-values value.
Definition: DomainFact.h:152
DomainObject representation for JSON transfer.
Definition: DomainObject.h:28
void set_name(const std::string &name)
Set name value.
Definition: DomainObject.h:135
void set_type(const std::string &type)
Set type value.
Definition: DomainObject.h:152
void set_apiVersion(const std::string &apiVersion)
Set apiVersion value.
Definition: DomainObject.h:118
void set_kind(const std::string &kind)
Set kind value.
Definition: DomainObject.h:101
static std::string api_version()
Get version of implemented API.
Definition: DomainObject.h:48
DomainOperatorParameter representation for JSON transfer.
void set_type(const std::string &type)
Set type value.
void set_name(const std::string &name)
Set name value.
DomainOperator representation for JSON transfer.
void addto_parameters(const std::shared_ptr< DomainOperatorParameter > &&parameters)
Add element to parameters array.
void set_apiVersion(const std::string &apiVersion)
Set apiVersion value.
void set_kind(const std::string &kind)
Set kind value.
static std::string api_version()
Get version of implemented API.
void set_name(const std::string &name)
Set name value.
void set_wait_sensed(const bool &wait_sensed)
Set wait-sensed value.
std::optional< std::string > name() const
Get name value.
static std::string api_version()
Get version of implemented API.
static std::string api_version()
Get version of implemented API.
DomainPredicate representation for JSON transfer.
static std::string api_version()
Get version of implemented API.
void set_sensed(const bool &sensed)
Set sensed value.
void set_param_types(const std::vector< std::string > &param_types)
Set param-types value.
void set_name(const std::string &name)
Set name value.
void set_param_names(const std::vector< std::string > &param_names)
Set param-names value.
void set_kind(const std::string &kind)
Set kind value.
void set_apiVersion(const std::string &apiVersion)
Set apiVersion value.
Goal representation for JSON transfer.
Definition: Goal.h:28
void set_message(const std::string &message)
Set message value.
Definition: Goal.h:272
void set_acquired_resources(const std::vector< std::string > &acquired_resources)
Set acquired-resources value.
Definition: Goal.h:463
std::optional< std::string > id() const
Get id value.
Definition: Goal.h:126
void set_parameters(const std::vector< std::string > &parameters)
Set parameters value.
Definition: Goal.h:323
void set_id(const std::string &id)
Set id value.
Definition: Goal.h:135
void set_mode(const std::string &mode)
Set mode value.
Definition: Goal.h:203
void set_sub_type(const std::string &sub_type)
Set sub-type value.
Definition: Goal.h:169
void set_meta(const std::vector< std::string > &meta)
Set meta value.
Definition: Goal.h:358
void set_parent(const std::string &parent)
Set parent value.
Definition: Goal.h:289
void set_required_resources(const std::vector< std::string > &required_resources)
Set required-resources value.
Definition: Goal.h:428
void set_outcome(const std::string &outcome)
Set outcome value.
Definition: Goal.h:220
void set__class(const std::string &_class)
Set class value.
Definition: Goal.h:186
void set_kind(const std::string &kind)
Set kind value.
Definition: Goal.h:101
static std::string api_version()
Get version of implemented API.
Definition: Goal.h:48
void addto_plans(const std::string &&plans)
Add element to plans array.
Definition: Goal.h:401
void set_priority(const int64_t &priority)
Set priority value.
Definition: Goal.h:306
void set_error(const std::vector< std::string > &error)
Set error value.
Definition: Goal.h:237
void set_apiVersion(const std::string &apiVersion)
Set apiVersion value.
Definition: Goal.h:118
void set_type(const std::string &type)
Set type value.
Definition: Goal.h:152
static std::string api_version()
Get version of implemented API.
Definition: PlanAction.h:52
Plan representation for JSON transfer.
Definition: Plan.h:30
void set_id(const std::string &id)
Set id value.
Definition: Plan.h:137
void set_goal_id(const std::string &goal_id)
Set goal-id value.
Definition: Plan.h:154
static std::string api_version()
Get version of implemented API.
Definition: Plan.h:50
void set_kind(const std::string &kind)
Set kind value.
Definition: Plan.h:103
void set_actions(const std::vector< std::shared_ptr< PlanAction >> &actions)
Set actions value.
Definition: Plan.h:188
void set_cost(const float &cost)
Set cost value.
Definition: Plan.h:171
void set_apiVersion(const std::string &apiVersion)
Set apiVersion value.
Definition: Plan.h:120
Container to return array via REST.
Definition: rest_array.h:36
void push_back(M &m)
Add item at the back of the container.
Definition: rest_array.h:123
LockPtr< CLIPSEnvManager > clips_env_mgr
CLIPS environment manager.
Definition: clips_manager.h:44
Base class for exceptions in Fawkes.
Definition: exception.h:36
virtual const char * what_no_backtrace() const
Get primary string (does not implicitly print the back trace).
Definition: exception.cpp:663
Mutex * objmutex_ptr() const
Get object mutex.
Definition: lockptr.h:284
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
Mutex locking helper.
Definition: mutex_locker.h:34
Thread class encapsulation of pthreads.
Definition: thread.h:46
const char * name() const
Get name of thread.
Definition: thread.h:100
WebviewRestApiManager * webview_rest_api_manager
Webview REST API manager.
Definition: webview.h:55
void unregister_api(WebviewRestApi *api)
Remove a request processor.
void register_api(WebviewRestApi *api)
Add a REST API.
Webview REST API component.
Definition: rest_api.h:221
void add_handler(WebRequest::Method method, std::string path, Handler handler)
Add handler function.
Definition: rest_api.cpp:85
REST processing exception.
Definition: rest_api.h:71
REST parameters to pass to handlers.
Definition: rest_api.h:125
std::string path_arg(const std::string &what)
Get a path argument.
Definition: rest_api.h:142
Fawkes library namespace.