Skip to content

Commit

Permalink
[Darwin] Implement multiple read and subscribe (#25840)
Browse files Browse the repository at this point in the history
* Implement darwin multiple attribute, event read / subscribe

* restyle

* Add Exception check

* Remove unused code

* Restyle

* Modify from comment

* Restyle

* Add MTRAttributeRequestPath, EventRequestPath

* restyle

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.mm

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.mm

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.mm

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.mm

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.mm

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.mm

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.mm

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.mm

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.mm

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.mm

Co-authored-by: Boris Zbarsky <[email protected]>

* fix build error

* restyle

* Add set null eventPath

* Modify memort allocation

* restyle

* Modify delete -> memoryfree

* Update code

* remove unused code

* restyle

* Fix crash in Test

* Add TestCases, modify some issues

* restyle

* Add comment, modify testcase

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.mm

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.mm

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.h

Co-authored-by: Boris Zbarsky <[email protected]>

* modify code location, add some patch

* modify typo

* Add assert code

* restyle

* Update src/darwin/Framework/CHIP/MTRBaseDevice.mm

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/darwin/Framework/CHIP/MTRBaseDevice.mm

Co-authored-by: Boris Zbarsky <[email protected]>

* Add subscribe null check

* modify

* Modify using uniqur_ptr

* restyle

* Revert "restyle"

This reverts commit f855ea5.

* Revert "Modify using uniqur_ptr"

This reverts commit 40eca60.

* modify using scopeBuffer

* restyle

* Dispatch resubscription callback to the right queue.

---------

Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
joonhaengHeo and bzbarsky-apple authored Apr 18, 2023
1 parent 19909ce commit 4ccbbb7
Show file tree
Hide file tree
Showing 5 changed files with 816 additions and 298 deletions.
3 changes: 3 additions & 0 deletions src/app/EventPathParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ struct EventPathParams
inline bool HasWildcardEndpointId() const { return mEndpointId == kInvalidEndpointId; }
inline bool HasWildcardClusterId() const { return mClusterId == kInvalidClusterId; }
inline bool HasWildcardEventId() const { return mEventId == kInvalidEventId; }
inline void SetWildcardEndpointId() { mEndpointId = kInvalidEndpointId; }
inline void SetWildcardClusterId() { mClusterId = kInvalidClusterId; }
inline void SetWildcardEventId() { mEventId = kInvalidEventId; }

bool IsEventPathSupersetOf(const ConcreteEventPath & other) const
{
Expand Down
73 changes: 73 additions & 0 deletions src/darwin/Framework/CHIP/MTRBaseDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,38 @@ typedef NS_ENUM(uint8_t, MTRTransportType) {
MTRTransportTypeTCP,
} API_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4));

/**
* A path indicating an attribute being requested (for read or subscribe).
*
* nil is used to represent wildcards.
*/
MTR_NEWLY_AVAILABLE
@interface MTRAttributeRequestPath : NSObject <NSCopying>
@property (nonatomic, readonly, copy, nullable) NSNumber * endpoint;
@property (nonatomic, readonly, copy, nullable) NSNumber * cluster;
@property (nonatomic, readonly, copy, nullable) NSNumber * attribute;

+ (MTRAttributeRequestPath *)requestPathWithEndpointID:(NSNumber * _Nullable)endpointID
clusterID:(NSNumber * _Nullable)clusterID
attributeID:(NSNumber * _Nullable)attributeID MTR_NEWLY_AVAILABLE;
@end

/**
* A path indicating an event being requested (for read or subscribe).
*
* nil is used to represent wildcards.
*/
MTR_NEWLY_AVAILABLE
@interface MTREventRequestPath : NSObject <NSCopying>
@property (nonatomic, readonly, copy, nullable) NSNumber * endpoint;
@property (nonatomic, readonly, copy, nullable) NSNumber * cluster;
@property (nonatomic, readonly, copy, nullable) NSNumber * event;

+ (MTREventRequestPath *)requestPathWithEndpointID:(NSNumber * _Nullable)endpointID
clusterID:(NSNumber * _Nullable)clusterID
eventID:(NSNumber * _Nullable)eventID MTR_NEWLY_AVAILABLE;
@end

@interface MTRBaseDevice : NSObject

- (instancetype)init NS_UNAVAILABLE;
Expand Down Expand Up @@ -229,6 +261,26 @@ typedef NS_ENUM(uint8_t, MTRTransportType) {
completion:(MTRDeviceResponseHandler)completion
API_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4));

/**
* Reads multiple attribute or event paths from the device.
*
* Nil is treated as an empty array for attributePaths and eventPaths.
*
* Lists of attribute and event paths to read can be provided via attributePaths and eventPaths.
*
* The completion will be called with an error if the input parameters are invalid (e.g., both attributePaths and eventPaths are
* empty.) or the entire read interaction fails. Otherwise it will be called with values, which may be empty (e.g. if no paths
* matched the wildcard paths passed in) or may include per-path errors if particular paths failed.
*
* If the sum of the lengths of attributePaths and eventPaths exceeds 9, the read may fail due to the device not supporting that
* many read paths.
*/
- (void)readAttributePaths:(NSArray<MTRAttributeRequestPath *> * _Nullable)attributePaths
eventPaths:(NSArray<MTREventRequestPath *> * _Nullable)eventPaths
params:(MTRReadParams * _Nullable)params
queue:(dispatch_queue_t)queue
completion:(MTRDeviceResponseHandler)completion MTR_NEWLY_AVAILABLE;

/**
* Write to attribute in a designated attribute path
*
Expand Down Expand Up @@ -305,6 +357,27 @@ typedef NS_ENUM(uint8_t, MTRTransportType) {
subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished
API_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4));

/**
* Subscribes to multiple attribute or event paths.
*
* Nil is treated as an empty array for attributePaths and eventPaths.
*
* Lists of attribute and event paths to subscribe to can be provided via attributePaths and eventPaths.
*
* The reportHandler will be called with an error if the inputs are invalid (e.g., both attributePaths and eventPaths are
* empty), or if the subscription fails entirely.
*
* If the sum of the lengths of attributePaths and eventPaths exceeds 3, the subscribe may fail due to the device not supporting
* that many paths for a subscription.
*/
- (void)subscribeToAttributePaths:(NSArray<MTRAttributeRequestPath *> * _Nullable)attributePaths
eventPaths:(NSArray<MTREventRequestPath *> * _Nullable)eventPaths
params:(MTRSubscribeParams * _Nullable)params
queue:(dispatch_queue_t)queue
reportHandler:(MTRDeviceResponseHandler)reportHandler
subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished
resubscriptionScheduled:(MTRDeviceResubscriptionScheduledHandler _Nullable)resubscriptionScheduled MTR_NEWLY_AVAILABLE;

/**
* Deregister all local report handlers for a remote device
*
Expand Down
Loading

0 comments on commit 4ccbbb7

Please sign in to comment.