Skip to content

Commit

Permalink
Add Darwin methods to use attribute cache (#15877)
Browse files Browse the repository at this point in the history
* Define new object CHIPAttributeCacheContainer
  to represent cache per node
* Add new method to Darwin cluster library template
  to read attribute from cache object
* Add a method in the cache object to read attribute
  with generic path
* Add XPC protocol to support new method
* Fix CHIPDevice subscription handling errors and
  automatic resubscription by replacing callback bridge
  with implementation which can handle errors and by
  retaining attribute path object.
* Implement deregistering CHIPDevice subscriptions
  in order to support testing with clean states.
  • Loading branch information
kpark-apple authored and pull[bot] committed Dec 6, 2023
1 parent d4f3c28 commit b8d1743
Show file tree
Hide file tree
Showing 19 changed files with 24,463 additions and 112 deletions.
24 changes: 24 additions & 0 deletions src/darwin/Framework/CHIP.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
5A7947DE27BEC3F500434CF2 /* CHIPXPCListenerSampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A7947DD27BEC3F500434CF2 /* CHIPXPCListenerSampleTests.m */; };
5A7947E427C0129600434CF2 /* CHIPDeviceController+XPC.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A7947E327C0129500434CF2 /* CHIPDeviceController+XPC.m */; };
5A7947E527C0129F00434CF2 /* CHIPDeviceController+XPC.h in Headers */ = {isa = PBXBuildFile; fileRef = 5A7947E227C0101200434CF2 /* CHIPDeviceController+XPC.h */; settings = {ATTRIBUTES = (Public, ); }; };
5A830D6A27CFCB640053B85D /* CHIPDeviceControllerOverXPC+AttributeCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 5A830D6927CFCB570053B85D /* CHIPDeviceControllerOverXPC+AttributeCache.h */; };
5A830D6C27CFCF590053B85D /* CHIPDeviceControllerOverXPC_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 5A830D6B27CFCF590053B85D /* CHIPDeviceControllerOverXPC_Internal.h */; };
5A830D6E27CFCFF90053B85D /* CHIPDeviceControllerOverXPC+AttributeCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A830D6D27CFCFF90053B85D /* CHIPDeviceControllerOverXPC+AttributeCache.m */; };
5ACDDD7A27CD129700EFD68A /* CHIPAttributeCacheContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 5ACDDD7927CD129700EFD68A /* CHIPAttributeCacheContainer.h */; settings = {ATTRIBUTES = (Public, ); }; };
5ACDDD7D27CD16D200EFD68A /* CHIPAttributeCacheContainer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5ACDDD7C27CD16D200EFD68A /* CHIPAttributeCacheContainer.mm */; };
5ACDDD7E27CD3F3A00EFD68A /* CHIPAttributeCacheContainer_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 5ACDDD7B27CD14AF00EFD68A /* CHIPAttributeCacheContainer_Internal.h */; };
5AE6D4E427A99041001F2493 /* CHIPDeviceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AE6D4E327A99041001F2493 /* CHIPDeviceTests.m */; };
991DC0842475F45400C13860 /* CHIPDeviceController.h in Headers */ = {isa = PBXBuildFile; fileRef = 991DC0822475F45400C13860 /* CHIPDeviceController.h */; settings = {ATTRIBUTES = (Public, ); }; };
991DC0892475F47D00C13860 /* CHIPDeviceController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 991DC0872475F47D00C13860 /* CHIPDeviceController.mm */; };
Expand Down Expand Up @@ -158,6 +164,12 @@
5A7947DD27BEC3F500434CF2 /* CHIPXPCListenerSampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CHIPXPCListenerSampleTests.m; sourceTree = "<group>"; };
5A7947E227C0101200434CF2 /* CHIPDeviceController+XPC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CHIPDeviceController+XPC.h"; sourceTree = "<group>"; };
5A7947E327C0129500434CF2 /* CHIPDeviceController+XPC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "CHIPDeviceController+XPC.m"; sourceTree = "<group>"; };
5A830D6927CFCB570053B85D /* CHIPDeviceControllerOverXPC+AttributeCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CHIPDeviceControllerOverXPC+AttributeCache.h"; sourceTree = "<group>"; };
5A830D6B27CFCF590053B85D /* CHIPDeviceControllerOverXPC_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CHIPDeviceControllerOverXPC_Internal.h; sourceTree = "<group>"; };
5A830D6D27CFCFF90053B85D /* CHIPDeviceControllerOverXPC+AttributeCache.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "CHIPDeviceControllerOverXPC+AttributeCache.m"; sourceTree = "<group>"; };
5ACDDD7927CD129700EFD68A /* CHIPAttributeCacheContainer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CHIPAttributeCacheContainer.h; sourceTree = "<group>"; };
5ACDDD7B27CD14AF00EFD68A /* CHIPAttributeCacheContainer_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CHIPAttributeCacheContainer_Internal.h; sourceTree = "<group>"; };
5ACDDD7C27CD16D200EFD68A /* CHIPAttributeCacheContainer.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CHIPAttributeCacheContainer.mm; sourceTree = "<group>"; };
5AE6D4E327A99041001F2493 /* CHIPDeviceTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CHIPDeviceTests.m; sourceTree = "<group>"; };
991DC0822475F45400C13860 /* CHIPDeviceController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CHIPDeviceController.h; sourceTree = "<group>"; };
991DC0872475F47D00C13860 /* CHIPDeviceController.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CHIPDeviceController.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -289,6 +301,9 @@
2C222ACE255C620600E446B9 /* CHIPDevice.h */,
2C222ACF255C620600E446B9 /* CHIPDevice.mm */,
2C8C8FBE253E0C2100797F05 /* CHIPPersistentStorageDelegate.h */,
5ACDDD7927CD129700EFD68A /* CHIPAttributeCacheContainer.h */,
5ACDDD7B27CD14AF00EFD68A /* CHIPAttributeCacheContainer_Internal.h */,
5ACDDD7C27CD16D200EFD68A /* CHIPAttributeCacheContainer.mm */,
997DED152695343400975E97 /* CHIPThreadOperationalDataset.mm */,
997DED172695344800975E97 /* CHIPThreadOperationalDataset.h */,
2C8C8FBD253E0C2100797F05 /* CHIPPersistentStorageDelegateBridge.h */,
Expand Down Expand Up @@ -322,7 +337,10 @@
5A6FEC8B27B5609C00F25F42 /* CHIPDeviceOverXPC.h */,
5A6FEC9727B5C6AF00F25F42 /* CHIPDeviceOverXPC.m */,
5A6FEC8D27B5624E00F25F42 /* CHIPDeviceControllerOverXPC.h */,
5A830D6B27CFCF590053B85D /* CHIPDeviceControllerOverXPC_Internal.h */,
5A6FEC8F27B563D900F25F42 /* CHIPDeviceControllerOverXPC.m */,
5A830D6927CFCB570053B85D /* CHIPDeviceControllerOverXPC+AttributeCache.h */,
5A830D6D27CFCFF90053B85D /* CHIPDeviceControllerOverXPC+AttributeCache.m */,
5A6FEC9427B5976200F25F42 /* CHIPDeviceControllerXPCConnection.h */,
5A6FEC9527B5983000F25F42 /* CHIPDeviceControllerXPCConnection.m */,
);
Expand Down Expand Up @@ -365,6 +383,7 @@
51B22C222740CB1D008D5055 /* CHIPCommandPayloadsObjc.h in Headers */,
51B22C1E2740CB0A008D5055 /* CHIPStructsObjc.h in Headers */,
2CB7163B252E8A7B0026E2BB /* CHIPDevicePairingDelegateBridge.h in Headers */,
5ACDDD7A27CD129700EFD68A /* CHIPAttributeCacheContainer.h in Headers */,
1E16A90326B98AF100683C53 /* CHIPTestClustersObjc.h in Headers */,
5A6FEC9227B5669C00F25F42 /* CHIPDeviceControllerOverXPC.h in Headers */,
2C1B027B2641DB4E00780EF1 /* CHIPOperationalCredentialsDelegate.h in Headers */,
Expand All @@ -379,6 +398,8 @@
B2E0D7B8245B0B5C003C5B48 /* CHIPSetupPayload.h in Headers */,
997DED182695344800975E97 /* CHIPThreadOperationalDataset.h in Headers */,
9956064426420367000C28DE /* CHIPSetupPayload_Internal.h in Headers */,
5A830D6C27CFCF590053B85D /* CHIPDeviceControllerOverXPC_Internal.h in Headers */,
5ACDDD7E27CD3F3A00EFD68A /* CHIPAttributeCacheContainer_Internal.h in Headers */,
998F286D26D55E10001846C6 /* CHIPKeypair.h in Headers */,
1ED276E426C5832500547A89 /* CHIPCluster.h in Headers */,
5A6FEC9A27B5C89300F25F42 /* CHIPDeviceControllerXPCConnection.h in Headers */,
Expand All @@ -388,6 +409,7 @@
1EC4CE6425CC276600D7304F /* CHIPClustersObjc.h in Headers */,
2C5EEEF6268A85C400CAE3D3 /* CHIPDeviceConnectionBridge.h in Headers */,
2C8C8FC0253E0C2100797F05 /* CHIPPersistentStorageDelegateBridge.h in Headers */,
5A830D6A27CFCB640053B85D /* CHIPDeviceControllerOverXPC+AttributeCache.h in Headers */,
998F286F26D55EC5001846C6 /* CHIPP256KeypairBridge.h in Headers */,
2C222ADF255C811800E446B9 /* CHIPDevice_Internal.h in Headers */,
991DC08B247704DC00C13860 /* CHIPLogging.h in Headers */,
Expand Down Expand Up @@ -541,6 +563,7 @@
1ED276E026C57CF000547A89 /* CHIPCallbackBridge.mm in Sources */,
5A6FEC9627B5983000F25F42 /* CHIPDeviceControllerXPCConnection.m in Sources */,
1E85732D26551A490050A4D9 /* util.cpp in Sources */,
5ACDDD7D27CD16D200EFD68A /* CHIPAttributeCacheContainer.mm in Sources */,
513DDB8A2761F6F900DAA01A /* CHIPAttributeTLVValueDecoder.mm in Sources */,
2FD775552695557E00FF4B12 /* error-mapping.cpp in Sources */,
5A7947E427C0129600434CF2 /* CHIPDeviceController+XPC.m in Sources */,
Expand All @@ -554,6 +577,7 @@
B2E0D7B6245B0B5C003C5B48 /* CHIPManualSetupPayloadParser.mm in Sources */,
5A6FEC9827B5C6AF00F25F42 /* CHIPDeviceOverXPC.m in Sources */,
1E85732826551A490050A4D9 /* attribute-table.cpp in Sources */,
5A830D6E27CFCFF90053B85D /* CHIPDeviceControllerOverXPC+AttributeCache.m in Sources */,
1E85732626551A490050A4D9 /* attribute-storage.cpp in Sources */,
1E85732C26551A490050A4D9 /* DataModelHandler.cpp in Sources */,
);
Expand Down
1 change: 1 addition & 0 deletions src/darwin/Framework/CHIP/CHIP.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

