Skip to content

Commit 5821e42

Browse files
committed
ported examples and tests to new ReactionInternals design, now reactions have access only to their defined triggers, dependencies and effects
1 parent 21a4b65 commit 5821e42

File tree

22 files changed

+787
-638
lines changed

22 files changed

+787
-638
lines changed

examples/sdk-SrcSink-Fanout/Main/MainReactor.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@ void MainReactor::construction() {
88
snk = std::make_unique<SinkReactor>("Sink", this);
99
}
1010

11-
void MainReactor::assembling() {
12-
cout << "Assembling Main\n";
11+
void MainReactor::wiring() {
12+
cout << "Wiring Main\n";
1313

1414
src->req -->> snk->req;
1515
snk->rsp --> src->rsp;
16+
}
1617

18+
void REACTION_SCOPE(MainReactor)::add_reactions(MainReactor *reactor) {
1719
reaction("reaction_1").
18-
triggers(&startup).
20+
triggers(&reactor->startup).
1921
dependencies().
2022
effects().
2123
function(
22-
[&](Startup& startup) {
24+
[this](Startup& startup) {
2325
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<
2426
"Starting up reaction\n" << "Bank:" << bank_index << " name:" << parameters.alias.value << " fqn:" << fqn() << endl;
2527
}

examples/sdk-SrcSink-Fanout/Main/MainReactor.hh

+21-11
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,39 @@ using namespace sdk;
99

1010
class MainReactor: public Reactor {
1111
public:
12-
struct Parameters : public SystemParameter<string> {
13-
REACTOR_PARAMETER (string, alias, "Alternate name", "another", "another", "Src-Sink-Fanout-Example");
12+
struct Parameters {
13+
string alias = "Src-Sink-Fanout-Example";
14+
};
15+
private:
16+
struct PublishParameters : public SystemParameters<Parameters, string> {
17+
REACTOR_PARAMETER(string, alias, "Alternate name", "another", "another", defaults.alias);
1418

15-
Parameters(Reactor *container)
16-
: SystemParameter<string>(container) {
19+
PublishParameters(Reactor *container, Parameters &&param)
20+
: SystemParameters<Parameters, string>(container, std::forward<Parameters>(param)) {
1721
register_parameters (alias);
1822
}
19-
};
23+
};
24+
PublishParameters parameters;
2025

21-
private:
22-
Parameters parameters{this};
26+
REACTION_SCOPE_START(MainReactor, PublishParameters)
27+
void add_reactions(MainReactor *reactor);
28+
REACTION_SCOPE_END(this, parameters)
2329

2430
std::unique_ptr<SourceReactor> src;
2531
std::unique_ptr<SinkReactor> snk;
2632

2733
public:
2834
MainReactor(const std::string &name, Environment *env)
29-
: Reactor(name, env) {}
35+
: Reactor(name, env), parameters{this, Parameters{}} {}
3036
MainReactor(const std::string &name, Reactor *container)
31-
: Reactor(name, container) {}
37+
: Reactor(name, container), parameters{this, Parameters{}} {}
38+
39+
MainReactor(const std::string &name, Environment *env, Parameters && param)
40+
: Reactor(name, env), parameters{this, std::forward<Parameters>(param)} {}
41+
MainReactor(const std::string &name, Reactor *container, Parameters && param)
42+
: Reactor(name, container), parameters{this, std::forward<Parameters>(param)} {}
3243

3344
void construction() override;
34-
void assembling() override;
45+
void wiring() override;
3546
};
36-
3747

examples/sdk-SrcSink-Fanout/Sink/SinkReactor.cc

+9-8
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,34 @@ void SinkReactor::construction() {
77
rsp.set_width (parameters.n_ports.value);
88
}
99

10-
void SinkReactor::assembling() {
11-
12-
cout << "Assembling Sink\n";
10+
void SinkReactor::wiring() {
11+
cout << "Wiring Sink\n";
12+
}
1313

14+
void REACTION_SCOPE(SinkReactor)::add_reactions (SinkReactor *reactor) {
1415
reaction("startup_reaction").
15-
triggers(&startup).
16+
triggers(&reactor->startup).
1617
dependencies().
1718
effects().
1819
function(pass_function(startup_reaction)
1920
);
2021

2122
reaction("process_request").
22-
triggers(&req).
23+
triggers(&reactor->req).
2324
dependencies().
24-
effects(&rsp).
25+
effects(&reactor->rsp).
2526
function(pass_function(process_request)
2627
);
2728
}
2829

2930

3031

31-
void SinkReactor::startup_reaction (Startup& startup) {
32+
void REACTION_SCOPE(SinkReactor)::startup_reaction (Startup& startup) {
3233
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<
3334
"Starting up reaction\n" << "Bank:" << bank_index << " name:" << parameters.name.value << " fqn:" << fqn() << endl;
3435
}
3536

36-
void SinkReactor::process_request (MultiportInput<int>& req, MultiportOutput<int>& rsp) {
37+
void REACTION_SCOPE(SinkReactor)::process_request (MultiportInput<int>& req, MultiportOutput<int>& rsp) {
3738
for (int i = 0; i < parameters.n_ports.value; ++i) {
3839
if (req[i].is_present()) {
3940
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<

examples/sdk-SrcSink-Fanout/Sink/SinkReactor.hh

+27-12
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,44 @@ using namespace sdk;
66

77
class SinkReactor : public Reactor {
88
public:
9-
struct Parameters : public SystemParameter<string, int> {
10-
REACTOR_PARAMETER (string, name, "Alternate name", "Sink", "Sink", "Sink");
11-
REACTOR_PARAMETER (int, n_ports, "Size of multiports", 1, 10, 1);
129

13-
Parameters(Reactor *container)
14-
: SystemParameter<string, int>(container) {
10+
struct Parameters {
11+
string name = "Sink";
12+
int n_ports = 1;
13+
};
14+
private:
15+
struct PublishParameters : public SystemParameters<Parameters, string, int> {
16+
REACTOR_PARAMETER(string, name, "Alternate name", "Sink", "Sink", defaults.name);
17+
REACTOR_PARAMETER (int, n_ports, "Size of multiports", 1, 10, defaults.n_ports);
18+
19+
PublishParameters(Reactor *container, Parameters &&param)
20+
: SystemParameters<Parameters, string, int>(container, std::forward<Parameters>(param)) {
1521
register_parameters (name, n_ports);
1622
}
1723
};
24+
PublishParameters parameters;
25+
26+
REACTION_SCOPE_START(SinkReactor, PublishParameters)
27+
void add_reactions(SinkReactor *reactor);
28+
29+
void startup_reaction (Startup &startup);
30+
void process_request (MultiportInput<int>& req, MultiportOutput<int>& rsp);
31+
REACTION_SCOPE_END(this, parameters)
1832

33+
public:
1934
SinkReactor(const std::string &name, Environment *env)
20-
: Reactor(name, env) {}
35+
: Reactor(name, env), parameters{this, Parameters{}} {}
2136
SinkReactor(const std::string &name, Reactor *container)
22-
: Reactor(name, container) {}
37+
: Reactor(name, container), parameters{this, Parameters{}} {}
2338

24-
Parameters parameters{this};
39+
SinkReactor(const std::string &name, Environment *env, Parameters && param)
40+
: Reactor(name, env), parameters{this, std::forward<Parameters>(param)} {}
41+
SinkReactor(const std::string &name, Reactor *container, Parameters && param)
42+
: Reactor(name, container), parameters{this, std::forward<Parameters>(param)} {}
2543

2644
MultiportInput<int> req{"req", this};
2745
MultiportOutput<int> rsp{"rsp", this};
2846

2947
void construction() override;
30-
void assembling() override;
31-
32-
void startup_reaction (Startup &startup);
33-
void process_request (MultiportInput<int>& req, MultiportOutput<int>& rsp);
48+
void wiring() override;
3449
};

examples/sdk-SrcSink-Fanout/Source/SourceReactor.cc

+14-11
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ void SourceReactor::construction() {
77
cout << "Construction Source iterations:" << parameters.iterations.value << "\n";
88
}
99

10-
void SourceReactor::assembling() {
11-
cout << "Assembling Source iterations:" << parameters.iterations.value << "\n";
10+
void SourceReactor::wiring() {
11+
cout << "Wiring Source iterations:" << parameters.iterations.value << "\n";
12+
}
13+
14+
void REACTION_SCOPE(SourceReactor)::add_reactions(SourceReactor *reactor) {
1215
reaction("reaction_1").
13-
triggers(&startup).
16+
triggers(&reactor->startup).
1417
dependencies().
15-
effects(&sch).
18+
effects(&reactor->sch).
1619
function(
17-
[&](Startup& startup, LogicalAction<int>& sched) {
20+
[this](Startup& startup, LogicalAction<int>& sched) {
1821
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<
1922
"Starting up reaction\n" << "Bank:" << bank_index << " name:" << name << " fqn:" << fqn() << " iterations:" << parameters.iterations.value << endl;
2023
if (itr < parameters.iterations.value) {
@@ -25,23 +28,23 @@ void SourceReactor::assembling() {
2528
);
2629

2730
reaction("reaction_2").
28-
triggers(&sch).
31+
triggers(&reactor->sch).
2932
dependencies().
30-
effects(&req).
33+
effects(&reactor->req).
3134
function(
32-
[&](LogicalAction<int>& sch, Output<int>& req) {
35+
[this](LogicalAction<int>& sch, Output<int>& req) {
3336
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<
3437
"Scheduling iteration:" << *sch.get() << endl;
3538
req.set (*sch.get());
3639
}
3740
);
3841

3942
reaction("reaction_3").
40-
triggers(&rsp).
43+
triggers(&reactor->rsp).
4144
dependencies().
42-
effects(&sch).
45+
effects(&reactor->sch).
4346
function(
44-
[&](Input<int>& rsp, LogicalAction<int>& sch) {
47+
[this](Input<int>& rsp, LogicalAction<int>& sch) {
4548
if (rsp.is_present()) {
4649
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<
4750
"Recevied response:" << *rsp.get() << endl;

examples/sdk-SrcSink-Fanout/Source/SourceReactor.hh

+13-7
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,35 @@ using namespace sdk;
66

77
class SourceReactor : public Reactor {
88
public:
9-
struct Parameters : public SystemParameter<int> {
10-
REACTOR_PARAMETER (int, iterations, "Number of iterations", 1, 100, 10);
9+
struct Parameters : public SystemParametersStandalone<int> {
10+
REACTOR_PARAMETER(int, iterations, "Number of iterations", 1, 100, 10);
1111

1212
Parameters(Reactor *container)
13-
: SystemParameter<int>(container) {
13+
: SystemParametersStandalone<int>(container) {
1414
register_parameters (iterations);
1515
}
1616
};
1717
private:
18+
LogicalAction<int> sch{"sch", this};
19+
1820
Parameters parameters{this};
1921

20-
std::string name = "Source";
21-
int itr = 0;
22+
REACTION_SCOPE_START(SourceReactor, Parameters)
23+
std::string name = "Source";
24+
int itr = 0;
25+
26+
void add_reactions(SourceReactor *reactor);
27+
REACTION_SCOPE_END(this, parameters)
28+
2229
public:
2330
SourceReactor(const std::string &name, Environment *env)
2431
: Reactor(name, env) {}
2532
SourceReactor(const std::string &name, Reactor *container)
2633
: Reactor(name, container) {}
2734

28-
LogicalAction<int> sch{"sch", this};
2935
Input<int> rsp{"rsp", this};
3036
Output<int> req{"req", this};
3137

3238
void construction() override;
33-
void assembling() override;
39+
void wiring() override;
3440
};

examples/sdk-SrcSink/Main/MainReactor.cc

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ void MainReactor::construction() {
77
src = std::make_unique<SourceReactor>("Source", this);
88

99
for (int i = 0; i < parameters.n_sinks.value; i++) {
10-
snk.create_reactor(SinkReactor::DefaultParameters{.name = "Default Sink Name"});
10+
snk.create_reactor(SinkReactor::Parameters{.name = "Default Sink Name"});
1111
}
1212
}
1313

14-
void MainReactor::assembling() {
15-
cout << "Assembling Main n_sinks:" << parameters.n_sinks.value << " default n_sinks:" << parameters.defaults.n_sinks << "\n";
14+
void MainReactor::wiring() {
15+
cout << "Wiring Main n_sinks:" << parameters.n_sinks.value << " default n_sinks:" << parameters.defaults.n_sinks << "\n";
1616

1717
src->req --> snk.for_each(select_default(snk).req);
1818
// src->req --> snk.for_each(&SinkReactor::req); // alternative
@@ -25,13 +25,15 @@ void MainReactor::assembling() {
2525
// snk.for_each(&snk[0].rsp) --> src->rsp; // alternative
2626
// (snk->*(select_default(snk).rsp)) --> src->rsp; // alternative
2727
// (snk->*(&SinkReactor::rsp)) --> src->rsp; // alternative
28+
}
2829

30+
void REACTION_SCOPE(MainReactor)::add_reactions(MainReactor *reactor) {
2931
reaction("reaction_1").
30-
triggers(&startup).
32+
triggers(&reactor->startup).
3133
dependencies().
3234
effects().
3335
function(
34-
[&](Startup& startup) {
36+
[this](Startup& startup) {
3537
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<
3638
"Starting up reaction\n" << "Bank:" << bank_index << " name:" << parameters.alias.value << " fqn:" << fqn() << " n_sinks:" << parameters.n_sinks.value << endl;
3739
}

examples/sdk-SrcSink/Main/MainReactor.hh

+17-23
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,40 @@ using namespace sdk;
99

1010
class MainReactor: public Reactor {
1111
public:
12-
13-
struct DefaultParameters {
12+
struct Parameters {
1413
string alias = "Src-Sink-Example";
1514
int n_sinks = 2;
1615
};
17-
18-
struct Parameters : public SystemParameterWithDefault<DefaultParameters, string, int> {
16+
private:
17+
struct PublishParameters : public SystemParameters<Parameters, string, int> {
1918
REACTOR_PARAMETER(string, alias, "Alternate name", "another", "another", defaults.alias);
2019
REACTOR_PARAMETER(int, n_sinks, "Sink reactors bank width", 1, 10, defaults.n_sinks);
2120

22-
// Parameters(Reactor *container)
23-
// : SystemParameter<string, int>(container) {
24-
// register_parameters (alias, n_sinks);
25-
// }
26-
27-
Parameters(Reactor *container, DefaultParameters &&param)
28-
: SystemParameterWithDefault<DefaultParameters, string, int>(container, std::forward<DefaultParameters>(param)) {
21+
PublishParameters(Reactor *container, Parameters &&param)
22+
: SystemParameters<Parameters, string, int>(container, std::forward<Parameters>(param)) {
2923
register_parameters (alias, n_sinks);
3024
}
3125
};
26+
PublishParameters parameters;
3227

33-
private:
34-
Parameters parameters;
28+
REACTION_SCOPE_START(MainReactor, PublishParameters)
29+
void add_reactions(MainReactor *reactor);
30+
REACTION_SCOPE_END(this, parameters)
3531

3632
std::unique_ptr<SourceReactor> src;
3733
ReactorBank<SinkReactor> snk{"Sink", this};
3834

3935
public:
4036
MainReactor(const std::string &name, Environment *env)
41-
: Reactor(name, env), parameters{this, DefaultParameters{}} {}
37+
: Reactor(name, env), parameters{this, Parameters{}} {}
4238
MainReactor(const std::string &name, Reactor *container)
43-
: Reactor(name, container), parameters{this, DefaultParameters{}} {}
39+
: Reactor(name, container), parameters{this, Parameters{}} {}
4440

45-
MainReactor(const std::string &name, Environment *env, DefaultParameters && param)
46-
: Reactor(name, env), parameters{this, std::forward<DefaultParameters>(param)} {}
47-
MainReactor(const std::string &name, Reactor *container, DefaultParameters && param)
48-
: Reactor(name, container), parameters{this, std::forward<DefaultParameters>(param)} {}
41+
MainReactor(const std::string &name, Environment *env, Parameters && param)
42+
: Reactor(name, env), parameters{this, std::forward<Parameters>(param)} {}
43+
MainReactor(const std::string &name, Reactor *container, Parameters && param)
44+
: Reactor(name, container), parameters{this, std::forward<Parameters>(param)} {}
4945

5046
void construction() override;
51-
void assembling() override;
52-
};
53-
54-
47+
void wiring() override;
48+
};

0 commit comments

Comments
 (0)