1cf066aceSPatrick Venture #pragma once 2cf066aceSPatrick Venture 3cf066aceSPatrick Venture #include "status.hpp" 4cf066aceSPatrick Venture 5cf066aceSPatrick Venture #include <memory> 6cf066aceSPatrick Venture #include <sdbusplus/bus.hpp> 7cf066aceSPatrick Venture #include <string> 8cf066aceSPatrick Venture 9cf066aceSPatrick Venture namespace ipmi_flash 10cf066aceSPatrick Venture { 11cf066aceSPatrick Venture 12cf066aceSPatrick Venture /** 13cf066aceSPatrick Venture * Representation of what is used for triggering an action with systemd and 14cf066aceSPatrick Venture * checking the result by reading a file. 15cf066aceSPatrick Venture */ 16cf066aceSPatrick Venture class SystemdWithStatusFile : public TriggerableActionInterface 17cf066aceSPatrick Venture { 18cf066aceSPatrick Venture public: 19cf066aceSPatrick Venture /** 20cf066aceSPatrick Venture * Create a default SystemdWithStatusFile object that uses systemd to 21cf066aceSPatrick Venture * trigger the process. 22cf066aceSPatrick Venture * 23cf066aceSPatrick Venture * @param[in] bus - an sdbusplus handler for a bus to use. 24cf066aceSPatrick Venture * @param[in] path - the path to check for verification status. 25cf066aceSPatrick Venture * @param[in] service - the systemd service to start to trigger 26cf066aceSPatrick Venture * verification. 27cf066aceSPatrick Venture * @param[in] mode - the job-mode when starting the systemd Unit. 28cf066aceSPatrick Venture */ 29cf066aceSPatrick Venture static std::unique_ptr<TriggerableActionInterface> 30cf066aceSPatrick Venture CreateSystemdWithStatusFile(sdbusplus::bus::bus&& bus, 31cf066aceSPatrick Venture const std::string& path, 32cf066aceSPatrick Venture const std::string& service, 33cf066aceSPatrick Venture const std::string& mode); 34cf066aceSPatrick Venture 35cf066aceSPatrick Venture SystemdWithStatusFile(sdbusplus::bus::bus&& bus, const std::string& path, 36cf066aceSPatrick Venture const std::string& service, const std::string& mode) : 37cf066aceSPatrick Venture bus(std::move(bus)), 38cf066aceSPatrick Venture checkPath(path), triggerService(service), mode(mode) 39cf066aceSPatrick Venture { 40cf066aceSPatrick Venture } 41cf066aceSPatrick Venture 42cf066aceSPatrick Venture ~SystemdWithStatusFile() = default; 43cf066aceSPatrick Venture SystemdWithStatusFile(const SystemdWithStatusFile&) = delete; 44cf066aceSPatrick Venture SystemdWithStatusFile& operator=(const SystemdWithStatusFile&) = delete; 45cf066aceSPatrick Venture SystemdWithStatusFile(SystemdWithStatusFile&&) = default; 46cf066aceSPatrick Venture SystemdWithStatusFile& operator=(SystemdWithStatusFile&&) = default; 47cf066aceSPatrick Venture 48cf066aceSPatrick Venture bool trigger() override; 49cf066aceSPatrick Venture void abort() override; 50cf066aceSPatrick Venture ActionStatus status() override; 51cf066aceSPatrick Venture 52cf066aceSPatrick Venture const std::string getMode() const; 53cf066aceSPatrick Venture 54cf066aceSPatrick Venture private: 55cf066aceSPatrick Venture sdbusplus::bus::bus bus; 56cf066aceSPatrick Venture const std::string checkPath; 57cf066aceSPatrick Venture const std::string triggerService; 58cf066aceSPatrick Venture const std::string mode; 59cf066aceSPatrick Venture }; 60*e0216d23SPatrick Venture 61*e0216d23SPatrick Venture class SystemdNoFile : public TriggerableActionInterface 62*e0216d23SPatrick Venture { 63*e0216d23SPatrick Venture public: 64*e0216d23SPatrick Venture static std::unique_ptr<TriggerableActionInterface> 65*e0216d23SPatrick Venture CreateSystemdNoFile(sdbusplus::bus::bus&& bus, 66*e0216d23SPatrick Venture const std::string& service, 67*e0216d23SPatrick Venture const std::string& mode); 68*e0216d23SPatrick Venture 69*e0216d23SPatrick Venture SystemdNoFile(sdbusplus::bus::bus&& bus, const std::string& service, 70*e0216d23SPatrick Venture const std::string& mode) : 71*e0216d23SPatrick Venture bus(std::move(bus)), 72*e0216d23SPatrick Venture triggerService(service), mode(mode) 73*e0216d23SPatrick Venture { 74*e0216d23SPatrick Venture } 75*e0216d23SPatrick Venture 76*e0216d23SPatrick Venture ~SystemdNoFile() = default; 77*e0216d23SPatrick Venture SystemdNoFile(const SystemdNoFile&) = delete; 78*e0216d23SPatrick Venture SystemdNoFile& operator=(const SystemdNoFile&) = delete; 79*e0216d23SPatrick Venture SystemdNoFile(SystemdNoFile&&) = default; 80*e0216d23SPatrick Venture SystemdNoFile& operator=(SystemdNoFile&&) = default; 81*e0216d23SPatrick Venture 82*e0216d23SPatrick Venture bool trigger() override; 83*e0216d23SPatrick Venture void abort() override; 84*e0216d23SPatrick Venture ActionStatus status() override; 85*e0216d23SPatrick Venture 86*e0216d23SPatrick Venture const std::string getMode() const; 87*e0216d23SPatrick Venture 88*e0216d23SPatrick Venture private: 89*e0216d23SPatrick Venture sdbusplus::bus::bus bus; 90*e0216d23SPatrick Venture const std::string triggerService; 91*e0216d23SPatrick Venture const std::string mode; 92*e0216d23SPatrick Venture ActionStatus state = ActionStatus::unknown; 93*e0216d23SPatrick Venture }; 94*e0216d23SPatrick Venture 95cf066aceSPatrick Venture } // namespace ipmi_flash 96