1 #pragma once 2 3 #include "status.hpp" 4 5 #include <sdbusplus/bus.hpp> 6 #include <sdbusplus/bus/match.hpp> 7 8 #include <memory> 9 #include <string> 10 11 namespace ipmi_flash 12 { 13 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) 26 {} 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 52 /** 53 * Representation of what is used for triggering an action with systemd and 54 * checking the result by reading a file. 55 */ 56 class SystemdWithStatusFile : public SystemdNoFile 57 { 58 public: 59 /** 60 * Create a default SystemdWithStatusFile object that uses systemd to 61 * trigger the process. 62 * 63 * @param[in] bus - an sdbusplus handler for a bus to use. 64 * @param[in] path - the path to check for verification status. 65 * @param[in] service - the systemd service to start to trigger 66 * verification. 67 * @param[in] mode - the job-mode when starting the systemd Unit. 68 */ 69 static std::unique_ptr<TriggerableActionInterface> 70 CreateSystemdWithStatusFile(sdbusplus::bus::bus&& bus, 71 const std::string& path, 72 const std::string& service, 73 const std::string& mode); 74 75 SystemdWithStatusFile(sdbusplus::bus::bus&& bus, const std::string& path, 76 const std::string& service, const std::string& mode) : 77 SystemdNoFile(std::move(bus), service, mode), 78 checkPath(path) 79 {} 80 81 bool trigger() override; 82 ActionStatus status() override; 83 84 private: 85 const std::string checkPath; 86 }; 87 88 } // namespace ipmi_flash 89