rad  5.1.0
activity.hpp
Go to the documentation of this file.
1 
8 #ifndef RAD_ACTIVITY_HPP
9 #define RAD_ACTIVITY_HPP
10 
11 #include <scxml4cpp/Activity.h>
12 
13 #include <atomic>
14 #include <string>
15 #include <thread>
16 #include <mutex>
17 
18 namespace rad {
19 
44  public:
45  using Activity::Activity;
46 
48 
56  void start(scxml4cpp::Context* c) override;
57 
63  void stop(scxml4cpp::Context* c) override;
64 
68  virtual pthread_t GetNativeHandle() const = 0;
69 
75  inline bool IsStopRequested() const { return m_stop_requested.load(std::memory_order_acquire); }
76 
83  virtual bool IsThreadJoined() const = 0;
84 
85  protected:
86  // @todo Add error code?
87  virtual void StartThread() = 0;
88  virtual void JoinThread() = 0;
89  // returns true if thread is joined == not running.
90  // @}
91 
92  private:
93  std::atomic<bool> m_stop_requested; // Flag indicating whether the activity should stop.
94 };
95 
117  public:
119 
120  ThreadActivity(const ThreadActivity&) = delete;
122 
127  virtual void Run() = 0;
128 
132  pthread_t GetNativeHandle() const override;
133 
137  bool IsThreadJoined() const override;
138 
142  std::string GetName();
143 
150  int SetName(const std::string& name);
151 
152  protected:
153  void StartThread() override;
154  void JoinThread() override;
155 
156  private:
157  std::thread m_thread;
158 };
159 
160 } // namespace rad
161 
162 #endif // RAD_ACTIVITY_HPP
Activity header.
Definition: activity.hpp:116
ThreadActivity & operator=(const ThreadActivity &)=delete
virtual void Run()=0
void JoinThread() override
Definition: activity.cpp:59
bool IsThreadJoined() const override
Definition: activity.cpp:37
std::string GetName()
Definition: activity.cpp:73
pthread_t GetNativeHandle() const override
Definition: activity.cpp:118
ThreadActivity(const ThreadActivity &)=delete
int SetName(const std::string &name)
Definition: activity.cpp:92
void StartThread() override
Definition: activity.cpp:45
Definition: activity.hpp:43
virtual void JoinThread()=0
virtual bool IsThreadJoined() const =0
void stop(scxml4cpp::Context *c) override
Definition: activity.cpp:30
virtual void StartThread()=0
ThreadBaseActivity(ThreadBaseActivity const &)=delete
virtual pthread_t GetNativeHandle() const =0
bool IsStopRequested() const
Definition: activity.hpp:75
void start(scxml4cpp::Context *c) override
Definition: activity.cpp:23
Definition: Activity.h:52
Definition: Context.h:58
Definition: actionsApp.cpp:20
name
Definition: wscript:8