Skip to content

Commit

Permalink
Replace "Id" with "ID" in Darwin APIs. (#23389)
Browse files Browse the repository at this point in the history
This is a re-landing of PR #22558 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.
* MTRAttributeCacheContainer_Internal.h is not public API.
* MTRDeviceOverXPC.h is not public API.
* MTRDeviceControllerXPCConnection.h is not public API.
* MTRDeviceControllerOverXPC.h is not public API.
* MTRDeviceControllerOverXPC_Internal.h is not public API.
  • Loading branch information
bzbarsky-apple authored Oct 29, 2022
1 parent b774226 commit f1ebea8
Show file tree
Hide file tree
Showing 32 changed files with 1,072 additions and 740 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ 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()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class ReadAttribute : public ModelCommand {
MTRReadParams * params = [[MTRReadParams alloc] init];
params.fabricFiltered = mFabricFiltered.HasValue() ? [NSNumber numberWithBool:mFabricFiltered.Value()] : nil;
[device
readAttributeWithEndpointId:[NSNumber numberWithUnsignedShort:endpointId]
clusterId:[NSNumber numberWithUnsignedInteger:mClusterId]
attributeId:[NSNumber numberWithUnsignedInteger:mAttributeId]
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) {
Expand Down Expand Up @@ -129,9 +129,9 @@ class SubscribeAttribute : public ModelCommand {
= 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]
[device subscribeAttributeWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
clusterID:[NSNumber numberWithUnsignedInteger:mClusterId]
attributeID:[NSNumber numberWithUnsignedInteger:mAttributeId]
minInterval:[NSNumber numberWithUnsignedInteger:mMinInterval]
maxInterval:[NSNumber numberWithUnsignedInteger:mMaxInterval]
params:params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ 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()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
auto controller = [factory startControllerOnExistingFabric:controllerParams];
if (controller == nil) {
// Maybe we didn't have this fabric yet.
controllerParams.vendorId = @(chip::VendorId::TestVendor1);
controllerParams.vendorID = @(chip::VendorId::TestVendor1);
controller = [factory startControllerOnNewFabric:controllerParams];
}
if (controller == nil) {
Expand Down
4 changes: 2 additions & 2 deletions src/darwin/Framework/CHIP/MTRAttributeCacheContainer+XPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ NS_ASSUME_NONNULL_BEGIN

@interface MTRAttributeCacheContainer (XPC)
- (void)setXPCConnection:(MTRDeviceControllerXPCConnection *)xpcConnection
controllerId:(id<NSCopying>)controllerId
deviceId:(NSNumber *)deviceId;
controllerID:(id<NSCopying>)controllerID
deviceID:(NSNumber *)deviceID;
@end

NS_ASSUME_NONNULL_END
21 changes: 16 additions & 5 deletions src/darwin/Framework/CHIP/MTRAttributeCacheContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,30 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Reads an attribute with specific attribute path
*
* @param endpointId endpoint ID of the attribute
* @param clusterId cluster ID of the attribute
* @param attributeId attribute ID of the attribute
* @param endpointID endpoint ID of the attribute
* @param clusterID cluster ID of the attribute
* @param attributeID attribute ID of the attribute
* @param clientQueue client queue to dispatch the completion handler through
* @param completion block to receive the result.
* "values" received by the block will have the same format of object as the one received by completion block
* of CHIPDevice readAttributeWithEndpointId:clusterId:attributeId:clientQueue:completion method.
* of MTRBaseDevice readAttributeWithEndpointID:clusterID:attributeID:clientQueue:completion method.
*/
- (void)readAttributeWithEndpointID:(NSNumber * _Nullable)endpointID
clusterID:(NSNumber * _Nullable)clusterID
attributeID:(NSNumber * _Nullable)attributeID
clientQueue:(dispatch_queue_t)clientQueue
completion:(MTRDeviceResponseHandler)completion MTR_NEWLY_AVAILABLE;

@end

@interface MTRAttributeCacheContainer (Deprecated)

- (void)readAttributeWithEndpointId:(NSNumber * _Nullable)endpointId
clusterId:(NSNumber * _Nullable)clusterId
attributeId:(NSNumber * _Nullable)attributeId
clientQueue:(dispatch_queue_t)clientQueue
completion:(MTRDeviceResponseHandler)completion;
completion:(MTRDeviceResponseHandler)completion
MTR_NEWLY_DEPRECATED("Please use readAttributeWithEndpointID:clusterID:attributeID:clientQueue:completion:");

@end

Expand Down
73 changes: 45 additions & 28 deletions src/darwin/Framework/CHIP/MTRAttributeCacheContainer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ - (instancetype)init
}

- (void)setXPCConnection:(MTRDeviceControllerXPCConnection *)xpcConnection
controllerId:(id<NSCopying>)controllerId
deviceId:(NSNumber *)deviceId
controllerID:(id<NSCopying>)controllerID
deviceID:(NSNumber *)deviceID
{
self.xpcConnection = xpcConnection;
self.xpcControllerId = controllerId;
self.deviceId = deviceId;
self.xpcControllerID = controllerID;
self.deviceID = deviceID;
self.shouldUseXPC = YES;
}

Expand Down Expand Up @@ -78,9 +78,9 @@ static CHIP_ERROR AppendAttibuteValueToArray(
return err;
}

- (void)readAttributeWithEndpointId:(NSNumber * _Nullable)endpointId
clusterId:(NSNumber * _Nullable)clusterId
attributeId:(NSNumber * _Nullable)attributeId
- (void)readAttributeWithEndpointID:(NSNumber * _Nullable)endpointID
clusterID:(NSNumber * _Nullable)clusterID
attributeID:(NSNumber * _Nullable)attributeID
clientQueue:(dispatch_queue_t)clientQueue
completion:(MTRDeviceResponseHandler)completion
{
Expand All @@ -97,16 +97,16 @@ - (void)readAttributeWithEndpointId:(NSNumber * _Nullable)endpointId
completion(nil, [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeGeneralError userInfo:nil]);
return;
}
__auto_type controllerId = self.xpcControllerId;
NSNumber * nodeId = self.deviceId;
__auto_type controllerId = self.xpcControllerID;
NSNumber * nodeId = self.deviceID;
[xpcConnection
getProxyHandleWithCompletion:^(dispatch_queue_t _Nonnull queue, MTRDeviceControllerXPCProxyHandle * _Nullable handle) {
if (handle) {
[handle.proxy readAttributeCacheWithController:controllerId
nodeId:nodeId.unsignedLongLongValue
endpointId:endpointId
clusterId:clusterId
attributeId:attributeId
endpointId:endpointID
clusterId:clusterID
attributeId:attributeID
completion:^(id _Nullable values, NSError * _Nullable error) {
completion([MTRDeviceController decodeXPCResponseValues:values], error);
__auto_type handleRetainer = handle;
Expand All @@ -121,7 +121,7 @@ - (void)readAttributeWithEndpointId:(NSNumber * _Nullable)endpointId
}

dispatch_async(DeviceLayer::PlatformMgrImpl().GetWorkQueue(), ^{
if (endpointId == nil && clusterId == nil) {
if (endpointID == nil && clusterID == nil) {
MTR_LOG_ERROR("Error: currently read from attribute cache does not support wildcards for both endpoint and cluster");
completionHandler(nil, [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeInvalidArgument userInfo:nil]);
return;
Expand All @@ -135,39 +135,39 @@ - (void)readAttributeWithEndpointId:(NSNumber * _Nullable)endpointId

NSMutableArray * result = [[NSMutableArray alloc] init];
CHIP_ERROR err = CHIP_NO_ERROR;
if (endpointId == nil) {
if (endpointID == nil) {
err = self.cppAttributeCache->ForEachAttribute(
static_cast<chip::ClusterId>([clusterId unsignedLongValue]), [&](const app::ConcreteAttributePath & path) {
if (attributeId == nil
|| static_cast<chip::AttributeId>([attributeId unsignedLongValue]) == path.mAttributeId) {
static_cast<chip::ClusterId>([clusterID unsignedLongValue]), [&](const app::ConcreteAttributePath & path) {
if (attributeID == nil
|| static_cast<chip::AttributeId>([attributeID unsignedLongValue]) == path.mAttributeId) {
(void) AppendAttibuteValueToArray(path, self.cppAttributeCache, result);
}
return CHIP_NO_ERROR;
});
} else if (clusterId == nil) {
} else if (clusterID == nil) {
err = self.cppAttributeCache->ForEachCluster(
static_cast<chip::EndpointId>([endpointId unsignedShortValue]), [&](chip::ClusterId enumeratedClusterId) {
(void) self.cppAttributeCache->ForEachAttribute(static_cast<chip::EndpointId>([endpointId unsignedShortValue]),
static_cast<chip::EndpointId>([endpointID unsignedShortValue]), [&](chip::ClusterId enumeratedClusterId) {
(void) self.cppAttributeCache->ForEachAttribute(static_cast<chip::EndpointId>([endpointID unsignedShortValue]),
enumeratedClusterId, [&](const app::ConcreteAttributePath & path) {
if (attributeId == nil
|| static_cast<chip::AttributeId>([attributeId unsignedLongValue]) == path.mAttributeId) {
if (attributeID == nil
|| static_cast<chip::AttributeId>([attributeID unsignedLongValue]) == path.mAttributeId) {
(void) AppendAttibuteValueToArray(path, self.cppAttributeCache, result);
}
return CHIP_NO_ERROR;
});
return CHIP_NO_ERROR;
});
} else if (attributeId == nil) {
err = self.cppAttributeCache->ForEachAttribute(static_cast<chip::EndpointId>([endpointId unsignedShortValue]),
static_cast<chip::ClusterId>([clusterId unsignedLongValue]), [&](const app::ConcreteAttributePath & path) {
} else if (attributeID == nil) {
err = self.cppAttributeCache->ForEachAttribute(static_cast<chip::EndpointId>([endpointID unsignedShortValue]),
static_cast<chip::ClusterId>([clusterID unsignedLongValue]), [&](const app::ConcreteAttributePath & path) {
(void) AppendAttibuteValueToArray(path, self.cppAttributeCache, result);
return CHIP_NO_ERROR;
});
} else {
app::ConcreteAttributePath path;
path.mEndpointId = static_cast<chip::EndpointId>([endpointId unsignedShortValue]);
path.mClusterId = static_cast<chip::ClusterId>([clusterId unsignedLongValue]);
path.mAttributeId = static_cast<chip::AttributeId>([attributeId unsignedLongValue]);
path.mEndpointId = static_cast<chip::EndpointId>([endpointID unsignedShortValue]);
path.mClusterId = static_cast<chip::ClusterId>([clusterID unsignedLongValue]);
path.mAttributeId = static_cast<chip::AttributeId>([attributeID unsignedLongValue]);
err = AppendAttibuteValueToArray(path, self.cppAttributeCache, result);
}
if (err == CHIP_NO_ERROR) {
Expand All @@ -179,3 +179,20 @@ - (void)readAttributeWithEndpointId:(NSNumber * _Nullable)endpointId
}

@end

@implementation MTRAttributeCacheContainer (Deprecated)

- (void)readAttributeWithEndpointId:(NSNumber * _Nullable)endpointId
clusterId:(NSNumber * _Nullable)clusterId
attributeId:(NSNumber * _Nullable)attributeId
clientQueue:(dispatch_queue_t)clientQueue
completion:(MTRDeviceResponseHandler)completion
{
[self readAttributeWithEndpointID:endpointId
clusterID:clusterId
attributeID:attributeId
clientQueue:clientQueue
completion:completion];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ NS_ASSUME_NONNULL_BEGIN
@interface MTRAttributeCacheContainer ()

@property (atomic, readwrite, nullable) chip::app::ClusterStateCache * cppAttributeCache;
@property (nonatomic, readwrite, copy) NSNumber * deviceId;
@property (nonatomic, readwrite, copy) NSNumber * deviceID;
@property (nonatomic, readwrite, weak, nullable) MTRDeviceControllerXPCConnection * xpcConnection;
@property (nonatomic, readwrite, strong, nullable) id<NSCopying> xpcControllerId;
@property (nonatomic, readwrite, strong, nullable) id<NSCopying> xpcControllerID;
@property (atomic, readwrite) BOOL shouldUseXPC;

@end
Expand Down
Loading

0 comments on commit f1ebea8

Please sign in to comment.