vdi-cloud/terminal/kiosk-shell/src/state_machine.h
宋一鸣 162dcc1e02 初始化:导入 VDI 云终端代码与会话基础能力
变更详情:init: VDI 云终端代码(kiosk-shell 登录/桌面列表/Moonlight/RDP/看门狗)
2026-10-28 20:52:20 +08:00

65 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// kiosk-shell 状态机
//
// 对应《VDI 云桌面软件开发方案》3.2 节:
// 状态机:BOOT -> CONFIG(无配置)-> CONNECTING -> SESSION(嵌入 freerdp 窗口)
// -> RECONNECT -> ERROR
//
// 状态转换规则:
// BOOT 进程启动,读取本地配置
// CONFIG 无可用配置或用户停留在登录页,等待输入
// CONNECTING 正在建立 RDP 连接
// SESSION 远程会话进行中
// RECONNECT 会话意外断开,等待重连
// ERROR 不可恢复错误,提示后回到 CONFIG
#ifndef KIOSK_SHELL_STATE_MACHINE_H
#define KIOSK_SHELL_STATE_MACHINE_H
#include <QString>
#include <functional>
#include <string>
namespace vdi {
enum class State {
kBoot, // 启动中
kConfig, // 首配 / 登录页
kAuthenticating, // 正在认证
kDesktopList, // 桌面列表(登录成功后)
kConnecting, // 连接中
kSession, // 会话中
kReconnect, // 断线等待重连
kError, // 错误
};
const char* stateToString(State s);
class StateMachine {
public:
// 状态说明使用 QString,便于直接显示在状态条上
using StateListener = std::function<void(State from, State to, const QString& detail)>;
explicit StateMachine(StateListener listener = nullptr);
State current() const { return current_; }
bool isIn(State s) const { return current_ == s; }
// 尝试切换到目标状态;非法转换会被拒绝并返回 false
bool transitionTo(State next, const QString& detail = QString());
// 当前状态下允许执行的动作
bool canConnect() const;
bool canDisconnect() const;
bool canRetry() const;
private:
static bool isLegalTransition(State from, State to);
State current_ = State::kBoot;
StateListener listener_;
};
} // namespace vdi
#endif // KIOSK_SHELL_STATE_MACHINE_H