Fawkes API  Fawkes Development Version
be_adapter.h
1 
2 /***************************************************************************
3  * be_adapter.h - PLEXIL adapter for the Behavior Engine
4  *
5  * Created: Tue Aug 14 15:21:49 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 #ifndef __PLUGINS_PLEXIL_SKILL_ADAPTER_H_
23 #define __PLUGINS_PLEXIL_SKILL_ADAPTER_H_
24 
25 #include <blackboard/blackboard.h>
26 #include <blackboard/interface_listener.h>
27 #include <config/config.h>
28 #include <interfaces/SkillerInterface.h>
29 #include <logging/logger.h>
30 
31 #include <InterfaceAdapter.hh>
32 #include <Value.hh>
33 #include <mutex>
34 
35 namespace fawkes {
36 class ActionSkillMapping;
37 }
38 
39 /** Interface adapter to provide logging facilities. */
40 class BehaviorEnginePlexilAdapter : public PLEXIL::InterfaceAdapter,
42 {
43 public:
44  BehaviorEnginePlexilAdapter(PLEXIL::AdapterExecInterface &execInterface);
45  BehaviorEnginePlexilAdapter(PLEXIL::AdapterExecInterface &execInterface,
46  pugi::xml_node const xml);
47 
48  /// @cond DELETED
49  BehaviorEnginePlexilAdapter() = delete;
51  BehaviorEnginePlexilAdapter &operator=(const BehaviorEnginePlexilAdapter &) = delete;
52  /// @endcond
53 
55 
56  virtual bool initialize();
57  virtual bool start();
58  virtual bool stop();
59  virtual bool reset();
60  virtual bool shutdown();
61 
62  void executeCommand(PLEXIL::Command *cmd);
63  void invokeAbort(PLEXIL::Command *cmd);
64 
65  virtual void bb_interface_data_changed(fawkes::Interface *interface) throw();
66 
67 private:
68  struct skill_config
69  {
70  /// Specify a skill argument.
72  {
73  /// Name of skill argument
74  std::string name;
75  /// Expected type of skill argument
76  PLEXIL::ValueType type;
77  };
78 
79  std::string name;
80  std::vector<skill_argument> args;
81  std::string template_str;
82  };
83 
84  std::string format_skillstring(const std::vector<PLEXIL::Value> &values);
85  std::string map_skillstring(const std::string & name,
86  const skill_config & skill_config,
87  const std::vector<PLEXIL::Value> &values);
88  void call_skill(const std::string &skill_string, PLEXIL::Command *cmd);
89 
90 private:
91  fawkes::Configuration * config_;
92  fawkes::Logger * logger_;
93  fawkes::BlackBoard * blackboard_;
94  fawkes::SkillerInterface *skiller_if_;
95 
96  std::shared_ptr<fawkes::ActionSkillMapping> action_skill_mapping_;
97 
98  std::mutex exec_mutex_;
99 
100  std::string skill_string_;
101  unsigned int skill_msgid_;
102 
103  PLEXIL::Command *current_cmd_;
104 
105  std::map<std::string, skill_config> cfg_skills_;
106 };
107 
108 extern "C" {
109 void initBehaviorEngineAdapter();
110 }
111 
112 #endif
BehaviorEnginePlexilAdapter::skill_config::skill_argument::name
std::string name
Name of skill argument.
Definition: be_adapter.h:74
BehaviorEnginePlexilAdapter::invokeAbort
void invokeAbort(PLEXIL::Command *cmd)
Abort currently running execution.
Definition: be_adapter.cpp:366
BehaviorEnginePlexilAdapter::stop
virtual bool stop()
Stop adapter.
Definition: be_adapter.cpp:206
BehaviorEnginePlexilAdapter
Interface adapter to provide logging facilities.
Definition: be_adapter.h:40
BehaviorEnginePlexilAdapter::skill_config::skill_argument
Specify a skill argument.
Definition: be_adapter.h:71
fawkes::BlackBoardInterfaceListener
Definition: interface_listener.h:47
fawkes::BlackBoard
Definition: blackboard.h:50
fawkes::Configuration
Definition: config.h:70
BehaviorEnginePlexilAdapter::shutdown
virtual bool shutdown()
Shut adapter down.
Definition: be_adapter.cpp:224
fawkes::Logger
Definition: logger.h:41
BehaviorEnginePlexilAdapter::initialize
virtual bool initialize()
Initialize adapter.
Definition: be_adapter.cpp:69
BehaviorEnginePlexilAdapter::start
virtual bool start()
Start adapter.
Definition: be_adapter.cpp:177
fawkes
fawkes::Interface
Definition: interface.h:78
BehaviorEnginePlexilAdapter::~BehaviorEnginePlexilAdapter
virtual ~BehaviorEnginePlexilAdapter()
Destructor.
Definition: be_adapter.cpp:61
fawkes::SkillerInterface
Definition: SkillerInterface.h:39
BehaviorEnginePlexilAdapter::bb_interface_data_changed
virtual void bb_interface_data_changed(fawkes::Interface *interface)
BlackBoard data changed notification.
Definition: be_adapter.cpp:382
BehaviorEnginePlexilAdapter::skill_config::skill_argument::type
PLEXIL::ValueType type
Expected type of skill argument.
Definition: be_adapter.h:76
BehaviorEnginePlexilAdapter::reset
virtual bool reset()
Reset adapter.
Definition: be_adapter.cpp:215
BehaviorEnginePlexilAdapter::executeCommand
void executeCommand(PLEXIL::Command *cmd)
Perform given command.
Definition: be_adapter.cpp:332
BehaviorEnginePlexilAdapter::BehaviorEnginePlexilAdapter
BehaviorEnginePlexilAdapter(PLEXIL::AdapterExecInterface &execInterface)
Constructor.
Definition: be_adapter.cpp:42