-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Darwin: Add MTRCommissioningParameters.readEndpointInformation (#37118)
* Darwin: Tidy up some device type meta-data classes - Move MTRDeviceTypeRevision out of ServerEndpoint directory - Move MTRProductIdentity into its own file - Implement NSCopying and equality on MTRDeviceType and MTRProductIdentity - Implement description on all 3 types - Add tests * Darwin: Add MTRCommissioningParameters.readEndpointInformation Endpoint information is made availalable to the delegate via an MTRCommissioneeInfo object containing MTREndpointInfo objects. * Apply suggestions from code review Co-authored-by: Boris Zbarsky <[email protected]> * Use NSString literal for MTRDeviceTypeData * Process endpoints in best-effort fashion even with invalid / missing DeviceTypeList Also add some additional comments to parsing logic and a couple more tests. * Address further review comments for Darwin layer * Move MTRCommissioneeInfo into its own set of files * Make MTRCommissioneeInfo and related types conform to NSSecureCoding Also conform to NSCopying, mark as sendable, and implement isEqual/hash. * Fix terminology a bit. --------- Co-authored-by: Boris Zbarsky <[email protected]>
- Loading branch information
1 parent
2376bdd
commit 7f32ff8
Showing
32 changed files
with
1,543 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/darwin/Framework/CHIP/MTRAttributeTLVValueDecoder_Internal.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import "MTRAttributeTLVValueDecoder_Internal.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
using namespace chip; | ||
|
||
id _Nullable MTRDecodeAttributeValue(const chip::app::ConcreteAttributePath & aPath, | ||
const chip::app::ClusterStateCache & aCache, | ||
CHIP_ERROR * aError) | ||
{ | ||
TLV::TLVReader reader; | ||
*aError = aCache.Get(aPath, reader); | ||
VerifyOrReturnValue(*aError == CHIP_NO_ERROR, nil); | ||
return MTRDecodeAttributeValue(aPath, reader, aError); | ||
} | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import <Matter/MTRDefines.h> | ||
|
||
@class MTRProductIdentity; | ||
@class MTREndpointInfo; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
* Information read from the commissionee device during commissioning. | ||
*/ | ||
NS_SWIFT_SENDABLE | ||
MTR_NEWLY_AVAILABLE | ||
@interface MTRCommissioneeInfo : NSObject <NSCopying, NSSecureCoding> | ||
|
||
/** | ||
* The product identity (VID / PID) of the commissionee. | ||
*/ | ||
@property (nonatomic, copy, readonly) MTRProductIdentity * productIdentity; | ||
|
||
/** | ||
* Endpoint information for all endpoints of the commissionee. | ||
* Will be present only if readEndpointInformation is set to YES on MTRCommissioningParameters. | ||
* | ||
* Use `rootEndpoint` and `-[MTREndpointInfo children]` to traverse endpoints in composition order. | ||
*/ | ||
@property (nonatomic, copy, readonly, nullable) NSDictionary<NSNumber *, MTREndpointInfo *> * endpointsById; | ||
|
||
/** | ||
* Endpoint information for the root endpoint of the commissionee. | ||
* Will be present only if readEndpointInformation is set to YES on MTRCommissioningParameters. | ||
*/ | ||
@property (nonatomic, copy, readonly, nullable) MTREndpointInfo * rootEndpoint; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import "MTRCommissioneeInfo_Internal.h" | ||
|
||
#import "MTRDefines_Internal.h" | ||
#import "MTREndpointInfo_Internal.h" | ||
#import "MTRProductIdentity.h" | ||
#import "MTRUtilities.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
MTR_DIRECT_MEMBERS | ||
@implementation MTRCommissioneeInfo | ||
|
||
- (instancetype)initWithCommissioningInfo:(const chip::Controller::ReadCommissioningInfo &)info | ||
{ | ||
self = [super init]; | ||
_productIdentity = [[MTRProductIdentity alloc] initWithVendorID:@(info.basic.vendorId) productID:@(info.basic.productId)]; | ||
|
||
// TODO: We should probably hold onto our MTRCommissioningParameters so we can look at `readEndpointInformation` | ||
// instead of just reading whatever Descriptor cluster information happens to be in the cache. | ||
auto * endpoints = [MTREndpointInfo endpointsFromAttributeCache:info.attributes]; | ||
if (endpoints.count > 0) { | ||
_endpointsById = endpoints; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
static NSString * const sProductIdentityCodingKey = @"pi"; | ||
static NSString * const sEndpointsCodingKey = @"ep"; | ||
|
||
- (nullable instancetype)initWithCoder:(NSCoder *)coder | ||
{ | ||
self = [super init]; | ||
_productIdentity = [coder decodeObjectOfClass:MTRProductIdentity.class forKey:sProductIdentityCodingKey]; | ||
VerifyOrReturnValue(_productIdentity != nil, nil); | ||
_endpointsById = [coder decodeDictionaryWithKeysOfClass:NSNumber.class | ||
objectsOfClass:MTREndpointInfo.class | ||
forKey:sEndpointsCodingKey]; | ||
return self; | ||
} | ||
|
||
- (void)encodeWithCoder:(NSCoder *)coder | ||
{ | ||
[coder encodeObject:_productIdentity forKey:sProductIdentityCodingKey]; | ||
[coder encodeObject:_endpointsById forKey:sEndpointsCodingKey]; | ||
} | ||
|
||
+ (BOOL)supportsSecureCoding | ||
{ | ||
return YES; | ||
} | ||
|
||
- (NSUInteger)hash | ||
{ | ||
return _productIdentity.hash; | ||
} | ||
|
||
- (BOOL)isEqual:(id)object | ||
{ | ||
VerifyOrReturnValue([object class] == [self class], NO); | ||
MTRCommissioneeInfo * other = object; | ||
VerifyOrReturnValue(MTREqualObjects(_productIdentity, other->_productIdentity), NO); | ||
VerifyOrReturnValue(MTREqualObjects(_endpointsById, other->_endpointsById), NO); | ||
return YES; | ||
} | ||
|
||
- (id)copyWithZone:(nullable NSZone *)zone | ||
{ | ||
return self; // immutable | ||
} | ||
|
||
- (nullable MTREndpointInfo *)rootEndpoint | ||
{ | ||
return self.endpointsById[@0]; | ||
} | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import <Matter/MTRCommissioneeInfo.h> | ||
|
||
#import "MTRDefines_Internal.h" | ||
|
||
#include <controller/CommissioningDelegate.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
MTR_DIRECT_MEMBERS | ||
@interface MTRCommissioneeInfo () | ||
|
||
- (instancetype)initWithCommissioningInfo:(const chip::Controller::ReadCommissioningInfo &)info; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.