blob: 48e51770879a4a62442ab67aebb5a3a4b365dc50 [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) :
Patrick Williams42a44c22024-08-16 15:21:32 -040023 bus(std::move(bus)), triggerService(service), mode(mode)
Patrick Venture9b37b092020-05-28 20:58:57 -070024 {}
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080025
26 SystemdNoFile(const SystemdNoFile&) = delete;
27 SystemdNoFile& operator=(const SystemdNoFile&) = delete;
28 // sdbusplus match requires us to be pinned
29 SystemdNoFile(SystemdNoFile&&) = delete;
30 SystemdNoFile& operator=(SystemdNoFile&&) = delete;
31
32 bool trigger() override;
33 void abort() override;
34 ActionStatus status() override;
35
36 const std::string& getMode() const;
37
38 private:
Patrick Williams40fbb0c2022-07-22 19:26:57 -050039 sdbusplus::bus_t bus;
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080040 const std::string triggerService;
41 const std::string mode;
42
Patrick Williams40fbb0c2022-07-22 19:26:57 -050043 std::optional<sdbusplus::bus::match_t> jobMonitor;
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080044 std::optional<std::string> job;
45 ActionStatus currentStatus = ActionStatus::unknown;
46
Patrick Williams40fbb0c2022-07-22 19:26:57 -050047 void match(sdbusplus::message_t& m);
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080048};
49
Patrick Venture26a17262019-05-20 11:03:35 -070050/**
Patrick Venturecf066ac2019-08-06 09:03:47 -070051 * Representation of what is used for triggering an action with systemd and
52 * checking the result by reading a file.
Patrick Venture26a17262019-05-20 11:03:35 -070053 */
William A. Kennington IIIb22ebbf2019-11-19 17:03:48 -080054class SystemdWithStatusFile : public SystemdNoFile
Patrick Venture26a17262019-05-20 11:03:35 -070055{
56 public:
57 /**
Patrick Venturecf066ac2019-08-06 09:03:47 -070058 * Create a default SystemdWithStatusFile object that uses systemd to
59 * trigger the process.
Patrick Venture26a17262019-05-20 11:03:35 -070060 *
61 * @param[in] bus - an sdbusplus handler for a bus to use.
62 * @param[in] path - the path to check for verification status.
Patrick Ventureee614ec2019-08-05 12:08:44 -070063 * @param[in] service - the systemd service to start to trigger
Patrick Venture26a17262019-05-20 11:03:35 -070064 * verification.
Patrick Ventureee614ec2019-08-05 12:08:44 -070065 * @param[in] mode - the job-mode when starting the systemd Unit.
Patrick Venture26a17262019-05-20 11:03:35 -070066 */
Patrick Venture1d66fe62019-06-03 14:57:27 -070067 static std::unique_ptr<TriggerableActionInterface>
Patrick Williams42a44c22024-08-16 15:21:32 -040068 CreateSystemdWithStatusFile(
69 sdbusplus::bus_t&& bus, const std::string& path,
70 const std::string& service, const std::string& mode);
Patrick Venture26a17262019-05-20 11:03:35 -070071
Patrick Williams40fbb0c2022-07-22 19:26:57 -050072 SystemdWithStatusFile(sdbusplus::bus_t&& bus, const std::string& path,
Patrick Venture29af1e32019-08-05 13:42:28 -070073 const std::string& service, const std::string& mode) :
Patrick Williams42a44c22024-08-16 15:21:32 -040074 SystemdNoFile(std::move(bus), service, mode), checkPath(path)
Patrick Venture9b37b092020-05-28 20:58:57 -070075 {}
Patrick Venture26a17262019-05-20 11:03:35 -070076
William A. Kennington III93f3c552020-04-07 18:23:53 -070077 bool trigger() override;
Patrick Ventureda66fd82019-06-03 11:11:24 -070078 ActionStatus status() override;
Patrick Venture26a17262019-05-20 11:03:35 -070079
80 private:
Patrick Venture26a17262019-05-20 11:03:35 -070081 const std::string checkPath;
Patrick Venturee0216d22019-08-21 10:17:39 -070082};
83
Patrick Venture1d5a31c2019-05-20 11:38:22 -070084} // namespace ipmi_flash