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