diff options
author | Krzysztof Grobelny <krzysztof.grobelny@intel.com> | 2020-07-03 13:35:09 +0300 |
---|---|---|
committer | Karol Wachowski <karol.wachowski@intel.com> | 2020-07-17 09:48:46 +0300 |
commit | d113e4284674d112aff0744fe734581bd3fc4abf (patch) | |
tree | 727b644c30a050f39d5fdd21452f40d70cf1df1a /src/state/deactivating_state.hpp | |
parent | 1d453d987d5ece338aad08cee315fbacf179e692 (diff) | |
download | virtual-media-d113e4284674d112aff0744fe734581bd3fc4abf.tar.xz |
Fixing multiple problems with state machine in virtual media
- Previously machine did not handle AnyEvent correctly,
implementation in BaseState was always run
- Changing from ActiveState to ReadyState was bugged,
previously only one of event SubprocessStopped or UdevNotification
caused state change when it is required to wait for both
- Introduced longer timer when waiting for ReadyState during Eject and
ActiveState during Inject, because ndbkit can timeout during Eject and
it is required to complete before next inject can success.
- Added event notification when process is terminated
- Added resourcess classes to handle deletion and notifications
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
Signed-off-by: Karol Wachowski <karol.wachowski@intel.com>
Change-Id: Ie914e650c2f15bd73cdc87582ea77a94997a3472
Signed-off-by: Karol Wachowski <karol.wachowski@intel.com>
Diffstat (limited to 'src/state/deactivating_state.hpp')
-rw-r--r-- | src/state/deactivating_state.hpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/state/deactivating_state.hpp b/src/state/deactivating_state.hpp new file mode 100644 index 0000000..7f3010a --- /dev/null +++ b/src/state/deactivating_state.hpp @@ -0,0 +1,83 @@ +#pragma once + +#include "basic_state.hpp" +#include "ready_state.hpp" + +struct DeactivatingState : public BasicStateT<DeactivatingState> +{ + static std::string_view stateName() + { + return "DeactivatingState"; + } + + template <class EventT> + DeactivatingState(interfaces::MountPointStateMachine& machine, + std::unique_ptr<resource::Process> process, + std::unique_ptr<resource::Gadget> gadget, EventT event) : + BasicStateT(machine), + process(std::move(process)), gadget(std::move(gadget)) + { + handleEvent(std::move(event)); + } + + DeactivatingState(interfaces::MountPointStateMachine& machine, + std::unique_ptr<resource::Process> process, + std::unique_ptr<resource::Gadget> gadget) : + BasicStateT(machine), + process(std::move(process)), gadget(std::move(gadget)) + { + } + + std::unique_ptr<BasicState> onEnter() override + { + gadget = nullptr; + process = nullptr; + + return nullptr; + } + + std::unique_ptr<BasicState> handleEvent(UdevStateChangeEvent event) + { + udevStateChangeEvent = std::move(event); + return evaluate(); + } + + std::unique_ptr<BasicState> handleEvent(SubprocessStoppedEvent event) + { + subprocessStoppedEvent = std::move(event); + return evaluate(); + } + + template <class AnyEvent> + std::unique_ptr<BasicState> handleEvent(AnyEvent event) + { + LogMsg(Logger::Error, "Invalid event: ", event.eventName); + return nullptr; + } + + private: + std::unique_ptr<BasicState> evaluate() + { + if (udevStateChangeEvent && subprocessStoppedEvent) + { + if (udevStateChangeEvent->devState == StateChange::removed) + { + LogMsg(Logger::Debug, machine.getName(), + " udev StateChange::removed"); + } + else + { + LogMsg(Logger::Error, machine.getName(), " udev StateChange::", + static_cast<std::underlying_type_t<StateChange>>( + udevStateChangeEvent->devState)); + } + return std::make_unique<ReadyState>(machine); + } + return nullptr; + } + + std::unique_ptr<resource::Process> process; + std::unique_ptr<resource::Gadget> gadget; + std::optional<UdevStateChangeEvent> udevStateChangeEvent; + std::optional<SubprocessStoppedEvent> subprocessStoppedEvent; +}; |