RTC Toolkit  1.0.0
threadActivity.hpp
Go to the documentation of this file.
1 
12 #ifndef RTCTK_COMPONENTFRAMEWORK_THREADACTIVITY_HPP
13 #define RTCTK_COMPONENTFRAMEWORK_THREADACTIVITY_HPP
14 
17 
18 #include <functional>
19 #include <future>
20 #include <scxml4cpp/Activity.h>
21 
22 namespace rtctk::componentFramework {
23 
27 class ThreadActivity : public scxml4cpp::Activity {
28 public:
29  using ActivityMethod = std::function<void(StopToken)>;
30  using SuccessMethod = std::function<void()>;
31  using FailureMethod = std::function<void(std::exception_ptr)>;
32 
33  ThreadActivity(std::string const& id,
34  ActivityMethod activity,
35  SuccessMethod on_success = nullptr,
36  FailureMethod on_failure = nullptr);
37 
39 
40  ThreadActivity(const ThreadActivity&) = delete;
42 
43  void start(scxml4cpp::Context* c) override;
44  void stop(scxml4cpp::Context* c) override;
45 
46 private:
47  ActivityMethod m_activity_method;
48  SuccessMethod m_success_method;
49  FailureMethod m_failure_method;
50 
51  StopSource m_stop_source;
52  std::future<void> m_thread_observer;
53  bool m_is_stopped;
54 };
55 
56 } // namespace rtctk::componentFramework
57 
58 #endif // RTCTK_COMPONENTFRAMEWORK_THREADACTIVITY_HPP
exceptions.hpp
Provides macros and utilities for exception handling.
rtctk::componentFramework
Definition: commandReplier.cpp:20
rtctk::componentFramework::ThreadActivity::ThreadActivity
ThreadActivity(std::string const &id, ActivityMethod activity, SuccessMethod on_success=nullptr, FailureMethod on_failure=nullptr)
Definition: threadActivity.cpp:17
rtctk::componentFramework::ThreadActivity::ThreadActivity
ThreadActivity(const ThreadActivity &)=delete
rtctk::componentFramework::ThreadActivity::ActivityMethod
std::function< void(StopToken)> ActivityMethod
Definition: threadActivity.hpp:29
rtctk::componentFramework::StopToken
rad::StopToken StopToken
Definition: stopToken.hpp:19
rtctk::componentFramework::ThreadActivity::SuccessMethod
std::function< void()> SuccessMethod
Definition: threadActivity.hpp:30
rtctk::componentFramework::ThreadActivity::operator=
ThreadActivity & operator=(const ThreadActivity &)=delete
rtctk::componentFramework::ThreadActivity::FailureMethod
std::function< void(std::exception_ptr)> FailureMethod
Definition: threadActivity.hpp:31
rtctk::componentFramework::ThreadActivity
Class that handles state machine activities.
Definition: threadActivity.hpp:27
stopToken.hpp
A simple Stop Token.
rtctk::componentFramework::ThreadActivity::start
void start(scxml4cpp::Context *c) override
Definition: threadActivity.cpp:31
rtctk::componentFramework::StopSource
rad::StopSource StopSource
Definition: stopToken.hpp:18
rtctk::componentFramework::ThreadActivity::stop
void stop(scxml4cpp::Context *c) override
Definition: threadActivity.cpp:58
rtctk::componentFramework::ThreadActivity::~ThreadActivity
~ThreadActivity()
Definition: threadActivity.cpp:28