From 8e527138139306efdb98d3d9a4d640d21ece4c49 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Tue, 3 Dec 2024 08:56:57 +1100 Subject: [PATCH] add tracing for subscription addition/removal --- .../SwiftOCA/OCP.1/Ocp1Connection+Subscribe.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftOCA/OCP.1/Ocp1Connection+Subscribe.swift b/Sources/SwiftOCA/OCP.1/Ocp1Connection+Subscribe.swift index 4e6a9e5f..6ca21425 100644 --- a/Sources/SwiftOCA/OCP.1/Ocp1Connection+Subscribe.swift +++ b/Sources/SwiftOCA/OCP.1/Ocp1Connection+Subscribe.swift @@ -20,7 +20,7 @@ private let subscriber = OcaMethod(oNo: 1055, methodID: OcaMethodID("1.1")) public extension Ocp1Connection { /// a token that can be used by the client to unsubscribe - final class SubscriptionCancellable: Hashable, Sendable { + final class SubscriptionCancellable: Hashable, Sendable, CustomStringConvertible { public static func == ( lhs: Ocp1Connection.SubscriptionCancellable, rhs: Ocp1Connection.SubscriptionCancellable @@ -54,6 +54,14 @@ public extension Ocp1Connection { self.event = event self.callback = callback } + + public var description: String { + if let label { + "event: \(event), label: \(label)" + } else { + "event: \(event)" + } + } } func isSubscribed(event: OcaEvent) -> Bool { @@ -89,7 +97,9 @@ public extension Ocp1Connection { notificationDeliveryMode: .normal, destinationInformation: OcaNetworkAddress() ) + logger.trace("addSubscription: added new OCA subscription for \(event)") } + logger.trace("addSubscription: added \(cancellable) to subscription set") return cancellable } @@ -102,12 +112,14 @@ public extension Ocp1Connection { } eventSubscriptions.subscriptions.remove(cancellable) + logger.trace("removeSubscription: removed \(cancellable) from subscription set") if eventSubscriptions.subscriptions.isEmpty { subscriptions[cancellable.event] = nil try await subscriptionManager.removeSubscription( event: cancellable.event, subscriber: subscriber ) + logger.trace("removeSubscription: removed OCA subscription for \(cancellable.event)") } }