Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "status.hpp" |
Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 4 | |
| 5 | #include <memory> |
| 6 | #include <sdbusplus/bus.hpp> |
| 7 | #include <string> |
| 8 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 9 | namespace ipmi_flash |
Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 10 | { |
| 11 | |
| 12 | /** |
Patrick Venture | cf066ac | 2019-08-06 09:03:47 -0700 | [diff] [blame] | 13 | * Representation of what is used for triggering an action with systemd and |
| 14 | * checking the result by reading a file. |
Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 15 | */ |
Patrick Venture | 29af1e3 | 2019-08-05 13:42:28 -0700 | [diff] [blame] | 16 | class SystemdWithStatusFile : public TriggerableActionInterface |
Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 17 | { |
| 18 | public: |
| 19 | /** |
Patrick Venture | cf066ac | 2019-08-06 09:03:47 -0700 | [diff] [blame] | 20 | * Create a default SystemdWithStatusFile object that uses systemd to |
| 21 | * trigger the process. |
Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 22 | * |
| 23 | * @param[in] bus - an sdbusplus handler for a bus to use. |
| 24 | * @param[in] path - the path to check for verification status. |
Patrick Venture | ee614ec | 2019-08-05 12:08:44 -0700 | [diff] [blame] | 25 | * @param[in] service - the systemd service to start to trigger |
Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 26 | * verification. |
Patrick Venture | ee614ec | 2019-08-05 12:08:44 -0700 | [diff] [blame] | 27 | * @param[in] mode - the job-mode when starting the systemd Unit. |
Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 28 | */ |
Patrick Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 29 | static std::unique_ptr<TriggerableActionInterface> |
Patrick Venture | cf066ac | 2019-08-06 09:03:47 -0700 | [diff] [blame] | 30 | CreateSystemdWithStatusFile(sdbusplus::bus::bus&& bus, |
| 31 | const std::string& path, |
| 32 | const std::string& service, |
| 33 | const std::string& mode); |
Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 34 | |
Patrick Venture | 29af1e3 | 2019-08-05 13:42:28 -0700 | [diff] [blame] | 35 | SystemdWithStatusFile(sdbusplus::bus::bus&& bus, const std::string& path, |
| 36 | const std::string& service, const std::string& mode) : |
Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 37 | bus(std::move(bus)), |
Patrick Venture | ee614ec | 2019-08-05 12:08:44 -0700 | [diff] [blame] | 38 | checkPath(path), triggerService(service), mode(mode) |
Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 39 | { |
| 40 | } |
| 41 | |
Patrick Venture | 29af1e3 | 2019-08-05 13:42:28 -0700 | [diff] [blame] | 42 | ~SystemdWithStatusFile() = default; |
| 43 | SystemdWithStatusFile(const SystemdWithStatusFile&) = delete; |
| 44 | SystemdWithStatusFile& operator=(const SystemdWithStatusFile&) = delete; |
| 45 | SystemdWithStatusFile(SystemdWithStatusFile&&) = default; |
| 46 | SystemdWithStatusFile& operator=(SystemdWithStatusFile&&) = default; |
Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 47 | |
Patrick Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 48 | bool trigger() override; |
| 49 | void abort() override; |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 50 | ActionStatus status() override; |
Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 51 | |
Patrick Venture | ee614ec | 2019-08-05 12:08:44 -0700 | [diff] [blame] | 52 | const std::string getMode() const; |
| 53 | |
Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 54 | private: |
| 55 | sdbusplus::bus::bus bus; |
| 56 | const std::string checkPath; |
| 57 | const std::string triggerService; |
Patrick Venture | ee614ec | 2019-08-05 12:08:44 -0700 | [diff] [blame] | 58 | const std::string mode; |
Patrick Venture | 26a1726 | 2019-05-20 11:03:35 -0700 | [diff] [blame] | 59 | }; |
Patrick Venture | e0216d2 | 2019-08-21 10:17:39 -0700 | [diff] [blame^] | 60 | |
| 61 | class SystemdNoFile : public TriggerableActionInterface |
| 62 | { |
| 63 | public: |
| 64 | static std::unique_ptr<TriggerableActionInterface> |
| 65 | CreateSystemdNoFile(sdbusplus::bus::bus&& bus, |
| 66 | const std::string& service, |
| 67 | const std::string& mode); |
| 68 | |
| 69 | SystemdNoFile(sdbusplus::bus::bus&& bus, const std::string& service, |
| 70 | const std::string& mode) : |
| 71 | bus(std::move(bus)), |
| 72 | triggerService(service), mode(mode) |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | ~SystemdNoFile() = default; |
| 77 | SystemdNoFile(const SystemdNoFile&) = delete; |
| 78 | SystemdNoFile& operator=(const SystemdNoFile&) = delete; |
| 79 | SystemdNoFile(SystemdNoFile&&) = default; |
| 80 | SystemdNoFile& operator=(SystemdNoFile&&) = default; |
| 81 | |
| 82 | bool trigger() override; |
| 83 | void abort() override; |
| 84 | ActionStatus status() override; |
| 85 | |
| 86 | const std::string getMode() const; |
| 87 | |
| 88 | private: |
| 89 | sdbusplus::bus::bus bus; |
| 90 | const std::string triggerService; |
| 91 | const std::string mode; |
| 92 | ActionStatus state = ActionStatus::unknown; |
| 93 | }; |
| 94 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 95 | } // namespace ipmi_flash |