Skip to content

Commit

Permalink
Add generic interaction methods to CHIP Framework (#15272)
Browse files Browse the repository at this point in the history
* Add new methods to CHIPDevice for generic attribute and command paths
* Add a new method to CHIPDeviceController class to get CHIPDevice object
  executing over XPC interface.
  • Loading branch information
kpark-apple authored and pull[bot] committed Mar 3, 2022
1 parent a5798a9 commit 4186260
Show file tree
Hide file tree
Showing 16 changed files with 5,443 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/darwin/Framework/CHIP.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
51B22C262740CB32008D5055 /* CHIPStructsObjc.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51B22C252740CB32008D5055 /* CHIPStructsObjc.mm */; };
51B22C2A2740CB47008D5055 /* CHIPCommandPayloadsObjc.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51B22C292740CB47008D5055 /* CHIPCommandPayloadsObjc.mm */; };
51E24E73274E0DAC007CCF6E /* CHIPErrorTestUtils.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E24E72274E0DAC007CCF6E /* CHIPErrorTestUtils.mm */; };
5A6FEC9027B563D900F25F42 /* CHIPDeviceControllerOverXPC.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A6FEC8F27B563D900F25F42 /* CHIPDeviceControllerOverXPC.m */; };
5A6FEC9227B5669C00F25F42 /* CHIPDeviceControllerOverXPC.h in Headers */ = {isa = PBXBuildFile; fileRef = 5A6FEC8D27B5624E00F25F42 /* CHIPDeviceControllerOverXPC.h */; };
5A6FEC9627B5983000F25F42 /* CHIPDeviceControllerXPCConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A6FEC9527B5983000F25F42 /* CHIPDeviceControllerXPCConnection.m */; };
5A6FEC9827B5C6AF00F25F42 /* CHIPDeviceOverXPC.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A6FEC9727B5C6AF00F25F42 /* CHIPDeviceOverXPC.m */; };
5A6FEC9927B5C88900F25F42 /* CHIPDeviceOverXPC.h in Headers */ = {isa = PBXBuildFile; fileRef = 5A6FEC8B27B5609C00F25F42 /* CHIPDeviceOverXPC.h */; };
5A6FEC9A27B5C89300F25F42 /* CHIPDeviceControllerXPCConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 5A6FEC9427B5976200F25F42 /* CHIPDeviceControllerXPCConnection.h */; };
5A6FEC9D27B5E48900F25F42 /* CHIPXPCProtocolTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A6FEC9C27B5E48800F25F42 /* CHIPXPCProtocolTests.m */; };
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, ); }; };
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 */; };
991DC08B247704DC00C13860 /* CHIPLogging.h in Headers */ = {isa = PBXBuildFile; fileRef = 991DC08A247704DC00C13860 /* CHIPLogging.h */; };
Expand Down Expand Up @@ -137,6 +148,17 @@
51B22C252740CB32008D5055 /* CHIPStructsObjc.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CHIPStructsObjc.mm; path = "zap-generated/CHIPStructsObjc.mm"; sourceTree = "<group>"; };
51B22C292740CB47008D5055 /* CHIPCommandPayloadsObjc.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CHIPCommandPayloadsObjc.mm; path = "zap-generated/CHIPCommandPayloadsObjc.mm"; sourceTree = "<group>"; };
51E24E72274E0DAC007CCF6E /* CHIPErrorTestUtils.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CHIPErrorTestUtils.mm; sourceTree = "<group>"; };
5A6FEC8B27B5609C00F25F42 /* CHIPDeviceOverXPC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CHIPDeviceOverXPC.h; sourceTree = "<group>"; };
5A6FEC8D27B5624E00F25F42 /* CHIPDeviceControllerOverXPC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CHIPDeviceControllerOverXPC.h; sourceTree = "<group>"; };
5A6FEC8F27B563D900F25F42 /* CHIPDeviceControllerOverXPC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CHIPDeviceControllerOverXPC.m; sourceTree = "<group>"; };
5A6FEC9427B5976200F25F42 /* CHIPDeviceControllerXPCConnection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CHIPDeviceControllerXPCConnection.h; sourceTree = "<group>"; };
5A6FEC9527B5983000F25F42 /* CHIPDeviceControllerXPCConnection.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CHIPDeviceControllerXPCConnection.m; sourceTree = "<group>"; };
5A6FEC9727B5C6AF00F25F42 /* CHIPDeviceOverXPC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CHIPDeviceOverXPC.m; sourceTree = "<group>"; };
5A6FEC9C27B5E48800F25F42 /* CHIPXPCProtocolTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CHIPXPCProtocolTests.m; sourceTree = "<group>"; };
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>"; };
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>"; };
991DC08A247704DC00C13860 /* CHIPLogging.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CHIPLogging.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -291,10 +313,18 @@
B2E0D7B0245B0B5C003C5B48 /* CHIPSetupPayload.mm */,
991DC0822475F45400C13860 /* CHIPDeviceController.h */,
991DC0872475F47D00C13860 /* CHIPDeviceController.mm */,
5A7947E227C0101200434CF2 /* CHIPDeviceController+XPC.h */,
5A7947E327C0129500434CF2 /* CHIPDeviceController+XPC.m */,
B20252912459E34F00F97062 /* Info.plist */,
998F286C26D55E10001846C6 /* CHIPKeypair.h */,
998F286E26D55EC5001846C6 /* CHIPP256KeypairBridge.h */,
998F287026D56940001846C6 /* CHIPP256KeypairBridge.mm */,
5A6FEC8B27B5609C00F25F42 /* CHIPDeviceOverXPC.h */,
5A6FEC9727B5C6AF00F25F42 /* CHIPDeviceOverXPC.m */,
5A6FEC8D27B5624E00F25F42 /* CHIPDeviceControllerOverXPC.h */,
5A6FEC8F27B563D900F25F42 /* CHIPDeviceControllerOverXPC.m */,
5A6FEC9427B5976200F25F42 /* CHIPDeviceControllerXPCConnection.h */,
5A6FEC9527B5983000F25F42 /* CHIPDeviceControllerXPCConnection.m */,
);
path = CHIP;
sourceTree = "<group>";
Expand All @@ -305,6 +335,9 @@
51E24E72274E0DAC007CCF6E /* CHIPErrorTestUtils.mm */,
1EB41B7A263C4CC60048E4C1 /* CHIPClustersTests.m */,
99C65E0F267282F1003402F6 /* CHIPControllerTests.m */,
5AE6D4E327A99041001F2493 /* CHIPDeviceTests.m */,
5A6FEC9C27B5E48800F25F42 /* CHIPXPCProtocolTests.m */,
5A7947DD27BEC3F500434CF2 /* CHIPXPCListenerSampleTests.m */,
B2F53AF1245B0DCF0010745E /* CHIPSetupPayloadParserTests.m */,
997DED1926955D0200975E97 /* CHIPThreadOperationalDatasetTests.mm */,
B202529D2459E34F00F97062 /* Info.plist */,
Expand All @@ -328,10 +361,12 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
5A6FEC9927B5C88900F25F42 /* CHIPDeviceOverXPC.h in Headers */,
51B22C222740CB1D008D5055 /* CHIPCommandPayloadsObjc.h in Headers */,
51B22C1E2740CB0A008D5055 /* CHIPStructsObjc.h in Headers */,
2CB7163B252E8A7B0026E2BB /* CHIPDevicePairingDelegateBridge.h in Headers */,
1E16A90326B98AF100683C53 /* CHIPTestClustersObjc.h in Headers */,
5A6FEC9227B5669C00F25F42 /* CHIPDeviceControllerOverXPC.h in Headers */,
2C1B027B2641DB4E00780EF1 /* CHIPOperationalCredentialsDelegate.h in Headers */,
99D466E12798936D0089A18F /* CHIPCommissioningParameters.h in Headers */,
B289D4212639C0D300D4E314 /* CHIPOnboardingPayloadParser.h in Headers */,
Expand All @@ -346,6 +381,7 @@
9956064426420367000C28DE /* CHIPSetupPayload_Internal.h in Headers */,
998F286D26D55E10001846C6 /* CHIPKeypair.h in Headers */,
1ED276E426C5832500547A89 /* CHIPCluster.h in Headers */,
5A6FEC9A27B5C89300F25F42 /* CHIPDeviceControllerXPCConnection.h in Headers */,
5129BCFD26A9EE3300122DDF /* CHIPError.h in Headers */,
2C8C8FC1253E0C2100797F05 /* CHIPPersistentStorageDelegate.h in Headers */,
B2E0D7B5245B0B5C003C5B48 /* CHIPQRCodeSetupPayloadParser.h in Headers */,
Expand All @@ -355,6 +391,7 @@
998F286F26D55EC5001846C6 /* CHIPP256KeypairBridge.h in Headers */,
2C222ADF255C811800E446B9 /* CHIPDevice_Internal.h in Headers */,
991DC08B247704DC00C13860 /* CHIPLogging.h in Headers */,
5A7947E527C0129F00434CF2 /* CHIPDeviceController+XPC.h in Headers */,
B2E0D7B4245B0B5C003C5B48 /* CHIPError_Internal.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -502,16 +539,20 @@
1E85730C265519AE0050A4D9 /* callback-stub.cpp in Sources */,
1E857310265519AE0050A4D9 /* IMClusterCommandHandler.cpp in Sources */,
1ED276E026C57CF000547A89 /* CHIPCallbackBridge.mm in Sources */,
5A6FEC9627B5983000F25F42 /* CHIPDeviceControllerXPCConnection.m in Sources */,
1E85732D26551A490050A4D9 /* util.cpp in Sources */,
513DDB8A2761F6F900DAA01A /* CHIPAttributeTLVValueDecoder.mm in Sources */,
2FD775552695557E00FF4B12 /* error-mapping.cpp in Sources */,
5A7947E427C0129600434CF2 /* CHIPDeviceController+XPC.m in Sources */,
5A6FEC9027B563D900F25F42 /* CHIPDeviceControllerOverXPC.m in Sources */,
1E85732A26551A490050A4D9 /* ember-compatibility-functions.cpp in Sources */,
B289D4222639C0D300D4E314 /* CHIPOnboardingPayloadParser.m in Sources */,
1E85732F26551A490050A4D9 /* attribute-size-util.cpp in Sources */,
2C1B027A2641DB4E00780EF1 /* CHIPOperationalCredentialsDelegate.mm in Sources */,
1E85732926551A490050A4D9 /* af-event.cpp in Sources */,
B2E0D7B9245B0B5C003C5B48 /* CHIPSetupPayload.mm in Sources */,
B2E0D7B6245B0B5C003C5B48 /* CHIPManualSetupPayloadParser.mm in Sources */,
5A6FEC9827B5C6AF00F25F42 /* CHIPDeviceOverXPC.m in Sources */,
1E85732826551A490050A4D9 /* attribute-table.cpp in Sources */,
1E85732626551A490050A4D9 /* attribute-storage.cpp in Sources */,
1E85732C26551A490050A4D9 /* DataModelHandler.cpp in Sources */,
Expand All @@ -525,6 +566,9 @@
1EB41B7B263C4CC60048E4C1 /* CHIPClustersTests.m in Sources */,
997DED1A26955D0200975E97 /* CHIPThreadOperationalDatasetTests.mm in Sources */,
99C65E10267282F1003402F6 /* CHIPControllerTests.m in Sources */,
5A6FEC9D27B5E48900F25F42 /* CHIPXPCProtocolTests.m in Sources */,
5AE6D4E427A99041001F2493 /* CHIPDeviceTests.m in Sources */,
5A7947DE27BEC3F500434CF2 /* CHIPXPCListenerSampleTests.m in Sources */,
B2F53AF2245B0DCF0010745E /* CHIPSetupPayloadParserTests.m in Sources */,
51E24E73274E0DAC007CCF6E /* CHIPErrorTestUtils.mm in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@
BlueprintName = "CHIPTests"
ReferencedContainer = "container:CHIP.xcodeproj">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "CHIPDeviceTests">
</Test>
<Test
Identifier = "CHIPRemoteDeviceSampleTests">
</Test>
<Test
Identifier = "CHIPXPCListenerSampleTests">
</Test>
</SkippedTests>
</TestableReference>
</Testables>
</TestAction>
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 @@ -21,6 +21,7 @@
#import <CHIP/CHIPCommandPayloadsObjc.h>
#import <CHIP/CHIPCommissioningParameters.h>
#import <CHIP/CHIPDevice.h>
#import <CHIP/CHIPDeviceController+XPC.h>
#import <CHIP/CHIPDeviceController.h>
#import <CHIP/CHIPDevicePairingDelegate.h>
#import <CHIP/CHIPError.h>
Expand Down
108 changes: 108 additions & 0 deletions src/darwin/Framework/CHIP/CHIPDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@

NS_ASSUME_NONNULL_BEGIN

typedef void (^CHIPDeviceResponseHandler)(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error);

extern NSString * const kCHIPTypeKey;
extern NSString * const kCHIPValueKey;
extern NSString * const kCHIPTagKey;
extern NSString * const kCHIPSignedIntegerValueTypeKey;
extern NSString * const kCHIPUnsignedIntegerValueTypeKey;
extern NSString * const kCHIPBooleanValueTypeKey;
extern NSString * const kCHIPUTF8StringValueTypeKey;
extern NSString * const kCHIPOctetStringValueTypeKey;
extern NSString * const kCHIPFloatValueTypeKey;
extern NSString * const kCHIPDoubleValueTypeKey;
extern NSString * const kCHIPNullValueTypeKey;
extern NSString * const kCHIPStructureValueTypeKey;
extern NSString * const kCHIPArrayValueTypeKey;
extern NSString * const kCHIPListValueTypeKey;
extern NSString * const kCHIPEndpointIdKey;
extern NSString * const kCHIPClusterIdKey;
extern NSString * const kCHIPAttributeIdKey;
extern NSString * const kCHIPCommandIdKey;
extern NSString * const kCHIPDataKey;
extern NSString * const kCHIPStatusKey;

@interface CHIPDevice : NSObject

- (instancetype)init NS_UNAVAILABLE;
Expand Down Expand Up @@ -49,6 +72,91 @@ NS_ASSUME_NONNULL_BEGIN
maxInterval:(uint16_t)maxInterval
reportHandler:(void (^)(NSArray * _Nullable value, NSError * _Nullable error))reportHandler
subscriptionEstablished:(nullable void (^)(void))subscriptionEstablishedHandler;

/**
* Read attribute in a designated attribute path
*
* @param completion response handler will receive either value or error. value will be an NSArray object with NSDictionary
* elements. Each NSDictionary will have "endpointId", "clusterId", "attributeId", "status" and "data" keys. "endpointId",
* "clusterId", "attributeId" and "status" will be mapped to NSNumber objects. "status" with 0 value indicates success and non-zero
* value indicates failure. "data" key is present only when "status" value is 0. "data" key will be mapped to an NSDictionary
* object, representing attribute value of the path. NSDictionary representing attribute value will contain "type" and "value" keys.
* "type" will be mapped to "SignedInteger", "UnsignedInteger", "UTF8String", "OctetString", "Float",
* "Double", "Boolean", "Null", "Structure", "Array" or "List. "value" will be mapped to an NSNumber, NSString, nil or NSArray
* instance. When "type" is "OctetStriing", "value" will be an NSData object. When "type" is "Structure", "Array" or "List", "value"
* will be NSArray with NSDictionary elements. Each NSDictionary element will have "tag" and "value" keys. "tag" will be mapped to
* an NSNumber value. "value" will be mapped to an NSDictionary instance representing any attribute value recursively.
*/
- (void)readAttributeWithEndpointId:(NSUInteger)endpointId
clusterId:(NSUInteger)clusterId
attributeId:(NSUInteger)attributeId
clientQueue:(dispatch_queue_t)clientQueue
completion:(CHIPDeviceResponseHandler)completion;

