65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
// 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
|