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