Fawkes API  Fawkes Development Version
plexil_thread.h
1 
2 /***************************************************************************
3  * plexil_thread.h - PLEXIL executive plugin
4  *
5  * Created: Mon Aug 13 11:19:14 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_PLEXIL_THREAD_H_
23 #define __PLUGINS_PLEXIL_PLEXIL_THREAD_H_
24 
25 #include <aspect/blackboard.h>
26 #include <aspect/clock.h>
27 #include <aspect/configurable.h>
28 #include <aspect/logging.h>
29 #include <core/threading/thread.h>
30 #ifdef HAVE_NAVGRAPH
31 # include <aspect/thread_producer.h>
32 # include <core/utils/lockptr.h>
33 # include <navgraph/navgraph.h>
34 #endif
35 #include <utils/time/time.h>
36 
37 #include <AdapterFactory.hh>
38 #include <fstream>
39 #include <memory>
40 
41 namespace PLEXIL {
42 class ExecApplication;
43 }
44 
47 
49  public fawkes::LoggingAspect,
51  public fawkes::ClockAspect,
52 #ifdef HAVE_NAVGRAPH
54 #endif
56 {
57 public:
59  virtual ~PlexilExecutiveThread();
60 
61  virtual void init();
62  virtual void once();
63  virtual void loop();
64  virtual bool prepare_finalize_user();
65  virtual void finalize();
66 
67  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
68 protected:
69  virtual void
70  run()
71  {
72  Thread::run();
73  }
74 
75 private:
76  /// @cond INTERNAL
77  // Data structure for config parse result
78  struct plexil_interface_config
79  {
80  std::string type;
81  std::map<std::string, std::string> attr;
82  std::map<std::string, std::string> args;
83 
84  struct verbatim_arg
85  {
86  std::string tag;
87  bool has_text;
88  std::string text;
89  std::map<std::string, std::string> attr;
90  };
91  std::map<std::string, verbatim_arg> verbatim_args;
92  pugi::xml_document verbatim;
93  };
94  /// @endcond
95 
96  std::map<std::string, plexil_interface_config>
97  read_plexil_interface_configs(const std::string &config_prefix);
98  void add_plexil_interface_configs(
99  pugi::xml_node & parent,
100  const std::map<std::string, PlexilExecutiveThread::plexil_interface_config> &configs,
101  const char * tag_name,
102  const char * type_attr_name);
103  void plexil_compile(const std::string &ple_file);
104 
105 private:
106  std::string cfg_spec_;
107  std::string cfg_plan_plx_;
108  std::vector<std::string> cfg_plan_ple_;
109  bool cfg_plan_auto_compile_;
110  bool cfg_plan_force_compile_;
111 
112  std::unique_ptr<PLEXIL::ExecApplication> plexil_;
113 
114 #ifdef HAVE_NAVGRAPH
115  PlexilNavgraphAccessThread * navgraph_access_thread_;
117 #endif
118 
119  std::shared_ptr<PlexilLogStreamBuffer> log_buffer_;
120  std::shared_ptr<std::ostream> log_stream_;
121 
122  std::shared_ptr<pugi::xml_document> plan_plx_;
123 };
124 
125 #endif
fawkes::LockPtr< fawkes::NavGraph >
PlexilNavgraphAccessThread
Access to internal navgraph for Plexil.
Definition: navgraph_access_thread.h:29
PlexilExecutiveThread::init
virtual void init()
Initialize the thread.
Definition: plexil_thread.cpp:76
PlexilExecutiveThread::prepare_finalize_user
virtual bool prepare_finalize_user()
Prepare finalization user implementation.
Definition: plexil_thread.cpp:278
PlexilExecutiveThread::~PlexilExecutiveThread
virtual ~PlexilExecutiveThread()
Destructor.
Definition: plexil_thread.cpp:71
PlexilExecutiveThread::once
virtual void once()
Execute an action exactly once.
Definition: plexil_thread.cpp:261
fawkes::ThreadProducerAspect
Aspect for thread producing threads.
Definition: thread_producer.h:33
PlexilLogStreamBuffer
Log Plexil log output to Fawkes logger.
Definition: log_stream.h:31
fawkes::BlackBoardAspect
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
fawkes::LoggingAspect
Thread aspect to log output.
Definition: logging.h:33
PlexilExecutiveThread
Main thread of PLEXIL executive.
Definition: plexil_thread.h:56
PlexilExecutiveThread::loop
virtual void loop()
Code to execute in the thread.
Definition: plexil_thread.cpp:316
fawkes::Thread
Thread class encapsulation of pthreads.
Definition: thread.h:46
fawkes::ConfigurableAspect
Thread aspect to access configuration data.
Definition: configurable.h:33
PlexilExecutiveThread::PlexilExecutiveThread
PlexilExecutiveThread()
Constructor.
Definition: plexil_thread.cpp:64
PlexilExecutiveThread::finalize
virtual void finalize()
Finalize the thread.
Definition: plexil_thread.cpp:288
fawkes::ClockAspect
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:34
PlexilExecutiveThread::run
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: plexil_thread.h:70