From 5751f717281ebdc8bd725f1ae53ed8b5952f8599 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Thu, 21 Dec 2023 16:31:25 +0100 Subject: [PATCH] [Matter.framework] Add MTRDiagnosticLogsDelegate to darwin-framework-tool --- examples/darwin-framework-tool/BUILD.gn | 1 + .../commands/bdx/DiagnosticLogsDelegate.h | 36 ++++++++++++ .../commands/bdx/DiagnosticLogsDelegate.mm | 58 +++++++++++++++++++ .../commands/common/CHIPCommandBridge.h | 2 + .../commands/common/CHIPCommandBridge.mm | 3 + .../Matter.xcodeproj/project.pbxproj | 16 +++++ 6 files changed, 116 insertions(+) create mode 100644 examples/darwin-framework-tool/commands/bdx/DiagnosticLogsDelegate.h create mode 100644 examples/darwin-framework-tool/commands/bdx/DiagnosticLogsDelegate.mm diff --git a/examples/darwin-framework-tool/BUILD.gn b/examples/darwin-framework-tool/BUILD.gn index 7ee396dd04e24a..a8f9d7cd80c929 100644 --- a/examples/darwin-framework-tool/BUILD.gn +++ b/examples/darwin-framework-tool/BUILD.gn @@ -163,6 +163,7 @@ executable("darwin-framework-tool") { "${chip_root}/examples/chip-tool/commands/common/Commands.h", "${chip_root}/examples/chip-tool/commands/common/HexConversion.h", "${chip_root}/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp", + "commands/bdx/DiagnosticLogsDelegate.mm", "commands/clusters/ClusterCommandBridge.h", "commands/clusters/ModelCommandBridge.mm", "commands/clusters/ReportCommandBridge.h", diff --git a/examples/darwin-framework-tool/commands/bdx/DiagnosticLogsDelegate.h b/examples/darwin-framework-tool/commands/bdx/DiagnosticLogsDelegate.h new file mode 100644 index 00000000000000..f57abb413ec087 --- /dev/null +++ b/examples/darwin-framework-tool/commands/bdx/DiagnosticLogsDelegate.h @@ -0,0 +1,36 @@ +/* + * + * Copyright (c) 2023 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. + */ +#pragma once +#import + +@interface DiagnosticLogsDelegate : NSObject +- (void)handleBDXTransferSessionBeginForNodeID:(NSNumber * _Nonnull)nodeID + controller:(MTRDeviceController * _Nonnull)controller + fileDesignator:(NSString * _Nonnull)fileDesignator + completion:(MTRStatusCompletion _Nonnull)completion; + +- (void)handleBDXTransferSessionDataForNodeID:(NSNumber * _Nonnull)nodeID + controller:(MTRDeviceController * _Nonnull)controller + fileDesignator:(NSString * _Nonnull)fileDesignator + data:(NSData * _Nonnull)data + completion:(MTRStatusCompletion _Nonnull)completion; + +- (void)handleBDXTransferSessionEndForNodeID:(NSNumber * _Nonnull)nodeID + controller:(MTRDeviceController * _Nonnull)controller + fileDesignator:(NSString * _Nonnull)fileDesignator + error:(NSError * _Nullable)error; +@end diff --git a/examples/darwin-framework-tool/commands/bdx/DiagnosticLogsDelegate.mm b/examples/darwin-framework-tool/commands/bdx/DiagnosticLogsDelegate.mm new file mode 100644 index 00000000000000..8268379358ee8a --- /dev/null +++ b/examples/darwin-framework-tool/commands/bdx/DiagnosticLogsDelegate.mm @@ -0,0 +1,58 @@ +/* + * + * Copyright (c) 2023 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. + */ + +#include "DiagnosticLogsDelegate.h" + +@interface DiagnosticLogsDelegate () +@end + +@implementation DiagnosticLogsDelegate + +- (instancetype)init +{ + if (self = [super init]) { + } + return self; +} + +- (void)handleBDXTransferSessionBeginForNodeID:(NSNumber * _Nonnull)nodeID + controller:(MTRDeviceController * _Nonnull)controller + fileDesignator:(NSString * _Nonnull)fileDesignator + completion:(MTRStatusCompletion _Nonnull)completion +{ + NSLog(@"BDX Transfer Session Begin: %@", fileDesignator); + completion(nil); +} + +- (void)handleBDXTransferSessionDataForNodeID:(NSNumber * _Nonnull)nodeID + controller:(MTRDeviceController * _Nonnull)controller + fileDesignator:(NSString * _Nonnull)fileDesignator + data:(NSData * _Nonnull)data + completion:(MTRStatusCompletion _Nonnull)completion +{ + NSLog(@"BDX Transfer Session Data: %@: %@", fileDesignator, data); + completion(nil); +} + +- (void)handleBDXTransferSessionEndForNodeID:(NSNumber * _Nonnull)nodeID + controller:(MTRDeviceController * _Nonnull)controller + fileDesignator:(NSString * _Nonnull)fileDesignator + error:(NSError * _Nullable)error +{ + NSLog(@"BDX Transfer Session End: %@: %@", fileDesignator, error); +} +@end diff --git a/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h b/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h index 842ded8f839ab7..c5a5bbf3535738 100644 --- a/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h +++ b/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h @@ -24,6 +24,7 @@ #include #include +#include "../bdx/DiagnosticLogsDelegate.h" #include "../provider/OTAProviderDelegate.h" #pragma once @@ -66,6 +67,7 @@ class CHIPCommandBridge : public Command { StopWaiting(); } + static DiagnosticLogsDelegate * mDiagnosticLogsDelegate; static OTAProviderDelegate * mOTADelegate; protected: diff --git a/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm b/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm index 205b56d6a64e3d..6ef8f663c2cf37 100644 --- a/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm +++ b/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm @@ -31,6 +31,7 @@ std::map CHIPCommandBridge::mControllers; dispatch_queue_t CHIPCommandBridge::mOTAProviderCallbackQueue; OTAProviderDelegate * CHIPCommandBridge::mOTADelegate; +DiagnosticLogsDelegate * CHIPCommandBridge::mDiagnosticLogsDelegate; constexpr char kTrustStorePathVariable[] = "PAA_TRUST_STORE_PATH"; CHIPToolKeypair * gNocSigner = [[CHIPToolKeypair alloc] init]; @@ -116,6 +117,7 @@ storage = [[CHIPToolPersistentStorageDelegate alloc] init]; mOTADelegate = [[OTAProviderDelegate alloc] init]; + mDiagnosticLogsDelegate = [[DiagnosticLogsDelegate alloc] init]; auto factory = [MTRDeviceControllerFactory sharedInstance]; if (factory == nil) { @@ -126,6 +128,7 @@ auto params = [[MTRDeviceControllerFactoryParams alloc] initWithStorage:storage]; params.shouldStartServer = YES; params.otaProviderDelegate = mOTADelegate; + params.diagnosticLogsDelegate = mDiagnosticLogsDelegate; NSArray * paaCertResults; ReturnLogErrorOnFailure(GetPAACertsFromFolder(&paaCertResults)); if ([paaCertResults count] > 0) { diff --git a/src/darwin/Framework/Matter.xcodeproj/project.pbxproj b/src/darwin/Framework/Matter.xcodeproj/project.pbxproj index 2447bdd2f650f2..cf8af9c090eb52 100644 --- a/src/darwin/Framework/Matter.xcodeproj/project.pbxproj +++ b/src/darwin/Framework/Matter.xcodeproj/project.pbxproj @@ -306,6 +306,8 @@ B4E262172AA0CF2000DBA5BC /* RemoteDataModelLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = B4E262132AA0C7A300DBA5BC /* RemoteDataModelLogger.h */; }; B4E2621B2AA0D02000DBA5BC /* SleepCommand.mm in Sources */ = {isa = PBXBuildFile; fileRef = B4E262192AA0D01D00DBA5BC /* SleepCommand.mm */; }; B4E2621E2AA0D02D00DBA5BC /* WaitForCommissioneeCommand.mm in Sources */ = {isa = PBXBuildFile; fileRef = B4E2621C2AA0D02A00DBA5BC /* WaitForCommissioneeCommand.mm */; }; + B4ECD4842B3B3E2E0022E16B /* DiagnosticLogsDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = B4ECD4822B3B3E2E0022E16B /* DiagnosticLogsDelegate.mm */; }; + B4ECD4852B3B3E2E0022E16B /* DiagnosticLogsDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = B4ECD4832B3B3E2E0022E16B /* DiagnosticLogsDelegate.h */; }; BA09EB43247477BA00605257 /* libCHIP.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BA09EB3F2474762900605257 /* libCHIP.a */; }; D4772A46285AE98400383630 /* MTRClusterConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = D4772A45285AE98300383630 /* MTRClusterConstants.h */; settings = {ATTRIBUTES = (Public, ); }; }; /* End PBXBuildFile section */ @@ -679,6 +681,8 @@ B4E262132AA0C7A300DBA5BC /* RemoteDataModelLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteDataModelLogger.h; sourceTree = ""; }; B4E262192AA0D01D00DBA5BC /* SleepCommand.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SleepCommand.mm; sourceTree = ""; }; B4E2621C2AA0D02A00DBA5BC /* WaitForCommissioneeCommand.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WaitForCommissioneeCommand.mm; sourceTree = ""; }; + B4ECD4822B3B3E2E0022E16B /* DiagnosticLogsDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DiagnosticLogsDelegate.mm; sourceTree = ""; }; + B4ECD4832B3B3E2E0022E16B /* DiagnosticLogsDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiagnosticLogsDelegate.h; sourceTree = ""; }; BA09EB3F2474762900605257 /* libCHIP.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libCHIP.a; path = lib/libCHIP.a; sourceTree = BUILT_PRODUCTS_DIR; }; BA107AEE2470CFBB004287EB /* chip_xcode_build_connector.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = chip_xcode_build_connector.sh; sourceTree = ""; }; D437613E285BDC0D0051FEA2 /* MTRErrorTestUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRErrorTestUtils.h; sourceTree = ""; }; @@ -747,6 +751,7 @@ 037C3D7B2991BD4F00B7EEE2 /* commands */ = { isa = PBXGroup; children = ( + B4ECD4812B3B3E2E0022E16B /* bdx */, B4E262182AA0CFFE00DBA5BC /* delay */, 03FB93DA2A46200A0048CB35 /* discover */, 037C3D7C2991BD4F00B7EEE2 /* pairing */, @@ -1348,6 +1353,15 @@ path = delay; sourceTree = ""; }; + B4ECD4812B3B3E2E0022E16B /* bdx */ = { + isa = PBXGroup; + children = ( + B4ECD4822B3B3E2E0022E16B /* DiagnosticLogsDelegate.mm */, + B4ECD4832B3B3E2E0022E16B /* DiagnosticLogsDelegate.h */, + ); + path = bdx; + sourceTree = ""; + }; BA09EB3E2474762900605257 /* Frameworks */ = { isa = PBXGroup; children = ( @@ -1374,6 +1388,7 @@ 039546A02991DFC5006D42A8 /* json_tool.h in Headers */, 037C3DB12991BD5000B7EEE2 /* OpenCommissioningWindowCommand.h in Headers */, 039145E92993179300257B3E /* GetCommissionerNodeIdCommand.h in Headers */, + B4ECD4852B3B3E2E0022E16B /* DiagnosticLogsDelegate.h in Headers */, 037C3DCE2991BD5100B7EEE2 /* CHIPCommandBridge.h in Headers */, 037C3DD22991BD5200B7EEE2 /* InteractiveCommands.h in Headers */, 037C3DAF2991BD4F00B7EEE2 /* DeviceControllerDelegateBridge.h in Headers */, @@ -1664,6 +1679,7 @@ B45373D72A9FEB0C00807602 /* lws_dll2.c in Sources */, B45373FE2A9FEC4F00807602 /* unix-fds.c in Sources */, B45373C72A9FEA9100807602 /* pollfd.c in Sources */, + B4ECD4842B3B3E2E0022E16B /* DiagnosticLogsDelegate.mm in Sources */, B45373BE2A9FEA9100807602 /* network.c in Sources */, B45373BD2A9FEA9100807602 /* service.c in Sources */, 0395469E2991DFC5006D42A8 /* json_writer.cpp in Sources */,