blob: 821d09cc53df1234aad8b72cd378e4569d1f7fa0 [file] [log] [blame]
Patrick Venture3ecb3502019-05-17 11:03:51 -07001#pragma once
2
3#include <cstdint>
Patrick Williams41dedad2023-07-13 18:25:19 -05004#include <functional>
Patrick Venture3ecb3502019-05-17 11:03:51 -07005
Patrick Venture1d5a31c2019-05-20 11:38:22 -07006namespace ipmi_flash
Patrick Venture3ecb3502019-05-17 11:03:51 -07007{
8
Patrick Ventureda66fd82019-06-03 11:11:24 -07009/** The status of the update mechanism or the verification mechanism */
10enum class ActionStatus : std::uint8_t
Patrick Venture8e801e12019-05-20 13:42:45 -070011{
12 running = 0,
13 success = 1,
14 failed = 2,
15 unknown = 3,
16};
17
Patrick Venture1d66fe62019-06-03 14:57:27 -070018class TriggerableActionInterface
19{
20 public:
Patrick Williams41dedad2023-07-13 18:25:19 -050021 using Callback = std::move_only_function<void(TriggerableActionInterface&)>;
William A. Kennington III4175b4c2020-12-23 22:45:18 -080022
Patrick Venture1d66fe62019-06-03 14:57:27 -070023 virtual ~TriggerableActionInterface() = default;
24
25 /**
26 * Trigger action.
27 *
28 * @return true if successfully started, false otherwise.
29 */
30 virtual bool trigger() = 0;
31
32 /** Abort the action if possible. */
33 virtual void abort() = 0;
34
35 /** Check the current state of the action. */
36 virtual ActionStatus status() = 0;
William A. Kennington III4175b4c2020-12-23 22:45:18 -080037
38 /** Sets the callback that is executed on completion of the trigger. */
39 void setCallback(Callback&& cb)
40 {
41 this->cb = std::move(cb);
42 }
43
44 protected:
45 Callback cb;
Patrick Venture1d66fe62019-06-03 14:57:27 -070046};
47
Patrick Venture8e801e12019-05-20 13:42:45 -070048} // namespace ipmi_flash