Skip to content

Commit 2e32f4e

Browse files
committed
make refreshing subscriptions on reconnect optional
1 parent 9e330ae commit 2e32f4e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Sources/SwiftOCA/OCP.1/Ocp1Connection+Connect.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ extension Ocp1Connection {
136136
}
137137
}
138138

139+
private func _refreshSubscriptionsWithPolicy() async {
140+
if options.flags.contains(.refreshSubscriptionsOnReconnection) {
141+
logger.trace("refreshing subscriptions")
142+
await refreshSubscriptions()
143+
await refreshCachedObjectProperties()
144+
}
145+
}
146+
139147
func updateConnectionState(_ connectionState: Ocp1ConnectionState) {
140148
logger.trace("_updateConnectionState: \(_connectionState.value) => \(connectionState)")
141149
_connectionState.send(connectionState)
@@ -158,8 +166,7 @@ extension Ocp1Connection {
158166
objectWillChange.send()
159167
#endif
160168

161-
await refreshSubscriptions()
162-
await refreshCachedObjectProperties()
169+
await _refreshSubscriptionsWithPolicy()
163170
await _refreshDeviceTreeWithPolicy()
164171

165172
logger.info("connected to \(self)")

Sources/SwiftOCA/OCP.1/Ocp1Connection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public struct Ocp1ConnectionFlags: OptionSet, Sendable {
6464
public static let refreshDeviceTreeOnConnection = Ocp1ConnectionFlags(rawValue: 1 << 1)
6565
public static let retainObjectCacheAfterDisconnect = Ocp1ConnectionFlags(rawValue: 1 << 2)
6666
public static let enableTracing = Ocp1ConnectionFlags(rawValue: 1 << 3)
67+
public static let refreshSubscriptionsOnReconnection = Ocp1ConnectionFlags(rawValue: 1 << 4)
6768

6869
public typealias RawValue = UInt
6970

0 commit comments

Comments
 (0)