99#ifndef REACTOR_CPP_ACTION_HH
1010#define REACTOR_CPP_ACTION_HH
1111
12+ #include " environment.hh"
13+ #include " fwd.hh"
1214#include " logical_time.hh"
1315#include " reactor.hh"
1416#include " value_ptr.hh"
@@ -37,6 +39,12 @@ protected:
3739 : ReactorElement(name, ReactorElement::Type::Action, container)
3840 , min_delay_(min_delay)
3941 , logical_(logical) {}
42+ BaseAction (const std::string& name, Environment* environment, bool logical, Duration min_delay)
43+ : ReactorElement(name, ReactorElement::Type::Action, environment)
44+ , min_delay_(min_delay)
45+ , logical_(logical) {
46+ environment->register_input_action (this );
47+ }
4048
4149public:
4250 [[nodiscard]] auto inline triggers () const noexcept -> const auto& { return triggers_; }
@@ -63,6 +71,8 @@ protected:
6371
6472 Action (const std::string& name, Reactor* container, bool logical, Duration min_delay)
6573 : BaseAction(name, container, logical, min_delay) {}
74+ Action (const std::string& name, Environment* environment, bool logical, Duration min_delay)
75+ : BaseAction(name, environment, logical, min_delay) {}
6676
6777public:
6878 // Normally, we should lock the mutex while moving to make this
@@ -107,6 +117,8 @@ template <> class Action<void> : public BaseAction {
107117protected:
108118 Action (const std::string& name, Reactor* container, bool logical, Duration min_delay)
109119 : BaseAction(name, container, logical, min_delay) {}
120+ Action (const std::string& name, Environment* environment, bool logical, Duration min_delay)
121+ : BaseAction(name, environment, logical, min_delay) {}
110122
111123public:
112124 template <class Dur = Duration> void schedule (Dur delay = Dur::zero());
@@ -118,7 +130,11 @@ public:
118130template <class T > class PhysicalAction : public Action <T> {
119131public:
120132 PhysicalAction (const std::string& name, Reactor* container)
121- : Action<T>(name, container, false , Duration::zero()) {}
133+ : Action<T>(name, container, false , Duration::zero()) {
134+ // all physical actions act as input actions to the program as they can be
135+ // scheduled from external threads
136+ container->environment ()->register_input_action (this );
137+ }
122138};
123139
124140template <class T > class LogicalAction : public Action <T> {
0 commit comments