blob: 9b334603deee9ae35bd0902a1361ac8fbb2b7e2d [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>
18 CreateSystemdNoFile(sdbusplus::bus::bus&& bus,
19 const std::string& service,
20 const std::string& mode);
21
22 SystemdNoFile(sdbusplus::bus::bus&& bus, const std::string& service,
23 const std::string& mode) :
24 bus(std::move(bus)),
25 triggerService(service), mode(mode)
Patrick Venture9b37b092020-05-28 20:58:57 -070026 {}
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080027
28 SystemdNoFile(const SystemdNoFile&) = delete;
29 SystemdNoFile& operator=(const SystemdNoFile&) = delete;
30 // sdbusplus match requires us to be pinned
31 SystemdNoFile(SystemdNoFile&&) = delete;
32 SystemdNoFile& operator=(SystemdNoFile&&) = delete;
33
34 bool trigger() override;
35 void abort() override;
36 ActionStatus status() override;
37
38 const std::string& getMode() const;
39
40 private:
41 sdbusplus::bus::bus bus;
42 const std::string triggerService;
43 const std::string mode;
44
45 std::optional<sdbusplus::bus::match::match> jobMonitor;
46 std::optional<std::string> job;
47 ActionStatus currentStatus = ActionStatus::unknown;
48
49 void match(sdbusplus::message::message& m);
50};
51
Patrick Venture26a17262019-05-20 11:03:35 -070052/**
Patrick Venturecf066ac2019-08-06 09:03:47 -070053 * Representation of what is used for triggering an action with systemd and
54 * checking the result by reading a file.
Patrick Venture26a17262019-05-20 11:03:35 -070055 */
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080056class SystemdWithStatusFile : public SystemdNoFile
Patrick Venture26a17262019-05-20 11:03:35 -070057{
58 public:
59 /**
Patrick Venturecf066ac2019-08-06 09:03:47 -070060 * Create a default SystemdWithStatusFile object that uses systemd to
61 * trigger the process.
Patrick Venture26a17262019-05-20 11:03:35 -070062 *
63 * @param[in] bus - an sdbusplus handler for a bus to use.
64 * @param[in] path - the path to check for verification status.
Patrick Ventureee614ec2019-08-05 12:08:44 -070065 * @param[in] service - the systemd service to start to trigger
Patrick Venture26a17262019-05-20 11:03:35 -070066 * verification.
Patrick Ventureee614ec2019-08-05 12:08:44 -070067 * @param[in] mode - the job-mode when starting the systemd Unit.
Patrick Venture26a17262019-05-20 11:03:35 -070068 */
Patrick Venture1d66fe62019-06-03 14:57:27 -070069 static std::unique_ptr<TriggerableActionInterface>
Patrick Venturecf066ac2019-08-06 09:03:47 -070070 CreateSystemdWithStatusFile(sdbusplus::bus::bus&& bus,
71 const std::string& path,
72 const std::string& service,
73 const std::string& mode);
Patrick Venture26a17262019-05-20 11:03:35 -070074
Patrick Venture29af1e32019-08-05 13:42:28 -070075 SystemdWithStatusFile(sdbusplus::bus::bus&& bus, const std::string& path,
76 const std::string& service, const std::string& mode) :
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080077 SystemdNoFile(std::move(bus), service, mode),
78 checkPath(path)
Patrick Venture9b37b092020-05-28 20:58:57 -070079 {}
Patrick Venture26a17262019-05-20 11:03:35 -070080
William A. Kennington III93f3c552020-04-07 18:23:53 -070081 bool trigger() override;
Patrick Ventureda66fd82019-06-03 11:11:24 -070082 ActionStatus status() override;
Patrick Venture26a17262019-05-20 11:03:35 -070083
84 private:
Patrick Venture26a17262019-05-20 11:03:35 -070085 const std::string checkPath;
Patrick Venturee0216d22019-08-21 10:17:39 -070086};
87
Patrick Venture1d5a31c2019-05-20 11:38:22 -070088} // namespace ipmi_flash