mirror of
https://github.com/chenx-dust/EZ4Connect.git
synced 2026-09-20 02:13:32 +08:00
55 lines
1.1 KiB
C++
55 lines
1.1 KiB
C++
#ifndef CONNECTIONSESSIONSTATE_H
|
|
#define CONNECTIONSESSIONSTATE_H
|
|
|
|
#include "connectionerror.h"
|
|
|
|
enum class ConnectionState
|
|
{
|
|
Disconnected,
|
|
Starting,
|
|
Running,
|
|
Stopping,
|
|
Reconnecting,
|
|
Interrupted,
|
|
Failed,
|
|
};
|
|
|
|
struct ReconnectPolicy
|
|
{
|
|
bool enabled = false;
|
|
int delayMs = 1000;
|
|
};
|
|
|
|
enum class ProcessFinishAction
|
|
{
|
|
Complete,
|
|
Reconnect,
|
|
};
|
|
|
|
class ConnectionSessionState
|
|
{
|
|
public:
|
|
ConnectionState state() const;
|
|
ZJU_ERROR error() const;
|
|
bool isActive() const;
|
|
bool wantsConnection() const;
|
|
int reconnectDelayMs() const;
|
|
|
|
bool requestStart(const ReconnectPolicy &policy);
|
|
void connectionEstablished();
|
|
void recordError(ZJU_ERROR error);
|
|
bool requestStop();
|
|
ProcessFinishAction processFinished();
|
|
void beginReconnect();
|
|
|
|
private:
|
|
static bool isReconnectable(ZJU_ERROR error);
|
|
|
|
ConnectionState currentState = ConnectionState::Disconnected;
|
|
ZJU_ERROR currentError = ZJU_ERROR::NONE;
|
|
ReconnectPolicy reconnectPolicy;
|
|
bool desiredConnected = false;
|
|
};
|
|
|
|
#endif // CONNECTIONSESSIONSTATE_H
|