| /* |
| * |
| * Copyright (c) 2023 Project CHIP Authors |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| 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 { |
| |
| {% 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( |
| (cluster, callback, commandArguments) -> { |
| ((ChipClusters.{{cluster.name}}Cluster) cluster).read{{attribute.definition.name | upfirst}}Attribute( |
| ({{ attribute | chipClustersCallbackName(typeLookup) }}) callback |
| ); |
| }, |
| () -> new ClusterInfoMapping.{{ attribute | delegatedCallbackName(typeLookup)}}(), |
| read{{cluster.name}}{{attribute.definition.name | upfirst}}CommandParams |
| ); |
| 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 -%} |
| }}; |
| } |
| } |
| |