#pragma once #include "basic_state.hpp" #include "ready_state.hpp" struct DeactivatingState : public BasicStateT { static std::string_view stateName() { return "DeactivatingState"; } template DeactivatingState(interfaces::MountPointStateMachine& machine, std::unique_ptr process, std::unique_ptr gadget, EventT event) : BasicStateT(machine), process(std::move(process)), gadget(std::move(gadget)) { handleEvent(std::move(event)); } DeactivatingState(interfaces::MountPointStateMachine& machine, std::unique_ptr process, std::unique_ptr gadget) : BasicStateT(machine), process(std::move(process)), gadget(std::move(gadget)) { } std::unique_ptr onEnter() override { gadget = nullptr; process = nullptr; return nullptr; } std::unique_ptr handleEvent(UdevStateChangeEvent event) { udevStateChangeEvent = std::move(event); return evaluate(); } std::unique_ptr handleEvent(SubprocessStoppedEvent event) { subprocessStoppedEvent = std::move(event); return evaluate(); } template [[noreturn]] std::unique_ptr handleEvent(AnyEvent event) { LogMsg(Logger::Error, "Invalid event: ", event.eventName); throw sdbusplus::exception::SdBusError(EBUSY, "Resource is busy"); } private: std::unique_ptr evaluate() { if (udevStateChangeEvent && subprocessStoppedEvent) { if (udevStateChangeEvent->devState == StateChange::removed) { LogMsg(Logger::Info, machine.getName(), " udev StateChange::removed"); } else { LogMsg(Logger::Error, machine.getName(), " udev StateChange::", static_cast>( udevStateChangeEvent->devState)); } return std::make_unique(machine); } return nullptr; } std::unique_ptr process; std::unique_ptr gadget; std::optional udevStateChangeEvent; std::optional subprocessStoppedEvent; };