Skip to content

Commit deff77a

Browse files
Rename expectedResult to requiredResponse in the invokeCommands API. (#37416)
The old naming was too confusing, and this more accurately represents what is actually going on.
1 parent 09833eb commit deff77a

11 files changed

+61
-61
lines changed

src/darwin/Framework/CHIP/MTRCommandWithExpectedResult.h src/darwin/Framework/CHIP/MTRCommandWithRequiredResponse.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
NS_ASSUME_NONNULL_BEGIN
2121

2222
/**
23-
* An object representing a single command to be invoked and the expected
24-
* result of invoking it.
23+
* An object representing a single command to be invoked and the response
24+
* required for the invoke to be considered successful.
2525
*/
2626
MTR_AVAILABLE(ios(18.4), macos(15.4), watchos(11.4), tvos(18.4))
27-
@interface MTRCommandWithExpectedResult : NSObject <NSCopying, NSSecureCoding>
27+
@interface MTRCommandWithRequiredResponse : NSObject <NSCopying, NSSecureCoding>
2828

2929
/**
3030
* The path of the command being invoked.
@@ -39,22 +39,22 @@ MTR_AVAILABLE(ios(18.4), macos(15.4), watchos(11.4), tvos(18.4))
3939
@property (nonatomic, retain, nullable) NSDictionary<NSString *, id> * commandFields;
4040

4141
/**
42-
* The expected result of invoking the command.
42+
* The response that represents this command succeeding.
4343
*
4444
* If this is nil, that indicates that the invoke is considered successful if it
4545
* does not result in an error status response.
4646
*
47-
* If this is is not nil, then invoke is considered successful if
48-
* it results in a data response and for each entry in the provided
49-
* expectedResult the field whose field ID matches the key of the entry has a
47+
* If this is is not nil, then the invoke is considered successful if
48+
* the response is a data response and for each entry in the provided
49+
* requiredResponse the field whose field ID matches the key of the entry has a
5050
* value that equals the value of the entry. Values of entries are data-value
5151
* dictionaries.
5252
*/
53-
@property (nonatomic, copy, nullable) NSDictionary<NSNumber *, NSDictionary<NSString *, id> *> * expectedResult;
53+
@property (nonatomic, copy, nullable) NSDictionary<NSNumber *, NSDictionary<NSString *, id> *> * requiredResponse;
5454

5555
- (instancetype)initWithPath:(MTRCommandPath *)path
5656
commandFields:(nullable NSDictionary<NSString *, id> *)commandFields
57-
expectedResult:(nullable NSDictionary<NSNumber *, NSDictionary<NSString *, id> *> *)expectedResult;
57+
requiredResponse:(nullable NSDictionary<NSNumber *, NSDictionary<NSString *, id> *> *)requiredResponse;
5858

5959
@end
6060

src/darwin/Framework/CHIP/MTRCommandWithExpectedResult.mm src/darwin/Framework/CHIP/MTRCommandWithRequiredResponse.mm

+20-20
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,35 @@
1818
#import "MTRLogging_Internal.h"
1919
#import <Matter/Matter.h>
2020

21-
@implementation MTRCommandWithExpectedResult
21+
@implementation MTRCommandWithRequiredResponse
2222
- (instancetype)initWithPath:(MTRCommandPath *)path
2323
commandFields:(nullable NSDictionary<NSString *, id> *)commandFields
24-
expectedResult:(nullable NSDictionary<NSNumber *, NSDictionary<NSString *, id> *> *)expectedResult
24+
requiredResponse:(nullable NSDictionary<NSNumber *, NSDictionary<NSString *, id> *> *)requiredResponse
2525
{
2626
if (self = [super init]) {
2727
self.path = path;
2828
self.commandFields = commandFields;
29-
self.expectedResult = expectedResult;
29+
self.requiredResponse = requiredResponse;
3030
}
3131

3232
return self;
3333
}
3434

3535
- (id)copyWithZone:(NSZone *)zone
3636
{
37-
return [[MTRCommandWithExpectedResult alloc] initWithPath:self.path commandFields:self.commandFields expectedResult:self.expectedResult];
37+
return [[MTRCommandWithRequiredResponse alloc] initWithPath:self.path commandFields:self.commandFields requiredResponse:self.requiredResponse];
3838
}
3939

4040
- (NSString *)description
4141
{
42-
return [NSString stringWithFormat:@"<%@: %p, path: %@, fields: %@, expectedResult: %@", NSStringFromClass(self.class), self, self.path, self.commandFields, self.expectedResult];
42+
return [NSString stringWithFormat:@"<%@: %p, path: %@, fields: %@, requiredResponse: %@", NSStringFromClass(self.class), self, self.path, self.commandFields, self.requiredResponse];
4343
}
4444

45-
#pragma mark - MTRCommandWithExpectedResult NSSecureCoding implementation
45+
#pragma mark - MTRCommandWithRequiredResponse NSSecureCoding implementation
4646

4747
static NSString * const sPathKey = @"pathKey";
4848
static NSString * const sFieldsKey = @"fieldsKey";
49-
static NSString * const sExpectedResultKey = @"expectedResultKey";
49+
static NSString * const sExpectedResultKey = @"requiredResponseKey";
5050

5151
+ (BOOL)supportsSecureCoding
5252
{
@@ -62,38 +62,38 @@ - (nullable instancetype)initWithCoder:(NSCoder *)decoder
6262

6363
_path = [decoder decodeObjectOfClass:MTRCommandPath.class forKey:sPathKey];
6464
if (!_path || ![_path isKindOfClass:MTRCommandPath.class]) {
65-
MTR_LOG_ERROR("MTRCommandWithExpectedResult decoded %@ for endpoint, not MTRCommandPath.", _path);
65+
MTR_LOG_ERROR("MTRCommandWithRequiredResponse decoded %@ for endpoint, not MTRCommandPath.", _path);
6666
return nil;
6767
}
6868

6969
_commandFields = [decoder decodeObjectOfClass:NSDictionary.class forKey:sFieldsKey];
7070
if (_commandFields) {
7171
if (![_commandFields isKindOfClass:NSDictionary.class]) {
72-
MTR_LOG_ERROR("MTRCommandWithExpectedResult decoded %@ for commandFields, not NSDictionary.", _commandFields);
72+
MTR_LOG_ERROR("MTRCommandWithRequiredResponse decoded %@ for commandFields, not NSDictionary.", _commandFields);
7373
return nil;
7474
}
7575

7676
if (!MTRDataValueDictionaryIsWellFormed(_commandFields) || ![MTRStructureValueType isEqual:_commandFields[MTRTypeKey]]) {
77-
MTR_LOG_ERROR("MTRCommandWithExpectedResult decoded %@ for commandFields, not a structure-typed data-value dictionary.", _commandFields);
77+
MTR_LOG_ERROR("MTRCommandWithRequiredResponse decoded %@ for commandFields, not a structure-typed data-value dictionary.", _commandFields);
7878
return nil;
7979
}
8080
}
8181

82-
_expectedResult = [decoder decodeObjectOfClass:NSDictionary.class forKey:sExpectedResultKey];
83-
if (_expectedResult) {
84-
if (![_expectedResult isKindOfClass:NSDictionary.class]) {
85-
MTR_LOG_ERROR("MTRCommandWithExpectedResult decoded %@ for expectedResult, not NSDictionary.", _expectedResult);
82+
_requiredResponse = [decoder decodeObjectOfClass:NSDictionary.class forKey:sExpectedResultKey];
83+
if (_requiredResponse) {
84+
if (![_requiredResponse isKindOfClass:NSDictionary.class]) {
85+
MTR_LOG_ERROR("MTRCommandWithRequiredResponse decoded %@ for requiredResponse, not NSDictionary.", _requiredResponse);
8686
return nil;
8787
}
8888

89-
for (id key in _expectedResult) {
89+
for (id key in _requiredResponse) {
9090
if (![key isKindOfClass:NSNumber.class]) {
91-
MTR_LOG_ERROR("MTRCommandWithExpectedResult decoded key %@ in expectedResult", key);
91+
MTR_LOG_ERROR("MTRCommandWithRequiredResponse decoded key %@ in requiredResponse", key);
9292
return nil;
9393
}
9494

95-
if (![_expectedResult[key] isKindOfClass:NSDictionary.class] || !MTRDataValueDictionaryIsWellFormed(_expectedResult[key])) {
96-
MTR_LOG_ERROR("MTRCommandWithExpectedResult decoded value %@ for key %@ in expectedResult", _expectedResult[key], key);
95+
if (![_requiredResponse[key] isKindOfClass:NSDictionary.class] || !MTRDataValueDictionaryIsWellFormed(_requiredResponse[key])) {
96+
MTR_LOG_ERROR("MTRCommandWithRequiredResponse decoded value %@ for key %@ in requiredResponse", _requiredResponse[key], key);
9797
return nil;
9898
}
9999
}
@@ -111,8 +111,8 @@ - (void)encodeWithCoder:(NSCoder *)coder
111111
if (self.commandFields) {
112112
[coder encodeObject:self.commandFields forKey:sFieldsKey];
113113
}
114-
if (self.expectedResult) {
115-
[coder encodeObject:self.expectedResult forKey:sExpectedResultKey];
114+
if (self.requiredResponse) {
115+
[coder encodeObject:self.requiredResponse forKey:sExpectedResultKey];
116116
}
117117
}
118118

src/darwin/Framework/CHIP/MTRDevice.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#import <Matter/MTRAttributeValueWaiter.h>
2020
#import <Matter/MTRBaseClusters.h>
2121
#import <Matter/MTRBaseDevice.h>
22-
#import <Matter/MTRCommandWithExpectedResult.h>
22+
#import <Matter/MTRCommandWithRequiredResponse.h>
2323
#import <Matter/MTRDefines.h>
2424

2525
NS_ASSUME_NONNULL_BEGIN
@@ -316,7 +316,7 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))
316316
* response. In this case the data-value representing the response will be
317317
* the value of this field.
318318
*/
319-
- (void)invokeCommands:(NSArray<NSArray<MTRCommandWithExpectedResult *> *> *)commands
319+
- (void)invokeCommands:(NSArray<NSArray<MTRCommandWithRequiredResponse *> *> *)commands
320320
queue:(dispatch_queue_t)queue
321321
completion:(MTRDeviceResponseHandler)completion MTR_AVAILABLE(ios(18.4), macos(15.4), watchos(11.4), tvos(18.4));
322322

src/darwin/Framework/CHIP/MTRDevice.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ - (void)_invokeKnownCommandWithEndpointID:(NSNumber *)endpointID
523523
completion:responseHandler];
524524
}
525525

526-
- (void)invokeCommands:(NSArray<NSArray<MTRCommandWithExpectedResult *> *> *)commands
526+
- (void)invokeCommands:(NSArray<NSArray<MTRCommandWithRequiredResponse *> *> *)commands
527527
queue:(dispatch_queue_t)queue
528528
completion:(MTRDeviceResponseHandler)completion
529529
{

src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ - (NSXPCInterface *)_interfaceForServerProtocol
150150
argumentIndex:0
151151
ofReply:YES];
152152

153-
// invokeCommands gets handed MTRCommandWithExpectedResult (which includes
153+
// invokeCommands gets handed MTRCommandWithRequiredResponse (which includes
154154
// MTRCommandPath, which is already in allowedClasses).
155155
[allowedClasses addObjectsFromArray:@[
156-
[MTRCommandWithExpectedResult class],
156+
[MTRCommandWithRequiredResponse class],
157157
]];
158158
[interface setClasses:allowedClasses
159159
forSelector:@selector(deviceController:nodeID:invokeCommands:completion:)

src/darwin/Framework/CHIP/MTRDevice_Concrete.mm

+7-7
Original file line numberDiff line numberDiff line change
@@ -3306,7 +3306,7 @@ - (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
33063306
commandFields];
33073307
}
33083308

3309-
- (BOOL)_invokeResponse:(MTRDeviceResponseValueDictionary)response matchesExpectedResult:(NSDictionary<NSNumber *, MTRDeviceDataValueDictionary> *)expectedResult
3309+
- (BOOL)_invokeResponse:(MTRDeviceResponseValueDictionary)response matchesRequiredResponse:(NSDictionary<NSNumber *, MTRDeviceDataValueDictionary> *)requiredResponse
33103310
{
33113311
if (response[MTRDataKey] == nil) {
33123312
MTR_LOG_ERROR("%@ invokeCommands expects a data response for %@ but got no data", self, response[MTRCommandPathKey]);
@@ -3321,7 +3321,7 @@ - (BOOL)_invokeResponse:(MTRDeviceResponseValueDictionary)response matchesExpect
33213321

33223322
NSArray<NSDictionary<NSString *, id> *> * fields = data[MTRValueKey];
33233323

3324-
for (NSNumber * fieldID in expectedResult) {
3324+
for (NSNumber * fieldID in requiredResponse) {
33253325
// Check that this field is present in the response.
33263326
MTRDeviceDataValueDictionary _Nullable fieldValue = nil;
33273327
for (NSDictionary<NSString *, id> * field in fields) {
@@ -3336,7 +3336,7 @@ - (BOOL)_invokeResponse:(MTRDeviceResponseValueDictionary)response matchesExpect
33363336
return NO;
33373337
}
33383338

3339-
auto * expected = expectedResult[fieldID];
3339+
auto * expected = requiredResponse[fieldID];
33403340
if (![expected isEqual:fieldValue]) {
33413341
MTR_LOG_ERROR("%@ invokeCommands response for %@ field %@ got %@ but expected %@", self, response[MTRCommandPathKey], fieldID, fieldValue, expected);
33423342
return NO;
@@ -3346,7 +3346,7 @@ - (BOOL)_invokeResponse:(MTRDeviceResponseValueDictionary)response matchesExpect
33463346
return YES;
33473347
}
33483348

3349-
- (void)invokeCommands:(NSArray<NSArray<MTRCommandWithExpectedResult *> *> *)commands
3349+
- (void)invokeCommands:(NSArray<NSArray<MTRCommandWithRequiredResponse *> *> *)commands
33503350
queue:(dispatch_queue_t)queue
33513351
completion:(MTRDeviceResponseHandler)completion
33523352
{
@@ -3361,10 +3361,10 @@ - (void)invokeCommands:(NSArray<NSArray<MTRCommandWithExpectedResult *> *> *)com
33613361
// We want to invoke the command groups in order, stopping after failures as needed. Build up a
33623362
// linked list of groups via chaining the completions, with calls out to the original
33633363
// completion instead of going to the next list item when we want to stop.
3364-
for (NSArray<MTRCommandWithExpectedResult *> * commandGroup in [commands reverseObjectEnumerator]) {
3364+
for (NSArray<MTRCommandWithRequiredResponse *> * commandGroup in [commands reverseObjectEnumerator]) {
33653365
// We want to invoke all the commands in the group in order, propagating along the list of
33663366
// current responses. Build up that linked list of command invokes via chaining the completions.
3367-
for (MTRCommandWithExpectedResult * command in [commandGroup reverseObjectEnumerator]) {
3367+
for (MTRCommandWithRequiredResponse * command in [commandGroup reverseObjectEnumerator]) {
33683368
auto commandInvokeBlock = ^(BOOL allSucceededSoFar, NSArray<MTRDeviceResponseValueDictionary> * previousResponses) {
33693369
[self invokeCommandWithEndpointID:command.path.endpoint
33703370
clusterID:command.path.cluster
@@ -3394,7 +3394,7 @@ - (void)invokeCommands:(NSArray<NSArray<MTRCommandWithExpectedResult *> *> *)com
33943394

33953395
BOOL nextAllSucceeded = allSucceededSoFar;
33963396
MTRDeviceResponseValueDictionary response = responses[0];
3397-
if (command.expectedResult != nil && ![self _invokeResponse:response matchesExpectedResult:command.expectedResult]) {
3397+
if (command.requiredResponse != nil && ![self _invokeResponse:response matchesRequiredResponse:command.requiredResponse]) {
33983398
nextAllSucceeded = NO;
33993399
}
34003400

src/darwin/Framework/CHIP/MTRDevice_XPC.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ - (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
459459
}
460460
}
461461

462-
- (void)invokeCommands:(NSArray<NSArray<MTRCommandWithExpectedResult *> *> *)commands
462+
- (void)invokeCommands:(NSArray<NSArray<MTRCommandWithRequiredResponse *> *> *)commands
463463
queue:(dispatch_queue_t)queue
464464
completion:(MTRDeviceResponseHandler)completion
465465
{

src/darwin/Framework/CHIP/Matter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#import <Matter/MTRClusterStateCacheContainer.h>
3535
#import <Matter/MTRClusters.h>
3636
#import <Matter/MTRCommandPayloadsObjc.h>
37-
#import <Matter/MTRCommandWithExpectedResult.h>
37+
#import <Matter/MTRCommandWithRequiredResponse.h>
3838
#import <Matter/MTRCommissionableBrowserDelegate.h>
3939
#import <Matter/MTRCommissionableBrowserResult.h>
4040
#import <Matter/MTRCommissioneeInfo.h>

src/darwin/Framework/CHIP/XPC Protocol/MTRXPCServerProtocol.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ MTR_AVAILABLE(ios(18.2), macos(15.2), watchos(11.2), tvos(18.2))
5252
*/
5353
- (oneway void)deviceController:(NSUUID *)controller nodeID:(NSNumber *)nodeID downloadLogOfType:(MTRDiagnosticLogType)type timeout:(NSTimeInterval)timeout completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion;
5454

55-
- (oneway void)deviceController:(NSUUID *)controller nodeID:(NSNumber *)nodeID invokeCommands:(NSArray<NSArray<MTRCommandWithExpectedResult *> *> *)commands completion:(MTRDeviceResponseHandler)completion MTR_AVAILABLE(ios(18.4), macos(15.4), watchos(11.4), tvos(18.4));
55+
- (oneway void)deviceController:(NSUUID *)controller nodeID:(NSNumber *)nodeID invokeCommands:(NSArray<NSArray<MTRCommandWithRequiredResponse *> *> *)commands completion:(MTRDeviceResponseHandler)completion MTR_AVAILABLE(ios(18.4), macos(15.4), watchos(11.4), tvos(18.4));
5656

5757
@end
5858

0 commit comments

Comments
 (0)