blob: e3342d20c0159d67bbec8945b943776c76c6a777 [file] [log] [blame]
Patrick Venture3ecb3502019-05-17 11:03:51 -07001#pragma once
2
William A. Kennington III4175b4c2020-12-23 22:45:18 -08003#include <function2/function2.hpp>
4
Patrick Venture3ecb3502019-05-17 11:03:51 -07005#include <cstdint>
6
Patrick Venture1d5a31c2019-05-20 11:38:22 -07007namespace ipmi_flash
Patrick Venture3ecb3502019-05-17 11:03:51 -07008{
9
Patrick Ventureda66fd82019-06-03 11:11:24 -070010/** The status of the update mechanism or the verification mechanism */
11enum class ActionStatus : std::uint8_t
Patrick Venture8e801e12019-05-20 13:42:45 -070012{
13 running = 0,
14 success = 1,
15 failed = 2,
16 unknown = 3,
17};
18
Patrick Venture1d66fe62019-06-03 14:57:27 -070019class TriggerableActionInterface
20{
21 public:
William A. Kennington III4175b4c2020-12-23 22:45:18 -080022 using Callback = fu2::unique_function<void(TriggerableActionInterface&)>;
23
Patrick Venture1d66fe62019-06-03 14:57:27 -070024 virtual ~TriggerableActionInterface() = default;
25
26 /**
27 * Trigger action.
28 *
29 * @return true if successfully started, false otherwise.
30 */
31 virtual bool trigger() = 0;
32
33 /** Abort the action if possible. */
34 virtual void abort() = 0;
35
36 /** Check the current state of the action. */
37 virtual ActionStatus status() = 0;
William A. Kennington III4175b4c2020-12-23 22:45:18 -080038
39 /** Sets the callback that is executed on completion of the trigger. */
40 void setCallback(Callback&& cb)
41 {
42 this->cb = std::move(cb);
43 }
44
45 protected:
46 Callback cb;
Patrick Venture1d66fe62019-06-03 14:57:27 -070047};
48
Patrick Venture8e801e12019-05-20 13:42:45 -070049} // namespace ipmi_flash