/**
* Write to attribute in a designated attribute path
*
* @param completion response handler will receive either value or error. value will be an NSArray object with NSDictionary
* elements. Each NSDictionary will have "endpointId", "clusterId", "attributeId" and "status" keys. "endpointId", "clusterId",
* "attributeId" and "status" will be mapped to NSNumber objects. "status" with 0 value indicates success and non-zero value
* indicates failure.
*/
- (void)writeAttributeWithEndpointId:(NSUInteger)endpointId
clusterId:(NSUInteger)clusterId
attributeId:(NSUInteger)attributeId
value:(id)value
clientQueue:(dispatch_queue_t)clientQueue
completion:(CHIPDeviceResponseHandler)completion;

/**
* Invoke a command with a designated command path
*
* @param commandFields command fields object. The object must be an NSDictionary object representing attribute value
* as described in the readAttributeWithEndpointId:clusterId:attributeId:clientQueue:responseHandler: method.
* The attribute must be a Structure, i.e., the NSDictionary "type" key must have the value "Structure".
*
* @param completion response handler will receive either value or error. value will be an NSArray object with NSDictionary
* elements. Each NSDictionary will have "endpointId", "clusterId", "commandId", "status" and "responseData" keys. "endpointId",
* "clusterId", "attributeId" and "status" will be mapped to NSNumber objects. "status" with 0 value indicates success and non-zero
* value indicates failure. "responseData" key will be included only when "status" key has 0 value and there is response data for
* the command. "responseData" key value will be an NSDictionary object representing attribute value as described in the
* readAttributeWithEndpointId:clusterId:attributeId:clientQueue:responseHandler: method.
*/
- (void)invokeCommandWithEndpointId:(NSUInteger)endpointId
clusterId:(NSUInteger)clusterId
commandId:(NSUInteger)commandId
commandFields:(id)commandFields
clientQueue:(dispatch_queue_t)clientQueue
completion:(CHIPDeviceResponseHandler)completion;

