Skip to content

Commit

Permalink
add name() support inside reactions, validation of name against fqn i…
Browse files Browse the repository at this point in the history
…n test file
  • Loading branch information
OmerMajNition committed Oct 30, 2024
1 parent 8f2366e commit 1633b41
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions core/src/main/resources/lib/cpp/lfutil.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public:
reactor::Duration get_elapsed_physical_time() const { return reactor->get_elapsed_physical_time(); }
reactor::Environment* environment() const { return reactor->environment(); }
const std::string& fqn() const { return reactor->fqn(); }
const std::string& name() const { return reactor->name(); }
void request_stop() const { return environment()->sync_shutdown(); }
};

Expand Down
36 changes: 28 additions & 8 deletions test/Cpp/src/FqnTest.lf
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,73 @@ target Cpp {
workers: 1
}

public preamble {=
inline bool name_validation (const std::string& fqn, const std::string& name) {
size_t last_dot = fqn.find_last_of('.');
return (last_dot == std::string::npos) ? (name == fqn) : (name == fqn.substr(last_dot + 1));
}
=}

reactor A(bank_index: size_t = 0) {
reaction(startup) {=
std::cout << fqn() << " Started\n";
std::cout << "fqn:" << fqn() << " name:" << name() << " Started\n";
assert (name_validation(fqn(), name()));
=}

reaction(shutdown) {=
std::cout << fqn() << " Terminated\n";
std::cout << "fqn:" << fqn() << " name:" << name() << " Terminated\n";
=}
}

reactor B(bank_index: size_t = 0) {
a = new[3] A()

reaction(startup) {=
std::cout << fqn() << " Started\n";
std::cout << "fqn:" << fqn() << " name:" << name() << " Started\n";
assert (name_validation(fqn(), name()));
=}

reaction(shutdown) {=
std::cout << fqn() << " Terminated\n";
std::cout << "fqn:" << fqn() << " name:" << name() << " Terminated\n";
=}
}

reactor C(bank_index: size_t = 0) {
b = new[2] B()

reaction(startup) {=
std::cout << fqn() << " Started\n";
std::cout << "fqn:" << fqn() << " name:" << name() << " Started\n";
assert (name_validation(fqn(), name()));
=}

reaction(shutdown) {=
std::cout << fqn() << " Terminated\n";
std::cout << "fqn:" << fqn() << " name:" << name() << " Terminated\n";
=}
}

reactor D(bank_index: size_t = 0) {
a = new[2] A()

reaction(startup) {=
std::cout << fqn() << " Started\n";
std::cout << "fqn:" << fqn() << " name:" << name() << " Started\n";
assert (name_validation(fqn(), name()));
=}

reaction(shutdown) {=
std::cout << fqn() << " Terminated\n";
std::cout << "fqn:" << fqn() << " name:" << name() << " Terminated\n";
=}
}

main reactor {
c = new[2] C()
d = new[3] D()

reaction(startup) {=
std::cout << "fqn:" << fqn() << " name:" << name() << " Started\n";
assert (name_validation(fqn(), name()));
=}

reaction(shutdown) {=
std::cout << "fqn:" << fqn() << " name:" << name() << " Terminated\n";
=}
}

0 comments on commit 1633b41

Please sign in to comment.