Skip to content

Commit 5b07ca5

Browse files
committed
base changes for sdk, bug fix for export_dependency_graph to a .dot file
1 parent 36dd4d2 commit 5b07ca5

File tree

5 files changed

+47
-9
lines changed

5 files changed

+47
-9
lines changed

include/reactor-cpp/action.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public:
152152
};
153153

154154
class Timer : public BaseAction {
155-
private:
155+
protected:
156156
Duration offset_{0};
157157
Duration period_{0};
158158

include/reactor-cpp/environment.hh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ constexpr bool default_fast_fwd_execution = false;
3030
enum class Phase : std::uint8_t {
3131
Construction = 0,
3232
Assembly = 1,
33-
Startup = 2,
34-
Execution = 3,
35-
Shutdown = 4,
36-
Deconstruction = 5
33+
Indexing = 2,
34+
Startup = 3,
35+
Execution = 4,
36+
Shutdown = 5,
37+
Deconstruction = 6
3738
};
3839

3940
class Environment {
@@ -107,7 +108,9 @@ public:
107108
void register_reactor(Reactor* reactor);
108109
void register_port(BasePort* port) noexcept;
109110
void register_input_action(BaseAction* action);
111+
void construct();
110112
void assemble();
113+
void dependency_graph_and_indexes();
111114
auto startup() -> std::thread;
112115
void sync_shutdown();
113116
void async_shutdown();

include/reactor-cpp/reactor.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public:
5252
void shutdown() final;
5353

5454
virtual void assemble() = 0;
55+
virtual void construct() {}
5556

5657
[[nodiscard]] static auto get_physical_time() noexcept -> TimePoint;
5758
[[nodiscard]] auto get_logical_time() const noexcept -> TimePoint;

lib/environment.cc

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@ void Environment::optimize() {
6767
optimized_graph_ = graph_;
6868
}
6969

70+
void recursive_construct(Reactor* container) {
71+
container->construct();
72+
for (auto* reactor : container->reactors()) {
73+
recursive_construct(reactor);
74+
}
75+
}
76+
77+
void Environment::construct() {
78+
// phase_ = Phase::Assembly;
79+
80+
log::Info() << "Start Contruction of reactors";
81+
for (auto* reactor : top_level_reactors_) {
82+
recursive_construct(reactor);
83+
}
84+
85+
for (auto* env : contained_environments_) {
86+
env->construct();
87+
}
88+
}
89+
7090
void recursive_assemble(Reactor* container) {
7191
container->assemble();
7292
for (auto* reactor : container->reactors()) {
@@ -80,7 +100,7 @@ void Environment::assemble() { // NOLINT(readability-function-cognitive-complexi
80100
// constructing all the reactors
81101
// this mainly tell the reactors that they should connect their ports and actions not ports and ports
82102

83-
log::Debug() << "start assembly of reactors";
103+
log::Info() << "start assembly of reactors";
84104
for (auto* reactor : top_level_reactors_) {
85105
recursive_assemble(reactor);
86106
}
@@ -112,6 +132,8 @@ void Environment::assemble() { // NOLINT(readability-function-cognitive-complexi
112132
source_port->add_outward_binding(destination_port);
113133
log::Debug() << "from: " << source_port->fqn() << "(" << source_port << ")"
114134
<< " --> to: " << destination_port->fqn() << "(" << destination_port << ")";
135+
reactor::validate(source_port != destination_port,
136+
"Self wiring detected; from " + source_port->fqn() + " --> " + destination_port->fqn());
115137
}
116138
} else {
117139
if (properties.type_ == ConnectionType::Enclaved || properties.type_ == ConnectionType::PhysicalEnclaved ||
@@ -221,6 +243,8 @@ void Environment::export_dependency_graph(const std::string& path) {
221243
std::ofstream dot;
222244
dot.open(path);
223245

246+
dependency_graph_and_indexes();
247+
224248
// sort all reactions_ by their index
225249
std::map<unsigned int, std::vector<Reaction*>> reactions_by_index;
226250
for (auto* reaction : reactions_) {
@@ -317,7 +341,7 @@ auto Environment::startup() -> std::thread {
317341
return startup(get_physical_time());
318342
}
319343

320-
auto Environment::startup(const TimePoint& start_time) -> std::thread {
344+
void Environment::dependency_graph_and_indexes() {
321345
validate(this->phase() == Phase::Assembly, "startup() may only be called during assembly phase!");
322346

323347
log::Debug() << "Building the Dependency-Graph";
@@ -327,7 +351,17 @@ auto Environment::startup(const TimePoint& start_time) -> std::thread {
327351

328352
calculate_indexes();
329353

330-
log_.debug() << "Starting the execution";
354+
phase_ = Phase::Indexing;
355+
}
356+
357+
auto Environment::startup(const TimePoint& start_time) -> std::thread {
358+
if (phase_ == Phase::Assembly) {
359+
dependency_graph_and_indexes();
360+
}
361+
362+
validate(this->phase() == Phase::Indexing, "startup() may only be called during Indexing phase!");
363+
364+
log_.info() << "Starting the execution";
331365
phase_ = Phase::Startup;
332366

333367
this->start_tag_ = Tag::from_physical_time(start_time);

lib/reactor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void Reactor::register_output(BasePort* port) {
4747
reactor_assert(port != nullptr);
4848
reactor::validate(this->environment()->phase() == Phase::Construction,
4949
"Ports can only be registered during construction phase!");
50-
[[maybe_unused]] bool result = inputs_.insert(port).second;
50+
[[maybe_unused]] bool result = outputs_.insert(port).second;
5151
reactor_assert(result);
5252
Statistics::increment_ports();
5353
}

0 commit comments

Comments
 (0)