// pull together CHIP headers
#import <CHIP/CHIPAttributeCacheContainer.h>
#import <CHIP/CHIPCluster.h>
#import <CHIP/CHIPClustersObjc.h>
#import <CHIP/CHIPCommandPayloadsObjc.h>
Expand Down
59 changes: 59 additions & 0 deletions src/darwin/Framework/CHIP/CHIPAttributeCacheContainer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
*
* Copyright (c) 2022 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 <Foundation/Foundation.h>

#import <CHIP/CHIPDeviceController.h>

NS_ASSUME_NONNULL_BEGIN

@interface CHIPAttributeCacheContainer : NSObject

/**
* Subscribes to all attributes to update attribute cache.
*
* @param deviceController device controller to retrieve connected device from
* @param deviceId device identifier of the device to cache attributes of
* @param clientQueue client queue to dispatch the completion handler through
* @param completion completion handler
*/
- (void)subscribeWithDeviceController:(CHIPDeviceController *)deviceController
deviceId:(uint64_t)deviceId
clientQueue:(dispatch_queue_t)clientQueue
completion:(void (^)(NSError * _Nullable error))completion;

/**
* 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 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.
*/
- (void)readAttributeWithEndpointId:(NSUInteger)endpointId
clusterId:(NSUInteger)clusterId
attributeId:(NSUInteger)attributeId
clientQueue:(dispatch_queue_t)clientQueue
completion:(void (^)(NSArray<NSDictionary<NSString *, id> *> * _Nullable values,
NSError * _Nullable error))completion;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit b8d1743

Please sign in to comment.