/**
* Subscribe an attribute in a designated attribute path
*
* @param reportHandler handler for the reports. Note that only the report handler by the last call to this method per the same
* attribute path will receive reports. Report handler will receive either value or error. value will be an NSDictionary object. The
* NSDictionary object will have "endpointId", "clusterId", "attributeId" and "value" keys. "endpointId", "clusterId" and
* "attributeId" will be mapped to NSNumber objects. "value" key value will be an NSDictionary object representing attribute value
* as described in the readAttributeWithEndpointId:clusterId:attributeId:clientQueue:responseHandler: method.
*/
- (void)subscribeAttributeWithEndpointId:(NSUInteger)endpointId
clusterId:(NSUInteger)clusterId
attributeId:(NSUInteger)attributeId
minInterval:(NSUInteger)minInterval
maxInterval:(NSUInteger)maxInterval
clientQueue:(dispatch_queue_t)clientQueue
reportHandler:(void (^)(NSDictionary<NSString *, id> * _Nullable value,
NSError * _Nullable error))reportHandler
subscriptionEstablished:(nullable void (^)(void))subscriptionEstablishedHandler;

/**
* Deregister all local report handlers for a remote device
*
* This method is applicable only for a remote device. For a local device, the stack has to be shutdown to stop report handlers.
* There could be multiple clients accessing a node through a remote controller object and hence it is not appropriate
* for one of those clients to shut down the entire stack to stop receiving reports.
*/
- (void)deregisterReportHandlersWithClientQueue:(dispatch_queue_t)clientQueue completion:(void (^)(void))completion;

@end

@interface CHIPAttributePath : NSObject
Expand Down
Loading

0 comments on commit 4186260

Please sign in to comment.