Skip to content

Commit

Permalink
add tracing for subscription addition/removal
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoward committed Dec 2, 2024
1 parent 49da3ec commit 8e52713
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Sources/SwiftOCA/OCP.1/Ocp1Connection+Subscribe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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)")
}
}

Expand Down

0 comments on commit 8e52713

Please sign in to comment.