Skip to content

Commit

Permalink
[darwin] Make sure the prefixes on the enum names match the type (pro…
Browse files Browse the repository at this point in the history
…ject-chip#23646)

This is a re-landing of PR project-chip#22673 but with backwards-compat preserved.

* Update generated code

Co-authored-by: Vivien Nicolas <[email protected]>
  • Loading branch information
2 people authored and adbridge committed Nov 18, 2022
1 parent ded72bf commit 066ec50
Show file tree
Hide file tree
Showing 4 changed files with 9,376 additions and 4,656 deletions.
103 changes: 60 additions & 43 deletions src/darwin/Framework/CHIP/templates/MTRClusterConstants.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,69 @@

typedef NS_ENUM(uint32_t, MTRClusterIDType) {
{{#zcl_clusters}}
MTRCluster{{asUpperCamelCase label}}ID {{#if (isStrEqual (asUpperCamelCase label) "UnitTesting")}}MTR_NEWLY_AVAILABLE{{/if}}= {{asMEI manufacturerCode code}},
{{#if (isStrEqual (asUpperCamelCase label) "UnitTesting")}}
MTRClusterTestClusterID MTR_NEWLY_DEPRECATED("Please use MTRClusterUnitTestingID") = {{asMEI manufacturerCode code}},
{{/if}}
MTRCluster{{compatClusterNameRemapping label}}ID MTR_NEWLY_DEPRECATED("Please use MTRClusterIDType{{asUpperCamelCase label}}ID")= {{asMEI manufacturerCode code}},
{{/zcl_clusters}}
{{#zcl_clusters}}
MTRClusterIDType{{asUpperCamelCase label}}ID MTR_NEWLY_AVAILABLE = {{asMEI manufacturerCode code}},
{{/zcl_clusters}}
};

#pragma mark - Attributes IDs

typedef NS_ENUM(uint32_t, MTRClusterAttributeIDType) {
typedef NS_ENUM(uint32_t, MTRAttributeIDType) {
// Deprecated global attribute names
{{#zcl_attributes_server}}
{{#unless clusterRef}}
MTRClusterGlobalAttribute{{asUpperCamelCase label}}ID
MTR_NEWLY_DEPRECATED("Please use MTRAttributeIDTypeGlobalAttribute{{asUpperCamelCase label}}ID")
= {{asMEI manufacturerCode code}},
{{/unless}}
{{/zcl_attributes_server}}

// Global attributes
{{#zcl_attributes_server}}
{{#unless clusterRef}}
MTRClusterGlobalAttribute{{asUpperCamelCase label}}ID = {{asMEI manufacturerCode code}},
MTRAttributeIDTypeGlobalAttribute{{asUpperCamelCase label}}ID MTR_NEWLY_AVAILABLE = {{asMEI manufacturerCode code}},
{{/unless}}
{{/zcl_attributes_server}}

{{#zcl_clusters}}
{{#*inline "attributeIDs"}}
{{#zcl_attributes_server}}
{{#first}}
// Cluster {{asUpperCamelCase ../clusterName}} attributes
// Cluster {{compatClusterNameRemapping ../clusterName}} deprecated attribute names
{{/first}}
{{#if clusterRef}}
{{! TODO: We need a better setup for the API_AVALABLE annotations here; this does not scale at all sanely. }}
MTRCluster{{asUpperCamelCase ../clusterName}}Attribute{{asUpperCamelCase label}}ID
{{! TODO: We need a better setup for the API_AVAILABLE annotations here; this does not scale at all sanely. }}
MTRCluster{{compatClusterNameRemapping ../clusterName}}Attribute{{asUpperCamelCase label}}ID
MTR_NEWLY_DEPRECATED("Please use MTRAttributeIDTypeCluster{{asUpperCamelCase ../clusterName}}Attribute{{asUpperCamelCase label}}ID")
{{#if (isStrEqual (asUpperCamelCase ../clusterName) "Descriptor")}}
{{#if (isStrEqual (asUpperCamelCase label) "DeviceTypeList")}}
API_AVAILABLE(ios(16.2), macos(13.1), watchos(9.2), tvos(16.2))
{{/if}}
{{else if (isStrEqual (asUpperCamelCase ../clusterName) "TestCluster")}}
MTR_NEWLY_DEPRECATED("Please use MTRClusterUnitTestingAttribute{{asUpperCamelCase label}}ID")
{{else if (isStrEqual (asUpperCamelCase ../clusterName) "UnitTesting")}}
MTR_NEWLY_AVAILABLE
{{/if}}
= {{asMEI manufacturerCode code}},
{{!Backwards compat for now: DeviceList as an alias for DeviceTypeList}}
{{#if (isStrEqual (asUpperCamelCase ../clusterName) "Descriptor")}}
{{#if (isStrEqual (asUpperCamelCase label) "DeviceTypeList")}}
MTRClusterDescriptorAttributeDeviceListID = {{asMEI manufacturerCode code}},
MTRClusterDescriptorAttributeDeviceListID MTR_NEWLY_DEPRECATED("Please use MTRAttributeIDTypeCluster{{asUpperCamelCase ../clusterName}}Attribute{{asUpperCamelCase label}}ID") = {{asMEI manufacturerCode code}},
{{/if}}
{{/if}}
{{else}}
MTRCluster{{compatClusterNameRemapping ../clusterName}}Attribute{{asUpperCamelCase label}}ID MTR_NEWLY_DEPRECATED("Please use MTRAttributeIDTypeCluster{{asUpperCamelCase parent.label}}Attribute{{asUpperCamelCase label}}ID") = MTRClusterGlobalAttribute{{asUpperCamelCase label}}ID,
{{/if}}
{{#last}}

{{/last}}
{{/zcl_attributes_server}}
{{#zcl_attributes_server}}
{{#first}}
// Cluster {{asUpperCamelCase ../clusterName}} attributes
{{/first}}
{{#if clusterRef}}
MTRAttributeIDTypeCluster{{asUpperCamelCase parent.label}}Attribute{{asUpperCamelCase label}}ID MTR_NEWLY_AVAILABLE = {{asMEI manufacturerCode code}},
{{else}}
MTRCluster{{asUpperCamelCase ../clusterName}}Attribute{{asUpperCamelCase label}}ID = MTRClusterGlobalAttribute{{asUpperCamelCase label}}ID,
MTRAttributeIDTypeCluster{{asUpperCamelCase ../clusterName}}Attribute{{asUpperCamelCase label}}ID MTR_NEWLY_AVAILABLE= MTRAttributeIDTypeGlobalAttribute{{asUpperCamelCase label}}ID,
{{/if}}
{{#last}}

Expand All @@ -59,69 +78,67 @@ MTRCluster{{asUpperCamelCase ../clusterName}}Attribute{{asUpperCamelCase label}}
{{/inline}}

{{> attributeIDs clusterName=label}}
{{#if (isStrEqual (asUpperCamelCase label) "UnitTesting")}}

{{> attributeIDs clusterName="TestCluster"}}
{{/if}}
{{/zcl_clusters}}
};

#pragma mark - Commands IDs

typedef NS_ENUM(uint32_t, MTRClusterCommandIDType) {
typedef NS_ENUM(uint32_t, MTRCommandIDType) {
{{#zcl_clusters}}
{{#*inline "commandIDs"}}
{{#zcl_commands}}
{{#first}}
// Cluster {{asUpperCamelCase ../clusterName}} commands
// Cluster {{compatClusterNameRemapping ../clusterName}} deprecated command id names
{{/first}}
MTRCluster{{asUpperCamelCase ../clusterName}}Command{{asUpperCamelCase label}}ID
{{#if (isStrEqual (asUpperCamelCase ../clusterName) "TestCluster")}}
MTR_NEWLY_DEPRECATED("Please use MTRClusterUnitTestingCommand{{asUpperCamelCase label}}ID")
{{else if (isStrEqual (asUpperCamelCase ../clusterName) "UnitTesting")}}
MTR_NEWLY_AVAILABLE
{{/if}}
MTRCluster{{compatClusterNameRemapping ../clusterName}}Command{{asUpperCamelCase label}}ID
MTR_NEWLY_DEPRECATED("Please use MTRCommandIDTypeCluster{{asUpperCamelCase ../clusterName}}Command{{asUpperCamelCase label}}ID")
= {{asMEI manufacturerCode code}},
{{#last}}

{{/last}}
{{/zcl_commands}}
{{#zcl_commands}}
{{#first}}
// Cluster {{asUpperCamelCase ../clusterName}} commands
{{/first}}
MTRCommandIDTypeCluster{{asUpperCamelCase ../clusterName}}Command{{asUpperCamelCase label}}ID MTR_NEWLY_AVAILABLE = {{asMEI manufacturerCode code}},
{{#last}}

{{/last}}
{{/zcl_commands}}
{{/inline}}

{{> commandIDs clusterName=label}}
{{#if (isStrEqual (asUpperCamelCase label) "UnitTesting")}}

{{> commandIDs clusterName="TestCluster"}}
{{/if}}
{{/zcl_clusters}}
};

#pragma mark - Events IDs

typedef NS_ENUM(uint32_t, MTRClusterEventIDType) {
typedef NS_ENUM(uint32_t, MTREventIDType) {
{{#zcl_clusters}}
{{#*inline "eventIDs"}}
{{#zcl_events}}
{{#first}}
// Cluster {{asUpperCamelCase ../clusterName}} events
// Cluster {{compatClusterNameRemapping ../clusterName}} deprecated event names
{{/first}}
MTRCluster{{asUpperCamelCase ../clusterName}}Event{{asUpperCamelCase name}}ID
{{#if (isStrEqual (asUpperCamelCase ../clusterName) "TestCluster")}}
MTR_NEWLY_DEPRECATED("Please use MTRClusterUnitTestingEvent{{asUpperCamelCase name}}ID")
{{else if (isStrEqual (asUpperCamelCase ../clusterName) "UnitTesting")}}
MTR_NEWLY_AVAILABLE
{{/if}}
MTRCluster{{compatClusterNameRemapping ../clusterName}}Event{{asUpperCamelCase name}}ID
MTR_NEWLY_DEPRECATED("Please use MTREventIDTypeCluster{{asUpperCamelCase ../clusterName}}Event{{asUpperCamelCase name}}ID")
= {{asMEI manufacturerCode code}},
{{#last}}

{{/last}}
{{/zcl_events}}
{{#zcl_events}}
{{#first}}
// Cluster {{asUpperCamelCase ../clusterName}} events
{{/first}}
MTREventIDTypeCluster{{asUpperCamelCase ../clusterName}}Event{{asUpperCamelCase name}}ID MTR_NEWLY_AVAILABLE = {{asMEI manufacturerCode code}},
{{#last}}

{{/last}}
{{/zcl_events}}
{{/inline}}

{{> eventIDs clusterName=label}}
{{#if (isStrEqual (asUpperCamelCase label) "UnitTesting")}}

{{> eventIDs clusterName="TestCluster"}}
{{/if}}
{{/zcl_clusters}}
};
4 changes: 2 additions & 2 deletions src/darwin/Framework/CHIP/templates/MTRClusters-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ using chip::SessionHandle;
{{!Backwards compat for now: Treat DeviceTypeList as DeviceList. Ideally we would have both, not just DeviceList. }}
{{#*inline "attribute"}}Attribute{{#if (isStrEqual (asUpperCamelCase parent.name) "Descriptor")}}{{#if (isStrEqual (asUpperCamelCase name) "DeviceTypeList")}}DeviceList{{else}}{{asUpperCamelCase name}}{{/if}}{{else}}{{asUpperCamelCase name}}{{/if}}{{/inline}}
- (NSDictionary<NSString *, id> *)read{{>attribute}}WithParams:(MTRReadParams * _Nullable)params {
return [self.device readAttributeWithEndpointID:@(_endpoint) clusterID:@(MTRCluster{{asUpperCamelCase parent.name}}ID) attributeID:@(MTRCluster{{asUpperCamelCase parent.name}}Attribute{{asUpperCamelCase name}}ID) params:params];
return [self.device readAttributeWithEndpointID:@(_endpoint) clusterID:@(MTRClusterIDType{{asUpperCamelCase parent.name}}ID) attributeID:@(MTRAttributeIDTypeCluster{{asUpperCamelCase parent.name}}Attribute{{asUpperCamelCase name}}ID) params:params];
}

{{#if isWritableAttribute}}
Expand All @@ -143,7 +143,7 @@ using chip::SessionHandle;
}
{{/if}}

[self.device writeAttributeWithEndpointID:@(_endpoint) clusterID:@(MTRCluster{{asUpperCamelCase parent.name}}ID) attributeID:@(MTRCluster{{asUpperCamelCase parent.name}}Attribute{{asUpperCamelCase name}}ID) value:dataValueDictionary expectedValueInterval:expectedValueIntervalMs timedWriteTimeout:timedWriteTimeout];
[self.device writeAttributeWithEndpointID:@(_endpoint) clusterID:@(MTRClusterIDType{{asUpperCamelCase parent.name}}ID) attributeID:@(MTRAttributeIDTypeCluster{{asUpperCamelCase parent.name}}Attribute{{asUpperCamelCase name}}ID) value:dataValueDictionary expectedValueInterval:expectedValueIntervalMs timedWriteTimeout:timedWriteTimeout];
}

{{/if}}
Expand Down
Loading

0 comments on commit 066ec50

Please sign in to comment.