Skip to content

Commit 1013520

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Revert, for now, Darwin API changes that did not happen early enough. (#23155)
This PR was generated by doing the following: 1. Revert the following commits, in order, resolving minor conflicts in generated code along the way: * af09de0 * b829121 * a7475d3 * 7301ecf * 2060105 * 8e2c926 * f72807b * 5d140df * 2aaf589 * 46b4649 * 2466360 * 7862371 * 9989fc1 (only the parts in the Darwin framework and darwin-framework-tool, so not via git revert) * e3160eb * e62b0f1 * bae0bc7 * 8e1c833 * 1e66f4b * 5757068 * 6527ae3 * 8c4675f * 91db05d * 72d838a * bad4408 * 9c131da * 5caec5a * cdb4969 * 9ababd1 * 6a45e43 * 81f7284 * 43d7fd2 * b89aa66 2. Pick up the ZAP change to undo the Darwin casing changes in ZAP. 3. Rerun ZAP codegen to pick up some changes to the generated code for some of the commits that were not reverted. 4. Cherry-pick the following commits (which were reverted above, to reduce potential conflicts), in order, resolving conflicts as needed: * 81f7284 * 2466360 * 46b4649 * f72807b * 8e2c926 * 2060105 * 7301ecf * a7475d3 * b829121 * af09de0 5. Make computePaseVerifier an instance method on MTRDeviceController again. 6. Make manual changes to the MTRClusters, MTRBaseClusters, MTRClusterConstants, MTRStructsObjc zapt files to keep the "DeviceList" naming in the APIs for reading and subscribing to "DeviceTypeList" and the "DeviceType" naming for "DeviceTypeStruct". Make corresponding changes to darwin-framework-tool codegen as well. 7. Manually re-mark the attributes in MTROptionalQRCodeInfo and MTRSetupPayload that can be nil as nullable. 8. Manually add back documentation for MTROTAHeader and mark the properties on it that can be nil as nullable. 9. Manually add back the leak fix from 6527ae3.
1 parent b08037d commit 1013520

File tree

144 files changed

+102880
-93345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+102880
-93345
lines changed

examples/darwin-framework-tool/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ executable("darwin-framework-tool") {
112112
"commands/common/MTRError_Utils.h",
113113
"commands/common/MTRLogging.h",
114114
"commands/pairing/Commands.h",
115-
"commands/pairing/DeviceControllerDelegateBridge.mm",
116115
"commands/pairing/OpenCommissioningWindowCommand.h",
117116
"commands/pairing/OpenCommissioningWindowCommand.mm",
118117
"commands/pairing/PairingCommandBridge.mm",
118+
"commands/pairing/PairingDelegateBridge.mm",
119119
"commands/payload/SetupPayloadParseCommand.mm",
120120
"commands/provider/Commands.h",
121121
"commands/provider/OTAProviderDelegate.mm",

examples/darwin-framework-tool/commands/clusters/ClusterCommandBridge.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ class ClusterCommand : public ModelCommand {
7474
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
7575

7676
while (repeatCount--) {
77-
[device invokeCommandWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
78-
clusterID:[NSNumber numberWithUnsignedInteger:clusterId]
79-
commandID:[NSNumber numberWithUnsignedInteger:commandId]
77+
[device invokeCommandWithEndpointId:[NSNumber numberWithUnsignedShort:endpointId]
78+
clusterId:[NSNumber numberWithUnsignedInteger:clusterId]
79+
commandId:[NSNumber numberWithUnsignedInteger:commandId]
8080
commandFields:commandFields
8181
timedInvokeTimeout:mTimedInteractionTimeoutMs.HasValue()
8282
? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()]
8383
: nil
84-
queue:callbackQueue
84+
clientQueue:callbackQueue
8585
completion:^(
8686
NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
8787
responsesNeeded--;

examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.mm

+22-6
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,31 @@
2525

2626
CHIP_ERROR ModelCommand::RunCommand()
2727
{
28+
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip-tool.command", DISPATCH_QUEUE_SERIAL);
29+
2830
MTRDeviceController * commissioner = CurrentCommissioner();
2931
ChipLogProgress(chipTool, "Sending command to node 0x" ChipLogFormatX64, ChipLogValueX64(mNodeId));
30-
auto * device = [MTRBaseDevice deviceWithNodeID:@(mNodeId) controller:commissioner];
31-
CHIP_ERROR err = SendCommand(device, mEndPointId);
32+
[commissioner getBaseDevice:mNodeId
33+
queue:callbackQueue
34+
completionHandler:^(MTRBaseDevice * _Nullable device, NSError * _Nullable error) {
35+
if (error != nil) {
36+
SetCommandExitStatus(error, "Error getting connected device");
37+
return;
38+
}
39+
40+
CHIP_ERROR err;
41+
if (device == nil) {
42+
err = CHIP_ERROR_INTERNAL;
43+
} else {
44+
err = SendCommand(device, mEndPointId);
45+
}
3246

33-
if (err != CHIP_NO_ERROR) {
34-
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(err));
35-
return err;
36-
}
47+
if (err != CHIP_NO_ERROR) {
48+
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(err));
49+
SetCommandExitStatus(err);
50+
return;
51+
}
52+
}];
3753
return CHIP_NO_ERROR;
3854
}
3955

examples/darwin-framework-tool/commands/clusters/ReportCommandBridge.h

+36-43
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,24 @@ class ReadAttribute : public ModelCommand {
5454
{
5555
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
5656
MTRReadParams * params = [[MTRReadParams alloc] init];
57-
if (mFabricFiltered.HasValue()) {
58-
params.fabricFiltered = mFabricFiltered.Value();
59-
}
60-
[device readAttributePathWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
61-
clusterID:[NSNumber numberWithUnsignedInteger:mClusterId]
62-
attributeID:[NSNumber numberWithUnsignedInteger:mAttributeId]
63-
params:params
64-
queue:callbackQueue
65-
completion:^(
66-
NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
67-
if (error != nil) {
68-
LogNSError("Error reading attribute", error);
69-
}
70-
if (values) {
71-
for (id item in values) {
72-
NSLog(@"Response Item: %@", [item description]);
73-
}
74-
}
75-
SetCommandExitStatus(error);
76-
}];
57+
params.fabricFiltered = mFabricFiltered.HasValue() ? [NSNumber numberWithBool:mFabricFiltered.Value()] : nil;
58+
[device
59+
readAttributeWithEndpointId:[NSNumber numberWithUnsignedShort:endpointId]
60+
clusterId:[NSNumber numberWithUnsignedInteger:mClusterId]
61+
attributeId:[NSNumber numberWithUnsignedInteger:mAttributeId]
62+
params:params
63+
clientQueue:callbackQueue
64+
completion:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
65+
if (error != nil) {
66+
LogNSError("Error reading attribute", error);
67+
}
68+
if (values) {
69+
for (id item in values) {
70+
NSLog(@"Response Item: %@", [item description]);
71+
}
72+
}
73+
SetCommandExitStatus(error);
74+
}];
7775
return CHIP_NO_ERROR;
7876
}
7977

@@ -126,22 +124,18 @@ class SubscribeAttribute : public ModelCommand {
126124
{
127125
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
128126

129-
MTRSubscribeParams * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(mMinInterval) maxInterval:@(mMaxInterval)];
130-
if (mFabricFiltered.HasValue()) {
131-
params.fabricFiltered = mFabricFiltered.Value();
132-
}
133-
if (mKeepSubscriptions.HasValue()) {
134-
params.keepPreviousSubscriptions = mKeepSubscriptions.Value();
135-
}
136-
if (mAutoResubscribe.HasValue()) {
137-
params.autoResubscribe = mAutoResubscribe.Value();
138-
}
139-
140-
[device subscribeAttributePathWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
141-
clusterID:[NSNumber numberWithUnsignedInteger:mClusterId]
142-
attributeID:[NSNumber numberWithUnsignedInteger:mAttributeId]
127+
MTRSubscribeParams * params = [[MTRSubscribeParams alloc] init];
128+
params.keepPreviousSubscriptions
129+
= mKeepSubscriptions.HasValue() ? [NSNumber numberWithBool:mKeepSubscriptions.Value()] : nil;
130+
params.autoResubscribe = mAutoResubscribe.HasValue() ? [NSNumber numberWithBool:mAutoResubscribe.Value()] : nil;
131+
132+
[device subscribeAttributeWithEndpointId:[NSNumber numberWithUnsignedShort:endpointId]
133+
clusterId:[NSNumber numberWithUnsignedInteger:mClusterId]
134+
attributeId:[NSNumber numberWithUnsignedInteger:mAttributeId]
135+
minInterval:[NSNumber numberWithUnsignedInteger:mMinInterval]
136+
maxInterval:[NSNumber numberWithUnsignedInteger:mMaxInterval]
143137
params:params
144-
queue:callbackQueue
138+
clientQueue:callbackQueue
145139
reportHandler:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
146140
if (values) {
147141
for (id item in values) {
@@ -198,17 +192,16 @@ class SubscribeEvent : public ModelCommand {
198192
{
199193
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
200194

201-
MTRSubscribeParams * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(mMinInterval) maxInterval:@(mMaxInterval)];
202-
if (mKeepSubscriptions.HasValue()) {
203-
params.keepPreviousSubscriptions = mKeepSubscriptions.Value();
204-
}
205-
if (mAutoResubscribe.HasValue()) {
206-
params.autoResubscribe = mAutoResubscribe.Value();
207-
}
195+
MTRSubscribeParams * params = [[MTRSubscribeParams alloc] init];
196+
params.keepPreviousSubscriptions
197+
= mKeepSubscriptions.HasValue() ? [NSNumber numberWithBool:mKeepSubscriptions.Value()] : nil;
198+
params.autoResubscribe = mAutoResubscribe.HasValue() ? [NSNumber numberWithBool:mAutoResubscribe.Value()] : nil;
208199

209200
[device subscribeWithQueue:callbackQueue
201+
minInterval:mMinInterval
202+
maxInterval:mMaxInterval
210203
params:params
211-
clusterStateCacheContainer:nil
204+
cacheContainer:nil
212205
attributeReportHandler:^(NSArray * value) {
213206
SetCommandExitStatus(CHIP_NO_ERROR);
214207
}

examples/darwin-framework-tool/commands/clusters/WriteAttributeCommandBridge.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ class WriteAttribute : public ModelCommand {
7474
{
7575
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
7676
[device
77-
writeAttributeWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
78-
clusterID:[NSNumber numberWithUnsignedInteger:clusterId]
79-
attributeID:[NSNumber numberWithUnsignedInteger:attributeId]
77+
writeAttributeWithEndpointId:[NSNumber numberWithUnsignedShort:endpointId]
78+
clusterId:[NSNumber numberWithUnsignedInteger:clusterId]
79+
attributeId:[NSNumber numberWithUnsignedInteger:attributeId]
8080
value:value
8181
timedWriteTimeout:mTimedInteractionTimeoutMs.HasValue()
8282
? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()]
8383
: nil
84-
queue:callbackQueue
84+
clientQueue:callbackQueue
8585
completion:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
8686
if (error != nil) {
8787
LogNSError("Error writing attribute", error);

examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm

+18-15
Original file line numberDiff line numberDiff line change
@@ -111,26 +111,25 @@
111111

112112
mOTADelegate = [[OTAProviderDelegate alloc] init];
113113

114-
auto factory = [MTRDeviceControllerFactory sharedInstance];
114+
auto factory = [MTRControllerFactory sharedInstance];
115115
if (factory == nil) {
116116
ChipLogError(chipTool, "Controller factory is nil");
117117
return CHIP_ERROR_INTERNAL;
118118
}
119119

120-
auto params = [[MTRDeviceControllerFactoryParams alloc] initWithStorage:storage];
120+
auto params = [[MTRControllerFactoryParams alloc] initWithStorage:storage];
121121
params.port = @(kListenPort);
122-
params.shouldStartServer = YES;
122+
params.startServer = YES;
123123
params.otaProviderDelegate = mOTADelegate;
124124
NSArray<NSData *> * paaCertResults;
125125
ReturnLogErrorOnFailure(GetPAACertsFromFolder(&paaCertResults));
126126
if ([paaCertResults count] > 0) {
127127
params.paaCerts = paaCertResults;
128128
}
129129

130-
NSError * error;
131-
if ([factory startControllerFactory:params error:&error] == NO) {
130+
if ([factory startup:params] == NO) {
132131
ChipLogError(chipTool, "Controller factory startup failed");
133-
return MTRErrorToCHIPErrorCode(error);
132+
return CHIP_ERROR_INTERNAL;
134133
}
135134

136135
ReturnLogErrorOnFailure([gNocSigner createOrLoadKeys:storage]);
@@ -139,19 +138,21 @@
139138

140139
constexpr const char * identities[] = { kIdentityAlpha, kIdentityBeta, kIdentityGamma };
141140
for (size_t i = 0; i < ArraySize(identities); ++i) {
142-
auto controllerParams = [[MTRDeviceControllerStartupParams alloc] initWithIPK:ipk fabricID:@(i + 1) nocSigner:gNocSigner];
141+
auto controllerParams = [[MTRDeviceControllerStartupParams alloc] initWithSigningKeypair:gNocSigner
142+
fabricId:(i + 1)
143+
ipk:ipk];
143144

144145
// We're not sure whether we're creating a new fabric or using an
145146
// existing one, so just try both.
146-
auto controller = [factory createControllerOnExistingFabric:controllerParams error:&error];
147+
auto controller = [factory startControllerOnExistingFabric:controllerParams];
147148
if (controller == nil) {
148149
// Maybe we didn't have this fabric yet.
149-
controllerParams.vendorID = @(chip::VendorId::TestVendor1);
150-
controller = [factory createControllerOnNewFabric:controllerParams error:&error];
150+
controllerParams.vendorId = @(chip::VendorId::TestVendor1);
151+
controller = [factory startControllerOnNewFabric:controllerParams];
151152
}
152153
if (controller == nil) {
153154
ChipLogError(chipTool, "Controller startup failure.");
154-
return MTRErrorToCHIPErrorCode(error);
155+
return CHIP_ERROR_INTERNAL;
155156
}
156157

157158
mControllers[identities[i]] = controller;
@@ -194,14 +195,16 @@
194195
{
195196
StopCommissioners();
196197

197-
auto factory = [MTRDeviceControllerFactory sharedInstance];
198+
auto factory = [MTRControllerFactory sharedInstance];
198199
NSData * ipk = [gNocSigner getIPK];
199200

200201
constexpr const char * identities[] = { kIdentityAlpha, kIdentityBeta, kIdentityGamma };
201202
for (size_t i = 0; i < ArraySize(identities); ++i) {
202-
auto controllerParams = [[MTRDeviceControllerStartupParams alloc] initWithIPK:ipk fabricID:@(i + 1) nocSigner:gNocSigner];
203+
auto controllerParams = [[MTRDeviceControllerStartupParams alloc] initWithSigningKeypair:gNocSigner
204+
fabricId:(i + 1)
205+
ipk:ipk];
203206

204-
auto controller = [factory createControllerOnExistingFabric:controllerParams error:nil];
207+
auto controller = [factory startControllerOnExistingFabric:controllerParams];
205208
mControllers[identities[i]] = controller;
206209
}
207210
}
@@ -213,7 +216,7 @@
213216
mControllers.clear();
214217
mCurrentController = nil;
215218

216-
[[MTRDeviceControllerFactory sharedInstance] stopControllerFactory];
219+
[[MTRControllerFactory sharedInstance] shutdown];
217220
}
218221

219222
CHIP_ERROR CHIPCommandBridge::StartWaiting(chip::System::Clock::Timeout duration)

examples/darwin-framework-tool/commands/common/CHIPCommandStorageDelegate.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
NS_ASSUME_NONNULL_BEGIN
55

6-
@interface CHIPToolPersistentStorageDelegate : NSObject <MTRStorage>
6+
@interface CHIPToolPersistentStorageDelegate : NSObject <MTRPersistentStorageDelegate>
77
- (nullable NSData *)storageDataForKey:(NSString *)key;
88
- (BOOL)setStorageData:(NSData *)value forKey:(NSString *)key;
99
- (BOOL)removeStorageDataForKey:(NSString *)key;

examples/darwin-framework-tool/commands/pairing/Commands.h

+10-7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ class PairCodeThread : public PairingCommandBridge
4141
PairCodeThread() : PairingCommandBridge("code-thread", PairingMode::Code, PairingNetworkType::Thread) {}
4242
};
4343

44+
class PairWithIPAddress : public PairingCommandBridge
45+
{
46+
public:
47+
PairWithIPAddress() : PairingCommandBridge("ethernet", PairingMode::Ethernet, PairingNetworkType::Ethernet) {}
48+
};
49+
4450
class PairBleWiFi : public PairingCommandBridge
4551
{
4652
public:
@@ -64,13 +70,10 @@ void registerCommandsPairing(Commands & commands)
6470
const char * clusterName = "Pairing";
6571

6672
commands_list clusterCommands = {
67-
make_unique<PairCode>(),
68-
make_unique<PairCodeWifi>(),
69-
make_unique<PairCodeThread>(),
70-
make_unique<PairBleWiFi>(),
71-
make_unique<PairBleThread>(),
72-
make_unique<Unpair>(),
73-
make_unique<OpenCommissioningWindowCommand>(),
73+
make_unique<PairCode>(), make_unique<PairWithIPAddress>(),
74+
make_unique<PairCodeWifi>(), make_unique<PairCodeThread>(),
75+
make_unique<PairBleWiFi>(), make_unique<PairBleThread>(),
76+
make_unique<Unpair>(), make_unique<OpenCommissioningWindowCommand>(),
7477
};
7578

7679
commands.Register(clusterName, clusterCommands);

0 commit comments

Comments
 (0)