Fawkes API  Fawkes Development Version
blackboard_adapter.h
1 
2 /***************************************************************************
3  * blackboard_adapter.h - PLEXIL adapter for Fawkes' blackboard
4  *
5  * Created: Sun Feb 17 12:46:23 2019 +0100
6  * Copyright 2006-2019 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_BLACKBOARD_ADAPTER_H_
23 #define __PLUGINS_PLEXIL_BLACKBOARD_ADAPTER_H_
24 
25 #include <blackboard/blackboard.h>
26 #include <blackboard/interface_listener.h>
27 #include <logging/logger.h>
28 
29 #include <InterfaceAdapter.hh>
30 #include <Value.hh>
31 #include <functional>
32 #include <map>
33 #include <mutex>
34 #include <string>
35 
36 namespace fawkes {
37 class Interface;
38 }
39 
40 /**
41  * @brief An interface adapter using standard POSIX time facilities
42  * to implement LookupNow and LookupOnChange.
43  */
44 class BlackboardPlexilAdapter : public PLEXIL::InterfaceAdapter,
46 {
47 public:
48  BlackboardPlexilAdapter(PLEXIL::AdapterExecInterface &execInterface);
49  BlackboardPlexilAdapter(PLEXIL::AdapterExecInterface &execInterface, pugi::xml_node const xml);
50 
51  /// @cond DELETED
52  BlackboardPlexilAdapter() = delete;
54  BlackboardPlexilAdapter &operator=(const BlackboardPlexilAdapter &) = delete;
55  /// @endcond
56 
57  virtual ~BlackboardPlexilAdapter();
58 
59  virtual bool initialize();
60  virtual bool start();
61  virtual bool stop();
62  virtual bool reset();
63  virtual bool shutdown();
64 
65  virtual void lookupNow(PLEXIL::State const &state, PLEXIL::StateCacheEntry &cacheEntry);
66 
67  virtual void subscribe(const PLEXIL::State &state);
68  virtual void unsubscribe(const PLEXIL::State &state);
69 
70  virtual void executeCommand(PLEXIL::Command *cmd);
71 
72 private:
73  virtual void bb_interface_data_changed(fawkes::Interface *interface) throw();
74 
75  void bb_open_for_reading(PLEXIL::Command *cmd);
76  void bb_close(PLEXIL::Command *cmd);
77  void bb_read(PLEXIL::Command *cmd);
78  void bb_read_all(PLEXIL::Command *cmd);
79  void bb_print(PLEXIL::Command *cmd);
80 
81 private:
82  fawkes::Logger * logger_;
83  fawkes::BlackBoard *blackboard_;
84 
85  std::mutex ifs_read_mutex_;
86  std::map<std::string, fawkes::Interface *> ifs_read_;
87 
88  std::map<std::string, std::function<void(PLEXIL::Command *)>> commands_;
89 
90  std::multimap<std::string, PLEXIL::State> subscribed_states_;
91 };
92 
93 extern "C" {
94 void initFawkesBlackboardAdapter();
95 }
96 
97 #endif
BlackboardPlexilAdapter::lookupNow
virtual void lookupNow(PLEXIL::State const &state, PLEXIL::StateCacheEntry &cacheEntry)
Immediate lookup of value.
Definition: blackboard_adapter.cpp:160
BlackboardPlexilAdapter::initialize
virtual bool initialize()
Initialize adapter.
Definition: blackboard_adapter.cpp:74
BlackboardPlexilAdapter::shutdown
virtual bool shutdown()
Shut adapter down.
Definition: blackboard_adapter.cpp:142
BlackboardPlexilAdapter::executeCommand
virtual void executeCommand(PLEXIL::Command *cmd)
Perform given command.
Definition: blackboard_adapter.cpp:439
BlackboardPlexilAdapter::stop
virtual bool stop()
Stop adapter.
Definition: blackboard_adapter.cpp:124
BlackboardPlexilAdapter::reset
virtual bool reset()
Reset adapter.
Definition: blackboard_adapter.cpp:133
fawkes::BlackBoardInterfaceListener
Definition: interface_listener.h:45
fawkes::BlackBoard
Definition: blackboard.h:48
fawkes::Logger
Definition: logger.h:40
fawkes
fawkes::Interface
Definition: interface.h:77
BlackboardPlexilAdapter::~BlackboardPlexilAdapter
virtual ~BlackboardPlexilAdapter()
Destructor.
Definition: blackboard_adapter.cpp:66
BlackboardPlexilAdapter::subscribe
virtual void subscribe(const PLEXIL::State &state)
Subscribe to updates for given state.
Definition: blackboard_adapter.cpp:347
BlackboardPlexilAdapter
An interface adapter using standard POSIX time facilities to implement LookupNow and LookupOnChange.
Definition: blackboard_adapter.h:43
BlackboardPlexilAdapter::unsubscribe
virtual void unsubscribe(const PLEXIL::State &state)
Unsubscribe from updates.
Definition: blackboard_adapter.cpp:379
BlackboardPlexilAdapter::start
virtual bool start()
Start adapter.
Definition: blackboard_adapter.cpp:115
BlackboardPlexilAdapter::BlackboardPlexilAdapter
BlackboardPlexilAdapter(PLEXIL::AdapterExecInterface &execInterface)
Constructor.
Definition: blackboard_adapter.cpp:49