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

Issue 20336 - Darwin: rename MTRDevice and MTRClsutersObjc files and classes #20345

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
2 changes: 1 addition & 1 deletion .restyled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ exclude:
- "scripts/idl/tests/outputs/**/*" # Matches generated output 1:1
- "examples/chef/sample_app_util/test_files/*.yaml"
- "examples/chef/zzz_generated/**/*"
- "src/darwin/Framework/CHIP/zap-generated/MTRClustersObjc.mm" # https://github.com/project-chip/connectedhomeip/issues/20236
- "src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm" # https://github.com/project-chip/connectedhomeip/issues/20236


changed_paths:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ BOOL MTRIsDevicePaired(uint64_t id);
BOOL MTRGetConnectedDevice(MTRDeviceConnectionCallback completionHandler);
BOOL MTRGetConnectedDeviceWithID(uint64_t deviceId, MTRDeviceConnectionCallback completionHandler);
void MTRUnpairDeviceWithID(uint64_t deviceId);
MTRDevice * _Nullable MTRGetDeviceBeingCommissioned(void);
MTRBaseDevice * _Nullable MTRGetDeviceBeingCommissioned(void);

@interface CHIPToolPersistentStorageDelegate : NSObject <MTRPersistentStorageDelegate>
- (nullable NSData *)storageDataForKey:(NSString *)key;
Expand Down
15 changes: 7 additions & 8 deletions src/darwin/CHIPTool/CHIPTool/Framework Helpers/DefaultsUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ BOOL MTRGetConnectedDevice(MTRDeviceConnectionCallback completionHandler)

// Let's use the last device that was paired
uint64_t deviceId = MTRGetLastPairedDeviceId();
return [controller getDevice:deviceId queue:dispatch_get_main_queue() completionHandler:completionHandler];
return [controller getBaseDevice:deviceId queue:dispatch_get_main_queue() completionHandler:completionHandler];
}

