Skip to content

Commit

Permalink
Fix ordering issue with subscribeToAttributesWithEndpointID over XPC. (
Browse files Browse the repository at this point in the history
…#26850)

We had an extra queue hop for reports compared with the subscriptionEstablished
notification, so the API consumer could get subscriptionEstablished before
getting all the priming reports.

The fix is to just ensure that the code flows the same way, in terms of queue
dispatch, for both priming reports and subscriptionEstablished.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Nov 10, 2023
1 parent 58d53f4 commit 1731593
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/darwin/Framework/CHIP/MTRDeviceControllerXPCConnection.h
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
7 changes: 7 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceControllerXPCConnection.mm
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

0 comments on commit 1731593

Please sign in to comment.