Fawkes API  Fawkes Development Version
clips-executive-rest-api.h
1 
2 /***************************************************************************
3  * clips-executive-rest-api.h - CLIPS Executive REST API
4  *
5  * Created: Fri Mar 16 17:15:34 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 #pragma once
23 
24 #include "model/DomainFact.h"
25 #include "model/DomainObject.h"
26 #include "model/DomainOperator.h"
27 #include "model/DomainPreconditionAtom.h"
28 #include "model/DomainPreconditionCompound.h"
29 #include "model/DomainPredicate.h"
30 #include "model/Goal.h"
31 #include "model/Plan.h"
32 
33 #include <aspect/logging.h>
34 #include <aspect/webview.h>
35 #include <clipsmm/fact.h>
36 #include <core/threading/thread.h>
37 #include <core/utils/lockptr.h>
38 #include <plugins/clips/aspect/clips_manager.h>
39 #include <webview/rest_api.h>
40 #include <webview/rest_array.h>
41 
42 namespace CLIPS {
43 class Environment;
44 }
45 
47  public fawkes::LoggingAspect,
48  public fawkes::WebviewAspect,
50 {
51 public:
54 
55  virtual void init();
56  virtual void loop();
57  virtual void finalize();
58 
59 private:
60  typedef std::pair<std::string, std::string> PlanKey;
61  typedef std::tuple<std::string, std::string, int64_t> PlanActionKey;
62  typedef std::list<CLIPS::Fact::pointer> ClipsFactList;
63  typedef std::map<PlanActionKey, ClipsFactList> PreCompoundMap;
64  typedef std::map<PlanActionKey, ClipsFactList> PreAtomMap;
65  typedef std::map<PlanKey, CLIPS::Fact::pointer> PlanMap;
66  typedef std::map<PlanKey, ClipsFactList> PlanActionMap;
67 
68 private:
69  WebviewRestArray<Goal> cb_list_goals();
70  WebviewRestArray<DomainOperator> cb_list_domain_operators();
71  WebviewRestArray<DomainObject> cb_list_domain_objects();
72  WebviewRestArray<DomainPredicate> cb_list_domain_predicates();
73  WebviewRestArray<DomainFact> cb_list_domain_facts();
74  WebviewRestArray<Plan> cb_list_plans();
75 
76  Goal cb_get_goal(fawkes::WebviewRestParams &params);
77  Plan cb_get_plan(fawkes::WebviewRestParams &params);
78 
79  Goal generate_goal(CLIPS::Fact::pointer fact);
80  void gen_plan_precompute(std::map<PlanKey, CLIPS::Fact::pointer> &plans,
81  std::map<PlanKey, ClipsFactList> & plan_actions,
82  PreCompoundMap & prec,
83  PreAtomMap & prea);
84  std::shared_ptr<DomainPreconditionAtom>
85  gen_domain_precondition_atom(const CLIPS::Fact::pointer fact);
86 
87  std::shared_ptr<DomainPreconditionCompound>
88  gen_domain_precondition_compound(const CLIPS::Fact::pointer fact,
89  const PlanActionKey & plan_action_key,
90  PreCompoundMap & prec,
91  PreAtomMap & prea);
92 
93  Plan gen_plan(const PlanKey & plan_key,
94  const CLIPS::Fact::pointer fact,
95  PlanActionMap & plan_actions,
96  PreCompoundMap & prec,
97  PreAtomMap & prea);
98 
99 private:
100  fawkes::WebviewRestApi * rest_api_;
102 };
fawkes::LockPtr< CLIPS::Environment >
Goal
Goal representation for JSON transfer.
Definition: Goal.h:28
ClipsExecutiveRestApi::init
virtual void init()
Initialize the thread.
Definition: clips-executive-rest-api.cpp:46
ClipsExecutiveRestApi::ClipsExecutiveRestApi
ClipsExecutiveRestApi()
Constructor.
Definition: clips-executive-rest-api.cpp:35
fawkes::LoggingAspect
Thread aspect to log output.
Definition: logging.h:33
Plan
Plan representation for JSON transfer.
Definition: Plan.h:30
WebviewRestArray
Container to return array via REST.
Definition: rest_array.h:36
ClipsExecutiveRestApi
REST API backend for the CLIPS executive.
Definition: clips-executive-rest-api.h:50
fawkes::WebviewRestParams
REST parameters to pass to handlers.
Definition: rest_api.h:125
fawkes::WebviewAspect
Thread aspect to provide web pages via Webview.
Definition: webview.h:37
fawkes::WebviewRestApi
Webview REST API component.
Definition: rest_api.h:221
fawkes::Thread
Thread class encapsulation of pthreads.
Definition: thread.h:46
ClipsExecutiveRestApi::loop
virtual void loop()
Code to execute in the thread.
Definition: clips-executive-rest-api.cpp:98
ClipsExecutiveRestApi::~ClipsExecutiveRestApi
~ClipsExecutiveRestApi()
Destructor.
Definition: clips-executive-rest-api.cpp:41
fawkes::CLIPSManagerAspect
Thread aspect access the CLIPS environment manager.
Definition: clips_manager.h:36
ClipsExecutiveRestApi::finalize
virtual void finalize()
Finalize the thread.
Definition: clips-executive-rest-api.cpp:91
Environment
Environment representation for JSON transfer.
Definition: Environment.h:28