Skip to content

Commit

Permalink
refactor for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLiuZhuoCheng committed Nov 17, 2021
1 parent dedc1cd commit 61db15b
Show file tree
Hide file tree
Showing 8 changed files with 8,215 additions and 8,201 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
65 changes: 4 additions & 61 deletions src/controller/java/templates/ClusterInfo-java.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ 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 {
Expand Down Expand Up @@ -261,9 +263,9 @@ 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 = getWriteAttributeMap();
Map<String, Map<String, InteractionInfo>> writeAttributeMap = new ClusterWriteMapping().getWriteAttributeMap();
combineCommand(clusterMap, writeAttributeMap);
return clusterMap;
}
Expand Down Expand Up @@ -336,65 +338,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;
}

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<>();
// write attribute
{{#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 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}}
57 changes: 57 additions & 0 deletions src/controller/java/templates/ClusterInfo-read-interaction.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{{> header}}
{{#if (chip_has_client_clusters)}}

package chip.devicecontroller;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.List;
import java.util.HashMap;
import chip.clusterinfo.ClusterInfo;
import chip.clusterinfo.InteractionInfo;
import chip.clusterinfo.CommandParameterInfo;
import chip.clusterinfo.DelegatedClusterCallback;
import chip.clusterinfo.ClusterCommandCallback;
import chip.clusterinfo.CommandResponseInfo;
import chip.devicecontroller.ChipClusters.DefaultClusterCallback;
import chip.devicecontroller.ClusterInfoMapping.DelegatedIntegerAttributeCallback;



public class ClusterReadMapping {

public Map<String, Map<String, InteractionInfo>> getReadAttributeMap() {
ClusterInfoMapping clusterInfoMapping = new ClusterInfoMapping();
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}}
() -> clusterInfoMapping.new Delegated{{asUpperCamelCase name}}AttributeCallback(),
{{else}}
() -> clusterInfoMapping.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}}

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

package chip.devicecontroller;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.List;
import java.util.HashMap;
import chip.clusterinfo.ClusterInfo;
import chip.clusterinfo.InteractionInfo;
import chip.clusterinfo.CommandParameterInfo;
import chip.clusterinfo.DelegatedClusterCallback;
import chip.clusterinfo.ClusterCommandCallback;
import chip.clusterinfo.CommandResponseInfo;
import chip.devicecontroller.ChipClusters.DefaultClusterCallback;


public class ClusterWriteMapping {
public Map<String, Map<String, InteractionInfo>> getWriteAttributeMap() {
ClusterInfoMapping clusterInfoMapping = new ClusterInfoMapping();
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")
);
},
() -> clusterInfoMapping.new 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 61db15b

Please sign in to comment.