Skip to content

Commit

Permalink
Add a way to do non-fabric-filtered reads on Darwin. (#15353)
Browse files Browse the repository at this point in the history
We only add the new ReadParams for attributes that are actually
fabric-scoped lists for now.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Feb 27, 2024
1 parent 84a65b4 commit 2221682
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 103 deletions.
15 changes: 15 additions & 0 deletions src/darwin/Framework/CHIP/CHIPCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,19 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)new NS_UNAVAILABLE;
@end

/**
* CHIPReadParams
* This is used to control the behavior of attribute reads.
*/
@interface CHIPReadParams : NSObject

/**
* Whether the read is fabric-filtered. nil (the default), or YES value,
* means fabric-filtered. NO means not fabric-filtered.
*/
@property (strong, nonatomic, nullable) NSNumber * fabricFiltered;

- (instancetype)init;
@end

NS_ASSUME_NONNULL_END
11 changes: 11 additions & 0 deletions src/darwin/Framework/CHIP/CHIPCluster.mm
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,14 @@ - (instancetype)initWithDevice:(CHIPDevice *)device endpoint:(EndpointId)endpoin
[value lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
}
@end

@implementation CHIPReadParams
- (instancetype)init
{
if (self = [super init]) {
_fabricFiltered = nil;
}
return self;
}

@end
26 changes: 22 additions & 4 deletions src/darwin/Framework/CHIP/templates/CHIPClustersObjc-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ using namespace chip::app::Clusters;

