Skip to content

Commit

Permalink
Issue 20336 - Darwin: rename MTRDevice and MTRClsutersObjc files and …
Browse files Browse the repository at this point in the history
…classes
  • Loading branch information
jtung-apple committed Jul 6, 2022
1 parent 5398442 commit 83228d1
Show file tree
Hide file tree
Showing 36 changed files with 366 additions and 354 deletions.
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
11 changes: 5 additions & 6 deletions src/darwin/CHIPTool/CHIPTool/Framework Helpers/DefaultsUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ BOOL MTRGetConnectedDevice(MTRDeviceConnectionCallback completionHandler)
return [controller getDevice: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 Down Expand Up @@ -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,14 +108,14 @@ - (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
MTRBaseClusterDescriptor * descriptorCluster = [[MTRBaseClusterDescriptor alloc] initWithDevice:device
endpoint:0
queue:dispatch_get_main_queue()];
NSLog(@"Reading parts list to get list of endpoints in use...");
Expand All @@ -131,7 +131,7 @@ - (void)enumerate
[self updateResult:resultLog];

for (NSNumber * endpoint in endpointsInUse) {
MTRDescriptor * descriptorCluster = [[MTRDescriptor alloc] initWithDevice:device
MTRBaseClusterDescriptor * descriptorCluster = [[MTRBaseClusterDescriptor alloc] initWithDevice:device
endpoint:[endpoint unsignedShortValue]
queue:dispatch_get_main_queue()];
[descriptorCluster readAttributeDeviceListWithCompletionHandler:^(
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 @@ -78,7 +78,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 @@ -467,7 +467,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
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,16 @@ - (void)updateTempInUI:(int)newTemp
NSLog(@"Status: Updated temp in UI to %@", _temperatureLabel.text);
}

// MARK: MTRTemperatureMeasurement
// MARK: MTRBaseClusterTemperatureMeasurement

- (void)readCurrentTemperature
{
if (MTRGetConnectedDevice(^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (MTRGetConnectedDevice(^(MTRBaseDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (chipDevice) {
MTRTemperatureMeasurement * cluster = [[MTRTemperatureMeasurement alloc] initWithDevice:chipDevice
endpoint:1
queue:dispatch_get_main_queue()];
MTRBaseClusterTemperatureMeasurement * cluster =
[[MTRBaseClusterTemperatureMeasurement alloc] initWithDevice:chipDevice
endpoint:1
queue:dispatch_get_main_queue()];

[cluster readAttributeMeasuredValueWithCompletionHandler:^(NSNumber * _Nullable value, NSError * _Nullable error) {
if (error != nil)
Expand All @@ -218,7 +219,7 @@ - (void)reportFromUserEnteredSettings
NSLog(
@"Sending temp reporting values: min %@ max %@ value %@", @(minIntervalSeconds), @(maxIntervalSeconds), @(deltaInCelsius));

if (MTRGetConnectedDevice(^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (MTRGetConnectedDevice(^(MTRBaseDevice * _Nullable chipDevice, NSError * _Nullable error) {
if (chipDevice) {
// Use a wildcard subscription
[chipDevice subscribeWithQueue:dispatch_get_main_queue()
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRAttributeCacheContainer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#import <Foundation/Foundation.h>

#import "MTRAttributeCacheContainer_Internal.h"
#import "MTRBaseDevice_Internal.h"
#import "MTRCluster.h"
#import "MTRDeviceControllerXPCConnection.h"
#import "MTRDevice_Internal.h"
#import "MTRError.h"
#import "MTRError_Internal.h"
#import "MTRLogging.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extern NSString * const MTRArrayValueType;
@class MTRReadParams;
@class MTRSubscribeParams;

@interface MTRDevice : NSObject
@interface MTRBaseDevice : NSObject

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
Expand Down
Loading

0 comments on commit 83228d1

Please sign in to comment.