Skip to content

Commit 6eb494a

Browse files
committed
added conveneient macros to ease out reactions definition inside reactor
1 parent 591bc73 commit 6eb494a

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

examples/sdk-WorkersParams/main.cc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,12 @@ class Relay : public Reactor {
5656
Relay(const std::string &name, Reactor *container, Parameters &&param)
5757
: Reactor(name, container), parameters{std::forward<Parameters>(param)} {}
5858

59-
class Internals : public ReactionInternals<Relay, Parameters> {
59+
REACTION_SCOPE_START(Relay, Parameters)
6060
const int &n_outputs = parameters.n_outputs;
6161

6262
int index = 0;
6363
int *busy = 0;
6464

65-
public:
66-
Internals(Reactor *reactor, Parameters &params)
67-
: ReactionInternals<Relay, Parameters>(reactor, params) {}
68-
6965
void add_reactions(Relay *reactor) override {
7066
reaction("reaction_1").
7167
triggers(&reactor->startup).
@@ -134,9 +130,7 @@ class Relay : public Reactor {
134130
}
135131
);
136132
}
137-
};
138-
139-
Internals reaction_internals{this, parameters};
133+
REACTION_SCOPE_END(this, parameters)
140134

141135
void construction() override {
142136
out_req.set_width(n_outputs);

include/reactor-sdk/Reaction.hh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,15 @@ public:
300300
void request_stop() { reactor_->environment()->sync_shutdown(); }
301301
};
302302

303+
#define REACTION_SCOPE_START(ReactorType, ParamType) \
304+
class Internals : public ReactionInternals<ReactorType, ParamType> { \
305+
public: \
306+
Internals(Reactor *reactor, ParamType &params) \
307+
: ReactionInternals<ReactorType, ParamType>(reactor, params) {} \
308+
private:
309+
310+
#define REACTION_SCOPE_END(reactor, param) \
311+
}; \
312+
Internals reaction_internals{reactor, param};
313+
303314
} // namespace sdk

0 commit comments

Comments
 (0)