Skip to content

Commit

Permalink
Remove the MfgSpecificPing command from Darwin API. (#24139)
Browse files Browse the repository at this point in the history
* Remove the MfgSpecificPing command from Darwin API.

Except for the backwards-compat shims, of course.

The template refactorings are to reduce repetition and to enable
handling for removal and renaming of commands.

* Fix darwin-framework-tool compile.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Dec 19, 2023
1 parent b846b39 commit 984b476
Show file tree
Hide file tree
Showing 21 changed files with 231 additions and 171 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/zap_regeneration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

runs-on: ubuntu-20.04
container:
image: connectedhomeip/chip-build:0.6.23
image: connectedhomeip/chip-build:0.6.24
defaults:
run:
shell: sh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/zap_templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

runs-on: ubuntu-20.04
container:
image: connectedhomeip/chip-build:0.6.23
image: connectedhomeip/chip-build:0.6.24
defaults:
run:
shell: sh
Expand Down
4 changes: 4 additions & 0 deletions examples/darwin-framework-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
{{> cluster_header}}

{{#chip_cluster_commands}}
{{#unless (wasRemoved (asUpperCamelCase clusterName preserveAcronyms=true) command=(asUpperCamelCase name preserveAcronyms=true))}}
/*
* Command {{asUpperCamelCase name}}
*/
Expand Down Expand Up @@ -87,6 +88,7 @@ private:
{{/chip_cluster_command_arguments}}
};

{{/unless}}
{{/chip_cluster_commands}}

{{#chip_server_cluster_attributes}}
Expand Down Expand Up @@ -257,7 +259,9 @@ void registerCluster{{asUpperCamelCase name}}(Commands & commands)
commands_list clusterCommands = {
make_unique<ClusterCommand>(Id), //
{{#chip_cluster_commands}}
{{#unless (wasRemoved (asUpperCamelCase clusterName preserveAcronyms=true) command=(asUpperCamelCase name preserveAcronyms=true))}}
make_unique<{{asUpperCamelCase clusterName}}{{asUpperCamelCase name}}>(), //
{{/unless}}
{{/chip_cluster_commands}}
{{#chip_server_cluster_attributes}}
{{#first}}
Expand Down
3 changes: 2 additions & 1 deletion examples/darwin-framework-tool/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"resources": {
"pics-metafile": "../../../src/app/tests/suites/certification/PICS.yaml",
"certification-metadir": "../../../src/app/tests/suites/certification",
"test-metadir": "../../../src/app/tests/suites"
"test-metadir": "../../../src/app/tests/suites",
"availability-data": "../../../src/darwin/Framework/CHIP/templates/availability.yaml"
},
"override": "../../../src/app/zap-templates/common/override.js",
"partials": [
Expand Down
41 changes: 31 additions & 10 deletions src/darwin/Framework/CHIP/templates/MTRBaseClusters-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,26 @@ using chip::SessionHandle;
}

{{#chip_cluster_commands}}
{{#*inline "cluster"}}{{asUpperCamelCase parent.name preserveAcronyms=true}}{{/inline}}
{{#*inline "command"}}{{asUpperCamelCase name preserveAcronyms=true}}{{/inline}}
{{#*inline "callbackName"}}{{#if hasSpecificResponse}}{{>cluster}}Cluster{{asUpperCamelCase responseName preserveAcronyms=true}}{{else}}CommandSuccess{{/if}}{{/inline}}
{{! 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)))}}
{{#*inline "callbackName"}}{{#if hasSpecificResponse}}{{cluster}}Cluster{{asUpperCamelCase responseName preserveAcronyms=true}}{{else}}CommandSuccess{{/if}}{{/inline}}
{{#*inline "paramsType"}}
{{#if (wasRemoved cluster command=command)}}
MTR{{compatClusterNameRemapping parent.name}}Cluster{{compatCommandNameRemapping parent.name name}}Params
{{else}}
MTR{{cluster}}Cluster{{command}}Params
{{/if}}
{{/inline}}
{{#unless (hasArguments)}}
- (void){{asLowerCamelCase name}}WithCompletion:({{>command_completion_type command=.}})completion
{
[self {{asLowerCamelCase name}}WithParams:nil completion:completion];
}
{{/unless}}
- (void){{asLowerCamelCase name}}WithParams: (MTR{{>cluster}}Cluster{{>command}}Params * {{#unless (commandHasRequiredField .)}}_Nullable{{/unless}})params completion:({{>command_completion_type command=.}})completion
- (void){{asLowerCamelCase name}}WithParams: ({{> paramsType}} * {{#unless (commandHasRequiredField .)}}_Nullable{{/unless}})params completion:({{>command_completion_type command=.}})completion
{
// Make a copy of params before we go async.
params = [params copy];
Expand Down Expand Up @@ -100,6 +110,10 @@ using chip::SessionHandle;
});
std::move(*bridge).DispatchAction(self.device);
}
{{/unless}}
{{/inline}}
{{> commandImpl cluster=(asUpperCamelCase parent.name preserveAcronyms=true)
command=(asUpperCamelCase name preserveAcronyms=true)}}
{{/chip_cluster_commands}}

{{#chip_server_cluster_attributes}}
Expand Down Expand Up @@ -212,31 +226,37 @@ reportHandler:(void (^)({{asObjectiveCClass type parent.name}} * _Nullable value
@implementation MTRBaseCluster{{compatClusterNameRemapping name}} (Deprecated)

{{#chip_cluster_commands}}
- (void){{asLowerCamelCase name}}WithParams:(MTR{{compatClusterNameRemapping parent.name}}Cluster{{asUpperCamelCase name}}Params * {{#unless (commandHasRequiredField .)}}_Nullable{{/unless}})params completionHandler:({{>command_completion_type command=. compatRemapClusterName=true}})completionHandler
{{! Takes two arguments: cluster name and command name, plus the ambient state where the command is "this" }}
{{#*inline "commandImpl"}}
{{#unless (wasRemoved 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:
{{#if hasSpecificResponse}}
^(MTR{{asUpperCamelCase parent.name preserveAcronyms=true}}Cluster{{asUpperCamelCase responseName preserveAcronyms=true}}Params * _Nullable data, NSError * _Nullable error) {
// Cast is safe because subclass does not add any selectors.
completionHandler(static_cast<MTR{{compatClusterNameRemapping parent.name}}Cluster{{asUpperCamelCase responseName}}Params *>(data), error);
completionHandler(static_cast<MTR{{cluster}}Cluster{{compatCommandNameRemapping parent.name responseName}}Params *>(data), error);
}
{{else}}
completionHandler
{{/if}}
];
}
{{#unless (hasArguments)}}
- (void){{asLowerCamelCase name}}WithCompletionHandler:({{>command_completion_type command=. compatRemapClusterName=true}})completionHandler
- (void){{asLowerCamelCase command}}WithCompletionHandler:({{>command_completion_type command=. compatRemapNames=true}})completionHandler
{
[self {{asLowerCamelCase name}}WithParams:nil completionHandler:completionHandler];
}
{{/unless}}
{{/unless}}
{{/inline}}
{{> commandImpl cluster=(compatClusterNameRemapping parent.name)
command=(compatCommandNameRemapping parent.name name)}}
{{/chip_cluster_commands}}

{{#chip_server_cluster_attributes}}
{{!Backwards compat for now: Treat DeviceTypeList as DeviceList. That's OK, since this is a deprecated API. }}
{{#*inline "attribute"}}Attribute{{#if (isStrEqual (asUpperCamelCase parent.name) "Descriptor")}}{{#if (isStrEqual (asUpperCamelCase name) "DeviceTypeList")}}DeviceList{{else}}{{asUpperCamelCase name}}{{/if}}{{else}}{{asUpperCamelCase name}}{{/if}}{{/inline}}
{{! TODO: We need a better setup for the API_AVALABLE annotations here; this does not scale at all sanely. }}
{{#if (wasIntroducedBeforeRelease "First major API revamp" (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~}}
Params:(MTRReadParams * _Nullable)params completionHandler:
Expand Down Expand Up @@ -288,6 +308,7 @@ subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptio
}];
}
{{/if}}
{{/if}}
{{/chip_server_cluster_attributes}}

- (nullable instancetype)initWithDevice:(MTRBaseDevice *)device
Expand Down
29 changes: 20 additions & 9 deletions src/darwin/Framework/CHIP/templates/MTRBaseClusters.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@ NS_ASSUME_NONNULL_BEGIN
queue:(dispatch_queue_t)queue NS_DESIGNATED_INITIALIZER {{availability (asUpperCamelCase name preserveAcronyms=true) minimalRelease="First major API revamp"}};

{{#chip_cluster_commands}}
{{! Takes two arguments: cluster name and command name, plus the ambient state where the command is "this" }}
{{#*inline "commandDecl"}}
{{#unless (wasRemoved cluster command=command)}}
/**
* Command {{name}}
*
* {{description}}
*/
{{#*inline "cluster"}}{{asUpperCamelCase parent.name preserveAcronyms=true}}{{/inline~}}
{{~#*inline "command"}}{{asUpperCamelCase name preserveAcronyms=true}}{{/inline~}}
- (void){{asLowerCamelCase name}}WithParams:(MTR{{>cluster}}Cluster{{>command}}Params * {{#unless (commandHasRequiredField .)}}_Nullable{{/unless}})params completion:({{>command_completion_type command=.}})completion {{availability (asUpperCamelCase parent.name preserveAcronyms=true) command=(asUpperCamelCase name preserveAcronyms=true) minimalRelease="First major API revamp"}};
- (void){{asLowerCamelCase name}}WithParams:(MTR{{cluster}}Cluster{{command}}Params * {{#unless (commandHasRequiredField .)}}_Nullable{{/unless}})params completion:({{>command_completion_type command=.}})completion {{availability cluster command=command minimalRelease="First major API revamp"}};
{{#unless (hasArguments)}}
- (void){{asLowerCamelCase name}}WithCompletion:({{>command_completion_type command=.}})completion {{availability (asUpperCamelCase parent.name preserveAcronyms=true) command=(asUpperCamelCase name preserveAcronyms=true) minimalRelease="First major API revamp"}};
- (void){{asLowerCamelCase name}}WithCompletion:({{>command_completion_type command=.}})completion {{availability cluster command=command minimalRelease="First major API revamp"}};
{{/unless}}
{{/unless}}
{{/inline}}
{{> commandDecl cluster=(asUpperCamelCase parent.name preserveAcronyms=true)
command=(asUpperCamelCase name preserveAcronyms=true)}}
{{/chip_cluster_commands}}

{{#chip_server_cluster_attributes}}
Expand Down Expand Up @@ -117,14 +122,20 @@ typedef NS_OPTIONS({{asUnderlyingZclType name}}, {{objCEnumName clusterName labe
queue:(dispatch_queue_t)queue {{availability (compatClusterNameRemapping name) deprecatedRelease="First major API revamp" deprecationMessage="Please use initWithDevice:endpointID:queue:"}};

{{#chip_cluster_commands}}
{{#if (wasIntroducedBeforeRelease "First major API revamp" (compatClusterNameRemapping parent.name) command=(asUpperCamelCase name))}}
- (void){{asLowerCamelCase name}}WithParams:(MTR{{compatClusterNameRemapping parent.name}}Cluster{{asUpperCamelCase name}}Params * {{#unless (commandHasRequiredField .)}}_Nullable{{/unless}})params completionHandler:({{>command_completion_type command=. compatRemapClusterName=true}})completionHandler
{{availability (compatClusterNameRemapping parent.name) command=(asUpperCamelCase name) deprecatedRelease="First major API revamp" deprecationMessage=(concat "Please use " (asLowerCamelCase name) "WithParams:completion:")}};
{{! Takes two arguments: cluster name and command name, plus the ambient state where the command is "this" }}
{{#*inline "commandDecl"}}
{{#if (and (wasIntroducedBeforeRelease "First major API revamp" cluster command=command)
(not (wasRemoved 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
{{availability cluster command=command deprecatedRelease="First major API revamp" deprecationMessage=(concat "Please use " (asLowerCamelCase name) "WithParams:completion:")}};
{{#unless (hasArguments)}}
- (void){{asLowerCamelCase name}}WithCompletionHandler:({{>command_completion_type command=. compatRemapClusterName=true}})completionHandler
{{availability (compatClusterNameRemapping parent.name) command=(asUpperCamelCase name) deprecatedRelease="First major API revamp" deprecationMessage=(concat "Please use " (asLowerCamelCase name) "WithCompletion:")}};
- (void){{asLowerCamelCase command}}WithCompletionHandler:({{>command_completion_type command=. compatRemapNames=true}})completionHandler
{{availability cluster command=command deprecatedRelease="First major API revamp" deprecationMessage=(concat "Please use " (asLowerCamelCase name) "WithCompletion:")}};
{{/unless}}
{{/if}}
{{/inline}}
{{> commandDecl cluster=(compatClusterNameRemapping parent.name)
command=(compatCommandNameRemapping parent.name name)}}
{{/chip_cluster_commands}}

{{#chip_server_cluster_attributes}}
Expand Down
22 changes: 17 additions & 5 deletions src/darwin/Framework/CHIP/templates/MTRClusterConstants.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,34 @@ typedef NS_ENUM(uint32_t, MTRCommandIDType) {
// Cluster {{compatClusterNameRemapping ../clusterName}} deprecated command id names
{{/if}}
{{/first}}
{{#if (wasIntroducedBeforeRelease "First major API revamp" (compatClusterNameRemapping ../clusterName) command=(asUpperCamelCase label) isForIds=true)}}
MTRCluster{{compatClusterNameRemapping ../clusterName}}Command{{asUpperCamelCase label}}ID
{{availability (compatClusterNameRemapping ../clusterName) command=(asUpperCamelCase label) deprecatedRelease="First major API revamp" deprecationMessage=(concat "Please use MTRCommandIDTypeCluster" (asUpperCamelCase ../clusterName preserveAcronyms=true) "Command" (asUpperCamelCase label preserveAcronyms=true) "ID") isForIds=true}}
{{! Takes two arguments: cluster name and command name, plus the ambient state where the command is "this" }}
{{#*inline "commandIdDecl"}}
{{#if (and (wasIntroducedBeforeRelease "First major API revamp" cluster command=command isForIds=true)
(not (wasRemoved cluster command=command isForIds=true)))}}
MTRCluster{{cluster}}Command{{command}}ID
{{availability cluster command=command deprecatedRelease="First major API revamp" deprecationMessage=(concat "Please use MTRCommandIDTypeCluster" (asUpperCamelCase ../clusterName preserveAcronyms=true) "Command" (asUpperCamelCase name preserveAcronyms=true) "ID") isForIds=true}}
= {{asMEI manufacturerCode code}},
{{/if}}
{{/inline}}
{{> commandIdDecl cluster=(compatClusterNameRemapping ../clusterName)
command=(compatCommandNameRemapping ../clusterName name)}}
{{#last}}

{{/last}}
{{/zcl_commands}}
{{#zcl_commands}}
{{~#*inline "cluster"}}{{asUpperCamelCase ../clusterName preserveAcronyms=true}}{{/inline~}}
{{~#*inline "command"}}{{asUpperCamelCase label preserveAcronyms=true}}{{/inline~}}
{{#first}}
// Cluster {{>cluster}} commands
{{/first}}
MTRCommandIDTypeCluster{{>cluster}}Command{{>command}}ID {{availability (asUpperCamelCase ../clusterName preserveAcronyms=true) command=(asUpperCamelCase label preserveAcronyms=true) minimalRelease="First major API revamp" isForIds=true}} = {{asMEI manufacturerCode code}},
{{! Takes two arguments: cluster name and command name, plus the ambient state where the command is "this" }}
{{#*inline "commandIdDecl"}}
{{#unless (wasRemoved cluster command=command isForIds=true)}}
MTRCommandIDTypeCluster{{cluster}}Command{{command}}ID {{availability cluster command=command minimalRelease="First major API revamp" isForIds=true}} = {{asMEI manufacturerCode code}},
{{/unless}}
{{/inline}}
{{> commandIdDecl cluster=(asUpperCamelCase ../clusterName preserveAcronyms=true)
command=(asUpperCamelCase name preserveAcronyms=true)}}
{{#last}}

{{/last}}
Expand Down
Loading

0 comments on commit 984b476

Please sign in to comment.