From 1700393828174d0de40db18f3e59b79db90607ea Mon Sep 17 00:00:00 2001 From: Carol Yang Date: Tue, 5 Jul 2022 14:39:58 -0700 Subject: [PATCH] [OTA] Add Darwin Framework APIs for OTA Provider delegate (#20295) --- .../ota-provider/ota-provider-delegate.h | 2 +- .../Framework/CHIP/MTROTAProviderDelegate.h | 55 +++++++++++++++++++ .../CHIP/MTROTAProviderDelegateBridge.h | 49 +++++++++++++++++ src/darwin/Framework/CHIP/Matter.h | 1 + .../Matter.xcodeproj/project.pbxproj | 8 +++ 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 src/darwin/Framework/CHIP/MTROTAProviderDelegate.h create mode 100644 src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.h diff --git a/src/app/clusters/ota-provider/ota-provider-delegate.h b/src/app/clusters/ota-provider/ota-provider-delegate.h index 17065194bfbbb2..3d7426ea4fd14e 100644 --- a/src/app/clusters/ota-provider/ota-provider-delegate.h +++ b/src/app/clusters/ota-provider/ota-provider-delegate.h @@ -34,7 +34,7 @@ namespace Clusters { /** @brief * Defines methods for implementing application-specific logic for the OTA Provider Cluster. */ -class OTAProviderDelegate +class DLL_EXPORT OTAProviderDelegate { public: /** diff --git a/src/darwin/Framework/CHIP/MTROTAProviderDelegate.h b/src/darwin/Framework/CHIP/MTROTAProviderDelegate.h new file mode 100644 index 00000000000000..163957072dd62f --- /dev/null +++ b/src/darwin/Framework/CHIP/MTROTAProviderDelegate.h @@ -0,0 +1,55 @@ +/** + * + * Copyright (c) 2022 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +/** + * The protocol definition for the MTROTAProviderDelegate + * + * All delegate methods will be called on the supplied Delegate Queue. + */ +@protocol MTROTAProviderDelegate +@optional +/** + * Notify the delegate when query image command is received + * + */ +- (void)handleQueryImage:(MTROtaSoftwareUpdateProviderClusterQueryImageParams *)params + completionHandler:(void (^)(MTROtaSoftwareUpdateProviderClusterQueryImageResponseParams * _Nullable data, + NSError * _Nullable error))completionHandler; + +/** + * Notify the delegate when apply update request command is received + * + */ +- (void)handleApplyUpdateRequest:(MTROtaSoftwareUpdateProviderClusterApplyUpdateRequestParams *)params + completionHandler:(void (^)(MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data, + NSError * _Nullable error))completionHandler; + +/** + * Notify the delegate when notify update applied command is received + * + */ +- (void)handleNotifyUpdateApplied:(MTROtaSoftwareUpdateProviderClusterNotifyUpdateAppliedParams *)params + completionHandler:(StatusCompletion)completionHandler; + +@end + +NS_ASSUME_NONNULL_END diff --git a/src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.h b/src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.h new file mode 100644 index 00000000000000..4b36d91f0eb804 --- /dev/null +++ b/src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.h @@ -0,0 +1,49 @@ +/** + * + * Copyright (c) 2022 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "MTROTAProviderDelegate.h" + +#include + +NS_ASSUME_NONNULL_BEGIN + +class MTROTAProviderDelegateBridge : public chip::app::Clusters::OTAProviderDelegate +{ +public: + MTROTAProviderDelegateBridge(); + ~MTROTAProviderDelegateBridge(); + + void setDelegate(id delegate, dispatch_queue_t queue); + + void HandleQueryImage( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::QueryImage::DecodableType & commandData) override; + + void HandleApplyUpdateRequest( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::ApplyUpdateRequest::DecodableType & commandData) override; + + void HandleNotifyUpdateApplied( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::NotifyUpdateApplied::DecodableType & commandData) override; + +private: + _Nullable id mDelegate; + _Nullable dispatch_queue_t mQueue; +}; + +NS_ASSUME_NONNULL_END diff --git a/src/darwin/Framework/CHIP/Matter.h b/src/darwin/Framework/CHIP/Matter.h index 76ee38e643596e..0d5e8c403e3e37 100644 --- a/src/darwin/Framework/CHIP/Matter.h +++ b/src/darwin/Framework/CHIP/Matter.h @@ -34,6 +34,7 @@ #import #import #import +#import #import #import #import diff --git a/src/darwin/Framework/Matter.xcodeproj/project.pbxproj b/src/darwin/Framework/Matter.xcodeproj/project.pbxproj index 32b41bcba8786e..305a9f857e9937 100644 --- a/src/darwin/Framework/Matter.xcodeproj/project.pbxproj +++ b/src/darwin/Framework/Matter.xcodeproj/project.pbxproj @@ -92,6 +92,8 @@ 99AECC802798A57F00B6355B /* MTRCommissioningParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 99AECC7F2798A57E00B6355B /* MTRCommissioningParameters.m */; }; 99C65E10267282F1003402F6 /* MTRControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 99C65E0F267282F1003402F6 /* MTRControllerTests.m */; }; 99D466E12798936D0089A18F /* MTRCommissioningParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 99D466E02798936D0089A18F /* MTRCommissioningParameters.h */; settings = {ATTRIBUTES = (Public, ); }; }; + AF1CB86E2874B03B00865A96 /* MTROTAProviderDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = AF1CB86D2874B03B00865A96 /* MTROTAProviderDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; + AF1CB8702874B04C00865A96 /* MTROTAProviderDelegateBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = AF1CB86F2874B04C00865A96 /* MTROTAProviderDelegateBridge.h */; }; B20252972459E34F00F97062 /* Matter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B202528D2459E34F00F97062 /* Matter.framework */; }; B289D4212639C0D300D4E314 /* MTROnboardingPayloadParser.h in Headers */ = {isa = PBXBuildFile; fileRef = B289D41F2639C0D300D4E314 /* MTROnboardingPayloadParser.h */; settings = {ATTRIBUTES = (Public, ); }; }; B289D4222639C0D300D4E314 /* MTROnboardingPayloadParser.m in Sources */ = {isa = PBXBuildFile; fileRef = B289D4202639C0D300D4E314 /* MTROnboardingPayloadParser.m */; }; @@ -205,6 +207,8 @@ 99AECC7F2798A57E00B6355B /* MTRCommissioningParameters.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MTRCommissioningParameters.m; sourceTree = ""; }; 99C65E0F267282F1003402F6 /* MTRControllerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MTRControllerTests.m; sourceTree = ""; }; 99D466E02798936D0089A18F /* MTRCommissioningParameters.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MTRCommissioningParameters.h; sourceTree = ""; }; + AF1CB86D2874B03B00865A96 /* MTROTAProviderDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MTROTAProviderDelegate.h; sourceTree = ""; }; + AF1CB86F2874B04C00865A96 /* MTROTAProviderDelegateBridge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MTROTAProviderDelegateBridge.h; sourceTree = ""; }; B202528D2459E34F00F97062 /* Matter.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Matter.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B20252912459E34F00F97062 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; B20252962459E34F00F97062 /* MatterTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MatterTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -336,6 +340,8 @@ 2CB7163E252F731E0026E2BB /* MTRDevicePairingDelegate.h */, 2CB71638252E8A7B0026E2BB /* MTRDevicePairingDelegateBridge.h */, 2CB71639252E8A7B0026E2BB /* MTRDevicePairingDelegateBridge.mm */, + AF1CB86F2874B04C00865A96 /* MTROTAProviderDelegateBridge.h */, + AF1CB86D2874B03B00865A96 /* MTROTAProviderDelegate.h */, B2E0D7A8245B0B5C003C5B48 /* Matter.h */, B2E0D7AB245B0B5C003C5B48 /* MTRError_Internal.h */, 5129BCFC26A9EE3300122DDF /* MTRError.h */, @@ -438,6 +444,7 @@ 88EBF8CE27FABDD500686BC1 /* MTRDeviceAttestationDelegate.h in Headers */, 2C222AD0255C620600E446B9 /* MTRDevice.h in Headers */, 991DC0842475F45400C13860 /* MTRDeviceController.h in Headers */, + AF1CB86E2874B03B00865A96 /* MTROTAProviderDelegate.h in Headers */, 754F3DF427FBB94B00E60580 /* MTREventTLVValueDecoder_Internal.h in Headers */, B2E0D7B2245B0B5C003C5B48 /* MTRManualSetupPayloadParser.h in Headers */, B2E0D7B1245B0B5C003C5B48 /* Matter.h in Headers */, @@ -455,6 +462,7 @@ 5A6FEC9A27B5C89300F25F42 /* MTRDeviceControllerXPCConnection.h in Headers */, 5129BCFD26A9EE3300122DDF /* MTRError.h in Headers */, 2C8C8FC1253E0C2100797F05 /* MTRPersistentStorageDelegate.h in Headers */, + AF1CB8702874B04C00865A96 /* MTROTAProviderDelegateBridge.h in Headers */, B2E0D7B5245B0B5C003C5B48 /* MTRQRCodeSetupPayloadParser.h in Headers */, 1EC4CE6425CC276600D7304F /* MTRClustersObjc.h in Headers */, 2C5EEEF6268A85C400CAE3D3 /* MTRDeviceConnectionBridge.h in Headers */,