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