bmc: add preparation step before data is received
Add a preparation systemd trigger event before data is received. On
systems under memory pressure, this'll trigger a service that can do
things like flush caches.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I175177f4a91b58d9f163098572a9d2614002b718
diff --git a/prepare_systemd.hpp b/prepare_systemd.hpp
new file mode 100644
index 0000000..af8e065
--- /dev/null
+++ b/prepare_systemd.hpp
@@ -0,0 +1,40 @@
+#pragma once
+
+#include "status.hpp"
+
+#include <memory>
+#include <sdbusplus/bus.hpp>
+#include <string>
+
+namespace ipmi_flash
+{
+
+class SystemdPreparation : public TriggerableActionInterface
+{
+ public:
+ static std::unique_ptr<TriggerableActionInterface>
+ CreatePreparation(sdbusplus::bus::bus&& bus,
+ const std::string& service);
+
+ SystemdPreparation(sdbusplus::bus::bus&& bus, const std::string& service) :
+ bus(std::move(bus)), triggerService(service)
+ {
+ }
+
+ ~SystemdPreparation() = default;
+ SystemdPreparation(const SystemdPreparation&) = delete;
+ SystemdPreparation& operator=(const SystemdPreparation&) = delete;
+ SystemdPreparation(SystemdPreparation&&) = default;
+ SystemdPreparation& operator=(SystemdPreparation&&) = default;
+
+ bool trigger() override;
+ void abort() override;
+ ActionStatus status() override;
+
+ private:
+ sdbusplus::bus::bus bus;
+ const std::string triggerService;
+ ActionStatus state = ActionStatus::unknown;
+};
+
+} // namespace ipmi_flash