#pragma once #include "activating_state.hpp" #include "basic_state.hpp" #include "logger.hpp" #include #include #include #include #include struct ReadyState : public BasicStateT { static std::string_view stateName() { return "ReadyState"; } struct Error { std::errc code; std::string message; }; ReadyState(interfaces::MountPointStateMachine& machine) : BasicStateT(machine) { machine.notify(); }; ReadyState(interfaces::MountPointStateMachine& machine, const std::errc& ec, const std::string& message) : BasicStateT(machine), error{{ec, message}} { LogMsg(Logger::Error, machine.getName(), " Errno = ", static_cast(ec), " : ", message); machine.notify(std::make_error_code(ec)); } std::unique_ptr onEnter() override { // Cleanup after previously mounted device LogMsg(Logger::Debug, "exitCode: ", machine.getExitCode()); machine.getTarget() = std::nullopt; machine.getConfig().remainingInactivityTimeout = std::chrono::seconds(0); return nullptr; } std::unique_ptr handleEvent(MountEvent event) { machine.notificationStart(); if (event.target) { machine.getTarget() = std::move(event.target); } return std::make_unique(machine); } [[noreturn]] std::unique_ptr handleEvent(UnmountEvent event) { LogMsg(Logger::Error, "InvalidĀ event: ", event.eventName); throw sdbusplus::exception::SdBusError( EPERM, "Operation not permitted in ready state"); } template std::unique_ptr handleEvent(AnyEvent event) { LogMsg(Logger::Error, "Invalid event: ", event.eventName); return nullptr; } std::optional error; };