1 #pragma once 2 3 #include <function2/function2.hpp> 4 5 #include <cstdint> 6 7 namespace ipmi_flash 8 { 9 10 /** The status of the update mechanism or the verification mechanism */ 11 enum class ActionStatus : std::uint8_t 12 { 13 running = 0, 14 success = 1, 15 failed = 2, 16 unknown = 3, 17 }; 18 19 class TriggerableActionInterface 20 { 21 public: 22 using Callback = fu2::unique_function<void(TriggerableActionInterface&)>; 23 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; 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; 47 }; 48 49 } // namespace ipmi_flash 50