Skip to content

Commit

Permalink
Revert, for now, Darwin API changes that did not happen early enough. (
Browse files Browse the repository at this point in the history
…project-chip#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.
  • Loading branch information
bzbarsky-apple authored Oct 13, 2022
1 parent 26dab6c commit 12802fb
Show file tree
Hide file tree
Showing 144 changed files with 102,880 additions and 93,345 deletions.
2 changes: 1 addition & 1 deletion examples/darwin-framework-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ executable("darwin-framework-tool") {
"commands/common/MTRError_Utils.h",
"commands/common/MTRLogging.h",
"commands/pairing/Commands.h",
"commands/pairing/DeviceControllerDelegateBridge.mm",
"commands/pairing/OpenCommissioningWindowCommand.h",
"commands/pairing/OpenCommissioningWindowCommand.mm",
"commands/pairing/PairingCommandBridge.mm",
"commands/pairing/PairingDelegateBridge.mm",
"commands/payload/SetupPayloadParseCommand.mm",
"commands/provider/Commands.h",
"commands/provider/OTAProviderDelegate.mm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ class ClusterCommand : public ModelCommand {
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);

while (repeatCount--) {
[device invokeCommandWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
clusterID:[NSNumber numberWithUnsignedInteger:clusterId]
commandID:[NSNumber numberWithUnsignedInteger:commandId]
[device invokeCommandWithEndpointId:[NSNumber numberWithUnsignedShort:endpointId]
clusterId:[NSNumber numberWithUnsignedInteger:clusterId]
commandId:[NSNumber numberWithUnsignedInteger:commandId]
commandFields:commandFields
timedInvokeTimeout:mTimedInteractionTimeoutMs.HasValue()
? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()]
: nil
queue:callbackQueue
clientQueue:callbackQueue
completion:^(
NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
responsesNeeded--;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,31 @@

CHIP_ERROR ModelCommand::RunCommand()
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip-tool.command", DISPATCH_QUEUE_SERIAL);

MTRDeviceController * commissioner = CurrentCommissioner();
ChipLogProgress(chipTool, "Sending command to node 0x" ChipLogFormatX64, ChipLogValueX64(mNodeId));
auto * device = [MTRBaseDevice deviceWithNodeID:@(mNodeId) controller:commissioner];
CHIP_ERROR err = SendCommand(device, mEndPointId);
[commissioner getBaseDevice:mNodeId
queue:callbackQueue
completionHandler:^(MTRBaseDevice * _Nullable device, NSError * _Nullable error) {
if (error != nil) {
SetCommandExitStatus(error, "Error getting connected device");
return;
}

CHIP_ERROR err;
if (device == nil) {
err = CHIP_ERROR_INTERNAL;
} else {
err = SendCommand(device, mEndPointId);
}

if (err != CHIP_NO_ERROR) {
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(err));
return err;
}
if (err != CHIP_NO_ERROR) {
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(err));
SetCommandExitStatus(err);
return;
}
}];
return CHIP_NO_ERROR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,24 @@ class ReadAttribute : public ModelCommand {
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
MTRReadParams * params = [[MTRReadParams alloc] init];
if (mFabricFiltered.HasValue()) {
params.fabricFiltered = mFabricFiltered.Value();
}
[device readAttributePathWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
clusterID:[NSNumber numberWithUnsignedInteger:mClusterId]
attributeID:[NSNumber numberWithUnsignedInteger:mAttributeId]
params:params
queue:callbackQueue
completion:^(
NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (error != nil) {
LogNSError("Error reading attribute", error);
}
if (values) {
for (id item in values) {
NSLog(@"Response Item: %@", [item description]);
}
}
SetCommandExitStatus(error);
}];
params.fabricFiltered = mFabricFiltered.HasValue() ? [NSNumber numberWithBool:mFabricFiltered.Value()] : nil;
[device
readAttributeWithEndpointId:[NSNumber numberWithUnsignedShort:endpointId]
clusterId:[NSNumber numberWithUnsignedInteger:mClusterId]
attributeId:[NSNumber numberWithUnsignedInteger:mAttributeId]
params:params
clientQueue:callbackQueue
completion:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (error != nil) {
LogNSError("Error reading attribute", error);
}
if (values) {
for (id item in values) {
NSLog(@"Response Item: %@", [item description]);
}
}
SetCommandExitStatus(error);
}];
return CHIP_NO_ERROR;
}

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

MTRSubscribeParams * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(mMinInterval) maxInterval:@(mMaxInterval)];
if (mFabricFiltered.HasValue()) {
params.fabricFiltered = mFabricFiltered.Value();
}
if (mKeepSubscriptions.HasValue()) {
params.keepPreviousSubscriptions = mKeepSubscriptions.Value();
}
if (mAutoResubscribe.HasValue()) {
params.autoResubscribe = mAutoResubscribe.Value();
}

