Skip to content

Commit

Permalink
[Darwin] Implemented download diagnostics log for MTRDevice_XPC
Browse files Browse the repository at this point in the history
- Implemented the downloadLogOfType API on MTRDevice_XPC to call into
  XPC server to forward the request
- Fixed the protocol to take controllerID which is missing from existing
  protocol
  • Loading branch information
anush-apple committed Oct 9, 2024
1 parent 12fe9df commit 96eae59
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/darwin/Framework/CHIP/MTRDevice_XPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,39 @@ - (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
}
}

- (void)downloadLogOfType:(MTRDiagnosticLogType)type
timeout:(NSTimeInterval)timeout
queue:(dispatch_queue_t)queue
completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion
{
NSXPCConnection * xpcConnection = [(MTRDeviceController_XPC *) [self deviceController] xpcConnection];

@try {
[[xpcConnection remoteObjectProxyWithErrorHandler:^(NSError * _Nonnull error) {
MTR_LOG_ERROR("Error: %@", error);
dispatch_async(queue, ^{
completion(nil, [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeGeneralError userInfo:nil]);
});
}] deviceController:[[self deviceController] uniqueIdentifier]
nodeID:[self nodeID]
downloadLogOfType:type
timeout:timeout
completion:^(NSURL * _Nullable url, NSError * _Nullable error) {
dispatch_async(queue, ^{
completion(url, error);
if (url) {
[[NSFileManager defaultManager] removeItemAtPath:url.path error:nil];
}
});
}];
} @catch (NSException * exception) {
MTR_LOG_ERROR("Exception sending XPC messsage: %@", exception);
dispatch_async(queue, ^{
completion(nil, [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeGeneralError userInfo:nil]);
});
}
}

// Not Supported via XPC
//- (oneway void)deviceController:(NSUUID *)controller nodeID:(NSNumber *)nodeID openCommissioningWindowWithSetupPasscode:(NSNumber *)setupPasscode discriminator:(NSNumber *)discriminator duration:(NSNumber *)duration completion:(MTRDeviceOpenCommissioningWindowHandler)completion;
//- (oneway void)deviceController:(NSUUID *)controller nodeID:(NSNumber *)nodeID openCommissioningWindowWithDiscriminator:(NSNumber *)discriminator duration:(NSNumber *)duration completion:(MTRDeviceOpenCommissioningWindowHandler)completion;
Expand Down
4 changes: 4 additions & 0 deletions src/darwin/Framework/CHIP/XPC Protocol/MTRXPCServerProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ MTR_NEWLY_AVAILABLE
- (oneway void)deviceController:(NSUUID *)controller nodeID:(NSNumber *)nodeID openCommissioningWindowWithSetupPasscode:(NSNumber *)setupPasscode discriminator:(NSNumber *)discriminator duration:(NSNumber *)duration completion:(MTRDeviceOpenCommissioningWindowHandler)completion;

- (oneway void)downloadLogOfType:(MTRDiagnosticLogType)type nodeID:(NSNumber *)nodeID timeout:(NSTimeInterval)timeout completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion;

@optional
- (oneway void)deviceController:(NSUUID *)controller nodeID:(NSNumber *)nodeID downloadLogOfType:(MTRDiagnosticLogType)type timeout:(NSTimeInterval)timeout completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion;

@end

MTR_NEWLY_AVAILABLE
Expand Down

0 comments on commit 96eae59

Please sign in to comment.