{{#chip_server_cluster_attributes}}
{{#*inline "attribute"}}Attribute{{asUpperCamelCase name}}{{/inline}}
- (void)read{{>attribute}}WithCompletionHandler:(void (^)({{asObjectiveCClass type parent.name}} * _Nullable value, NSError * _Nullable error))completionHandler
- (void)read{{>attribute}}With
{{~#if_is_fabric_scoped_struct type~}}
Params:(CHIPReadParams * _Nullable)params completionHandler:
{{~else~}}
CompletionHandler:
{{~/if_is_fabric_scoped_struct~}}
(void (^)({{asObjectiveCClass type parent.name}} * _Nullable value, NSError * _Nullable error))completionHandler
{
new CHIP{{>attribute_data_callback_name}}CallbackBridge(self.callbackQueue,
{{! This treats completionHandler as taking an id for the data. This is
Expand All @@ -93,7 +99,11 @@ using namespace chip::app::Clusters;
using TypeInfo = {{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::TypeInfo;
auto successFn = Callback<{{>attribute_data_callback_name}}Callback>::FromCancelable(success);
auto failureFn = Callback<CHIPDefaultFailureCallbackType>::FromCancelable(failure);
return self.cppCluster.ReadAttribute<TypeInfo>(successFn->mContext, successFn->mCall, failureFn->mCall);
return self.cppCluster.ReadAttribute<TypeInfo>(successFn->mContext, successFn->mCall, failureFn->mCall
{{~#if_is_fabric_scoped_struct type~}}
, params == nil || params.fabricFiltered == nil || [params.fabricFiltered boolValue]
{{~/if_is_fabric_scoped_struct~}}
);
});
}

Expand Down Expand Up @@ -126,7 +136,11 @@ using namespace chip::app::Clusters;

{{/if}}
{{#if isReportableAttribute}}
- (void) subscribe{{>attribute}}WithMinInterval:(NSNumber * _Nonnull)minInterval maxInterval:(NSNumber * _Nonnull)maxInterval subscriptionEstablished:(SubscriptionEstablishedHandler _Nullable)subscriptionEstablishedHandler reportHandler:(void (^)({{asObjectiveCClass type parent.name}} * _Nullable value, NSError * _Nullable error))reportHandler
- (void) subscribe{{>attribute}}WithMinInterval:(NSNumber * _Nonnull)minInterval maxInterval:(NSNumber * _Nonnull)maxInterval
{{#if_is_fabric_scoped_struct type}}
params:(CHIPReadParams * _Nullable)params
{{/if_is_fabric_scoped_struct}}
subscriptionEstablished:(SubscriptionEstablishedHandler _Nullable)subscriptionEstablishedHandler reportHandler:(void (^)({{asObjectiveCClass type parent.name}} * _Nullable value, NSError * _Nullable error))reportHandler
{
new CHIP{{>attribute_data_callback_name}}CallbackSubscriptionBridge(self.callbackQueue,
{{! This treats reportHandler as taking an id for the data. This is
Expand All @@ -136,7 +150,11 @@ using namespace chip::app::Clusters;
using TypeInfo = {{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::TypeInfo;
auto successFn = Callback<{{>attribute_data_callback_name}}Callback>::FromCancelable(success);
auto failureFn = Callback<CHIPDefaultFailureCallbackType>::FromCancelable(failure);
return self.cppCluster.SubscribeAttribute<TypeInfo>(successFn->mContext, successFn->mCall, failureFn->mCall, [minInterval unsignedShortValue], [maxInterval unsignedShortValue], CHIP{{>attribute_data_callback_name}}CallbackSubscriptionBridge::OnSubscriptionEstablished);
return self.cppCluster.SubscribeAttribute<TypeInfo>(successFn->mContext, successFn->mCall, failureFn->mCall, [minInterval unsignedShortValue], [maxInterval unsignedShortValue], CHIP{{>attribute_data_callback_name}}CallbackSubscriptionBridge::OnSubscriptionEstablished
{{~#if_is_fabric_scoped_struct type~}}
, params == nil || params.fabricFiltered == nil || [params.fabricFiltered boolValue]
{{~/if_is_fabric_scoped_struct~}}
);
}, subscriptionEstablishedHandler);
}

Expand Down
14 changes: 12 additions & 2 deletions src/darwin/Framework/CHIP/templates/CHIPClustersObjc.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,22 @@ NS_ASSUME_NONNULL_BEGIN

{{#chip_server_cluster_attributes}}
{{#*inline "attribute"}}Attribute{{asUpperCamelCase name}}{{/inline}}
- (void)read{{>attribute}}WithCompletionHandler:(void (^)({{asObjectiveCClass type parent.name}} * _Nullable value, NSError * _Nullable error))completionHandler;
- (void)read{{>attribute}}With
{{~#if_is_fabric_scoped_struct type~}}
Params:(CHIPReadParams * _Nullable)params completionHandler:
{{~else~}}
CompletionHandler:
{{~/if_is_fabric_scoped_struct~}}
(void (^)({{asObjectiveCClass type parent.name}} * _Nullable value, NSError * _Nullable error))completionHandler;
{{#if isWritableAttribute}}
- (void)write{{>attribute}}WithValue:({{asObjectiveCType type parent.name}})value completionHandler:(StatusCompletion)completionHandler;
{{/if}}
{{#if isReportableAttribute}}
- (void) subscribe{{>attribute}}WithMinInterval:(NSNumber * _Nonnull)minInterval maxInterval:(NSNumber * _Nonnull)maxInterval subscriptionEstablished:(SubscriptionEstablishedHandler _Nullable)subscriptionEstablishedHandler reportHandler:(void (^)({{asObjectiveCClass type parent.name}} * _Nullable value, NSError * _Nullable error))reportHandler;
- (void) subscribe{{>attribute}}WithMinInterval:(NSNumber * _Nonnull)minInterval maxInterval:(NSNumber * _Nonnull)maxInterval
{{#if_is_fabric_scoped_struct type}}
params:(CHIPReadParams * _Nullable)params
{{/if_is_fabric_scoped_struct}}
subscriptionEstablished:(SubscriptionEstablishedHandler _Nullable)subscriptionEstablishedHandler reportHandler:(void (^)({{asObjectiveCClass type parent.name}} * _Nullable value, NSError * _Nullable error))reportHandler;
{{/if}}
{{/chip_server_cluster_attributes}}

Expand Down
16 changes: 15 additions & 1 deletion src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,15 @@ ResponseHandler {{> subscribeDataCallback}} = nil;
{{#chip_tests_item_parameters}}
{{asObjectiveCBasicType type}} {{asLowerCamelCase name}}Argument = {{asTypedLiteral definedValue type}};
{{/chip_tests_item_parameters}}
{{#if_is_fabric_scoped_struct attributeObject.type}}
CHIPReadParams * params = [[CHIPReadParams alloc] init];
params.fabricFiltered = [NSNumber numberWithBool:{{fabricFiltered}}];
{{/if_is_fabric_scoped_struct}}
[cluster subscribeAttribute{{asUpperCamelCase attribute}}WithMinInterval:@(minIntervalArgument)
maxInterval:@(maxIntervalArgument)
{{#if_is_fabric_scoped_struct attributeObject.type}}
params:params
{{/if_is_fabric_scoped_struct}}
subscriptionEstablished:^{
XCTAssertEqual(testSendCluster{{parent.filename}}_{{asTestIndex waitForReport.index}}_{{asUpperCamelCase waitForReport.command}}_Fulfilled, true);
[expectation fulfill];
Expand All @@ -63,7 +70,14 @@ ResponseHandler {{> subscribeDataCallback}} = nil;
{{else if isWaitForReport}}
{{> subscribeDataCallback }} = ^({{asObjectiveCClass attributeObject.type cluster forceList=attributeObject.isArray}} * _Nullable value, NSError * _Nullable err) {
{{else if isReadAttribute}}
[cluster readAttribute{{asUpperCamelCase attribute}}WithCompletionHandler:^({{asObjectiveCClass attributeObject.type cluster forceList=attributeObject.isArray}} * _Nullable value, NSError * _Nullable err) {
{{#if_is_fabric_scoped_struct attributeObject.type}}
CHIPReadParams * params = [[CHIPReadParams alloc] init];
params.fabricFiltered = [NSNumber numberWithBool:{{fabricFiltered}}];
[cluster readAttribute{{asUpperCamelCase attribute}}WithParams:params completionHandler:
{{else}}
[cluster readAttribute{{asUpperCamelCase attribute}}WithCompletionHandler:
{{/if_is_fabric_scoped_struct}}
^({{asObjectiveCClass attributeObject.type cluster forceList=attributeObject.isArray}} * _Nullable value, NSError * _Nullable err) {
{{else if isWriteAttribute}}
{{#chip_tests_item_parameters}}
id {{asLowerCamelCase name}}Argument;
Expand Down
33 changes: 22 additions & 11 deletions src/darwin/Framework/CHIP/zap-generated/CHIPClustersObjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2221682

Please sign in to comment.