Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ordering issue with subscribeToAttributesWithEndpointID over XPC. #26850

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef void (^MTRGetProxyHandleHandler)(dispatch_queue_t queue, MTRDeviceContro
@interface MTRDeviceControllerXPCConnection<MTRDeviceControllerClientProtocol> : NSObject

/**
* This method is just for test purpsoe.
* This method is just for test purpose.
*/
+ (MTRDeviceControllerXPCConnection *)connectionWithWorkQueue:(dispatch_queue_t)workQueue
connectBlock:(MTRXPCConnectBlock)connectBlock;
Expand All @@ -55,6 +55,7 @@ typedef void (^MTRGetProxyHandleHandler)(dispatch_queue_t queue, MTRDeviceContro
- (void)deregisterReportHandlersWithController:(id<NSCopying>)controller
nodeID:(NSNumber *)nodeID
completion:(dispatch_block_t)completion;
- (void)callSubscriptionEstablishedHandler:(dispatch_block_t)handler;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,11 @@ - (void)handleReportWithController:(id)controller
});
}

- (void)callSubscriptionEstablishedHandler:(dispatch_block_t)handler
{
// Call the handler from our _workQueue, so that we guarantee the same
// number of queue hops as for handleReportWithController.
dispatch_async(_workQueue, handler);
}

@end
18 changes: 10 additions & 8 deletions src/darwin/Framework/CHIP/MTRDeviceOverXPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,16 @@ - (void)subscribeToAttributesWithEndpointID:(NSNumber * _Nullable)endpointID
maxInterval:params.maxInterval
params:[MTRDeviceController encodeXPCSubscribeParams:params]
establishedHandler:^{
dispatch_async(queue, ^{
MTR_LOG_DEBUG("Subscription established");
subscriptionEstablishedHandler();
// The following captures the proxy handle in the closure so that the handle
// won't be released prior to block call.
__auto_type handleRetainer = handle;
(void) handleRetainer;
});
[self.xpcConnection callSubscriptionEstablishedHandler:^{
dispatch_async(queue, ^{
MTR_LOG_DEBUG("Subscription established");
subscriptionEstablishedHandler();
// The following captures the proxy handle in the closure so that the handle
// won't be released prior to block call.
__auto_type handleRetainer = handle;
(void) handleRetainer;
});
}];
}];
};

Expand Down