blob: c7fe4cb8081ae6018ea8d67c98093a28174ee3ef [file] [log] [blame]
Patrick Venture26a17262019-05-20 11:03:35 -07001#pragma once
2
3#include "status.hpp"
Patrick Venture26a17262019-05-20 11:03:35 -07004
5#include <memory>
6#include <sdbusplus/bus.hpp>
7#include <string>
8
Patrick Venture1d5a31c2019-05-20 11:38:22 -07009namespace ipmi_flash
Patrick Venture26a17262019-05-20 11:03:35 -070010{
11
12/**
Patrick Venturecf066ac2019-08-06 09:03:47 -070013 * Representation of what is used for triggering an action with systemd and
14 * checking the result by reading a file.
Patrick Venture26a17262019-05-20 11:03:35 -070015 */
Patrick Venture29af1e32019-08-05 13:42:28 -070016class SystemdWithStatusFile : public TriggerableActionInterface
Patrick Venture26a17262019-05-20 11:03:35 -070017{
18 public:
19 /**
Patrick Venturecf066ac2019-08-06 09:03:47 -070020 * Create a default SystemdWithStatusFile object that uses systemd to
21 * trigger the process.
Patrick Venture26a17262019-05-20 11:03:35 -070022 *
23 * @param[in] bus - an sdbusplus handler for a bus to use.
24 * @param[in] path - the path to check for verification status.
Patrick Ventureee614ec2019-08-05 12:08:44 -070025 * @param[in] service - the systemd service to start to trigger
Patrick Venture26a17262019-05-20 11:03:35 -070026 * verification.
Patrick Ventureee614ec2019-08-05 12:08:44 -070027 * @param[in] mode - the job-mode when starting the systemd Unit.
Patrick Venture26a17262019-05-20 11:03:35 -070028 */
Patrick Venture1d66fe62019-06-03 14:57:27 -070029 static std::unique_ptr<TriggerableActionInterface>
Patrick Venturecf066ac2019-08-06 09:03:47 -070030 CreateSystemdWithStatusFile(sdbusplus::bus::bus&& bus,
31 const std::string& path,
32 const std::string& service,
33 const std::string& mode);
Patrick Venture26a17262019-05-20 11:03:35 -070034
Patrick Venture29af1e32019-08-05 13:42:28 -070035 SystemdWithStatusFile(sdbusplus::bus::bus&& bus, const std::string& path,
36 const std::string& service, const std::string& mode) :
Patrick Venture26a17262019-05-20 11:03:35 -070037 bus(std::move(bus)),
Patrick Ventureee614ec2019-08-05 12:08:44 -070038 checkPath(path), triggerService(service), mode(mode)
Patrick Venture26a17262019-05-20 11:03:35 -070039 {
40 }
41
Patrick Venture29af1e32019-08-05 13:42:28 -070042 ~SystemdWithStatusFile() = default;
43 SystemdWithStatusFile(const SystemdWithStatusFile&) = delete;
44 SystemdWithStatusFile& operator=(const SystemdWithStatusFile&) = delete;
45 SystemdWithStatusFile(SystemdWithStatusFile&&) = default;
46 SystemdWithStatusFile& operator=(SystemdWithStatusFile&&) = default;
Patrick Venture26a17262019-05-20 11:03:35 -070047
Patrick Venture1d66fe62019-06-03 14:57:27 -070048 bool trigger() override;
49 void abort() override;
Patrick Ventureda66fd82019-06-03 11:11:24 -070050 ActionStatus status() override;
Patrick Venture26a17262019-05-20 11:03:35 -070051
Patrick Ventureee614ec2019-08-05 12:08:44 -070052 const std::string getMode() const;
53
Patrick Venture26a17262019-05-20 11:03:35 -070054 private:
55 sdbusplus::bus::bus bus;
56 const std::string checkPath;
57 const std::string triggerService;
Patrick Ventureee614ec2019-08-05 12:08:44 -070058 const std::string mode;
Patrick Venture26a17262019-05-20 11:03:35 -070059};
Patrick Venturee0216d22019-08-21 10:17:39 -070060
61class 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
Patrick Venture1d5a31c2019-05-20 11:38:22 -070095} // namespace ipmi_flash