37 lines
812 B
Swift
37 lines
812 B
Swift
//
|
|
// SDLSuperServiceProxy.swift
|
|
// punchnet
|
|
//
|
|
// Created by 安礼成 on 2026/5/21.
|
|
//
|
|
import Foundation
|
|
|
|
actor SDLSuperServiceProxy {
|
|
private var superService: SDLSuperService?
|
|
private var generation: UInt64 = 0
|
|
|
|
func replace(_ superService: SDLSuperService?) async {
|
|
self.generation &+= 1
|
|
|
|
let oldSuperService = self.superService
|
|
self.superService = superService
|
|
|
|
if oldSuperService !== superService {
|
|
await oldSuperService?.stop()
|
|
}
|
|
}
|
|
|
|
func stop() async {
|
|
self.generation &+= 1
|
|
|
|
let superService = self.superService
|
|
self.superService = nil
|
|
|
|
await superService?.stop()
|
|
}
|
|
|
|
func send(type: SDLPacketType, data: Data) async {
|
|
await self.superService?.send(type: type, data: data)
|
|
}
|
|
}
|