Skip to content

Commit

Permalink
finish generating write attributes (#11804)
Browse files Browse the repository at this point in the history
* finish generating write attributes

* refactor for comments

* resolve comments

* swap public and static keyword
  • Loading branch information
JasonLiuZhuoCheng authored and pull[bot] committed Dec 16, 2021
1 parent 6bf7a59 commit 3274723
Show file tree
Hide file tree
Showing 8 changed files with 8,364 additions and 6,629 deletions.
2 changes: 2 additions & 0 deletions src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ android_library("java") {
"src/chip/devicecontroller/PaseVerifierParams.java",
"zap-generated/chip/devicecontroller/ChipClusters.java",
"zap-generated/chip/devicecontroller/ClusterInfoMapping.java",
"zap-generated/chip/devicecontroller/ClusterReadMapping.java",
"zap-generated/chip/devicecontroller/ClusterWriteMapping.java",
]

javac_flags = [ "-Xlint:deprecation" ]
Expand Down
53 changes: 13 additions & 40 deletions src/controller/java/templates/ClusterInfo-java.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import chip.clusterinfo.DelegatedClusterCallback;
import chip.clusterinfo.ClusterCommandCallback;
import chip.clusterinfo.CommandResponseInfo;
import chip.devicecontroller.ChipClusters.DefaultClusterCallback;

import chip.devicecontroller.ClusterReadMapping;
import chip.devicecontroller.ClusterWriteMapping;

public class ClusterInfoMapping {

public class DelegatedCharStringAttributeCallback implements ChipClusters.CharStringAttributeCallback, DelegatedClusterCallback {
public static class DelegatedCharStringAttributeCallback implements ChipClusters.CharStringAttributeCallback, DelegatedClusterCallback {
/** Indicates a successful read for a CHAR_STRING attribute. */
private ClusterCommandCallback callback;

Expand All @@ -42,7 +43,7 @@ public class ClusterInfoMapping {
}
}

public class DelegatedOctetStringAttributeCallback implements ChipClusters.OctetStringAttributeCallback, DelegatedClusterCallback {
public static class DelegatedOctetStringAttributeCallback implements ChipClusters.OctetStringAttributeCallback, DelegatedClusterCallback {
/** Indicates a successful read for an OCTET_STRING attribute. */
private ClusterCommandCallback callback;

Expand All @@ -65,7 +66,7 @@ public class ClusterInfoMapping {
}
}

public class DelegatedIntegerAttributeCallback implements ChipClusters.IntegerAttributeCallback, DelegatedClusterCallback {
public static class DelegatedIntegerAttributeCallback implements ChipClusters.IntegerAttributeCallback, DelegatedClusterCallback {
private ClusterCommandCallback callback;

@Override
Expand All @@ -87,7 +88,7 @@ public class ClusterInfoMapping {
}
}

public class DelegatedLongAttributeCallback implements ChipClusters.LongAttributeCallback, DelegatedClusterCallback {
public static class DelegatedLongAttributeCallback implements ChipClusters.LongAttributeCallback, DelegatedClusterCallback {
private ClusterCommandCallback callback;

@Override
Expand All @@ -109,7 +110,7 @@ public class ClusterInfoMapping {
}
}

public class DelegatedBooleanAttributeCallback implements ChipClusters.BooleanAttributeCallback, DelegatedClusterCallback {
public static class DelegatedBooleanAttributeCallback implements ChipClusters.BooleanAttributeCallback, DelegatedClusterCallback {
private ClusterCommandCallback callback;

@Override
Expand All @@ -131,7 +132,7 @@ public class ClusterInfoMapping {
}
}

class DelegatedDefaultClusterCallback implements DefaultClusterCallback, DelegatedClusterCallback {
public static class DelegatedDefaultClusterCallback implements DefaultClusterCallback, DelegatedClusterCallback {
private ClusterCommandCallback callback;

@Override
Expand All @@ -153,7 +154,7 @@ public class ClusterInfoMapping {
}
{{#chip_client_clusters}}
{{#chip_cluster_responses}}
public class Delegated{{asUpperCamelCase name}}Callback implements ChipClusters.{{asUpperCamelCase ../name}}Cluster.{{asUpperCamelCase name}}Callback, DelegatedClusterCallback {
public static class Delegated{{asUpperCamelCase name}}Callback implements ChipClusters.{{asUpperCamelCase ../name}}Cluster.{{asUpperCamelCase name}}Callback, DelegatedClusterCallback {
private ClusterCommandCallback callback;
@Override
public void setCallbackDelegate(ClusterCommandCallback callback) {
Expand Down Expand Up @@ -201,7 +202,7 @@ public class ClusterInfoMapping {

{{/if}}

public class Delegated{{asUpperCamelCase name}}AttributeCallback implements ChipClusters.{{asUpperCamelCase ../name}}Cluster.{{asUpperCamelCase name}}AttributeCallback, DelegatedClusterCallback {
public static class Delegated{{asUpperCamelCase name}}AttributeCallback implements ChipClusters.{{asUpperCamelCase ../name}}Cluster.{{asUpperCamelCase name}}AttributeCallback, DelegatedClusterCallback {
private ClusterCommandCallback callback;
@Override
public void setCallbackDelegate(ClusterCommandCallback callback) {
Expand Down Expand Up @@ -261,8 +262,10 @@ public class ClusterInfoMapping {
Map<String, ClusterInfo> clusterMap = initializeClusterMap();
Map<String, Map<String, InteractionInfo>> commandMap = getCommandMap();
combineCommand(clusterMap, commandMap);
Map<String, Map<String, InteractionInfo>> readAttributeMap = getReadAttributeMap();
Map<String, Map<String, InteractionInfo>> readAttributeMap = new ClusterReadMapping().getReadAttributeMap();
combineCommand(clusterMap, readAttributeMap);
Map<String, Map<String, InteractionInfo>> writeAttributeMap = new ClusterWriteMapping().getWriteAttributeMap();
combineCommand(clusterMap, writeAttributeMap);
return clusterMap;
}

Expand Down Expand Up @@ -334,36 +337,6 @@ public class ClusterInfoMapping {
return commandMap;
}

public Map<String, Map<String, InteractionInfo>> getReadAttributeMap() {
Map<String, Map<String, InteractionInfo>> readAttributeMap = new HashMap<>();
{{#chip_client_clusters}}
Map<String, InteractionInfo> read{{asUpperCamelCase name}}InteractionInfo = new LinkedHashMap<>();
// read attribute
{{#chip_server_cluster_attributes}}
Map<String, CommandParameterInfo> read{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}CommandParams = new LinkedHashMap<String, CommandParameterInfo>();
InteractionInfo read{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}AttributeInteractionInfo = new InteractionInfo(
(cluster, callback, commandArguments) -> {
((ChipClusters.{{asUpperCamelCase ../name}}Cluster) cluster).read{{asUpperCamelCase name}}Attribute(
{{#if isList}}
(ChipClusters.{{asUpperCamelCase ../name}}Cluster.{{asUpperCamelCase name}}AttributeCallback) callback
{{else}}
(ChipClusters.{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback) callback
{{/if}}
);
},
{{#if isList}}
() -> new Delegated{{asUpperCamelCase name}}AttributeCallback(),
{{else}}
() -> new Delegated{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback(),
{{/if}}
read{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}CommandParams
);
read{{asUpperCamelCase ../name}}InteractionInfo.put("read{{asUpperCamelCase name}}Attribute", read{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}AttributeInteractionInfo);
{{/chip_server_cluster_attributes}}
readAttributeMap.put("{{asLowerCamelCase name}}", read{{asUpperCamelCase name}}InteractionInfo);
{{/chip_client_clusters}}
return readAttributeMap;
}
}

{{/if}}
45 changes: 45 additions & 0 deletions src/controller/java/templates/ClusterInfo-read-interaction.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{> header}}
{{#if (chip_has_client_clusters)}}

package chip.devicecontroller;

import chip.clusterinfo.CommandParameterInfo;
import chip.clusterinfo.InteractionInfo;
import java.util.HashMap;
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<>();
{{#chip_client_clusters}}
Map<String, InteractionInfo> read{{asUpperCamelCase name}}InteractionInfo = new LinkedHashMap<>();
{{#chip_server_cluster_attributes}}
Map<String, CommandParameterInfo> read{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}CommandParams = new LinkedHashMap<String, CommandParameterInfo>();
InteractionInfo read{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}AttributeInteractionInfo = new InteractionInfo(
(cluster, callback, commandArguments) -> {
((ChipClusters.{{asUpperCamelCase ../name}}Cluster) cluster).read{{asUpperCamelCase name}}Attribute(
{{#if isList}}
(ChipClusters.{{asUpperCamelCase ../name}}Cluster.{{asUpperCamelCase name}}AttributeCallback) callback
{{else}}
(ChipClusters.{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback) callback
{{/if}}
);
},
{{#if isList}}
() -> new ClusterInfoMapping.Delegated{{asUpperCamelCase name}}AttributeCallback(),
{{else}}
() -> new ClusterInfoMapping.Delegated{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback(),
{{/if}}
read{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}CommandParams
);
read{{asUpperCamelCase ../name}}InteractionInfo.put("read{{asUpperCamelCase name}}Attribute", read{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}AttributeInteractionInfo);
{{/chip_server_cluster_attributes}}
readAttributeMap.put("{{asLowerCamelCase name}}", read{{asUpperCamelCase name}}InteractionInfo);
{{/chip_client_clusters}}
return readAttributeMap;
}
}

{{/if}}
43 changes: 43 additions & 0 deletions src/controller/java/templates/ClusterInfo-write-interaction.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{> header}}
{{#if (chip_has_client_clusters)}}

package chip.devicecontroller;

import chip.clusterinfo.CommandParameterInfo;
import chip.clusterinfo.InteractionInfo;
import chip.devicecontroller.ChipClusters.DefaultClusterCallback;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public class ClusterWriteMapping {
public Map<String, Map<String, InteractionInfo>> getWriteAttributeMap() {
Map<String, Map<String, InteractionInfo>> writeAttributeMap = new HashMap<>();
{{#chip_client_clusters}}
Map<String, InteractionInfo> write{{asUpperCamelCase name}}InteractionInfo = new LinkedHashMap<>();
{{#chip_server_cluster_attributes}}
{{#if isWritableAttribute}}
Map<String, CommandParameterInfo> write{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}CommandParams = new LinkedHashMap<String, CommandParameterInfo>();
CommandParameterInfo {{asLowerCamelCase ../name}}{{asLowerCamelCase name}}CommandParameterInfo = new CommandParameterInfo("value", {{asJavaBasicType type}}.class);
write{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}CommandParams.put("value",{{asLowerCamelCase ../name}}{{asLowerCamelCase name}}CommandParameterInfo);
InteractionInfo write{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}AttributeInteractionInfo = new InteractionInfo(
(cluster, callback, commandArguments) -> {
((ChipClusters.{{asUpperCamelCase ../name}}Cluster) cluster).write{{asUpperCamelCase name}}Attribute(
(DefaultClusterCallback) callback,
({{asJavaBoxedType type}})
commandArguments.get("value")
);
},
() -> new ClusterInfoMapping.DelegatedDefaultClusterCallback(),
write{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}CommandParams
);
write{{asUpperCamelCase ../name}}InteractionInfo.put("write{{asUpperCamelCase name}}Attribute", write{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}AttributeInteractionInfo);
{{/if}}
{{/chip_server_cluster_attributes}}
writeAttributeMap.put("{{asLowerCamelCase name}}", write{{asUpperCamelCase name}}InteractionInfo);
{{/chip_client_clusters}}
return writeAttributeMap;
}
}

{{/if}}
10 changes: 10 additions & 0 deletions src/controller/java/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@
"path": "ClusterInfo-java.zapt",
"name": "Cluster information mapping for Java",
"output": "src/controller/java/zap-generated/chip/devicecontroller/ClusterInfoMapping.java"
},
{
"path": "ClusterInfo-read-interaction.zapt",
"name": "Generate read interaction for cluster information map",
"output": "src/controller/java/zap-generated/chip/devicecontroller/ClusterReadMapping.java"
},
{
"path": "ClusterInfo-write-interaction.zapt",
"name": "Generate write interaction for cluster information map",
"output": "src/controller/java/zap-generated/chip/devicecontroller/ClusterWriteMapping.java"
}
]
}
Loading

0 comments on commit 3274723

Please sign in to comment.