1 #pragma once 2 3 #include <cstdint> 4 #include <functional> 5 6 namespace ipmi_flash 7 { 8 9 /** The status of the update mechanism or the verification mechanism */ 10 enum class ActionStatus : std::uint8_t 11 { 12 running = 0, 13 success = 1, 14 failed = 2, 15 unknown = 3, 16 }; 17 18 class TriggerableActionInterface 19 { 20 public: 21 using Callback = std::move_only_function<void(TriggerableActionInterface&)>; 22 23 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; 37 38 /** Sets the callback that is executed on completion of the trigger. */ setCallback(Callback && cb)39 void setCallback(Callback&& cb) 40 { 41 this->cb = std::move(cb); 42 } 43 44 protected: 45 Callback cb; 46 }; 47 48 } // namespace ipmi_flash 49