Skip to content

Commit

Permalink
allow device event delegates to be notified of controller expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoward committed Jan 27, 2025
1 parent 7248064 commit fa367d3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions Examples/OCADevice/DeviceApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Android

final class DeviceEventDelegate: OcaDeviceEventDelegate {
public func onEvent(_ event: SwiftOCA.OcaEvent, parameters: Data) async {}
public func onControllerExpiry(_ controller: OcaController) {}
}

@main
Expand Down
4 changes: 3 additions & 1 deletion Sources/SwiftOCADevice/OCA/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public protocol OcaDeviceEventDelegate: AnyObject, Sendable {
_ event: OcaEvent,
parameters: Data
) async

func onControllerExpiry(_ controller: OcaController)
}

@globalActor
Expand All @@ -40,7 +42,7 @@ public actor OcaDevice {
var endpoints = [OcaDeviceEndpoint]()
var logger = Logger(label: "com.padl.SwiftOCADevice")

private weak var eventDelegate: OcaDeviceEventDelegate?
weak var eventDelegate: OcaDeviceEventDelegate?

public func allocateObjectNumber() -> OcaONo {
repeat {
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftOCADevice/OCP.1/Ocp1ControllerInternal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ extension Ocp1ControllerInternal {
let now = ContinuousClock.now
if connectionIsStale(now) {
try? await onConnectionBecomingStale()
await endpoint?.device.eventDelegate?.onControllerExpiry(self)
await endpoint?.remove(controller: self as! Endpoint.ControllerType)
endpoint?.logger.info("expired controller", controller: self)
break
Expand Down

0 comments on commit fa367d3

Please sign in to comment.