Skip to content

Commit

Permalink
Switch from wasRemoved to isSupported for Darwin codegen.
Browse files Browse the repository at this point in the history
isSupported allows things to be marked as "provisional", which unlike "removed"
can be overridden by a later "introduced" annotation.
  • Loading branch information
bzbarsky-apple committed Apr 18, 2023
1 parent 856963e commit 9ff312f
Show file tree
Hide file tree
Showing 17 changed files with 221 additions and 209 deletions.
36 changes: 18 additions & 18 deletions examples/darwin-framework-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
{{> clusters_header}}

{{#all_user_clusters side='client'}}
{{#unless (wasRemoved (asUpperCamelCase name preserveAcronyms=true))}}
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
{{> cluster_header}}

{{#zcl_commands}}
{{#if (is_str_equal source 'client')}}
{{#unless (wasRemoved (asUpperCamelCase parent.name preserveAcronyms=true) command=(asUpperCamelCase name preserveAcronyms=true))}}
{{#if (isSupported (asUpperCamelCase parent.name preserveAcronyms=true) command=(asUpperCamelCase name preserveAcronyms=true))}}
/*
* Command {{asUpperCamelCase name}}
*/
Expand Down Expand Up @@ -90,12 +90,12 @@ private:
{{/zcl_command_arguments}}
};

{{/unless}}
{{/if}}
{{/if}}
{{/zcl_commands}}

{{#zcl_attributes_server removeKeys='isOptional'}}
{{#unless (wasRemoved (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))}}
{{#if (isSupported (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))}}
{{#*inline "cluster"}}Cluster{{asUpperCamelCase parent.name preserveAcronyms=true}}{{/inline}}
{{#*inline "attribute"}}Attribute{{asUpperCamelCase name preserveAcronyms=true}}{{/inline}}

Expand Down Expand Up @@ -247,16 +247,16 @@ public:
};

{{/if}}
{{/unless}}
{{/if}}
{{/zcl_attributes_server}}
{{/unless}}
{{/if}}
{{/all_user_clusters}}

/*----------------------------------------------------------------------------*\
| Register all Clusters commands |
\*----------------------------------------------------------------------------*/
{{#all_user_clusters side='client'}}
{{#unless (wasRemoved (asUpperCamelCase name preserveAcronyms=true))}}
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
void registerCluster{{asUpperCamelCase name}}(Commands & commands)
{
using namespace chip::app::Clusters::{{asUpperCamelCase name}};
Expand All @@ -267,34 +267,34 @@ void registerCluster{{asUpperCamelCase name}}(Commands & commands)
make_unique<ClusterCommand>(Id), //
{{#zcl_commands}}
{{#if (is_str_equal source 'client')}}
{{#unless (wasRemoved (asUpperCamelCase parent.name preserveAcronyms=true) command=(asUpperCamelCase name preserveAcronyms=true))}}
{{#if (isSupported (asUpperCamelCase parent.name preserveAcronyms=true) command=(asUpperCamelCase name preserveAcronyms=true))}}
make_unique<{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}>(), //
{{/unless}}
{{/if}}
{{/if}}
{{/zcl_commands}}
{{#zcl_attributes_server removeKeys='isOptional'}}
{{#first}}
make_unique<ReadAttribute>(Id), //
{{/first}}
{{#unless (wasRemoved (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))}}
{{#if (isSupported (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))}}
make_unique<Read{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}>(), //
{{/unless}}
{{/if}}
{{#first}}
make_unique<WriteAttribute>(Id), //
{{/first}}
{{#unless (wasRemoved (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))}}
{{#if (isSupported (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))}}
{{#if isWritableAttribute}}
make_unique<Write{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}>(), //
{{/if}}
{{/unless}}
{{/if}}
{{#first}}
make_unique<SubscribeAttribute>(Id), //
{{/first}}
{{#unless (wasRemoved (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))}}
{{#if (isSupported (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))}}
{{#if isReportableAttribute}}
make_unique<SubscribeAttribute{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}>(), //
{{/if}}
{{/unless}}
{{/if}}
{{/zcl_attributes_server}}
{{#zcl_events}}
{{#first}}
Expand All @@ -306,7 +306,7 @@ void registerCluster{{asUpperCamelCase name}}(Commands & commands)

commands.Register(clusterName, clusterCommands);
}
{{/unless}}
{{/if}}
{{/all_user_clusters}}

void registerClusterAny(Commands & commands)
Expand All @@ -330,8 +330,8 @@ void registerClusters(Commands & commands)
{
registerClusterAny(commands);
{{#all_user_clusters side='client'}}
{{#unless (wasRemoved (asUpperCamelCase name preserveAcronyms=true))}}
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
registerCluster{{asUpperCamelCase name}}(commands);
{{/unless}}
{{/if}}
{{/all_user_clusters}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ id MTRDecodeAttributeValue(const ConcreteAttributePath & aPath, TLV::TLVReader &
switch (aPath.mClusterId)
{
{{#all_user_clusters side='client'}}
{{#unless (wasRemoved (asUpperCamelCase name preserveAcronyms=true))}}
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
case Clusters::{{asUpperCamelCase name}}::Id: {
using namespace Clusters::{{asUpperCamelCase name}};
switch (aPath.mAttributeId)
{
{{#zcl_attributes_server removeKeys='isOptional'}}
{{#unless (wasRemoved (asUpperCamelCase ../name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))}}
{{#if (isSupported (asUpperCamelCase ../name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))}}
case Attributes::{{asUpperCamelCase name}}::Id: {
using TypeInfo = Attributes::{{asUpperCamelCase name}}::TypeInfo;
TypeInfo::DecodableType cppValue;
Expand All @@ -38,15 +38,15 @@ id MTRDecodeAttributeValue(const ConcreteAttributePath & aPath, TLV::TLVReader &
{{>decode_value target="value" source="cppValue" cluster=parent.name errorCode="*aError = err; return nil;" depth=0}}
return value;
}
{{/unless}}
{{/if}}
{{/zcl_attributes_server}}
default:
*aError = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB;
break;
}
break;
}
{{/unless}}
{{/if}}
{{/all_user_clusters}}
default: {
*aError = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB;
Expand Down
34 changes: 17 additions & 17 deletions src/darwin/Framework/CHIP/templates/MTRBaseClusters-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using chip::System::Clock::Seconds16;

// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks): Linter is unable to locate the delete on these objects.
{{#all_user_clusters side='client'}}
{{#unless (wasRemoved (asUpperCamelCase name preserveAcronyms=true))}}
{{#if (isSupported (asUpperCamelCase name preserveAcronyms=true))}}
@implementation MTRBaseCluster{{asUpperCamelCase name preserveAcronyms=true}}

- (instancetype)initWithDevice:(MTRBaseDevice *)device endpointID:(NSNumber *)endpointID queue:(dispatch_queue_t)queue
Expand All @@ -50,15 +50,15 @@ using chip::System::Clock::Seconds16;
{{! Takes two arguments: cluster name and command name, plus the ambient state where the command is "this" }}
{{#*inline "commandImpl"}}
{{! This is used as the implementation for both the new-name and old-name bits, so check for both here. }}
{{#unless (and (wasRemoved cluster command=command)
(wasRemoved (compatClusterNameRemapping parent.name) command=(compatCommandNameRemapping parent.name name)))}}
{{#if (or (isSupported cluster command=command)
(isSupported (compatClusterNameRemapping parent.name) command=(compatCommandNameRemapping parent.name name)))}}
{{#*inline "callbackName"}}{{#if hasSpecificResponse}}{{cluster}}Cluster{{asUpperCamelCase responseName preserveAcronyms=true}}{{else}}CommandSuccess{{/if}}{{/inline}}
{{#*inline "paramsType"}}
{{#if (wasRemoved cluster command=command)}}
{{#unless (isSupported cluster command=command)}}
MTR{{compatClusterNameRemapping parent.name}}Cluster{{compatCommandNameRemapping parent.name name}}Params
{{else}}
MTR{{cluster}}Cluster{{command}}Params
{{/if}}
{{/unless}}
{{/inline}}
{{#unless hasArguments}}
- (void){{asLowerCamelCase name}}WithCompletion:({{>command_completion_type command=.}})completion
Expand Down Expand Up @@ -124,7 +124,7 @@ MTR{{cluster}}Cluster{{command}}Params
});
std::move(*bridge).DispatchAction(self.device);
}
{{/unless}}
{{/if}}
{{/inline}}
{{> commandImpl cluster=(asUpperCamelCase parent.name preserveAcronyms=true)
command=(asUpperCamelCase name preserveAcronyms=true)}}
Expand All @@ -133,9 +133,9 @@ MTR{{cluster}}Cluster{{command}}Params

{{#zcl_attributes_server removeKeys='isOptional'}}
{{! This is used as the implementation for both the new-name and old-name bits, so check for both here. }}
{{#unless (and (wasRemoved (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))
(or (wasRemoved (compatClusterNameRemapping parent.name) attribute=(compatAttributeNameRemapping parent.name name))
(not wasIntroducedBeforeRelease "First major API revamp" (compatClusterNameRemapping parent.name) attribute=(compatAttributeNameRemapping parent.name name))))}}
{{#if (or (isSupported (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true))
(and (isSupported (compatClusterNameRemapping parent.name) attribute=(compatAttributeNameRemapping parent.name name))
(wasIntroducedBeforeRelease "First major API revamp" (compatClusterNameRemapping parent.name) attribute=(compatAttributeNameRemapping parent.name name))))}}
{{#*inline "attribute"}}Attribute{{asUpperCamelCase name preserveAcronyms=true}}{{/inline}}
- (void)read{{>attribute}}With
{{~#if_is_fabric_scoped_struct type~}}
Expand Down Expand Up @@ -233,28 +233,28 @@ reportHandler:(void (^)({{asObjectiveCClass type parent.name}} * _Nullable value
}

{{/if}}
{{/unless}}
{{/if}}
{{/zcl_attributes_server}}

@end
{{/unless}}
{{/if}}
{{#unless (isStrEqual (asUpperCamelCase name preserveAcronyms=true) (compatClusterNameRemapping name))}}
{{#unless (wasRemoved (compatClusterNameRemapping name))}}
{{#if (isSupported (compatClusterNameRemapping name))}}

@implementation MTRBaseCluster{{compatClusterNameRemapping name}}
@end
{{/unless}}
{{/if}}
{{/unless}}

{{#if (and (wasIntroducedBeforeRelease "First major API revamp" (compatClusterNameRemapping name))
(not (wasRemoved (compatClusterNameRemapping name))))}}
(isSupported (compatClusterNameRemapping name)))}}
@implementation MTRBaseCluster{{compatClusterNameRemapping name}} (Deprecated)

{{#zcl_commands}}
{{#if (is_str_equal source 'client')}}
{{! Takes two arguments: cluster name and command name, plus the ambient state where the command is "this" }}
{{#*inline "commandImpl"}}
{{#unless (wasRemoved cluster command=command)}}
{{#if (isSupported cluster command=command)}}
- (void){{asLowerCamelCase command}}WithParams:(MTR{{cluster}}Cluster{{command}}Params * {{#unless commandHasRequiredField}}_Nullable{{/unless}})params completionHandler:({{>command_completion_type command=. compatRemapNames=true}})completionHandler
{
[self {{asLowerCamelCase name}}WithParams:params completion:
Expand All @@ -274,7 +274,7 @@ reportHandler:(void (^)({{asObjectiveCClass type parent.name}} * _Nullable value
[self {{asLowerCamelCase command}}WithParams:nil completionHandler:completionHandler];
}
{{/unless}}
{{/unless}}
{{/if}}
{{/inline}}
{{> commandImpl cluster=(compatClusterNameRemapping parent.name)
command=(compatCommandNameRemapping parent.name name)}}
Expand All @@ -283,7 +283,7 @@ reportHandler:(void (^)({{asObjectiveCClass type parent.name}} * _Nullable value

{{#zcl_attributes_server removeKeys='isOptional'}}
{{#if (and (wasIntroducedBeforeRelease "First major API revamp" (compatClusterNameRemapping parent.name) attribute=(compatAttributeNameRemapping parent.name name))
(not (wasRemoved (compatClusterNameRemapping parent.name) attribute=(compatAttributeNameRemapping parent.name name))))}}
(isSupported (compatClusterNameRemapping parent.name) attribute=(compatAttributeNameRemapping parent.name name)))}}
{{#*inline "attribute"}}Attribute{{compatAttributeNameRemapping parent.name name}}{{/inline}}
- (void)read{{>attribute}}With
{{~#if_is_fabric_scoped_struct type~}}
Expand Down
Loading

0 comments on commit 9ff312f

Please sign in to comment.