Skip to content

Commit

Permalink
fix log result only one URL needed
Browse files Browse the repository at this point in the history
  • Loading branch information
nivi-apple committed Oct 16, 2023
1 parent e6442f8 commit ae33c61
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
24 changes: 1 addition & 23 deletions src/darwin/Framework/CHIP/MTRDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,6 @@ typedef NS_ENUM(NSInteger, MTRDiagnosticLogType) {

@protocol MTRDeviceDelegate;

@interface MTRDiagnosticLogResult : NSObject

/**
* The URL representing the location of the end user support log file that was downloaded.
* If no end user support log was requested or retrieved, this will be set to nil.
*/
@property (readonly, nonatomic, nullable) NSURL * endUserSupportLog;

/**
* The URL representing the location of the network diagnostics log file that was downloaded.
* If no network diagnostics log was requested or retreived, this will be set to nil.
*/
@property (readonly, nonatomic, nullable) NSURL * networkDiagnosticsLog;

/**
* The URL representing the location of the crash log file that was downloaded.
* If no crash log was requested or retrieved, this will be set to nil.
*/
@property (readonly, nonatomic, nullable) NSURL * crashLog;

@end

@interface MTRDevice : NSObject
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
Expand Down Expand Up @@ -251,7 +229,7 @@ typedef NS_ENUM(NSInteger, MTRDiagnosticLogType) {
- (void)downloadLogOfType:(MTRDiagnosticLogType)type
timeout:(NSTimeInterval)timeout
queue:(dispatch_queue_t)queue
completion:(void (^)(MTRDiagnosticLogResult * _Nullable logResult, NSError * error))completion;
completion:(void (^)(NSURL * _Nullable logResult, NSError * error))completion;

@end

Expand Down
22 changes: 15 additions & 7 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@
*/

#import <Matter/MTRDefines.h>
#import <Matter/MTRClusters.h>
#import <os/lock.h>

#import "MTRAsyncWorkQueue_Internal.h"
#import "MTRAttributeSpecifiedCheck.h"
#import "MTRBaseDevice_Internal.h"
#import "MTRBaseSubscriptionCallback.h"
#import "MTRCluster.h"
#import <Matter/MTRClusters.h>
#import "MTRClusters_Internal.h"
#import "MTRClusterConstants.h"
#import "MTRDeviceController_Internal.h"
#import "MTRDevice_Internal.h"
#import "MTRError_Internal.h"
#import "MTREventTLVValueDecoder_Internal.h"
#import "MTRLogging_Internal.h"
#include "MTRDiagnosticLogsTransferHandler.h"
#import "NSDataSpanConversion.h"
#import "NSStringSpanConversion.h"

#include "lib/core/CHIPError.h"
#include "lib/core/DataModelTypes.h"
Expand All @@ -43,6 +44,7 @@
#include <app/InteractionModelEngine.h>
#include <controller/CHIPDeviceControllerFactory.h>
#include <platform/PlatformManager.h>
#include "MTRDiagnosticLogsTransferHandler.h"

typedef void (^MTRDeviceAttributeReportHandler)(NSArray * _Nonnull);

Expand Down Expand Up @@ -1182,7 +1184,7 @@ - (NSString*)getFileDesignatorForLogType:(MTRDiagnosticLogType)type
- (void)_downloadLogOfType:(MTRDiagnosticLogType)type
timeout:(NSTimeInterval)timeout
queue:(dispatch_queue_t)queue
completion:(void (^)(MTRDiagnosticLogResult * _Nullable logResult, NSError * error))completion
completion:(void (^)(NSURL * _Nullable logResult, NSError * error))completion
{
if (type != MTRDiagnosticLogTypeEndUserSupport && type != MTRDiagnosticLogTypeNetworkDiagnostics && type != MTRDiagnosticLogTypeCrash)
{
Expand Down Expand Up @@ -1240,15 +1242,21 @@ - (void)_downloadLogOfType:(MTRDiagnosticLogType)type
requestParams.requestedProtocol = [NSNumber numberWithUnsignedChar:chip::to_underlying(chip::app::Clusters::DiagnosticLogs::TransferProtocolEnum::kBdx)];
requestParams.transferFileDesignator = [self getFileDesignatorForLogType:type];

[cluster retrieveLogsRequestWithParams:requestParams expectedValues:nil expectedValueInterval:nil completion:^(MTRDiagnosticLogsClusterRetrieveLogsResponseParams * _Nullable data, NSError * _Nullable error) {
[cluster retrieveLogsRequestWithParams:requestParams expectedValues:nil expectedValueInterval:nil completion:^(MTRDiagnosticLogsClusterRetrieveLogsResponseParams * _Nullable response, NSError * _Nullable error) {
if (error)
{
completion(nil, error);
return;
}
if (data != nil && data.logContent != nil)
if (response != nil && response.logContent != nil)
{
// Write the log content to the filepath URL and create the MTRDiagnosticLogResult and pass it.
if ([response.logContent writeToURL:filePath atomically:YES])
{
completion(filePath, nil);
} else {
NSError * error = [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeInvalidState userInfo:nil];
completion(nil, error);
}

//completion(data, error);
}
Expand All @@ -1258,7 +1266,7 @@ - (void)_downloadLogOfType:(MTRDiagnosticLogType)type
- (void)downloadLogOfType:(MTRDiagnosticLogType)type
timeout:(NSTimeInterval)timeout
queue:(dispatch_queue_t)queue
completion:(void (^)(MTRDiagnosticLogResult * _Nullable logResult, NSError * error))completion
completion:(void (^)(NSURL * _Nullable logResult, NSError * error))completion
{
[self _downloadLogOfType:type timeout:timeout queue:queue completion:completion];
}
Expand Down

0 comments on commit ae33c61

Please sign in to comment.