| 1 | #include "target.hpp" |
|---|---|
| 2 | |
| 3 | #include "ServiceManager.hpp" |
| 4 | |
| 5 | RegisterUnit(target, Target); |
| 6 | |
| 7 | Target::Target(const std::string &id, toml::table &table, std::shared_ptr<const Template> template_, const ArgumentMap &args) // |
| 8 | : Unit(id, table, template_, args) |
| 9 | { |
| 10 | } |
| 11 | |
| 12 | bool Target::Start() |
| 13 | { |
| 14 | for (const auto &partOf : GetMembers()) |
| 15 | { |
| 16 | if (!ServiceManager->StartUnit(id: partOf)) |
| 17 | { |
| 18 | std::cerr << "Failed to stop unit "<< partOf << " while stopping target "<< id << std::endl; |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | status.Started(msg: "reached"); |
| 23 | ServiceManager->OnUnitStarted(unit: this); |
| 24 | return true; |
| 25 | } |
| 26 | |
| 27 | bool Target::Stop() |
| 28 | { |
| 29 | status.Stopping(); |
| 30 | for (const auto &partOf : GetMembers()) |
| 31 | { |
| 32 | if (!ServiceManager->StopUnit(id: partOf)) |
| 33 | { |
| 34 | std::cerr << "Failed to stop unit "<< partOf << " while stopping target "<< id << std::endl; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | std::cout << "Target "<< id << " stopped."<< std::endl; |
| 39 | status.Inactive(); |
| 40 | ServiceManager->OnUnitStopped(unit: this); |
| 41 | return true; |
| 42 | } |
| 43 |