Skip to content

Commit 1607412

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Fix various miscellaneous Darwin API issues. (#22574)
* Rename readAttributeWithEndpointID to readAttributePathWithEndpointID * Document readAttributePathWithEndpointID * Rename subscribeAttributeWithEndpointID to subscribeAttributePathWithEndpointID * Document subscribeAttributePathWithEndpointID * Switch various things from "strong" to "copy" for paths, reports, etc. * Remove redundant "nonnull" declarations on properties. * Create typedefs for the NSData representations of certificates, for readability * Replace "(nullable X *)" with "(X * _Nullable)" in various places. * Fix various documentation. * Rename "failSafeExpiryTimeoutSecs" to "failSafeExpiryTimeout". Fixes #22531 Addresses part of #22420
1 parent 9a989e9 commit 1607412

Some content is hidden

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

48 files changed

+1817
-1786
lines changed

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

+18-18
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,23 @@ class ReadAttribute : public ModelCommand {
5555
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
5656
MTRReadParams * params = [[MTRReadParams alloc] init];
5757
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-
queue: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-
}];
58+
[device readAttributePathWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
59+
clusterID:[NSNumber numberWithUnsignedInteger:mClusterId]
60+
attributeID:[NSNumber numberWithUnsignedInteger:mAttributeId]
61+
params:params
62+
queue:callbackQueue
63+
completion:^(
64+
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+
}];
7575
return CHIP_NO_ERROR;
7676
}
7777

