Fawkes API  Fawkes Development Version
hardware_models_thread.h
1 
2 /***************************************************************************
3  * hardware_models_thread.h - Hardware Models plugin
4  *
5  * Created: Sun Mar 24 11:59:44 2019
6  * Copyright 2019 Daniel Habering [daniel@habering.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef _PLUGINS_HARDWARE_MODELS_HARDWARE_MODELS_THREAD_H_
24 #define _PLUGINS_HARDWARE_MODELS_HARDWARE_MODELS_THREAD_H_
25 
26 #include <aspect/blackboard.h>
27 #include <aspect/blocked_timing.h>
28 #include <aspect/clock.h>
29 #include <aspect/configurable.h>
30 #include <aspect/logging.h>
31 #include <blackboard/interface_listener.h>
32 #include <core/threading/thread.h>
33 #include <interfaces/HardwareModelsInterface.h>
34 #include <plugins/clips/aspect/clips_feature.h>
35 #include <utils/time/time.h>
36 
37 #include <clipsmm.h>
38 #include <memory>
39 
40 namespace fawkes {
41 }
42 
44  public fawkes::LoggingAspect,
47  public fawkes::CLIPSFeature,
50 {
51 public:
53 
54  virtual void init();
55  virtual void loop();
56  virtual void finalize();
57 
58  // for CLIPSFeature
59  virtual void clips_context_init(const std::string & env_name,
61  virtual void clips_context_destroyed(const std::string &env_name);
62 
63  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
64 protected:
65  virtual void
66  run()
67  {
68  Thread::run();
69  }
70 
71 private:
72  std::map<std::string, fawkes::LockPtr<CLIPS::Environment>> envs_;
73 
74  std::vector<std::string> components_;
75 
77 
78  void clips_add_terminal_state(fawkes::LockPtr<CLIPS::Environment> &clips,
79  const std::string & component,
80  const std::string & state);
81  void clips_add_component(fawkes::LockPtr<CLIPS::Environment> &clips,
82  const std::string & component,
83  const std::string & init_state);
84  void clips_add_edge(fawkes::LockPtr<CLIPS::Environment> &clips,
85  const std::string & component,
86  const std::string & from,
87  const std::string & to,
88  const std::string & trans);
89  void clips_add_transition(const std::string &component, const std::string &transition) noexcept;
90 };
91 
92 #endif
Main thread of Hardware Models Plugin.
virtual void finalize()
Finalize the thread.
virtual void loop()
Loop function to be executed when a new HardwareInterfaceMessage is recieved.
virtual void run()
Stub to see name in backtrace for easier debugging.
virtual void clips_context_destroyed(const std::string &env_name)
Notification that a CLIPS environment has been destroyed.
virtual void clips_context_init(const std::string &env_name, fawkes::LockPtr< CLIPS::Environment > &clips)
Initializes hardware components from yaml files for a clips environment.
virtual void init()
Initialize the thread.
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
BlackBoard interface listener.
Thread aspect to provide a feature to CLIPS environments.
Definition: clips_feature.h:58
CLIPS feature maintainer.
Definition: clips_feature.h:42
Thread aspect to access configuration data.
Definition: configurable.h:33
HardwareModelsInterface Fawkes BlackBoard Interface.
Thread aspect to log output.
Definition: logging.h:33
Thread class encapsulation of pthreads.
Definition: thread.h:46
Fawkes library namespace.