1 #pragma once 2 3 #include "status.hpp" 4 5 #include <memory> 6 #include <sdbusplus/bus.hpp> 7 #include <string> 8 9 namespace ipmi_flash 10 { 11 12 /** 13 * Representation of what is used for triggering an action with systemd and 14 * checking the result by reading a file. 15 */ 16 class SystemdWithStatusFile : public TriggerableActionInterface 17 { 18 public: 19 /** 20 * Create a default SystemdWithStatusFile object that uses systemd to 21 * trigger the process. 22 * 23 * @param[in] bus - an sdbusplus handler for a bus to use. 24 * @param[in] path - the path to check for verification status. 25 * @param[in] service - the systemd service to start to trigger 26 * verification. 27 * @param[in] mode - the job-mode when starting the systemd Unit. 28 */ 29 static std::unique_ptr<TriggerableActionInterface> 30 CreateSystemdWithStatusFile(sdbusplus::bus::bus&& bus, 31 const std::string& path, 32 const std::string& service, 33 const std::string& mode); 34 35 SystemdWithStatusFile(sdbusplus::bus::bus&& bus, const std::string& path, 36 const std::string& service, const std::string& mode) : 37 bus(std::move(bus)), 38 checkPath(path), triggerService(service), mode(mode) 39 { 40 } 41 42 ~SystemdWithStatusFile() = default; 43 SystemdWithStatusFile(const SystemdWithStatusFile&) = delete; 44 SystemdWithStatusFile& operator=(const SystemdWithStatusFile&) = delete; 45 SystemdWithStatusFile(SystemdWithStatusFile&&) = default; 46 SystemdWithStatusFile& operator=(SystemdWithStatusFile&&) = default; 47 48 bool trigger() override; 49 void abort() override; 50 ActionStatus status() override; 51 52 const std::string getMode() const; 53 54 private: 55 sdbusplus::bus::bus bus; 56 const std::string checkPath; 57 const std::string triggerService; 58 const std::string mode; 59 }; 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 95 } // namespace ipmi_flash 96