@@ -129,7 +129,7 @@ class SubscribeAttribute : public ModelCommand {
129129
= mKeepSubscriptions.HasValue() ? [NSNumber numberWithBool:mKeepSubscriptions.Value()] : nil;
130130
params.autoResubscribe = mAutoResubscribe.HasValue() ? [NSNumber numberWithBool:mAutoResubscribe.Value()] : nil;
131131

132-
[device subscribeAttributeWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
132+
[device subscribeAttributePathWithEndpointID:[NSNumber numberWithUnsignedShort:endpointId]
133133
clusterID:[NSNumber numberWithUnsignedInteger:mClusterId]
134134
attributeID:[NSNumber numberWithUnsignedInteger:mAttributeId]
135135
minInterval:[NSNumber numberWithUnsignedInteger:mMinInterval]

src/darwin/CHIPTool/CHIPTool/View Controllers/QRCode/QRCodeViewController.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ - (void)onPairingComplete:(NSError * _Nullable)error
506506
} else {
507507
MTRCommissioningParameters * params = [[MTRCommissioningParameters alloc] init];
508508
params.deviceAttestationDelegate = [[CHIPToolDeviceAttestationDelegate alloc] initWithViewController:self];
509-
params.failSafeExpiryTimeoutSecs = @600;
509+
params.failSafeExpiryTimeout = @600;
510510
NSError * error;
511511
if (![controller commissionDevice:deviceId commissioningParams:params error:&error]) {
512512
NSLog(@"Failed to commission Device %llu, with error %@", deviceId, error);
@@ -674,7 +674,7 @@ - (void)commissionWithSSID:(NSString *)ssid password:(NSString *)password
674674
params.wifiSSID = [ssid dataUsingEncoding:NSUTF8StringEncoding];
675675
params.wifiCredentials = [password dataUsingEncoding:NSUTF8StringEncoding];
676676
params.deviceAttestationDelegate = [[CHIPToolDeviceAttestationDelegate alloc] initWithViewController:self];
677-
params.failSafeExpiryTimeoutSecs = @600;
677+
params.failSafeExpiryTimeout = @600;
678678

679679
uint64_t deviceId = MTRGetNextAvailableDeviceID() - 1;
680680

src/darwin/Framework/CHIP/MTRBaseDevice.h

+53-37
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,21 @@ extern NSString * const MTRArrayValueType;
184184
resubscriptionScheduled:(MTRDeviceResubscriptionScheduledHandler _Nullable)resubscriptionScheduled;
185185

186186
/**
187-
* Read attribute in a designated attribute path
187+
* Reads the given attribute path from the device.
188+
*
189+
* nil values for endpointID, clusterID, attributeID indicate wildcards
190+
* (e.g. nil attributeID means "read all the attributes from the endpoint(s) and
191+
* cluster(s) that match endpointID/clusterID").
192+
*
193+
* A non-nil attributeID along with a nil clusterID will only succeed if the
194+
* attribute ID is for a global attribute that applies to all clusters.
188195
*/
189-
- (void)readAttributeWithEndpointID:(NSNumber * _Nullable)endpointID
190-
clusterID:(NSNumber * _Nullable)clusterID
191-
attributeID:(NSNumber * _Nullable)attributeID
192-
params:(MTRReadParams * _Nullable)params
193-
queue:(dispatch_queue_t)queue
194-
completion:(MTRDeviceResponseHandler)completion;
196+
- (void)readAttributePathWithEndpointID:(NSNumber * _Nullable)endpointID
197+
clusterID:(NSNumber * _Nullable)clusterID
198+
attributeID:(NSNumber * _Nullable)attributeID
199+
params:(MTRReadParams * _Nullable)params
200+
queue:(dispatch_queue_t)queue
201+
completion:(MTRDeviceResponseHandler)completion;
195202

196203
/**
197204
* Write to attribute in a designated attribute path
@@ -203,8 +210,8 @@ extern NSString * const MTRArrayValueType;
203210
*
204211
* @param completion response handler will receive either values or error.
205212
*
206-
* Received values are an NSArray object with response-value element as described in
207-
* readAttributeWithEndpointID:clusterID:attributeID:queue:completion:.
213+
* Received values are documented in the definition of
214+
* MTRDeviceResponseHandler.
208215
*/
209216
- (void)writeAttributeWithEndpointID:(NSNumber *)endpointID
210217
clusterID:(NSNumber *)clusterID
@@ -235,17 +242,24 @@ extern NSString * const MTRArrayValueType;
235242
completion:(MTRDeviceResponseHandler)completion;
236243

237244
/**
238-
* Subscribe an attribute in a designated attribute path
245+
* Subscribes to the given attribute path on the device.
246+
*
247+
* nil values for endpointID, clusterID, attributeID indicate wildcards
248+
* (e.g. nil attributeID means "read all the attributes from the endpoint(s) and
249+
* cluster(s) that match endpointID/clusterID").
250+
*
251+
* A non-nil attributeID along with a nil clusterID will only succeed if the
252+
* attribute ID is for a global attribute that applies to all clusters.
239253
*/
240-
- (void)subscribeAttributeWithEndpointID:(NSNumber * _Nullable)endpointID
241-
clusterID:(NSNumber * _Nullable)clusterID
242-
attributeID:(NSNumber * _Nullable)attributeID
243-
minInterval:(NSNumber *)minInterval
244-
maxInterval:(NSNumber *)maxInterval
245-
params:(MTRSubscribeParams * _Nullable)params
246-
queue:(dispatch_queue_t)queue
247-
reportHandler:(MTRDeviceResponseHandler)reportHandler
248-
subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished;
254+
- (void)subscribeAttributePathWithEndpointID:(NSNumber * _Nullable)endpointID
255+
clusterID:(NSNumber * _Nullable)clusterID
256+
attributeID:(NSNumber * _Nullable)attributeID
257+
minInterval:(NSNumber *)minInterval
258+
maxInterval:(NSNumber *)maxInterval
259+
params:(MTRSubscribeParams * _Nullable)params
260+
queue:(dispatch_queue_t)queue
261+
reportHandler:(MTRDeviceResponseHandler)reportHandler
262+
subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished;
249263

250264
/**
251265
* Deregister all local report handlers for a remote device
@@ -279,9 +293,9 @@ extern NSString * const MTRArrayValueType;
279293
@end
280294

281295
@interface MTRAttributePath : NSObject <NSCopying>
282-
@property (nonatomic, readonly, strong, nonnull) NSNumber * endpoint;
283-
@property (nonatomic, readonly, strong, nonnull) NSNumber * cluster;
284-
@property (nonatomic, readonly, strong, nonnull) NSNumber * attribute;
296+
@property (nonatomic, readonly, copy) NSNumber * endpoint;
297+
@property (nonatomic, readonly, copy) NSNumber * cluster;
298+
@property (nonatomic, readonly, copy) NSNumber * attribute;
285299

286300
+ (instancetype)attributePathWithEndpointID:(NSNumber *)endpointID
287301
clusterID:(NSNumber *)clusterID
@@ -292,9 +306,9 @@ extern NSString * const MTRArrayValueType;
292306
@end
293307

294308
@interface MTREventPath : NSObject
295-
@property (nonatomic, readonly, strong, nonnull) NSNumber * endpoint;
296-
@property (nonatomic, readonly, strong, nonnull) NSNumber * cluster;
297-
@property (nonatomic, readonly, strong, nonnull) NSNumber * event;
309+
@property (nonatomic, readonly, copy) NSNumber * endpoint;
310+
@property (nonatomic, readonly, copy) NSNumber * cluster;
311+
@property (nonatomic, readonly, copy) NSNumber * event;
298312

299313
+ (instancetype)eventPathWithEndpointID:(NSNumber *)endpointID clusterID:(NSNumber *)clusterID eventID:(NSNumber *)eventID;
300314

@@ -303,9 +317,9 @@ extern NSString * const MTRArrayValueType;
303317
@end
304318

305319
@interface MTRCommandPath : NSObject
306-
@property (nonatomic, readonly, strong, nonnull) NSNumber * endpoint;
307-
@property (nonatomic, readonly, strong, nonnull) NSNumber * cluster;
308-
@property (nonatomic, readonly, strong, nonnull) NSNumber * command;
320+
@property (nonatomic, readonly, copy) NSNumber * endpoint;
321+
@property (nonatomic, readonly, copy) NSNumber * cluster;
322+
@property (nonatomic, readonly, copy) NSNumber * command;
309323

310324
+ (instancetype)commandPathWithEndpointID:(NSNumber *)endpointID clusterID:(NSNumber *)clusterID commandID:(NSNumber *)commandID;
311325

@@ -314,25 +328,27 @@ extern NSString * const MTRArrayValueType;
314328
@end
315329

316330
@interface MTRAttributeReport : NSObject
317-
@property (nonatomic, readonly, strong, nonnull) MTRAttributePath * path;
331+
@property (nonatomic, readonly, copy) MTRAttributePath * path;
318332
// value is nullable because nullable attributes can have nil as value.
319-
@property (nonatomic, readonly, strong, nullable) id value;
333+
@property (nonatomic, readonly, copy, nullable) id value;
320334
// If this specific path resulted in an error, the error (in the
321335
// MTRInteractionErrorDomain or MTRErrorDomain) that corresponds to this
322336
// path.
323-
@property (nonatomic, readonly, strong, nullable) NSError * error;
337+
@property (nonatomic, readonly, copy, nullable) NSError * error;
324338
@end
325339

326340
@interface MTREventReport : NSObject
327-
@property (nonatomic, readonly, strong, nonnull) MTREventPath * path;
328-
@property (nonatomic, readonly, strong, nonnull) NSNumber * eventNumber; // chip::EventNumber type (uint64_t)
329-
@property (nonatomic, readonly, strong, nonnull) NSNumber * priority; // chip::app::PriorityLevel type (uint8_t)
330-
@property (nonatomic, readonly, strong, nonnull) NSNumber * timestamp; // chip::app::Timestamp.mValue type (uint64_t)
331-
@property (nonatomic, readonly, strong, nullable) id value;
341+
@property (nonatomic, readonly, copy) MTREventPath * path;
342+
@property (nonatomic, readonly, copy) NSNumber * eventNumber; // EventNumber type (uint64_t)
343+
@property (nonatomic, readonly, copy) NSNumber * priority; // PriorityLevel type (uint8_t)
344+
@property (nonatomic, readonly, copy) NSNumber * timestamp; // Timestamp type (uint64_t)
345+
// An instance of one of the event payload interfaces.
346+
@property (nonatomic, readonly, copy) id value;
347+
332348
// If this specific path resulted in an error, the error (in the
333349
// MTRInteractionErrorDomain or MTRErrorDomain) that corresponds to this
334350
// path.
335-
@property (nonatomic, readonly, strong, nullable) NSError * error;
351+
@property (nonatomic, readonly, copy, nullable) NSError * error;
336352
@end
337353

338354
NS_ASSUME_NONNULL_END

src/darwin/Framework/CHIP/MTRBaseDevice.mm

+29-19
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ - (void)invalidateCASESession
301301
- (void)subscribeWithQueue:(dispatch_queue_t)queue
302302
minInterval:(NSNumber *)minInterval
303303
maxInterval:(NSNumber *)maxInterval
304-
params:(nullable MTRSubscribeParams *)params
304+
params:(MTRSubscribeParams * _Nullable)params
305305
attributeCacheContainer:(MTRAttributeCacheContainer * _Nullable)attributeCacheContainer
306306
attributeReportHandler:(MTRDeviceReportHandler _Nullable)attributeReportHandler
307307
eventReportHandler:(MTRDeviceReportHandler _Nullable)eventReportHandler
@@ -771,12 +771,12 @@ void OnDeallocatePaths(chip::app::ReadPrepareParams && aReadPrepareParams) overr
771771
Platform::UniquePtr<app::ReadClient> mReadClient;
772772
};
773773

774-
- (void)readAttributeWithEndpointID:(NSNumber *)endpointID
775-
clusterID:(NSNumber *)clusterID
776-
attributeID:(NSNumber *)attributeID
777-
params:(MTRReadParams * _Nullable)params
778-
queue:(dispatch_queue_t)queue
779-
completion:(MTRDeviceResponseHandler)completion
774+
- (void)readAttributePathWithEndpointID:(NSNumber * _Nullable)endpointID
775+
clusterID:(NSNumber * _Nullable)clusterID
776+
attributeID:(NSNumber * _Nullable)attributeID
777+
params:(MTRReadParams * _Nullable)params
778+
queue:(dispatch_queue_t)queue
779+
completion:(MTRDeviceResponseHandler)completion
780780
{
781781
endpointID = (endpointID == nil) ? nil : [endpointID copy];
782782
clusterID = (clusterID == nil) ? nil : [clusterID copy];
@@ -1114,15 +1114,15 @@ new MTRDataValueDictionaryCallbackBridge(queue, self, completion,
11141114
});
11151115
}
11161116

1117-
- (void)subscribeAttributeWithEndpointID:(NSNumber * _Nullable)endpointID
1118-
clusterID:(NSNumber * _Nullable)clusterID
1119-
attributeID:(NSNumber * _Nullable)attributeID
1120-
minInterval:(NSNumber *)minInterval
1121-
maxInterval:(NSNumber *)maxInterval
1122-
params:(MTRSubscribeParams * _Nullable)params
1123-
queue:(dispatch_queue_t)queue
1124-
reportHandler:(MTRDeviceResponseHandler)reportHandler
1125-
subscriptionEstablished:(MTRSubscriptionEstablishedHandler)subscriptionEstablished
1117+
- (void)subscribeAttributePathWithEndpointID:(NSNumber * _Nullable)endpointID
1118+
clusterID:(NSNumber * _Nullable)clusterID
1119+
attributeID:(NSNumber * _Nullable)attributeID
1120+
minInterval:(NSNumber *)minInterval
1121+
maxInterval:(NSNumber *)maxInterval
1122+
params:(MTRSubscribeParams * _Nullable)params
1123+
queue:(dispatch_queue_t)queue
1124+
reportHandler:(MTRDeviceResponseHandler)reportHandler
1125+
subscriptionEstablished:(MTRSubscriptionEstablishedHandler)subscriptionEstablished
11261126
{
11271127
if (self.isPASEDevice) {
11281128
// We don't support subscriptions over PASE.
@@ -1525,6 +1525,11 @@ ConcreteEventPath path(static_cast<chip::EndpointId>([endpointID unsignedShortVa
15251525

15261526
return [[MTREventPath alloc] initWithPath:path];
15271527
}
1528+
1529+
- (id)copyWithZone:(NSZone *)zone
1530+
{
1531+
return [MTREventPath eventPathWithEndpointID:_endpoint clusterID:_cluster eventID:_event];
1532+
}
15281533
@end
15291534

15301535
@implementation MTRCommandPath
@@ -1545,10 +1550,15 @@ ConcreteCommandPath path(static_cast<chip::EndpointId>([endpointID unsignedShort
15451550

15461551
return [[MTRCommandPath alloc] initWithPath:path];
15471552
}
1553+
1554+
- (id)copyWithZone:(NSZone *)zone
1555+
{
1556+
return [MTRCommandPath commandPathWithEndpointID:_endpoint clusterID:_cluster commandID:_command];
1557+
}
15481558
@end
15491559

15501560
@implementation MTRAttributeReport
1551-
- (instancetype)initWithPath:(const ConcreteDataAttributePath &)path value:(nullable id)value error:(nullable NSError *)error
1561+
- (instancetype)initWithPath:(const ConcreteDataAttributePath &)path value:(id _Nullable)value error:(NSError * _Nullable)error
15521562
{
15531563
if (self = [super init]) {
15541564
_path = [[MTRAttributePath alloc] initWithPath:path];
@@ -1564,8 +1574,8 @@ - (instancetype)initWithPath:(const ConcreteEventPath &)path
15641574
eventNumber:(NSNumber *)eventNumber
15651575
priority:(NSNumber *)priority
15661576
timestamp:(NSNumber *)timestamp
1567-
value:(nullable id)value
1568-
error:(nullable NSError *)error
1577+
value:(id _Nullable)value
1578+
error:(NSError * _Nullable)error
15691579
{
15701580
if (self = [super init]) {
15711581
_path = [[MTREventPath alloc] initWithPath:path];

src/darwin/Framework/CHIP/MTRBaseDevice_Internal.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ NS_ASSUME_NONNULL_BEGIN
7575

7676
@interface MTRAttributeReport ()
7777
- (instancetype)initWithPath:(const chip::app::ConcreteDataAttributePath &)path
78-
value:(nullable id)value
79-
error:(nullable NSError *)error;
78+
value:(id _Nullable)value
79+
error:(NSError * _Nullable)error;
8080
@end
8181

8282
@interface MTREventReport ()
8383
- (instancetype)initWithPath:(const chip::app::ConcreteEventPath &)path
8484
eventNumber:(NSNumber *)eventNumber
8585
priority:(NSNumber *)priority
8686
timestamp:(NSNumber *)timestamp
87-
value:(nullable id)value
88-
error:(nullable NSError *)error;
87+
value:(id _Nullable)value
88+
error:(NSError * _Nullable)error;
8989
@end
9090

9191
// Exported utility function

0 commit comments

Comments
 (0)