MTRDevice * MTRGetDeviceBeingCommissioned(void)
MTRBaseDevice * MTRGetDeviceBeingCommissioned(void)
{
NSError * error;
MTRDeviceController * controller = InitializeMTR();
MTRDevice * device = [controller getDeviceBeingCommissioned:MTRGetLastPairedDeviceId() error:&error];
MTRBaseDevice * device = [controller getDeviceBeingCommissioned:MTRGetLastPairedDeviceId() error:&error];
if (error) {
NSLog(@"Error retrieving device being commissioned for deviceId %llu", MTRGetLastPairedDeviceId());
return nil;
Expand All @@ -154,7 +154,7 @@ BOOL MTRGetConnectedDeviceWithID(uint64_t deviceId, MTRDeviceConnectionCallback
{
MTRDeviceController * controller = InitializeMTR();

return [controller getDevice:deviceId queue:dispatch_get_main_queue() completionHandler:completionHandler];
return [controller getBaseDevice:deviceId queue:dispatch_get_main_queue() completionHandler:completionHandler];
}

BOOL MTRIsDevicePaired(uint64_t deviceId)
Expand All @@ -173,15 +173,14 @@ void MTRSetDevicePaired(uint64_t deviceId, BOOL paired)
void MTRUnpairDeviceWithID(uint64_t deviceId)
{
MTRSetDevicePaired(deviceId, NO);
MTRGetConnectedDeviceWithID(deviceId, ^(MTRDevice * _Nullable device, NSError * _Nullable error) {
MTRGetConnectedDeviceWithID(deviceId, ^(MTRBaseDevice * _Nullable device, NSError * _Nullable error) {
if (error) {
NSLog(@"Failed to unpair device %llu still removing from CHIPTool. %@", deviceId, error);
return;
}
NSLog(@"Attempting to unpair device %llu", deviceId);
MTROperationalCredentials * opCredsCluster = [[MTROperationalCredentials alloc] initWithDevice:device
endpoint:0
queue:dispatch_get_main_queue()];
MTRBaseClusterOperationalCredentials * opCredsCluster =
[[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 @@ -134,7 +134,7 @@ - (IBAction)bind:(id)sender
[scanner scanUnsignedLongLong:&nodeId];

// TODO Binding Support was removed from ObjC Clusters.h
if (MTRGetConnectedDevice(^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (MTRGetConnectedDevice(^(MTRBaseDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (chipDevice) {
NSString * resultString = [NSString stringWithFormat:@"Not Supported"];
NSLog(resultString, nil);
Expand All @@ -150,7 +150,7 @@ - (IBAction)bind:(id)sender

- (IBAction)unbind:(id)sender
{
if (MTRGetConnectedDevice(^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (MTRGetConnectedDevice(^(MTRBaseDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (chipDevice) {
NSString * resultString = [NSString stringWithFormat:@"Not Supported"];
NSLog(resultString, nil);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@ - (IBAction)sendMessage:(id)sender
// 4. Success?
- (void)enumerate
{
MTRGetConnectedDevice(^(MTRDevice * _Nullable device, NSError * _Nullable error) {
MTRGetConnectedDevice(^(MTRBaseDevice * _Nullable device, NSError * _Nullable error) {
if (error) {
NSString * resultLog = [[NSString alloc] initWithFormat:@"Unable to get connected device: Error: %@", error];
[self updateResult:resultLog];
return;
}

MTRDescriptor * descriptorCluster = [[MTRDescriptor alloc] initWithDevice:device
endpoint:0
queue:dispatch_get_main_queue()];
MTRBaseClusterDescriptor * descriptorCluster = [[MTRBaseClusterDescriptor alloc] initWithDevice:device
endpoint:0
queue:dispatch_get_main_queue()];
NSLog(@"Reading parts list to get list of endpoints in use...");
[descriptorCluster readAttributePartsListWithCompletionHandler:^(
NSArray<NSNumber *> * _Nullable endpointsInUse, NSError * _Nullable error) {
Expand All @@ -131,9 +131,10 @@ - (void)enumerate
[self updateResult:resultLog];

for (NSNumber * endpoint in endpointsInUse) {
MTRDescriptor * descriptorCluster = [[MTRDescriptor alloc] initWithDevice:device
endpoint:[endpoint unsignedShortValue]
queue:dispatch_get_main_queue()];
MTRBaseClusterDescriptor * descriptorCluster =
[[MTRBaseClusterDescriptor alloc] initWithDevice:device
endpoint:[endpoint unsignedShortValue]
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 @@ -217,11 +217,12 @@ - (void)updateFabricsListUIWithFabrics:(NSArray<MTROperationalCredentialsCluster
- (void)fetchCommissionedFabricsNumber
{
NSLog(@"Fetching the commissioned fabrics attribute");
if (MTRGetConnectedDevice(^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (MTRGetConnectedDevice(^(MTRBaseDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (chipDevice) {
MTROperationalCredentials * cluster = [[MTROperationalCredentials alloc] initWithDevice:chipDevice
endpoint:0
queue:dispatch_get_main_queue()];
MTRBaseClusterOperationalCredentials * cluster =
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:chipDevice
endpoint:0
queue:dispatch_get_main_queue()];
[cluster
readAttributeCurrentFabricIndexWithCompletionHandler:^(NSNumber * _Nullable value, NSError * _Nullable error) {
if (!error) {
Expand Down Expand Up @@ -265,11 +266,12 @@ - (void)fetchCommissionedFabricsNumber
- (void)fetchFabricsList
{
NSLog(@"Request to fetchFabricsList");
if (MTRGetConnectedDevice(^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (MTRGetConnectedDevice(^(MTRBaseDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (chipDevice) {
MTROperationalCredentials * cluster = [[MTROperationalCredentials alloc] initWithDevice:chipDevice
endpoint:0
queue:dispatch_get_main_queue()];
MTRBaseClusterOperationalCredentials * cluster =
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:chipDevice
endpoint:0
queue:dispatch_get_main_queue()];
[self updateResult:[NSString stringWithFormat:@"readAttributeFabrics command sent."] isError:NO];
MTRReadParams * params = [[MTRReadParams alloc] init];
params.fabricFiltered = @NO;
Expand Down Expand Up @@ -320,18 +322,18 @@ - (IBAction)removeAllFabricsButtonPressed:(id)sender
actionWithTitle:@"Remove"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
if (MTRGetConnectedDevice(^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (MTRGetConnectedDevice(^(MTRBaseDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (!chipDevice) {
[self
updateResult:[NSString
stringWithFormat:@"Failed to establish a connection with the device %@", error]
isError:YES];
}

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

dispatch_group_t removeGroup = dispatch_group_create();
// Loop over the list of all fabrics and for each, call remove
Expand Down Expand Up @@ -398,11 +400,12 @@ - (IBAction)updateFabricLabelButtonPressed:(id)sender
NSLog(@"Request to updateFabricLabel %@", label);
[self.updateFabricLabelTextField resignFirstResponder];

if (MTRGetConnectedDevice(^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (MTRGetConnectedDevice(^(MTRBaseDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (chipDevice) {
MTROperationalCredentials * cluster = [[MTROperationalCredentials alloc] initWithDevice:chipDevice
endpoint:0
queue:dispatch_get_main_queue()];
MTRBaseClusterOperationalCredentials * cluster =
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:chipDevice
endpoint:0
queue:dispatch_get_main_queue()];
[self updateResult:[NSString stringWithFormat:@"updateFabricLabel command sent."] isError:NO];
__auto_type * params = [[MTROperationalCredentialsClusterUpdateFabricLabelParams alloc] init];
params.label = label;
Expand Down Expand Up @@ -451,12 +454,14 @@ - (IBAction)removeFabricButtonPressed:(id)sender
{
NSNumber * fabricIndex = @([_removeFabricTextField.text intValue]);
NSLog(@"Request to fabric at index %@", fabricIndex);
if (MTRGetConnectedDevice(^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (MTRGetConnectedDevice(^(MTRBaseDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (chipDevice) {
[self updateResult:[NSString stringWithFormat:@"removeFabric command sent for fabricIndex %@.", fabricIndex]
isError:NO];
MTROperationalCredentials * opCredsCluster =
[[MTROperationalCredentials alloc] initWithDevice:chipDevice endpoint:0 queue:dispatch_get_main_queue()];
MTRBaseClusterOperationalCredentials * opCredsCluster =
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:chipDevice
endpoint:0
queue:dispatch_get_main_queue()];
MTROperationalCredentialsClusterRemoveFabricParams * params =
[[MTROperationalCredentialsClusterRemoveFabricParams alloc] init];
params.fabricIndex = fabricIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ - (IBAction)openPairingWindow:(id)sender
{
uint32_t setupPIN = arc4random();
[_deviceSelector forSelectedDevices:^(uint64_t deviceId) {
if (MTRGetConnectedDeviceWithID(deviceId, ^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (MTRGetConnectedDeviceWithID(deviceId, ^(MTRBaseDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (chipDevice) {
NSString * timeoutStr = [self.timeoutField text];
if (timeoutStr.length == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ - (IBAction)onButtonTapped:(id)sender
[self updateResult:[NSString stringWithFormat:@"On command sent on endpoint %@", @(endpoint)]];

[_deviceSelector forSelectedDevices:^(uint64_t deviceId) {
if (MTRGetConnectedDeviceWithID(deviceId, ^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (MTRGetConnectedDeviceWithID(deviceId, ^(MTRBaseDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (chipDevice) {
MTROnOff * onOff = [[MTROnOff alloc] initWithDevice:chipDevice
endpoint:endpoint
queue:dispatch_get_main_queue()];
MTRBaseClusterOnOff * onOff = [[MTRBaseClusterOnOff alloc] initWithDevice:chipDevice
endpoint:endpoint
queue:dispatch_get_main_queue()];
[onOff onWithCompletionHandler:^(NSError * error) {
NSString * resultString = (error != nil)
? [NSString stringWithFormat:@"An error occurred: 0x%02lx", error.code]
Expand All @@ -266,11 +266,11 @@ - (IBAction)offButtonTapped:(id)sender
[self updateResult:[NSString stringWithFormat:@"Off command sent on endpoint %@", @(endpoint)]];

[_deviceSelector forSelectedDevices:^(uint64_t deviceId) {
if (MTRGetConnectedDeviceWithID(deviceId, ^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (MTRGetConnectedDeviceWithID(deviceId, ^(MTRBaseDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (chipDevice) {
MTROnOff * onOff = [[MTROnOff alloc] initWithDevice:chipDevice
endpoint:endpoint
queue:dispatch_get_main_queue()];
MTRBaseClusterOnOff * onOff = [[MTRBaseClusterOnOff alloc] initWithDevice:chipDevice
endpoint:endpoint
queue:dispatch_get_main_queue()];
[onOff offWithCompletionHandler:^(NSError * error) {
NSString * resultString = (error != nil)
? [NSString stringWithFormat:@"An error occurred: 0x%02lx", error.code]
Expand All @@ -295,11 +295,11 @@ - (IBAction)toggleButtonTapped:(id)sender
[self updateResult:[NSString stringWithFormat:@"Toggle command sent on endpoint %@", @(endpoint)]];

[_deviceSelector forSelectedDevices:^(uint64_t deviceId) {
if (MTRGetConnectedDeviceWithID(deviceId, ^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (MTRGetConnectedDeviceWithID(deviceId, ^(MTRBaseDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (chipDevice) {
MTROnOff * onOff = [[MTROnOff alloc] initWithDevice:chipDevice
endpoint:endpoint
queue:dispatch_get_main_queue()];
MTRBaseClusterOnOff * onOff = [[MTRBaseClusterOnOff alloc] initWithDevice:chipDevice
endpoint:endpoint
queue:dispatch_get_main_queue()];
[onOff toggleWithCompletionHandler:^(NSError * error) {
NSString * resultString = (error != nil)
? [NSString stringWithFormat:@"An error occurred: 0x%02lx", error.code]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ @interface QRCodeViewController ()
@property (strong, nonatomic) UILabel * errorLabel;

@property (readwrite) MTRDeviceController * chipController;
@property (nonatomic, strong) MTRNetworkCommissioning * cluster;
@property (nonatomic, strong) MTRBaseClusterNetworkCommissioning * cluster;

@property (strong, nonatomic) NFCNDEFReaderSession * session;
@property (strong, nonatomic) MTRSetupPayload * setupPayload;
Expand Down Expand Up @@ -478,7 +478,7 @@ - (void)readerSession:(nonnull NFCNDEFReaderSession *)session didInvalidateWithE
- (void)setVendorIDOnAccessory
{
NSLog(@"Call to setVendorIDOnAccessory");
if (MTRGetConnectedDevice(^(MTRDevice * _Nullable device, NSError * _Nullable error) {
if (MTRGetConnectedDevice(^(MTRBaseDevice * _Nullable device, NSError * _Nullable error) {
if (!device) {
NSLog(@"Status: Failed to establish a connection with the device");
}
Expand Down
Loading