diff --git a/Sources/SwiftOCADevice/OCC/ControlClasses/Managers/SubscriptionManager.swift b/Sources/SwiftOCADevice/OCC/ControlClasses/Managers/SubscriptionManager.swift index 4d295dda..2dad30ca 100644 --- a/Sources/SwiftOCADevice/OCC/ControlClasses/Managers/SubscriptionManager.swift +++ b/Sources/SwiftOCADevice/OCC/ControlClasses/Managers/SubscriptionManager.swift @@ -25,20 +25,21 @@ public class OcaSubscriptionManager: OcaManager { var objectsChangedWhilstNotificationsDisabled = Set() - func addSubscription( + private func addSubscription( _ subscription: SwiftOCA.OcaSubscriptionManager.AddSubscriptionParameters, - from controller: any AES70Controller + from controller: any AES70Controller, + command: Ocp1Command ) async throws { - try await ensureWritable(by: controller) + try await ensureWritable(by: controller, command: command) try await controller.addSubscription(.subscription(subscription)) } - func removeSubscription( + private func removeSubscription( _ subscription: SwiftOCA.OcaSubscriptionManager.RemoveSubscriptionParameters, - from controller: any AES70Controller + from controller: any AES70Controller, + command: Ocp1Command ) async throws { - try await ensureWritable(by: controller) - + try await ensureWritable(by: controller, command: command) try await controller.removeSubscription( subscription.event, property: nil, @@ -46,19 +47,21 @@ public class OcaSubscriptionManager: OcaManager { ) } - func addPropertyChangeSubscription( + private func addPropertyChangeSubscription( _ subscription: SwiftOCA.OcaSubscriptionManager.AddPropertyChangeSubscriptionParameters, - from controller: any AES70Controller + from controller: any AES70Controller, + command: Ocp1Command ) async throws { - try await ensureWritable(by: controller) + try await ensureWritable(by: controller, command: command) try await controller.addSubscription(.propertyChangeSubscription(subscription)) } - func removePropertyChangeSubscription( + private func removePropertyChangeSubscription( _ subscription: SwiftOCA.OcaSubscriptionManager.RemovePropertyChangeSubscriptionParameters, - from controller: any AES70Controller + from controller: any AES70Controller, + command: Ocp1Command ) async throws { - try await ensureWritable(by: controller) + try await ensureWritable(by: controller, command: command) try await controller.removeSubscription( OcaEvent(emitterONo: subscription.emitter, eventID: OcaPropertyChangedEventID), property: subscription.property, @@ -66,8 +69,11 @@ public class OcaSubscriptionManager: OcaManager { ) } - func disableNotifications(from controller: any AES70Controller) async throws { - try await ensureWritable(by: controller) + private func disableNotifications( + from controller: any AES70Controller, + command: Ocp1Command + ) async throws { + try await ensureWritable(by: controller, command: command) state = .eventsDisabled let event = OcaEvent( emitterONo: objectNumber, @@ -76,8 +82,11 @@ public class OcaSubscriptionManager: OcaManager { try await deviceDelegate?.notifySubscribers(event) } - func reenableNotifications(from controller: any AES70Controller) async throws { - try await ensureWritable(by: controller) + private func reenableNotifications( + from controller: any AES70Controller, + command: Ocp1Command + ) async throws { + try await ensureWritable(by: controller, command: command) let event = OcaEvent( emitterONo: objectNumber, eventID: SwiftOCA.OcaSubscriptionManager.SynchronizeStateEventID @@ -89,35 +98,39 @@ public class OcaSubscriptionManager: OcaManager { state = .normal } - func addSubscription2( + private func addSubscription2( _ subscription: SwiftOCA.OcaSubscriptionManager.AddSubscription2Parameters, - from controller: any AES70Controller + from controller: any AES70Controller, + command: Ocp1Command ) async throws { - try await ensureWritable(by: controller) + try await ensureWritable(by: controller, command: command) try await controller.addSubscription(.subscription2(subscription)) } - func removeSubscription2( + private func removeSubscription2( _ subscription: SwiftOCA.OcaSubscriptionManager.RemoveSubscription2Parameters, - from controller: any AES70Controller + from controller: any AES70Controller, + command: Ocp1Command ) async throws { - try await ensureWritable(by: controller) + try await ensureWritable(by: controller, command: command) try await controller.removeSubscription(.subscription2(subscription)) } - func addPropertyChangeSubscription2( + private func addPropertyChangeSubscription2( _ subscription: SwiftOCA.OcaSubscriptionManager.AddPropertyChangeSubscription2Parameters, - from controller: any AES70Controller + from controller: any AES70Controller, + command: Ocp1Command ) async throws { - try await ensureWritable(by: controller) + try await ensureWritable(by: controller, command: command) try await controller.addSubscription(.propertyChangeSubscription2(subscription)) } - func removePropertyChangeSubscription2( + private func removePropertyChangeSubscription2( _ subscription: SwiftOCA.OcaSubscriptionManager.RemovePropertyChangeSubscription2Parameters, - from controller: any AES70Controller + from controller: any AES70Controller, + command: Ocp1Command ) async throws { - try await ensureWritable(by: controller) + try await ensureWritable(by: controller, command: command) try await controller.removeSubscription(.propertyChangeSubscription2(subscription)) } @@ -129,28 +142,36 @@ public class OcaSubscriptionManager: OcaManager { case OcaMethodID("3.1"): let subscription: SwiftOCA.OcaSubscriptionManager .AddSubscriptionParameters = try decodeCommand(command) - try await addSubscription(subscription, from: controller) + try await addSubscription(subscription, from: controller, command: command) return Ocp1Response() case OcaMethodID("3.2"): let subscription: SwiftOCA.OcaSubscriptionManager .RemoveSubscriptionParameters = try decodeCommand(command) - try await removeSubscription(subscription, from: controller) + try await removeSubscription(subscription, from: controller, command: command) return Ocp1Response() case OcaMethodID("3.3"): - try await disableNotifications(from: controller) + try await disableNotifications(from: controller, command: command) return Ocp1Response() case OcaMethodID("3.4"): - try await reenableNotifications(from: controller) + try await reenableNotifications(from: controller, command: command) return Ocp1Response() case OcaMethodID("3.5"): let subscription: SwiftOCA.OcaSubscriptionManager .AddPropertyChangeSubscriptionParameters = try decodeCommand(command) - try await addPropertyChangeSubscription(subscription, from: controller) + try await addPropertyChangeSubscription( + subscription, + from: controller, + command: command + ) return Ocp1Response() case OcaMethodID("3.6"): let subscription: SwiftOCA.OcaSubscriptionManager .RemovePropertyChangeSubscriptionParameters = try decodeCommand(command) - try await removePropertyChangeSubscription(subscription, from: controller) + try await removePropertyChangeSubscription( + subscription, + from: controller, + command: command + ) return Ocp1Response() case OcaMethodID("3.7"): // Returns maximum byte length of payload of EV1 subscriber context parameter that this @@ -160,22 +181,30 @@ public class OcaSubscriptionManager: OcaManager { case OcaMethodID("3.8"): let subscription: SwiftOCA.OcaSubscriptionManager .AddSubscription2Parameters = try decodeCommand(command) - try await addSubscription2(subscription, from: controller) + try await addSubscription2(subscription, from: controller, command: command) return Ocp1Response() case OcaMethodID("3.9"): let subscription: SwiftOCA.OcaSubscriptionManager .RemoveSubscription2Parameters = try decodeCommand(command) - try await removeSubscription2(subscription, from: controller) + try await removeSubscription2(subscription, from: controller, command: command) return Ocp1Response() case OcaMethodID("3.10"): let subscription: SwiftOCA.OcaSubscriptionManager .AddPropertyChangeSubscription2Parameters = try decodeCommand(command) - try await addPropertyChangeSubscription2(subscription, from: controller) + try await addPropertyChangeSubscription2( + subscription, + from: controller, + command: command + ) return Ocp1Response() case OcaMethodID("3.11"): let subscription: SwiftOCA.OcaSubscriptionManager .RemovePropertyChangeSubscription2Parameters = try decodeCommand(command) - try await removePropertyChangeSubscription2(subscription, from: controller) + try await removePropertyChangeSubscription2( + subscription, + from: controller, + command: command + ) return Ocp1Response() default: return try await super.handleCommand(command, from: controller) diff --git a/Sources/SwiftOCADevice/OCC/ControlClasses/Root.swift b/Sources/SwiftOCADevice/OCC/ControlClasses/Root.swift index f7984abd..e9440389 100644 --- a/Sources/SwiftOCADevice/OCC/ControlClasses/Root.swift +++ b/Sources/SwiftOCADevice/OCC/ControlClasses/Root.swift @@ -105,10 +105,10 @@ Sendable { let property = self[keyPath: propertyKeyPath] as! (any OcaDevicePropertyRepresentable) if command.methodID == property.getMethodID { - try await ensureReadable(by: controller) + try await ensureReadable(by: controller, command: command) return try await property.get(object: self) } else if command.methodID == property.setMethodID { - try await ensureWritable(by: controller) + try await ensureWritable(by: controller, command: command) try await property.set(object: self, command: command) return Ocp1Response() } @@ -154,9 +154,12 @@ Sendable { false } - open func ensureReadable(by controller: any AES70Controller) async throws { + open func ensureReadable( + by controller: any AES70Controller, + command: Ocp1Command + ) async throws { if let deviceManager = await deviceDelegate?.deviceManager, deviceManager != self { - try await deviceManager.ensureReadable(by: controller) + try await deviceManager.ensureReadable(by: controller, command: command) } switch lockState { @@ -171,9 +174,12 @@ Sendable { } } - open func ensureWritable(by controller: any AES70Controller) async throws { + open func ensureWritable( + by controller: any AES70Controller, + command: Ocp1Command + ) async throws { if let deviceManager = await deviceDelegate?.deviceManager, deviceManager != self { - try await deviceManager.ensureWritable(by: controller) + try await deviceManager.ensureWritable(by: controller, command: command) } switch lockState { diff --git a/Sources/SwiftOCADevice/OCC/ControlClasses/Workers/BlocksAndMatrices/Block.swift b/Sources/SwiftOCADevice/OCC/ControlClasses/Workers/BlocksAndMatrices/Block.swift index 3bae4ebd..27bea0d5 100644 --- a/Sources/SwiftOCADevice/OCC/ControlClasses/Workers/BlocksAndMatrices/Block.swift +++ b/Sources/SwiftOCADevice/OCC/ControlClasses/Workers/BlocksAndMatrices/Block.swift @@ -265,28 +265,28 @@ open class OcaBlock: OcaWorker { // 3.3 ConstructBlockUsingFactory // 3.4 DeleteMember case OcaMethodID("3.5"): - try await ensureReadable(by: controller) + try await ensureReadable(by: controller, command: command) let actionObjects = actionObjects.map(\.objectIdentification) return try encodeResponse(actionObjects) case OcaMethodID("3.6"): - try await ensureReadable(by: controller) + try await ensureReadable(by: controller, command: command) let actionObjects: [OcaBlockMember] = try await getActionObjectsRecursive(from: controller) return try encodeResponse(actionObjects) case OcaMethodID("3.7"): - try await ensureWritable(by: controller) + try await ensureWritable(by: controller, command: command) let path: OcaSignalPath = try decodeCommand(command) let index = try await add(signalPath: path) return try encodeResponse(index) case OcaMethodID("3.8"): - try await ensureWritable(by: controller) + try await ensureWritable(by: controller, command: command) let index: OcaUint16 = try decodeCommand(command) try await remove(signalPathAt: index) case OcaMethodID("3.9"): - try await ensureReadable(by: controller) + try await ensureReadable(by: controller, command: command) return try encodeResponse(signalPaths) case OcaMethodID("3.10"): - try await ensureReadable(by: controller) + try await ensureReadable(by: controller, command: command) let signalPaths: [OcaUint16: OcaSignalPath] = try await getSignalPathsRecursive(from: controller) return try encodeResponse(signalPaths) diff --git a/Sources/SwiftOCADevice/OCC/ControlClasses/Workers/BlocksAndMatrices/Matrix.swift b/Sources/SwiftOCADevice/OCC/ControlClasses/Workers/BlocksAndMatrices/Matrix.swift index 75bc9278..1e8a966f 100644 --- a/Sources/SwiftOCADevice/OCC/ControlClasses/Workers/BlocksAndMatrices/Matrix.swift +++ b/Sources/SwiftOCADevice/OCC/ControlClasses/Workers/BlocksAndMatrices/Matrix.swift @@ -262,7 +262,7 @@ open class OcaMatrix: OcaWorker { ) async throws -> Ocp1Response { switch command.methodID { case OcaMethodID("3.3"): - try await ensureReadable(by: controller) + try await ensureReadable(by: controller, command: command) let size = OcaVector2D( x: OcaMatrixCoordinate(members.nX), y: OcaMatrixCoordinate(members.nY) @@ -277,18 +277,18 @@ open class OcaMatrix: OcaWorker { ) return try encodeResponse(matrixSize) case OcaMethodID("3.5"): - try await ensureReadable(by: controller) + try await ensureReadable(by: controller, command: command) let members = members .map(defaultValue: OcaInvalidONo) { $0?.objectNumber ?? OcaInvalidONo } return try encodeResponse(OcaMatrixGetMembersParameters(members: members)) case OcaMethodID("3.7"): - try await ensureReadable(by: controller) + try await ensureReadable(by: controller, command: command) let coordinates: OcaVector2D = try decodeCommand(command) let objectNumber = members[Int(coordinates.x), Int(coordinates.y)]? .objectNumber ?? OcaInvalidONo return try encodeResponse(objectNumber) case OcaMethodID("3.8"): - try await ensureWritable(by: controller) + try await ensureWritable(by: controller, command: command) let parameters: OcaMatrixSetMemberParameters = try decodeCommand(command) guard parameters.x < members.nX, parameters.y < members.nY else { throw Ocp1Error.status(.parameterOutOfRange) @@ -304,10 +304,10 @@ open class OcaMatrix: OcaWorker { } members[Int(parameters.x), Int(parameters.y)] = object case OcaMethodID("3.9"): - try await ensureReadable(by: controller) + try await ensureReadable(by: controller, command: command) return try encodeResponse(proxy.objectNumber) case OcaMethodID("3.2"): - try await ensureWritable(by: controller) + try await ensureWritable(by: controller, command: command) let coordinates: OcaVector2D = try decodeCommand(command) guard coordinates.x < members.nX || coordinates.x == OcaMatrixWildcardCoordinate, coordinates.y < members.nY || coordinates.y == OcaMatrixWildcardCoordinate