Fawkes API  Fawkes Development Version
remote_adapter.h
1 
2 /***************************************************************************
3  * remote_adapter.h - Access Fawkes remotely from PLEXIL
4  *
5  * Created: Mon Aug 20 12:58:05 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_REMOTE_ADAPTER_H_
23 #define __PLUGINS_PLEXIL_REMOTE_ADAPTER_H_
24 
25 #include <core/utils/lockptr.h>
26 #include <utils/system/fam.h>
27 
28 #include <InterfaceAdapter.hh>
29 #include <Value.hh>
30 #include <functional>
31 #include <map>
32 #include <memory>
33 #include <mutex>
34 #include <string>
35 #include <thread>
36 
37 namespace fawkes {
38 class BlackBoard;
39 class Logger;
40 class NavGraph;
41 class Clock;
42 class NetworkConfiguration;
43 class FawkesNetworkClient;
44 class FileAlterationMonitor;
45 } // namespace fawkes
46 
47 /** Interface adapter to provide logging facilities. */
48 class FawkesRemotePlexilAdapter : public PLEXIL::InterfaceAdapter, public fawkes::FamListener
49 {
50 public:
51  FawkesRemotePlexilAdapter(PLEXIL::AdapterExecInterface &execInterface);
52  FawkesRemotePlexilAdapter(PLEXIL::AdapterExecInterface &execInterface, pugi::xml_node const xml);
53 
54  /// @cond DELETED
55  FawkesRemotePlexilAdapter() = delete;
57  FawkesRemotePlexilAdapter &operator=(const FawkesRemotePlexilAdapter &) = delete;
58  /// @endcond
59 
61 
62  virtual bool initialize();
63  virtual bool start();
64  virtual bool stop();
65  virtual bool reset();
66  virtual bool shutdown();
67 
68  void executeCommand(PLEXIL::Command *cmd);
69  void invokeAbort(PLEXIL::Command *cmd);
70 
71  virtual void fam_event(const char *filename, unsigned int mask);
72 
73 private:
74  std::string cfg_navgraph_filename_;
75 
76  fawkes::Clock * clock_;
77  std::unique_ptr<fawkes::FawkesNetworkClient> client_;
78  std::unique_ptr<fawkes::Logger> logger_;
79  std::unique_ptr<fawkes::BlackBoard> blackboard_;
80  std::unique_ptr<fawkes::NetworkConfiguration> config_;
82  std::unique_ptr<fawkes::FileAlterationMonitor> navgraph_fam_;
83  std::mutex navgraph_fam_mutex_;
84  std::thread navgraph_fam_thread_;
85 
86  std::map<std::string, std::function<void(PLEXIL::Command *)>> commands_;
87 };
88 
89 extern "C" {
90 void initNavGraphAdapter();
91 }
92 
93 #endif
fawkes::LockPtr< fawkes::NavGraph >
fawkes::FamListener
Definition: fam.h:39
FawkesRemotePlexilAdapter
Interface adapter to provide logging facilities.
Definition: remote_adapter.h:47
FawkesRemotePlexilAdapter::stop
virtual bool stop()
Stop adapter.
Definition: remote_adapter.cpp:200
FawkesRemotePlexilAdapter::~FawkesRemotePlexilAdapter
virtual ~FawkesRemotePlexilAdapter()
Destructor.
Definition: remote_adapter.cpp:72
fawkes
FawkesRemotePlexilAdapter::fam_event
virtual void fam_event(const char *filename, unsigned int mask)
Definition: remote_adapter.cpp:148
FawkesRemotePlexilAdapter::reset
virtual bool reset()
Reset adapter.
Definition: remote_adapter.cpp:209
FawkesRemotePlexilAdapter::executeCommand
void executeCommand(PLEXIL::Command *cmd)
Perform given command.
Definition: remote_adapter.cpp:234
FawkesRemotePlexilAdapter::shutdown
virtual bool shutdown()
Shut adapter down.
Definition: remote_adapter.cpp:218
FawkesRemotePlexilAdapter::FawkesRemotePlexilAdapter
FawkesRemotePlexilAdapter(PLEXIL::AdapterExecInterface &execInterface)
Constructor.
Definition: remote_adapter.cpp:55
FawkesRemotePlexilAdapter::initialize
virtual bool initialize()
Initialize adapter.
Definition: remote_adapter.cpp:80
FawkesRemotePlexilAdapter::invokeAbort
void invokeAbort(PLEXIL::Command *cmd)
Abort currently running execution.
Definition: remote_adapter.cpp:255
FawkesRemotePlexilAdapter::start
virtual bool start()
Start adapter.
Definition: remote_adapter.cpp:191
fawkes::Clock
Definition: clock.h:39