blob: 4df47470c438bec1bca699c50b4cfea334f5ea21 [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
Patrick Venture26a17262019-05-20 11:03:35 -07005#include <sdbusplus/bus.hpp>
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -08006#include <sdbusplus/bus/match.hpp>
Patrick Venture9b37b092020-05-28 20:58:57 -07007
8#include <memory>
Patrick Venture26a17262019-05-20 11:03:35 -07009#include <string>
10
Patrick Venture1d5a31c2019-05-20 11:38:22 -070011namespace ipmi_flash
Patrick Venture26a17262019-05-20 11:03:35 -070012{
13
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080014class SystemdNoFile : public TriggerableActionInterface
15{
16 public:
17 static std::unique_ptr<TriggerableActionInterface>
Patrick Williams40fbb0c2022-07-22 19:26:57 -050018 CreateSystemdNoFile(sdbusplus::bus_t&& bus, const std::string& service,
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080019 const std::string& mode);
20
Patrick Williams40fbb0c2022-07-22 19:26:57 -050021 SystemdNoFile(sdbusplus::bus_t&& bus, const std::string& service,
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080022 const std::string& mode) :
23 bus(std::move(bus)),
24 triggerService(service), mode(mode)
Patrick Venture9b37b092020-05-28 20:58:57 -070025 {}
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080026
27 SystemdNoFile(const SystemdNoFile&) = delete;
28 SystemdNoFile& operator=(const SystemdNoFile&) = delete;
29 // sdbusplus match requires us to be pinned
30 SystemdNoFile(SystemdNoFile&&) = delete;
31 SystemdNoFile& operator=(SystemdNoFile&&) = delete;
32
33 bool trigger() override;
34 void abort() override;
35 ActionStatus status() override;
36
37 const std::string& getMode() const;
38
39 private:
Patrick Williams40fbb0c2022-07-22 19:26:57 -050040 sdbusplus::bus_t bus;
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080041 const std::string triggerService;
42 const std::string mode;
43
Patrick Williams40fbb0c2022-07-22 19:26:57 -050044 std::optional<sdbusplus::bus::match_t> jobMonitor;
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080045 std::optional<std::string> job;
46 ActionStatus currentStatus = ActionStatus::unknown;
47
Patrick Williams40fbb0c2022-07-22 19:26:57 -050048 void match(sdbusplus::message_t& m);
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080049};
50
Patrick Venture26a17262019-05-20 11:03:35 -070051/**
Patrick Venturecf066ac2019-08-06 09:03:47 -070052 * Representation of what is used for triggering an action with systemd and
53 * checking the result by reading a file.
Patrick Venture26a17262019-05-20 11:03:35 -070054 */
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080055class SystemdWithStatusFile : public SystemdNoFile
Patrick Venture26a17262019-05-20 11:03:35 -070056{
57 public:
58 /**
Patrick Venturecf066ac2019-08-06 09:03:47 -070059 * Create a default SystemdWithStatusFile object that uses systemd to
60 * trigger the process.
Patrick Venture26a17262019-05-20 11:03:35 -070061 *
62 * @param[in] bus - an sdbusplus handler for a bus to use.
63 * @param[in] path - the path to check for verification status.
Patrick Ventureee614ec2019-08-05 12:08:44 -070064 * @param[in] service - the systemd service to start to trigger
Patrick Venture26a17262019-05-20 11:03:35 -070065 * verification.
Patrick Ventureee614ec2019-08-05 12:08:44 -070066 * @param[in] mode - the job-mode when starting the systemd Unit.
Patrick Venture26a17262019-05-20 11:03:35 -070067 */
Patrick Venture1d66fe62019-06-03 14:57:27 -070068 static std::unique_ptr<TriggerableActionInterface>
Patrick Williams40fbb0c2022-07-22 19:26:57 -050069 CreateSystemdWithStatusFile(sdbusplus::bus_t&& bus,
Patrick Venturecf066ac2019-08-06 09:03:47 -070070 const std::string& path,
71 const std::string& service,
72 const std::string& mode);
Patrick Venture26a17262019-05-20 11:03:35 -070073
Patrick Williams40fbb0c2022-07-22 19:26:57 -050074 SystemdWithStatusFile(sdbusplus::bus_t&& bus, const std::string& path,
Patrick Venture29af1e32019-08-05 13:42:28 -070075 const std::string& service, const std::string& mode) :
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080076 SystemdNoFile(std::move(bus), service, mode),
77 checkPath(path)
Patrick Venture9b37b092020-05-28 20:58:57 -070078 {}
Patrick Venture26a17262019-05-20 11:03:35 -070079
William A. Kennington III93f3c552020-04-07 18:23:53 -070080 bool trigger() override;
Patrick Ventureda66fd82019-06-03 11:11:24 -070081 ActionStatus status() override;
Patrick Venture26a17262019-05-20 11:03:35 -070082
83 private:
Patrick Venture26a17262019-05-20 11:03:35 -070084 const std::string checkPath;
Patrick Venturee0216d22019-08-21 10:17:39 -070085};
86
Patrick Venture1d5a31c2019-05-20 11:38:22 -070087} // namespace ipmi_flash