[device subscribeAttributePathWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
clusterID:[NSNumber numberWithUnsignedInteger:mClusterId]
attributeID:[NSNumber numberWithUnsignedInteger:mAttributeId]
MTRSubscribeParams * params = [[MTRSubscribeParams alloc] init];
params.keepPreviousSubscriptions
= mKeepSubscriptions.HasValue() ? [NSNumber numberWithBool:mKeepSubscriptions.Value()] : nil;
params.autoResubscribe = mAutoResubscribe.HasValue() ? [NSNumber numberWithBool:mAutoResubscribe.Value()] : nil;

[device subscribeAttributeWithEndpointId:[NSNumber numberWithUnsignedShort:endpointId]
clusterId:[NSNumber numberWithUnsignedInteger:mClusterId]
attributeId:[NSNumber numberWithUnsignedInteger:mAttributeId]
minInterval:[NSNumber numberWithUnsignedInteger:mMinInterval]
maxInterval:[NSNumber numberWithUnsignedInteger:mMaxInterval]
params:params
queue:callbackQueue
clientQueue:callbackQueue
reportHandler:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (values) {
for (id item in values) {
Expand Down Expand Up @@ -198,17 +192,16 @@ class SubscribeEvent : public ModelCommand {
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);

MTRSubscribeParams * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(mMinInterval) maxInterval:@(mMaxInterval)];
if (mKeepSubscriptions.HasValue()) {
params.keepPreviousSubscriptions = mKeepSubscriptions.Value();
}
if (mAutoResubscribe.HasValue()) {
params.autoResubscribe = mAutoResubscribe.Value();
}
MTRSubscribeParams * params = [[MTRSubscribeParams alloc] init];
params.keepPreviousSubscriptions
= mKeepSubscriptions.HasValue() ? [NSNumber numberWithBool:mKeepSubscriptions.Value()] : nil;
params.autoResubscribe = mAutoResubscribe.HasValue() ? [NSNumber numberWithBool:mAutoResubscribe.Value()] : nil;

[device subscribeWithQueue:callbackQueue
minInterval:mMinInterval
maxInterval:mMaxInterval
params:params
clusterStateCacheContainer:nil
cacheContainer:nil
attributeReportHandler:^(NSArray * value) {
SetCommandExitStatus(CHIP_NO_ERROR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ class WriteAttribute : public ModelCommand {
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
[device
writeAttributeWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
clusterID:[NSNumber numberWithUnsignedInteger:clusterId]
attributeID:[NSNumber numberWithUnsignedInteger:attributeId]
writeAttributeWithEndpointId:[NSNumber numberWithUnsignedShort:endpointId]
clusterId:[NSNumber numberWithUnsignedInteger:clusterId]
attributeId:[NSNumber numberWithUnsignedInteger:attributeId]
value:value
timedWriteTimeout:mTimedInteractionTimeoutMs.HasValue()
? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()]
: nil
queue:callbackQueue
clientQueue:callbackQueue
completion:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (error != nil) {
LogNSError("Error writing attribute", error);
Expand Down
33 changes: 18 additions & 15 deletions examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,25 @@

mOTADelegate = [[OTAProviderDelegate alloc] init];

auto factory = [MTRDeviceControllerFactory sharedInstance];
auto factory = [MTRControllerFactory sharedInstance];
if (factory == nil) {
ChipLogError(chipTool, "Controller factory is nil");
return CHIP_ERROR_INTERNAL;
}

auto params = [[MTRDeviceControllerFactoryParams alloc] initWithStorage:storage];
auto params = [[MTRControllerFactoryParams alloc] initWithStorage:storage];
params.port = @(kListenPort);
params.shouldStartServer = YES;
params.startServer = YES;
params.otaProviderDelegate = mOTADelegate;
NSArray<NSData *> * paaCertResults;
ReturnLogErrorOnFailure(GetPAACertsFromFolder(&paaCertResults));
if ([paaCertResults count] > 0) {
params.paaCerts = paaCertResults;
}

NSError * error;
if ([factory startControllerFactory:params error:&error] == NO) {
if ([factory startup:params] == NO) {
ChipLogError(chipTool, "Controller factory startup failed");
return MTRErrorToCHIPErrorCode(error);
return CHIP_ERROR_INTERNAL;
}

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

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

// We're not sure whether we're creating a new fabric or using an
// existing one, so just try both.
auto controller = [factory createControllerOnExistingFabric:controllerParams error:&error];
auto controller = [factory startControllerOnExistingFabric:controllerParams];
if (controller == nil) {
// Maybe we didn't have this fabric yet.
controllerParams.vendorID = @(chip::VendorId::TestVendor1);
controller = [factory createControllerOnNewFabric:controllerParams error:&error];
controllerParams.vendorId = @(chip::VendorId::TestVendor1);
controller = [factory startControllerOnNewFabric:controllerParams];
}
if (controller == nil) {
ChipLogError(chipTool, "Controller startup failure.");
return MTRErrorToCHIPErrorCode(error);
return CHIP_ERROR_INTERNAL;
}

mControllers[identities[i]] = controller;
Expand Down Expand Up @@ -194,14 +195,16 @@
{
StopCommissioners();

auto factory = [MTRDeviceControllerFactory sharedInstance];
auto factory = [MTRControllerFactory sharedInstance];
NSData * ipk = [gNocSigner getIPK];

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

auto controller = [factory createControllerOnExistingFabric:controllerParams error:nil];
auto controller = [factory startControllerOnExistingFabric:controllerParams];
mControllers[identities[i]] = controller;
}
}
Expand All @@ -213,7 +216,7 @@
mControllers.clear();
mCurrentController = nil;

[[MTRDeviceControllerFactory sharedInstance] stopControllerFactory];
[[MTRControllerFactory sharedInstance] shutdown];
}

CHIP_ERROR CHIPCommandBridge::StartWaiting(chip::System::Clock::Timeout duration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

NS_ASSUME_NONNULL_BEGIN

@interface CHIPToolPersistentStorageDelegate : NSObject <MTRStorage>
@interface CHIPToolPersistentStorageDelegate : NSObject <MTRPersistentStorageDelegate>
- (nullable NSData *)storageDataForKey:(NSString *)key;
- (BOOL)setStorageData:(NSData *)value forKey:(NSString *)key;
- (BOOL)removeStorageDataForKey:(NSString *)key;
Expand Down
17 changes: 10 additions & 7 deletions examples/darwin-framework-tool/commands/pairing/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class PairCodeThread : public PairingCommandBridge
PairCodeThread() : PairingCommandBridge("code-thread", PairingMode::Code, PairingNetworkType::Thread) {}
};

class PairWithIPAddress : public PairingCommandBridge
{
public:
PairWithIPAddress() : PairingCommandBridge("ethernet", PairingMode::Ethernet, PairingNetworkType::Ethernet) {}
};

class PairBleWiFi : public PairingCommandBridge
{
public:
Expand All @@ -64,13 +70,10 @@ void registerCommandsPairing(Commands & commands)
const char * clusterName = "Pairing";

commands_list clusterCommands = {
make_unique<PairCode>(),
make_unique<PairCodeWifi>(),
make_unique<PairCodeThread>(),
make_unique<PairBleWiFi>(),
make_unique<PairBleThread>(),
make_unique<Unpair>(),
make_unique<OpenCommissioningWindowCommand>(),
make_unique<PairCode>(), make_unique<PairWithIPAddress>(),
make_unique<PairCodeWifi>(), make_unique<PairCodeThread>(),
make_unique<PairBleWiFi>(), make_unique<PairBleThread>(),
make_unique<Unpair>(), make_unique<OpenCommissioningWindowCommand>(),
};

commands.Register(clusterName, clusterCommands);
Expand Down
Loading

0 comments on commit 12802fb

Please sign in to comment.