Skip to content

Commit

Permalink
Remove un-named callbacks and raw integers from Darwin framework API.
Browse files Browse the repository at this point in the history
Switches to typedefs for all the callbacks and using NSNumber for numbers,
except in MTRDeviceController (and the XPC version), which will need some more
complicated changes.

This is a re-landing of PR #22551 but modified to preserve the old APIs.

The header changes not accompanied by backwards-compat shims are OK for the
following reasons:

* MTRAttributeCacheContainer+XPC.h is not public API.
* The change to MTRAttributeCacheContainer.h is both source and binary
  compatible.
* MTRAttributeCacheContainer_Internal.h is not public API.
* The change to MTRBaseDevice's subscribeAttributeWithEndpointId is both source
  and binary compatible.
* The change to MTRBaseDevice's deregisterReportHandlersWithClientQueue is both
  source and binary compatible.
* The change to sharedControllerWithId in MTRDeviceController+XPC.h is both
  source and binary compatible.
* The change to getAnyDeviceControllerWithCompletion in
  MTRDeviceController+XPC.h is both source and binary compatible.
* MTRDeviceControllerOverXPC.h is not public API.
* MTRDeviceControllerXPCConnection.h is not public API.
* MTRDeviceController_Internal.h is not public API.
* MTRDevice_Internal.h is not public API.
* MTRDeviceOverXPC.h is not public API.
* The changes to MTROTAProviderDelegate.h are both source and binary compatible.
  • Loading branch information
