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
36namespace fawkes {
37class Interface;
38}
39
40/**
41 * @brief An interface adapter using standard POSIX time facilities
42 * to implement LookupNow and LookupOnChange.
43 */
44class BlackboardPlexilAdapter : public PLEXIL::InterfaceAdapter,
46{
47public:
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
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
72private:
73 virtual void bb_interface_data_refreshed(fawkes::Interface *interface) noexcept;
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
81private:
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
93extern "C" {
94void initFawkesBlackboardAdapter();
95}
96
97#endif
An interface adapter using standard POSIX time facilities to implement LookupNow and LookupOnChange.
virtual void executeCommand(PLEXIL::Command *cmd)
Perform given command.
virtual void unsubscribe(const PLEXIL::State &state)
Unsubscribe from updates.
virtual bool shutdown()
Shut adapter down.
virtual bool start()
Start adapter.
virtual void subscribe(const PLEXIL::State &state)
Subscribe to updates for given state.
virtual bool initialize()
Initialize adapter.
virtual void lookupNow(PLEXIL::State const &state, PLEXIL::StateCacheEntry &cacheEntry)
Immediate lookup of value.
virtual bool reset()
Reset adapter.
virtual ~BlackboardPlexilAdapter()
Destructor.
BlackboardPlexilAdapter(PLEXIL::AdapterExecInterface &execInterface)
Constructor.
virtual bool stop()
Stop adapter.
BlackBoard interface listener.
The BlackBoard abstract class.
Definition: blackboard.h:46
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
Interface for logging.
Definition: logger.h:42
Fawkes library namespace.