blob: 5c4c0e3f663d1f664c3f658f839806b0cc3a35a3 [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 Venture1d5a31c2019-05-20 11:38:22 -070060} // namespace ipmi_flash