Patrick Venture | 3ecb350 | 2019-05-17 11:03:51 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
William A. Kennington III | 4175b4c | 2020-12-23 22:45:18 -0800 | [diff] [blame] | 3 | #include <function2/function2.hpp> |
| 4 | |
Patrick Venture | 3ecb350 | 2019-05-17 11:03:51 -0700 | [diff] [blame] | 5 | #include <cstdint> |
| 6 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 7 | namespace ipmi_flash |
Patrick Venture | 3ecb350 | 2019-05-17 11:03:51 -0700 | [diff] [blame] | 8 | { |
| 9 | |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 10 | /** The status of the update mechanism or the verification mechanism */ |
| 11 | enum class ActionStatus : std::uint8_t |
Patrick Venture | 8e801e1 | 2019-05-20 13:42:45 -0700 | [diff] [blame] | 12 | { |
| 13 | running = 0, |
| 14 | success = 1, |
| 15 | failed = 2, |
| 16 | unknown = 3, |
| 17 | }; |
| 18 | |
Patrick Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 19 | class TriggerableActionInterface |
| 20 | { |
| 21 | public: |
William A. Kennington III | 4175b4c | 2020-12-23 22:45:18 -0800 | [diff] [blame] | 22 | using Callback = fu2::unique_function<void(TriggerableActionInterface&)>; |
| 23 | |
Patrick Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 24 | 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 III | 4175b4c | 2020-12-23 22:45:18 -0800 | [diff] [blame] | 38 | |
| 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 Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
Patrick Venture | 8e801e1 | 2019-05-20 13:42:45 -0700 | [diff] [blame] | 49 | } // namespace ipmi_flash |