blob: 590b339a66246f46ab8e5d9e1be091477ec645a4 [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>
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -08007#include <sdbusplus/bus/match.hpp>
Patrick Venture26a17262019-05-20 11:03:35 -07008#include <string>
9
Patrick Venture1d5a31c2019-05-20 11:38:22 -070010namespace ipmi_flash
Patrick Venture26a17262019-05-20 11:03:35 -070011{
12
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080013class SystemdNoFile : public TriggerableActionInterface
14{
15 public:
16 static std::unique_ptr<TriggerableActionInterface>
17 CreateSystemdNoFile(sdbusplus::bus::bus&& bus,
18 const std::string& service,
19 const std::string& mode);
20
21 SystemdNoFile(sdbusplus::bus::bus&& bus, const std::string& service,
22 const std::string& mode) :
23 bus(std::move(bus)),
24 triggerService(service), mode(mode)
25 {
26 }
27
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 Venture26a17262019-05-20 11:03:35 -070079 {
80 }
81
William A. Kennington III93f3c552020-04-07 18:23:53 -070082 bool trigger() override;
Patrick Ventureda66fd82019-06-03 11:11:24 -070083 ActionStatus status() override;
Patrick Venture26a17262019-05-20 11:03:35 -070084
85 private:
Patrick Venture26a17262019-05-20 11:03:35 -070086 const std::string checkPath;
Patrick Venturee0216d22019-08-21 10:17:39 -070087};
88
Patrick Venture1d5a31c2019-05-20 11:38:22 -070089} // namespace ipmi_flash