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