Skip to content

Commit

Permalink
Split up cluster read mapping (#26478)
Browse files Browse the repository at this point in the history
* New jinja file

* Fix unit tests

* Add type to return map sincew inference did not seem to work

* Suppress serialization warnings
  • Loading branch information
andy31415 authored and pull[bot] committed Dec 7, 2023
1 parent 9b89817 commit cdd2452
Show file tree
Hide file tree
Showing 3 changed files with 1,654 additions and 1,634 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ import java.util.LinkedHashMap;
import java.util.Map;

public class ClusterReadMapping {
public Map<String, Map<String, InteractionInfo>> getReadAttributeMap() {
Map<String, Map<String, InteractionInfo>> readAttributeMap = new HashMap<>();

{%- for cluster in clientClusters | sort(attribute='code') %}
{%- set typeLookup = idl | createLookupContext(cluster) %}
Map<String, InteractionInfo> read{{cluster.name}}InteractionInfo = new LinkedHashMap<>();
{%- for attribute in cluster.attributes | sort(attribute='name') | attributesWithCallback(typeLookup) %}
{% for cluster in clientClusters | sort(attribute='code') %}
{%- set typeLookup = idl | createLookupContext(cluster) %}
private static Map<String, InteractionInfo> read{{cluster.name}}InteractionInfo() {
Map<String, InteractionInfo> result = new LinkedHashMap<>();
{%- for attribute in cluster.attributes | sort(attribute='name') | attributesWithCallback(typeLookup) %}
{#- TODO: add support for struct-typed attributes -#}
Map<String, CommandParameterInfo> read{{cluster.name}}{{attribute.definition.name | upfirst}}CommandParams = new LinkedHashMap<String, CommandParameterInfo>();
InteractionInfo read{{cluster.name}}{{attribute.definition.name | upfirst}}AttributeInteractionInfo = new InteractionInfo(
Expand All @@ -41,11 +40,20 @@ public class ClusterReadMapping {
() -> new ClusterInfoMapping.{{ attribute | delegatedCallbackName(typeLookup)}}(),
read{{cluster.name}}{{attribute.definition.name | upfirst}}CommandParams
);
read{{cluster.name}}InteractionInfo.put("read{{attribute.definition.name | upfirst}}Attribute", read{{cluster.name}}{{attribute.definition.name | upfirst}}AttributeInteractionInfo);
{%- endfor %}
readAttributeMap.put("{{cluster.name | lowfirst_except_acronym}}", read{{cluster.name}}InteractionInfo);
result.put("read{{attribute.definition.name | upfirst}}Attribute", read{{cluster.name}}{{attribute.definition.name | upfirst}}AttributeInteractionInfo);
{% endfor %}
return result;
}

{%- endfor %}
@SuppressWarnings("serial")
public Map<String, Map<String, InteractionInfo>> getReadAttributeMap() {

return new HashMap<String, Map<String, InteractionInfo>>(){% raw %}{{{% endraw %}
{%- for cluster in clientClusters | sort(attribute='code') %}
put("{{cluster.name | lowfirst_except_acronym}}", read{{cluster.name}}InteractionInfo());
{%- endfor -%}
return readAttributeMap;
}};
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import java.util.Map;

public class ClusterReadMapping {
public Map<String, Map<String, InteractionInfo>> getReadAttributeMap() {
Map<String, Map<String, InteractionInfo>> readAttributeMap = new HashMap<>();
Map<String, InteractionInfo> readFirstInteractionInfo = new LinkedHashMap<>();Map<String, CommandParameterInfo> readFirstSomeIntegerCommandParams = new LinkedHashMap<String, CommandParameterInfo>();


private static Map<String, InteractionInfo> readFirstInteractionInfo() {
Map<String, InteractionInfo> result = new LinkedHashMap<>();Map<String, CommandParameterInfo> readFirstSomeIntegerCommandParams = new LinkedHashMap<String, CommandParameterInfo>();
InteractionInfo readFirstSomeIntegerAttributeInteractionInfo = new InteractionInfo(
(cluster, callback, commandArguments) -> {
((ChipClusters.FirstCluster) cluster).readSomeIntegerAttribute(
Expand All @@ -35,9 +36,12 @@ public Map<String, Map<String, InteractionInfo>> getReadAttributeMap() {
() -> new ClusterInfoMapping.DelegatedIntegerAttributeCallback(),
readFirstSomeIntegerCommandParams
);
readFirstInteractionInfo.put("readSomeIntegerAttribute", readFirstSomeIntegerAttributeInteractionInfo);
readAttributeMap.put("first", readFirstInteractionInfo);
Map<String, InteractionInfo> readSecondInteractionInfo = new LinkedHashMap<>();Map<String, CommandParameterInfo> readSecondSomeBytesCommandParams = new LinkedHashMap<String, CommandParameterInfo>();
result.put("readSomeIntegerAttribute", readFirstSomeIntegerAttributeInteractionInfo);

return result;
}
private static Map<String, InteractionInfo> readSecondInteractionInfo() {
Map<String, InteractionInfo> result = new LinkedHashMap<>();Map<String, CommandParameterInfo> readSecondSomeBytesCommandParams = new LinkedHashMap<String, CommandParameterInfo>();
InteractionInfo readSecondSomeBytesAttributeInteractionInfo = new InteractionInfo(
(cluster, callback, commandArguments) -> {
((ChipClusters.SecondCluster) cluster).readSomeBytesAttribute(
Expand All @@ -47,9 +51,12 @@ public Map<String, Map<String, InteractionInfo>> getReadAttributeMap() {
() -> new ClusterInfoMapping.DelegatedOctetStringAttributeCallback(),
readSecondSomeBytesCommandParams
);
readSecondInteractionInfo.put("readSomeBytesAttribute", readSecondSomeBytesAttributeInteractionInfo);
readAttributeMap.put("second", readSecondInteractionInfo);
Map<String, InteractionInfo> readThirdInteractionInfo = new LinkedHashMap<>();Map<String, CommandParameterInfo> readThirdSomeEnumCommandParams = new LinkedHashMap<String, CommandParameterInfo>();
result.put("readSomeBytesAttribute", readSecondSomeBytesAttributeInteractionInfo);

return result;
}
private static Map<String, InteractionInfo> readThirdInteractionInfo() {
Map<String, InteractionInfo> result = new LinkedHashMap<>();Map<String, CommandParameterInfo> readThirdSomeEnumCommandParams = new LinkedHashMap<String, CommandParameterInfo>();
InteractionInfo readThirdSomeEnumAttributeInteractionInfo = new InteractionInfo(
(cluster, callback, commandArguments) -> {
((ChipClusters.ThirdCluster) cluster).readSomeEnumAttribute(
Expand All @@ -59,7 +66,8 @@ public Map<String, Map<String, InteractionInfo>> getReadAttributeMap() {
() -> new ClusterInfoMapping.DelegatedIntegerAttributeCallback(),
readThirdSomeEnumCommandParams
);
readThirdInteractionInfo.put("readSomeEnumAttribute", readThirdSomeEnumAttributeInteractionInfo);Map<String, CommandParameterInfo> readThirdOptionsCommandParams = new LinkedHashMap<String, CommandParameterInfo>();
result.put("readSomeEnumAttribute", readThirdSomeEnumAttributeInteractionInfo);
Map<String, CommandParameterInfo> readThirdOptionsCommandParams = new LinkedHashMap<String, CommandParameterInfo>();
InteractionInfo readThirdOptionsAttributeInteractionInfo = new InteractionInfo(
(cluster, callback, commandArguments) -> {
((ChipClusters.ThirdCluster) cluster).readOptionsAttribute(
Expand All @@ -69,8 +77,17 @@ public Map<String, Map<String, InteractionInfo>> getReadAttributeMap() {
() -> new ClusterInfoMapping.DelegatedIntegerAttributeCallback(),
readThirdOptionsCommandParams
);
readThirdInteractionInfo.put("readOptionsAttribute", readThirdOptionsAttributeInteractionInfo);
readAttributeMap.put("third", readThirdInteractionInfo);return readAttributeMap;
result.put("readOptionsAttribute", readThirdOptionsAttributeInteractionInfo);

return result;
}
@SuppressWarnings("serial")
public Map<String, Map<String, InteractionInfo>> getReadAttributeMap() {

return new HashMap<String, Map<String, InteractionInfo>>(){{
put("first", readFirstInteractionInfo());
put("second", readSecondInteractionInfo());
put("third", readThirdInteractionInfo());}};
}
}

Loading

0 comments on commit cdd2452

Please sign in to comment.