64 lines
1.7 KiB
Swift
64 lines
1.7 KiB
Swift
//
|
|
// VPNConnectionState.swift
|
|
// PrivadoVPN
|
|
//
|
|
// Created by Juraldinio on 12/15/20.
|
|
// Copyright © 2020 Privado LLC. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
/// VPN connection state.
|
|
enum VPNConnectionState: CustomStringConvertible {
|
|
|
|
/// Initializing.
|
|
case initialize
|
|
/// Disconnected.
|
|
case disconnected
|
|
/// Prepare vpn connection.
|
|
case prepare
|
|
/// Connection.
|
|
case connecting
|
|
/// Connected.
|
|
case connected
|
|
/// Disconnecting. Initialized manual or by system.
|
|
case disconnecting(Bool)
|
|
/// Error occured.
|
|
case error(VPNError)
|
|
/// Reconnect
|
|
indirect case reconnect(VPNConnectionState)
|
|
|
|
// MARK: - CustomStringConvertible
|
|
|
|
var description: String {
|
|
switch self {
|
|
case .initialize: return "initialize"
|
|
case .prepare: return "prepare"
|
|
case .disconnected: return "disconnected"
|
|
case .connecting: return "connecting"
|
|
case .connected: return "connected"
|
|
case .disconnecting: return "disconnecting"
|
|
case let .error(error): return "error(\(error))"
|
|
case let .reconnect(state): return "reconnect(\(state))"
|
|
}
|
|
}
|
|
}
|
|
|
|
extension VPNConnectionState: Equatable {
|
|
static func == (lhs: VPNConnectionState, rhs: VPNConnectionState) -> Bool {
|
|
switch (lhs, rhs) {
|
|
case (initialize, initialize),
|
|
(prepare, prepare),
|
|
(disconnected, disconnected),
|
|
(connecting, connecting),
|
|
(connected, connected),
|
|
(disconnecting, disconnecting):
|
|
return true
|
|
case let (error(errorL), error(errorR)):
|
|
return errorL == errorR
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
}
|