-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Matter.framework] Add MTRDiagnosticLogsDelegate to the Matter.framework
- Loading branch information
1 parent
bae1085
commit 6c5a1f0
Showing
7 changed files
with
318 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* | ||
* 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. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <Matter/MTRCluster.h> | ||
#import <Matter/MTRDefines.h> | ||
|
||
@class MTRDeviceController; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
* The protocol definition for the MTRDiagnosticLogsDelegate. | ||
* | ||
*/ | ||
@protocol MTRDiagnosticLogsDelegate <NSObject> | ||
/** | ||
* Notify the delegate when a BDX Session starts for some logs. | ||
* The controller identifies the fabric the node is on, and the | ||
* nodeID identifies the node within that fabric. | ||
* | ||
* If completion is passed a non-nil error, that will be converted into | ||
* an error response to the sender. Otherwise a success response will be sent. | ||
*/ | ||
- (void)handleBDXTransferSessionBeginForNodeID:(NSNumber *)nodeID | ||
controller:(MTRDeviceController *)controller | ||
fileDesignator:(NSString *)fileDesignator | ||
completion:(MTRStatusCompletion)completion | ||
MTR_NEWLY_AVAILABLE; | ||
|
||
/** | ||
* Notify the delegate when some data is received on the BDX Session. | ||
* The controller identifies the fabric the node is on, and the | ||
* nodeID identifies the node within that fabric. | ||
* | ||
* If completion is passed a non-nil error, that will be converted into | ||
* an error response to the sender. Otherwise a success response will be sent. | ||
*/ | ||
- (void)handleBDXTransferSessionDataForNodeID:(NSNumber *)nodeID | ||
controller:(MTRDeviceController *)controller | ||
fileDesignator:(NSString *)fileDesignator | ||
data:(NSData *)data | ||
completion:(MTRStatusCompletion)completion | ||
MTR_NEWLY_AVAILABLE; | ||
|
||
/** | ||
* Notify the delegate when a BDX Session ends for some logs. | ||
* The controller identifies the fabric the node is on, and the | ||
* nodeID identifies the node within that fabric. | ||
*/ | ||
- (void)handleBDXTransferSessionEndForNodeID:(NSNumber *)nodeID | ||
controller:(MTRDeviceController *)controller | ||
fileDesignator:(NSString *)fileDesignator | ||
error:(NSError * _Nullable)error | ||
MTR_NEWLY_AVAILABLE; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
42 changes: 42 additions & 0 deletions
42
src/darwin/Framework/CHIP/MTRDiagnosticLogsDelegateBridge.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* | ||
* 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. | ||
*/ | ||
|
||
#import <Matter/MTRDiagnosticLogsDelegate.h> | ||
|
||
#include <protocols/bdx/BdxTransferServerDelegate.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
class MTRDiagnosticLogsDelegateBridge : public chip::bdx::BDXTransferServerDelegate | ||
{ | ||
public: | ||
MTRDiagnosticLogsDelegateBridge(); | ||
~MTRDiagnosticLogsDelegateBridge(); | ||
|
||
void SetDelegate(id<MTRDiagnosticLogsDelegate> delegate) { mDelegate = delegate; }; | ||
|
||
/////////// BDXTransferServerDelegate Interface ///////// | ||
CHIP_ERROR OnTransferBegin(chip::bdx::BDXTransferProxy * transfer) override; | ||
CHIP_ERROR OnTransferEnd(chip::bdx::BDXTransferProxy * transfer, CHIP_ERROR error) override; | ||
CHIP_ERROR OnTransferData(chip::bdx::BDXTransferProxy * transfer, const chip::ByteSpan & data) override; | ||
|
||
private: | ||
id<MTRDiagnosticLogsDelegate> mDelegate; | ||
dispatch_queue_t mDelegateNotificationQueue; | ||
}; | ||
|
||
NS_ASSUME_NONNULL_END |
137 changes: 137 additions & 0 deletions
137
src/darwin/Framework/CHIP/MTRDiagnosticLogsDelegateBridge.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/** | ||
* | ||
* 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. | ||
*/ | ||
|
||
#import "MTRDiagnosticLogsDelegateBridge.h" | ||
|
||
#import "MTRDeviceControllerFactory_Internal.h" | ||
#import "MTRDeviceController_Internal.h" | ||
#import "MTRError_Internal.h" | ||
#import "NSDataSpanConversion.h" | ||
#import "NSStringSpanConversion.h" | ||
|
||
constexpr const char kQueueName[] = "org.csa-iot.matter.framework.diagnosticlogs.workqueue"; | ||
|
||
MTRDiagnosticLogsDelegateBridge::MTRDiagnosticLogsDelegateBridge() | ||
{ | ||
mDelegateNotificationQueue = dispatch_queue_create(kQueueName, DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL); | ||
} | ||
|
||
MTRDiagnosticLogsDelegateBridge::~MTRDiagnosticLogsDelegateBridge() | ||
{ | ||
mDelegateNotificationQueue = nil; | ||
mDelegate = nil; | ||
} | ||
|
||
CHIP_ERROR MTRDiagnosticLogsDelegateBridge::OnTransferBegin(chip::bdx::BDXTransferProxy * transfer) | ||
{ | ||
VerifyOrReturnError(nil != mDelegate, CHIP_ERROR_NOT_IMPLEMENTED); | ||
|
||
auto fileDesignatorSpan = transfer->GetFileDesignator(); | ||
auto fileDesignator = AsString(fileDesignatorSpan); | ||
VerifyOrReturnError(nil != fileDesignator, CHIP_ERROR_INCORRECT_STATE); | ||
|
||
auto nodeId = @(transfer->GetPeerNodeId()); | ||
auto fabricIndex = transfer->GetFabricIndex(); | ||
auto * controller = [[MTRDeviceControllerFactory sharedInstance] runningControllerForFabricIndex:fabricIndex]; | ||
VerifyOrReturnError(controller != nil, CHIP_ERROR_INCORRECT_STATE); | ||
|
||
auto completionHandler = ^(NSError * _Nullable error) { | ||
[controller asyncDispatchToMatterQueue:^() { | ||
if (error != nil) { | ||
auto err = [MTRError errorToCHIPErrorCode:error]; | ||
transfer->Reject(err); | ||
} else { | ||
transfer->Accept(); | ||
} | ||
} errorHandler:^(NSError *) { | ||
// Not much we can do here | ||
}]; | ||
}; | ||
|
||
auto strongDelegate = mDelegate; | ||
dispatch_async( | ||
mDelegateNotificationQueue, ^{ | ||
[strongDelegate handleBDXTransferSessionBeginForNodeID:nodeId controller:controller fileDesignator:fileDesignator completion:completionHandler]; | ||
}); | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
||
CHIP_ERROR MTRDiagnosticLogsDelegateBridge::OnTransferEnd(chip::bdx::BDXTransferProxy * transfer, CHIP_ERROR error) | ||
{ | ||
VerifyOrReturnError(nil != mDelegate, CHIP_ERROR_NOT_IMPLEMENTED); | ||
|
||
auto fileDesignatorSpan = transfer->GetFileDesignator(); | ||
auto fileDesignator = AsString(fileDesignatorSpan); | ||
VerifyOrReturnError(nil != fileDesignator, CHIP_ERROR_INCORRECT_STATE); | ||
|
||
NSError * mtrError = nil; | ||
if (CHIP_NO_ERROR != error) { | ||
mtrError = [MTRError errorForCHIPErrorCode:error]; | ||
} | ||
|
||
auto nodeId = @(transfer->GetPeerNodeId()); | ||
auto fabricIndex = transfer->GetFabricIndex(); | ||
auto * controller = [[MTRDeviceControllerFactory sharedInstance] runningControllerForFabricIndex:fabricIndex]; | ||
VerifyOrReturnError(controller != nil, CHIP_ERROR_INCORRECT_STATE); | ||
|
||
auto strongDelegate = mDelegate; | ||
dispatch_async( | ||
mDelegateNotificationQueue, ^{ | ||
[strongDelegate handleBDXTransferSessionEndForNodeID:nodeId controller:controller fileDesignator:fileDesignator error:mtrError]; | ||
}); | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
||
CHIP_ERROR MTRDiagnosticLogsDelegateBridge::OnTransferData(chip::bdx::BDXTransferProxy * transfer, const chip::ByteSpan & dataSpan) | ||
{ | ||
VerifyOrReturnError(nil != mDelegate, CHIP_ERROR_NOT_IMPLEMENTED); | ||
|
||
auto fileDesignatorSpan = transfer->GetFileDesignator(); | ||
auto fileDesignator = AsString(fileDesignatorSpan); | ||
VerifyOrReturnError(nil != fileDesignator, CHIP_ERROR_INCORRECT_STATE); | ||
|
||
auto data = AsData(dataSpan); | ||
VerifyOrReturnError(nil != data, CHIP_ERROR_INCORRECT_STATE); | ||
|
||
auto nodeId = @(transfer->GetPeerNodeId()); | ||
auto fabricIndex = transfer->GetFabricIndex(); | ||
auto * controller = [[MTRDeviceControllerFactory sharedInstance] runningControllerForFabricIndex:fabricIndex]; | ||
VerifyOrReturnError(controller != nil, CHIP_ERROR_INCORRECT_STATE); | ||
|
||
auto completionHandler = ^(NSError * _Nullable error) { | ||
[controller asyncDispatchToMatterQueue:^() { | ||
if (error != nil) { | ||
auto err = [MTRError errorToCHIPErrorCode:error]; | ||
transfer->Reject(err); | ||
} else { | ||
transfer->Continue(); | ||
} | ||
} errorHandler:^(NSError *) { | ||
// Not much we can do here | ||
}]; | ||
}; | ||
|
||
auto strongDelegate = mDelegate; | ||
dispatch_async( | ||
mDelegateNotificationQueue, ^{ | ||
[strongDelegate handleBDXTransferSessionDataForNodeID:nodeId controller:controller fileDesignator:fileDesignator data:data completion:completionHandler]; | ||
}); | ||
|
||
return CHIP_NO_ERROR; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.