bzbarsky-apple committed Oct 27, 2022
1 parent 3b81f3f commit fb91aa6
Show file tree
Hide file tree
Showing 80 changed files with 9,992 additions and 6,715 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ class SubscribeEvent : public ModelCommand {
params.autoResubscribe = mAutoResubscribe.HasValue() ? [NSNumber numberWithBool:mAutoResubscribe.Value()] : nil;

[device subscribeWithQueue:callbackQueue
minInterval:mMinInterval
maxInterval:mMaxInterval
minInterval:@(mMinInterval)
maxInterval:@(mMaxInterval)
params:params
cacheContainer:nil
attributeCacheContainer:nil
attributeReportHandler:^(NSArray * value) {
SetCommandExitStatus(CHIP_NO_ERROR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
constexpr const char * identities[] = { kIdentityAlpha, kIdentityBeta, kIdentityGamma };
for (size_t i = 0; i < ArraySize(identities); ++i) {
auto controllerParams = [[MTRDeviceControllerStartupParams alloc] initWithSigningKeypair:gNocSigner
fabricId:(i + 1)
fabricID:@(i + 1)
ipk:ipk];

// We're not sure whether we're creating a new fabric or using an
Expand Down Expand Up @@ -201,7 +201,7 @@
constexpr const char * identities[] = { kIdentityAlpha, kIdentityBeta, kIdentityGamma };
for (size_t i = 0; i < ArraySize(identities); ++i) {
auto controllerParams = [[MTRDeviceControllerStartupParams alloc] initWithSigningKeypair:gNocSigner
fabricId:(i + 1)
fabricID:@(i + 1)
ipk:ipk];

auto controller = [factory startControllerOnExistingFabric:controllerParams];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

auto * self = this;
if (mCommissioningWindowOption == 0) {
auto * cluster = [[MTRClusterAdministratorCommissioning alloc] initWithDevice:device endpoint:0 queue:mWorkQueue];
auto * cluster = [[MTRClusterAdministratorCommissioning alloc] initWithDevice:device endpointID:@(0) queue:mWorkQueue];
auto * params = [[MTRAdministratorCommissioningClusterOpenBasicCommissioningWindowParams alloc] init];
params.commissioningTimeout = @(mCommissioningWindowTimeoutMs);
params.timedInvokeTimeoutMs = @(10000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
} else {
ChipLogProgress(chipTool, "Attempting to unpair device %llu", mNodeId);
MTRBaseClusterOperationalCredentials * opCredsCluster =
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpoint:0 queue:callbackQueue];
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpointID:@(0) queue:callbackQueue];
[opCredsCluster readAttributeCurrentFabricIndexWithCompletionHandler:^(
NSNumber * _Nullable value, NSError * _Nullable readError) {
if (readError) {
Expand Down
8 changes: 4 additions & 4 deletions examples/darwin-framework-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public:
ChipLogProgress(chipTool, "Sending cluster ({{asHex parent.code 8}}) command ({{asHex code 8}}) on endpoint %u", endpointId);

dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
MTRBaseCluster{{asUpperCamelCase clusterName}} * cluster = [[MTRBaseCluster{{asUpperCamelCase clusterName}} alloc] initWithDevice:device endpoint:endpointId queue:callbackQueue];
MTRBaseCluster{{asUpperCamelCase clusterName}} * cluster = [[MTRBaseCluster{{asUpperCamelCase clusterName}} alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue];
__auto_type * params = [[MTR{{asUpperCamelCase clusterName}}Cluster{{asUpperCamelCase name}}Params alloc] init];
params.timedInvokeTimeoutMs = mTimedInteractionTimeoutMs.HasValue() ? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()] : nil;
{{#chip_cluster_command_arguments}}
Expand Down Expand Up @@ -111,7 +111,7 @@ public:
ChipLogProgress(chipTool, "Sending cluster ({{asHex parent.code 8}}) ReadAttribute ({{asHex code 8}}) on endpoint %u", endpointId);

dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
MTRBaseCluster{{asUpperCamelCase parent.name}} * cluster = [[MTRBaseCluster{{asUpperCamelCase parent.name}} alloc] initWithDevice:device endpoint:endpointId queue:callbackQueue];
MTRBaseCluster{{asUpperCamelCase parent.name}} * cluster = [[MTRBaseCluster{{asUpperCamelCase parent.name}} alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue];
{{#if_is_fabric_scoped_struct type}}
MTRReadParams * params = [[MTRReadParams alloc] init];
params.fabricFiltered = mFabricFiltered.HasValue() ? [NSNumber numberWithBool:mFabricFiltered.Value()] : nil;
Expand Down Expand Up @@ -161,7 +161,7 @@ public:
{
ChipLogProgress(chipTool, "Sending cluster ({{asHex parent.code 8}}) WriteAttribute ({{asHex code 8}}) on endpoint %u", endpointId);
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
MTRBaseCluster{{asUpperCamelCase parent.name}} * cluster = [[MTRBaseCluster{{asUpperCamelCase parent.name}} alloc] initWithDevice:device endpoint:endpointId queue:callbackQueue];
MTRBaseCluster{{asUpperCamelCase parent.name}} * cluster = [[MTRBaseCluster{{asUpperCamelCase parent.name}} alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue];
MTRWriteParams * params = [[MTRWriteParams alloc] init];
params.timedWriteTimeout = mTimedInteractionTimeoutMs.HasValue() ? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()] : nil;
params.dataVersion = mDataVersion.HasValue() ? [NSNumber numberWithUnsignedInt:mDataVersion.Value()] : nil;
Expand Down Expand Up @@ -215,7 +215,7 @@ public:
{
ChipLogProgress(chipTool, "Sending cluster ({{asHex parent.code 8}}) ReportAttribute ({{asHex code 8}}) on endpoint %u", endpointId);
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
MTRBaseCluster{{asUpperCamelCase parent.name}} * cluster = [[MTRBaseCluster{{asUpperCamelCase parent.name}} alloc] initWithDevice:device endpoint:endpointId queue:callbackQueue];
MTRBaseCluster{{asUpperCamelCase parent.name}} * cluster = [[MTRBaseCluster{{asUpperCamelCase parent.name}} alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue];
MTRSubscribeParams * params = [[MTRSubscribeParams alloc] init];
params.keepPreviousSubscriptions = mKeepSubscriptions.HasValue() ? [NSNumber numberWithBool:mKeepSubscriptions.Value()] : nil;
params.fabricFiltered = mFabricFiltered.HasValue() ? [NSNumber numberWithBool:mFabricFiltered.Value()] : nil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class {{filename}}: public TestCommandBridge
return {{command}}("{{identity}}", value);
{{else}}
MTRBaseDevice * device = GetDevice("{{identity}}");
MTRBaseCluster{{asUpperCamelCase cluster}} * cluster = [[MTRBaseCluster{{asUpperCamelCase cluster}} alloc] initWithDevice:device endpoint:{{endpoint}} queue:mCallbackQueue];
MTRBaseCluster{{asUpperCamelCase cluster}} * cluster = [[MTRBaseCluster{{asUpperCamelCase cluster}} alloc] initWithDevice:device endpointID:@({{endpoint}}) queue:mCallbackQueue];
VerifyOrReturnError(cluster != nil, CHIP_ERROR_INCORRECT_STATE);

{{#if isCommand}}
Expand Down
2 changes: 2 additions & 0 deletions src/app/zap-templates/partials/header.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
* limitations under the License.
*/

{{#unless excludeZapComment}}
// THIS FILE IS GENERATED BY ZAP
{{/unless}}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void MTRSetNextAvailableDeviceID(uint64_t id)
return;
}

__auto_type * params = [[MTRDeviceControllerStartupParams alloc] initWithSigningKeypair:keys fabricId:1 ipk:keys.ipk];
__auto_type * params = [[MTRDeviceControllerStartupParams alloc] initWithSigningKeypair:keys fabricId:@(1) ipk:keys.ipk];
params.vendorId = @(kTestVendorId);

// We're not sure whether we have a fabric configured already; try as if
Expand All @@ -113,7 +113,7 @@ void MTRSetNextAvailableDeviceID(uint64_t id)
[controller shutdown];

NSLog(@"Starting up the stack");
__auto_type * params = [[MTRDeviceControllerStartupParams alloc] initWithSigningKeypair:keys fabricId:1 ipk:keys.ipk];
__auto_type * params = [[MTRDeviceControllerStartupParams alloc] initWithSigningKeypair:keys fabricId:@(1) ipk:keys.ipk];

sController = [[MTRControllerFactory sharedInstance] startControllerOnExistingFabric:params];

Expand Down Expand Up @@ -180,7 +180,7 @@ void MTRUnpairDeviceWithID(uint64_t deviceId)
}
NSLog(@"Attempting to unpair device %llu", deviceId);
MTRBaseClusterOperationalCredentials * opCredsCluster =
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpoint:0 queue:dispatch_get_main_queue()];
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpoint:@(0) queue:dispatch_get_main_queue()];
[opCredsCluster
readAttributeCurrentFabricIndexWithCompletionHandler:^(NSNumber * _Nullable value, NSError * _Nullable error) {
if (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ - (void)enumerate
}

MTRBaseClusterDescriptor * descriptorCluster = [[MTRBaseClusterDescriptor alloc] initWithDevice:device
endpoint:0
endpoint:@(0)
queue:dispatch_get_main_queue()];
NSLog(@"Reading parts list to get list of endpoints in use...");
[descriptorCluster readAttributePartsListWithCompletionHandler:^(
Expand All @@ -132,9 +132,7 @@ - (void)enumerate

for (NSNumber * endpoint in endpointsInUse) {
MTRBaseClusterDescriptor * descriptorCluster =
[[MTRBaseClusterDescriptor alloc] initWithDevice:device
endpoint:[endpoint unsignedShortValue]
queue:dispatch_get_main_queue()];
[[MTRBaseClusterDescriptor alloc] initWithDevice:device endpoint:endpoint queue:dispatch_get_main_queue()];
[descriptorCluster readAttributeDeviceListWithCompletionHandler:^(
NSArray * _Nullable value, NSError * _Nullable error) {
if (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ - (void)fetchCommissionedFabricsNumber
if (chipDevice) {
MTRBaseClusterOperationalCredentials * cluster =
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:chipDevice
endpoint:0
endpoint:@(0)
queue:dispatch_get_main_queue()];
[cluster
readAttributeCurrentFabricIndexWithCompletionHandler:^(NSNumber * _Nullable value, NSError * _Nullable error) {
Expand Down Expand Up @@ -270,7 +270,7 @@ - (void)fetchFabricsList
if (chipDevice) {
MTRBaseClusterOperationalCredentials * cluster =
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:chipDevice
endpoint:0
endpoint:@(0)
queue:dispatch_get_main_queue()];
[self updateResult:[NSString stringWithFormat:@"readAttributeFabrics command sent."] isError:NO];
MTRReadParams * params = [[MTRReadParams alloc] init];
Expand Down Expand Up @@ -332,7 +332,7 @@ - (IBAction)removeAllFabricsButtonPressed:(id)sender

MTRBaseClusterOperationalCredentials * opCredsCluster =
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:chipDevice
endpoint:0
endpoint:@(0)
queue:dispatch_get_main_queue()];

dispatch_group_t removeGroup = dispatch_group_create();
Expand Down Expand Up @@ -404,7 +404,7 @@ - (IBAction)updateFabricLabelButtonPressed:(id)sender
if (chipDevice) {
MTRBaseClusterOperationalCredentials * cluster =
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:chipDevice
endpoint:0
endpoint:@(0)
queue:dispatch_get_main_queue()];
[self updateResult:[NSString stringWithFormat:@"updateFabricLabel command sent."] isError:NO];
__auto_type * params = [[MTROperationalCredentialsClusterUpdateFabricLabelParams alloc] init];
Expand Down Expand Up @@ -460,7 +460,7 @@ - (IBAction)removeFabricButtonPressed:(id)sender
isError:NO];
MTRBaseClusterOperationalCredentials * opCredsCluster =
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:chipDevice
endpoint:0
endpoint:@(0)
queue:dispatch_get_main_queue()];
MTROperationalCredentialsClusterRemoveFabricParams * params =
[[MTROperationalCredentialsClusterRemoveFabricParams alloc] init];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ - (IBAction)onButtonTapped:(id)sender
if (MTRGetConnectedDeviceWithID(deviceId, ^(MTRBaseDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (chipDevice) {
MTRBaseClusterOnOff * onOff = [[MTRBaseClusterOnOff alloc] initWithDevice:chipDevice
endpoint:endpoint
endpoint:@(endpoint)
queue:dispatch_get_main_queue()];
[onOff onWithCompletionHandler:^(NSError * error) {
NSString * resultString = (error != nil)
Expand Down Expand Up @@ -269,7 +269,7 @@ - (IBAction)offButtonTapped:(id)sender
if (MTRGetConnectedDeviceWithID(deviceId, ^(MTRBaseDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (chipDevice) {
MTRBaseClusterOnOff * onOff = [[MTRBaseClusterOnOff alloc] initWithDevice:chipDevice
endpoint:endpoint
endpoint:@(endpoint)
queue:dispatch_get_main_queue()];
[onOff offWithCompletionHandler:^(NSError * error) {
NSString * resultString = (error != nil)
Expand Down Expand Up @@ -298,7 +298,7 @@ - (IBAction)toggleButtonTapped:(id)sender
if (MTRGetConnectedDeviceWithID(deviceId, ^(MTRBaseDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (chipDevice) {
MTRBaseClusterOnOff * onOff = [[MTRBaseClusterOnOff alloc] initWithDevice:chipDevice
endpoint:endpoint
endpoint:@(endpoint)
queue:dispatch_get_main_queue()];
[onOff toggleWithCompletionHandler:^(NSError * error) {
NSString * resultString = (error != nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ - (void)readCurrentTemperature
if (chipDevice) {
MTRBaseClusterTemperatureMeasurement * cluster =
[[MTRBaseClusterTemperatureMeasurement alloc] initWithDevice:chipDevice
endpoint:1
endpoint:@(1)
queue:dispatch_get_main_queue()];

[cluster readAttributeMeasuredValueWithCompletionHandler:^(NSNumber * _Nullable value, NSError * _Nullable error) {
Expand Down Expand Up @@ -223,10 +223,10 @@ - (void)reportFromUserEnteredSettings
if (chipDevice) {
// Use a wildcard subscription
[chipDevice subscribeWithQueue:dispatch_get_main_queue()
minInterval:minIntervalSeconds
maxInterval:maxIntervalSeconds
minInterval:@(minIntervalSeconds)
maxInterval:@(maxIntervalSeconds)
params:nil
cacheContainer:nil
attributeCacheContainer:nil
attributeReportHandler:^(NSArray * _Nullable reports) {
if (!reports)
return;
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRAttributeCacheContainer+XPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface MTRAttributeCacheContainer (XPC)
- (void)setXPCConnection:(MTRDeviceControllerXPCConnection *)xpcConnection
controllerId:(id<NSCopying>)controllerId
deviceId:(uint64_t)deviceId;
deviceId:(NSNumber *)deviceId;
@end

NS_ASSUME_NONNULL_END
4 changes: 2 additions & 2 deletions src/darwin/Framework/CHIP/MTRAttributeCacheContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#import <Foundation/Foundation.h>

#import <Matter/MTRBaseDevice.h>
#import <Matter/MTRDeviceController.h>

NS_ASSUME_NONNULL_BEGIN
Expand All @@ -40,8 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
clusterId:(NSNumber * _Nullable)clusterId
attributeId:(NSNumber * _Nullable)attributeId
clientQueue:(dispatch_queue_t)clientQueue
completion:(void (^)(NSArray<NSDictionary<NSString *, id> *> * _Nullable values,
NSError * _Nullable error))completion;
completion:(MTRDeviceResponseHandler)completion;

@end

Expand Down
Loading

0 comments on commit fb91aa6

Please sign in to comment.