Skip to content

Commit

Permalink
Add a "Darwin force write" configuration for darwin APIs (#30174)
Browse files Browse the repository at this point in the history
* Start adding darwin backwards compatibility

* Update conditional and also fix MTRClusters source

* Alter the files and zap regen

---------

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
andy31415 and andreilitvin authored Nov 2, 2023
1 parent 38fa902 commit 71a72ae
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/app/common/templates/config-data.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
DarwinForceWritable:
# Work-around for not allowing changes from writable to read-only
# happened in https://github.com/project-chip/connectedhomeip/pull/30134
- ApplicationLauncher::CurrentApp

WeakEnums:
# Allow-list of enums that we generate as enums, not enum classes.
# The goal is to drive this down to 0.
Expand Down
6 changes: 4 additions & 2 deletions src/darwin/Framework/CHIP/templates/MTRBaseClusters-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ MTR{{cluster}}Cluster{{command}}Params
completion:completion];
}

{{#if isWritableAttribute}}
{{#if (or isWritableAttribute
(isInConfigList (concat (asUpperCamelCase parent.name) "::" label) "DarwinForceWritable"))}}
- (void)write{{>attribute}}WithValue:({{asObjectiveCType type parent.name}})value completion:(MTRStatusCompletion)completion
{
[self write{{>attribute}}WithValue:({{asObjectiveCType type parent.name}})value params:nil completion:completion];
Expand Down Expand Up @@ -292,7 +293,8 @@ reportHandler:(void (^)({{asObjectiveCClass type parent.name}} * _Nullable value
completionHandler(static_cast<{{asObjectiveCClass type parent.name compatRemapClusterName=true}} *>(value), error);
}];
}
{{#if isWritableAttribute}}
{{#if (or isWritableAttribute
(isInConfigList (concat (asUpperCamelCase parent.name) "::" label) "DarwinForceWritable"))}}
- (void)write{{>attribute}}WithValue:({{asObjectiveCType type parent.name compatRemapClusterName=true}})value completionHandler:(MTRStatusCompletion)completionHandler
{
[self writeAttribute{{asUpperCamelCase name preserveAcronyms=true}}WithValue:value params:nil completion:completionHandler];
Expand Down
6 changes: 4 additions & 2 deletions src/darwin/Framework/CHIP/templates/MTRBaseClusters.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ NS_ASSUME_NONNULL_BEGIN
Completion:
{{~/if_is_fabric_scoped_struct~}}
(void (^)({{asObjectiveCClass type parent.name}} * _Nullable value, NSError * _Nullable error))completion {{availability (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true) minimalRelease="First major API revamp"}};
{{#if isWritableAttribute}}
{{#if (or isWritableAttribute
(isInConfigList (concat (asUpperCamelCase parent.name) "::" label) "DarwinForceWritable"))}}
- (void)write{{>attribute}}WithValue:({{asObjectiveCType type parent.name}})value completion:(MTRStatusCompletion)completion {{availability (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true) minimalRelease="First major API revamp"}};
- (void)write{{>attribute}}WithValue:({{asObjectiveCType type parent.name}})value params:(MTRWriteParams * _Nullable)params completion:(MTRStatusCompletion)completion {{availability (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true) minimalRelease="First major API revamp"}};
{{/if}}
Expand Down Expand Up @@ -238,7 +239,8 @@ typedef NS_OPTIONS({{asUnderlyingZclType name}}, {{objCEnumName clusterName bitm
CompletionHandler:
{{~/if_is_fabric_scoped_struct~}}
(void (^)({{asObjectiveCClass type parent.name compatRemapClusterName=true}} * _Nullable value, NSError * _Nullable error))completionHandler {{availability (compatClusterNameRemapping parent.name) attribute=(compatAttributeNameRemapping parent.name name) deprecatedRelease="First major API revamp" fabricScopedDeprecationMessage=(concat "Please use readAttribute" (asUpperCamelCase name preserveAcronyms=true) "WithParams:completion:") nonFabricScopedDeprecationMessage=(concat "Please use readAttribute" (asUpperCamelCase name preserveAcronyms=true) "WithCompletion:") type=type}};
{{#if isWritableAttribute}}
{{#if (or isWritableAttribute
(isInConfigList (concat (asUpperCamelCase parent.name) "::" label) "DarwinForceWritable"))}}
- (void)write{{>attribute}}WithValue:({{asObjectiveCType type parent.name compatRemapClusterName=true}})value completionHandler:(MTRStatusCompletion)completionHandler {{availability (compatClusterNameRemapping parent.name) attribute=(compatAttributeNameRemapping parent.name name) deprecatedRelease="First major API revamp" deprecationMessage=(concat "Please use writeAttribute" (asUpperCamelCase name preserveAcronyms=true) "WithValue:completion:")}};
- (void)write{{>attribute}}WithValue:({{asObjectiveCType type parent.name compatRemapClusterName=true}})value params:(MTRWriteParams * _Nullable)params completionHandler:(MTRStatusCompletion)completionHandler {{availability (compatClusterNameRemapping parent.name) attribute=(compatAttributeNameRemapping parent.name name) deprecatedRelease="First major API revamp" deprecationMessage=(concat "Please use writeAttribute" (asUpperCamelCase name preserveAcronyms=true) "WithValue:params:completion:")}};
{{/if}}
Expand Down
6 changes: 4 additions & 2 deletions src/darwin/Framework/CHIP/templates/MTRClusters-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ MTR{{cluster}}Cluster{{command}}Params
return [self.device readAttributeWithEndpointID:@(self.endpoint) clusterID:@(MTRClusterIDType{{>cluster}}ID) attributeID:@(MTRAttributeIDTypeCluster{{>cluster}}{{>attribute}}ID) params:params];
}

{{#if isWritableAttribute}}
{{#if (or isWritableAttribute
(isInConfigList (concat (asUpperCamelCase parent.name) "::" label) "DarwinForceWritable"))}}
{{#*inline "callbackName"}}DefaultSuccess{{/inline}}
- (void)write{{>attribute}}WithValue:(NSDictionary<NSString *, id> *)dataValueDictionary expectedValueInterval:(NSNumber *)expectedValueIntervalMs
{
Expand Down Expand Up @@ -207,7 +208,8 @@ MTR{{cluster}}Cluster{{command}}Params
{
return [self readAttribute{{asUpperCamelCase name preserveAcronyms=true}}WithParams:params];
}
{{#if isWritableAttribute}}
{{#if (or isWritableAttribute
(isInConfigList (concat (asUpperCamelCase parent.name) "::" label) "DarwinForceWritable"))}}
- (void)writeAttribute{{attribute}}WithValue:(NSDictionary<NSString *, id> *)dataValueDictionary expectedValueInterval:(NSNumber *)expectedValueIntervalMs
{
[self writeAttribute{{asUpperCamelCase name preserveAcronyms=true}}WithValue:dataValueDictionary expectedValueInterval:expectedValueIntervalMs];
Expand Down
6 changes: 4 additions & 2 deletions src/darwin/Framework/CHIP/templates/MTRClusters.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ NS_ASSUME_NONNULL_BEGIN
{{availability (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true)}}
{{/inline}}
- (NSDictionary<NSString *, id> * _Nullable)read{{>attribute}}WithParams:(MTRReadParams * _Nullable)params {{> availability}};
{{#if isWritableAttribute}}
{{#if (or isWritableAttribute
(isInConfigList (concat (asUpperCamelCase parent.name) "::" label) "DarwinForceWritable"))}}
- (void)write{{>attribute}}WithValue:(NSDictionary<NSString *, id> *)dataValueDictionary expectedValueInterval:(NSNumber *)expectedValueIntervalMs {{> availability}};
- (void)write{{>attribute}}WithValue:(NSDictionary<NSString *, id> *)dataValueDictionary expectedValueInterval:(NSNumber *)expectedValueIntervalMs params:(MTRWriteParams * _Nullable)params {{> availability}};
{{/if}}
Expand Down Expand Up @@ -130,7 +131,8 @@ NS_ASSUME_NONNULL_BEGIN
{{~#*inline "attributeDecls"}}
{{#unless (isStrEqual attribute (asUpperCamelCase name preserveAcronyms=true))}}
- (NSDictionary<NSString *, id> *)readAttribute{{attribute}}WithParams:(MTRReadParams * _Nullable)params {{availability cluster attribute=attribute deprecatedRelease="First major API revamp" deprecationMessage=(concat "Please use readAttribute" (asUpperCamelCase name preserveAcronyms=true) "WithParams on MTRCluster" (asUpperCamelCase parent.name preserveAcronyms=true))}};
{{#if isWritableAttribute}}
{{#if (or isWritableAttribute
(isInConfigList (concat (asUpperCamelCase parent.name) "::" label) "DarwinForceWritable"))}}
- (void)writeAttribute{{attribute}}WithValue:(NSDictionary<NSString *, id> *)dataValueDictionary expectedValueInterval:(NSNumber *)expectedValueIntervalMs {{availability cluster attribute=attribute deprecationMessage=(concat "Please use writeAttribute" (asUpperCamelCase name preserveAcronyms=true) "WithValue on MTRCluster" (asUpperCamelCase parent.name preserveAcronyms=true))}};
- (void)writeAttribute{{attribute}}WithValue:(NSDictionary<NSString *, id> *)dataValueDictionary expectedValueInterval:(NSNumber *)expectedValueIntervalMs params:(MTRWriteParams * _Nullable)params {{availability cluster attribute=attribute deprecationMessage=(concat "Please use writeAttribute" (asUpperCamelCase name preserveAcronyms=true) "WithValue on MTRCluster" (asUpperCamelCase parent.name preserveAcronyms=true))}};
{{/if}}
Expand Down
3 changes: 2 additions & 1 deletion src/darwin/Framework/CHIP/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"darwin/Framework/CHIP/templates/helper.js"
],
"resources": {
"availability-data": "availability.yaml"
"availability-data": "availability.yaml",
"config-data": "../../../../app/common/templates/config-data.yaml"
},
"override": "../../../../../src/app/zap-templates/common/override.js",
"partials": [
Expand Down
4 changes: 4 additions & 0 deletions src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h

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

46 changes: 46 additions & 0 deletions src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm

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

2 changes: 2 additions & 0 deletions src/darwin/Framework/CHIP/zap-generated/MTRClusters.h

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

11 changes: 11 additions & 0 deletions src/darwin/Framework/CHIP/zap-generated/MTRClusters.mm

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

0 comments on commit 71a72ae

Please sign in to comment.