Skip to content

Commit

Permalink
Replacing a state helper such as chip_server_cluster_attributes with …
Browse files Browse the repository at this point in the history
…a stateless helper zcl_attributes_server such that we can get deprecate the stateful helpers one by one. Also deprecating if_basic_global_response with if_basic_attribute.

The generation diff that is being seen here pertains to generating all server attributes for the corresponding client clusters instead of hacking the server attributes in the zap file. The hack here referes to how server attributes being generated are those attributes which have been enabled without the corresponding server cluster enabled. To avoid this hack, the code now generates all server attributes for the corresponding client cluster. This seems to be in sync with the non java/python templates in terms of generation.
Another generation diff seen here is that there is no basic global response for certain attributes which refer to atomic types such as group_id and vendor_id. I am not sure why that is the case. These attributes seem basic enough.
Github: ZAP#898
  • Loading branch information
brdandu committed Mar 15, 2023
1 parent a9e759b commit 8ef2aab
Show file tree
Hide file tree
Showing 22 changed files with 17,964 additions and 2,101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobject DecodeAttributeValue(const app::ConcreteAttributePath & aPath, TLV::TLVR
using namespace app::Clusters::{{asUpperCamelCase name}};
switch (aPath.mAttributeId)
{
{{#chip_server_cluster_attributes}}
{{#zcl_attributes_server removeKeys='isOptional'}}
case Attributes::{{asUpperCamelCase name}}::Id: {
using TypeInfo = Attributes::{{asUpperCamelCase name}}::TypeInfo;
TypeInfo::DecodableType cppValue;
Expand All @@ -54,7 +54,7 @@ jobject DecodeAttributeValue(const app::ConcreteAttributePath & aPath, TLV::TLVR
{{>decode_value target="value" source="cppValue" cluster=(asUpperCamelCase parent.name) depth=0 earlyReturn="nullptr"}}
return value;
}
{{/chip_server_cluster_attributes}}
{{/zcl_attributes_server}}
default:
*aError = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB;
break;
Expand Down
4 changes: 2 additions & 2 deletions src/controller/java/templates/CHIPCallbackTypes.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ typedef void (*CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase nam

{{! TODO: global response types?}}

{{#chip_server_cluster_attributes}}
{{#zcl_attributes_server}}
{{#if isArray}}
typedef void (*CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}AttributeCallbackType)(void *, const chip::app::Clusters::{{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::TypeInfo::DecodableType &);
{{else}}
typedef void (*CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}AttributeCallbackType)(void *, chip::app::Clusters::{{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::TypeInfo::DecodableArgType);
{{/if}}
{{/chip_server_cluster_attributes}}
{{/zcl_attributes_server}}
{{/chip_client_clusters}}
{{/if}}
9 changes: 5 additions & 4 deletions src/controller/java/templates/CHIPClustersWrite-JNI.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ using namespace chip;
using namespace chip::Controller;

{{#chip_client_clusters}}
{{#chip_server_cluster_attributes}}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#zcl_attributes_server removeKeys='isOptional'}}
{{#if_unsupported_attribute_callback type isArray ../id language='java'}}
{{else}}
{{#if isWritableAttribute}}

JNI_METHOD(void, {{asUpperCamelCase ../name}}Cluster, write{{asUpperCamelCase name}}Attribute)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback, {{asJniBasicType type true}} value, jobject timedWriteTimeoutMs)
Expand Down Expand Up @@ -74,8 +75,8 @@ JNI_METHOD(void, {{asUpperCamelCase ../name}}Cluster, write{{asUpperCamelCase na
onFailure.release();
}
{{/if}}
{{/unless}}
{{/chip_server_cluster_attributes}}
{{/if_unsupported_attribute_callback}}
{{/zcl_attributes_server}}
{{/chip_client_clusters}}
{{/if}}

Expand Down
17 changes: 9 additions & 8 deletions src/controller/java/templates/CHIPReadCallbacks-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ void CHIP{{chipCallback.name}}AttributeCallback::CallbackFn(void * context, {{ch
{{/chip_server_global_responses}}

{{#chip_client_clusters}}
{{#chip_server_cluster_attributes}}
{{#zcl_attributes_server removeKeys='isOptional'}}
{{! TODO: Add support for struct-typed attributes }}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#if_unsupported_attribute_callback type isArray ../id language='java'}}
{{else}}

{{#if_basic_global_response}}
{{#if_basic_attribute type ../id language='java'}}
{{else}}
CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback::CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback(jobject javaCallback, bool keepAlive) :
chip::Callback::Callback<CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}AttributeCallbackType>(CallbackFn, this), keepAlive(keepAlive)
Expand All @@ -116,7 +117,7 @@ CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback::
}
env->DeleteGlobalRef(javaCallbackRef);
}
{{/if_basic_global_response}}
{{/if_basic_attribute}}

{{#if isArray}}
void CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback::CallbackFn(void * context, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} list)
Expand Down Expand Up @@ -144,7 +145,7 @@ void CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallb
env->CallVoidMethod(javaCallbackRef, javaMethod, arrayListObj);
}
{{else}}
{{#if_basic_global_response}}
{{#if_basic_attribute type ../id language='java'}}
{{else}}
void CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback::CallbackFn(void * context, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} value)
{
Expand All @@ -168,10 +169,10 @@ void CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallb

env->CallVoidMethod(javaCallbackRef, javaMethod, javaValue);
}
{{/if_basic_global_response}}
{{/if_basic_attribute}}
{{/if}}
{{/unless}}
{{/chip_server_cluster_attributes}}
{{/if_unsupported_attribute_callback}}
{{/zcl_attributes_server}}
{{/chip_client_clusters}}

{{/if}}
13 changes: 7 additions & 6 deletions src/controller/java/templates/CHIPReadCallbacks.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ private:
{{/chip_server_global_responses}}

{{#chip_client_clusters}}
{{#chip_server_cluster_attributes}}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#if_basic_global_response}}
{{#zcl_attributes_server removeKeys='isOptional'}}
{{#if_unsupported_attribute_callback type isArray ../id language='java'}}
{{else}}
{{#if_basic_attribute type ../id language='java'}}
{{else}}
class CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback : public chip::Callback::Callback<CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}AttributeCallbackType>
{
Expand All @@ -65,10 +66,10 @@ private:
jobject javaCallbackRef;
bool keepAlive;
};
{{/if_basic_global_response}}
{{/if_basic_attribute}}

{{/unless}}
{{/chip_server_cluster_attributes}}
{{/if_unsupported_attribute_callback}}
{{/zcl_attributes_server}}
{{/chip_client_clusters}}

{{/if}}
55 changes: 29 additions & 26 deletions src/controller/java/templates/ChipClusters-java.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ public class ChipClusters {

{{/chip_cluster_responses}}

{{#chip_server_cluster_attributes}}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#if_basic_global_response}}
{{#zcl_attributes_server removeKeys='isOptional'}}
{{#if_unsupported_attribute_callback type isArray ../id language='java'}}
{{else}}
{{#if_basic_attribute type ../id language='java'}}
{{else}}
{{! NOTE: asJavaType ends up sniffing for isArray on the context. Since we want the type of our _entry_, force isArray to
false. }}
Expand All @@ -161,19 +162,20 @@ public class ChipClusters {
default void onSubscriptionEstablished(long subscriptionId) {}
}
{{/if}}
{{/if_basic_global_response}}
{{/unless}}
{{/chip_server_cluster_attributes}}
{{#chip_server_cluster_attributes}}
{{/if_basic_attribute}}
{{/if_unsupported_attribute_callback}}
{{/zcl_attributes_server}}
{{#zcl_attributes_server removeKeys='isOptional'}}
{{! TODO: Add support for struct-typed attributes }}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#if_unsupported_attribute_callback type isArray ../id language='java'}}
{{else}}

public void read{{asUpperCamelCase name}}Attribute(
{{#if_basic_global_response}}
{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback callback
{{#if_basic_attribute type ../id language='java'}}
{{as_underlying_java_zcl_type type ../id boolean="Boolean"}}AttributeCallback callback
{{else}}
{{asUpperCamelCase name}}AttributeCallback callback
{{/if_basic_global_response}}
{{/if_basic_attribute}}
) {
read{{asUpperCamelCase name}}Attribute(chipClusterPtr, callback);
}
Expand All @@ -190,42 +192,43 @@ public class ChipClusters {
{{/if}}
{{#if isReportableAttribute}}
public void subscribe{{asCamelCased name false}}Attribute(
{{#if_basic_global_response}}
{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback callback
{{#if_basic_attribute type ../id language='java'}}
{{as_underlying_java_zcl_type type ../id boolean="Boolean"}}AttributeCallback callback
{{else}}
{{asUpperCamelCase name}}AttributeCallback callback
{{/if_basic_global_response}},
{{/if_basic_attribute}},
int minInterval, int maxInterval) {
subscribe{{asCamelCased name false}}Attribute(chipClusterPtr, callback, minInterval, maxInterval);
}
{{/if}}
{{/unless}}
{{/chip_server_cluster_attributes}}
{{#chip_server_cluster_attributes}}
{{/if_unsupported_attribute_callback}}
{{/zcl_attributes_server}}
{{#zcl_attributes_server removeKeys='isOptional'}}
{{! TODO: Add support for struct-typed attributes }}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#if_unsupported_attribute_callback type isArray ../id language='java'}}
{{else}}

private native void read{{asUpperCamelCase name}}Attribute(long chipClusterPtr,
{{#if_basic_global_response}}
{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback callback
{{#if_basic_attribute type ../id language='java'}}
{{as_underlying_java_zcl_type type ../id boolean="Boolean"}}AttributeCallback callback
{{else}}
{{asUpperCamelCase name}}AttributeCallback callback
{{/if_basic_global_response}}
{{/if_basic_attribute}}
);
{{#if isWritableAttribute}}

private native void write{{asUpperCamelCase name}}Attribute(long chipClusterPtr, DefaultClusterCallback callback, {{asJavaType type chipType parent.name}} value, @Nullable Integer timedWriteTimeoutMs);
{{/if}}
{{#if isReportableAttribute}}
private native void subscribe{{asCamelCased name false}}Attribute(long chipClusterPtr,
{{#if_basic_global_response}}
{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback callback
{{#if_basic_attribute type ../id language='java'}}
{{as_underlying_java_zcl_type type ../id boolean="Boolean"}}AttributeCallback callback
{{else}}
{{asUpperCamelCase name}}AttributeCallback callback
{{/if_basic_global_response}}, int minInterval, int maxInterval);
{{/if_basic_attribute}}, int minInterval, int maxInterval);
{{/if}}
{{/unless}}
{{/chip_server_cluster_attributes}}
{{/if_unsupported_attribute_callback}}
{{/zcl_attributes_server}}
}
{{#not_last}}

Expand Down
4 changes: 2 additions & 2 deletions src/controller/java/templates/ChipIdLookup-java.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public final class ChipIdLookup {
public static String attributeIdToName(long clusterId, long attributeId) {
{{#chip_client_clusters}}
if (clusterId == {{code}}L) {
{{#chip_server_cluster_attributes}}
{{#zcl_attributes_server}}
if (attributeId == {{code}}L) {
return "{{asUpperCamelCase name}}";
}
{{/chip_server_cluster_attributes}}
{{/zcl_attributes_server}}
return "";
}
{{/chip_client_clusters}}
Expand Down
13 changes: 7 additions & 6 deletions src/controller/java/templates/ClusterInfo-java.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,10 @@ public class ClusterInfoMapping {
}

{{/chip_cluster_responses}}
{{#chip_server_cluster_attributes}}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#if_basic_global_response}}
{{#zcl_attributes_server removeKeys='isOptional'}}
{{#if_unsupported_attribute_callback type isArray ../id language='java'}}
{{else}}
{{#if_basic_attribute type ../id language='java'}}
{{else}}
public static class Delegated{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}AttributeCallback implements ChipClusters.{{asUpperCamelCase ../name}}Cluster.{{asUpperCamelCase name}}AttributeCallback, DelegatedClusterCallback {
private ClusterCommandCallback callback;
Expand Down Expand Up @@ -270,9 +271,9 @@ public class ClusterInfoMapping {
callback.onFailure(ex);
}
}
{{/if_basic_global_response}}
{{/unless}}
{{/chip_server_cluster_attributes}}
{{/if_basic_attribute}}
{{/if_unsupported_attribute_callback}}
{{/zcl_attributes_server}}

{{/chip_client_clusters}}

Expand Down
21 changes: 11 additions & 10 deletions src/controller/java/templates/ClusterInfo-read-interaction.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,31 @@ public class ClusterReadMapping {
Map<String, Map<String, InteractionInfo>> readAttributeMap = new HashMap<>();
{{#chip_client_clusters}}
Map<String, InteractionInfo> read{{asUpperCamelCase name}}InteractionInfo = new LinkedHashMap<>();
{{#chip_server_cluster_attributes}}
{{#zcl_attributes_server removeKeys='isOptional'}}
{{! TODO: Add support for struct-typed attributes }}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#if_unsupported_attribute_callback type isArray ../id language='java'}}
{{else}}
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_basic_global_response}}
ChipClusters.{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback
({{#if_basic_attribute type ../id language='java'}}
ChipClusters.{{as_underlying_java_zcl_type type ../id boolean="Boolean"}}AttributeCallback
{{else}}
ChipClusters.{{asUpperCamelCase ../name}}Cluster.{{asUpperCamelCase name}}AttributeCallback
{{/if_basic_global_response}}) callback
{{/if_basic_attribute}}) callback
);
},
{{#if_basic_global_response}}
() -> new ClusterInfoMapping.Delegated{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback(),
{{#if_basic_attribute type ../id language='java'}}
() -> new ClusterInfoMapping.Delegated{{as_underlying_java_zcl_type type ../id boolean="Boolean"}}AttributeCallback(),
{{else}}
() -> new ClusterInfoMapping.Delegated{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}AttributeCallback(),
{{/if_basic_global_response}}
{{/if_basic_attribute}}
read{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}CommandParams
);
read{{asUpperCamelCase ../name}}InteractionInfo.put("read{{asUpperCamelCase name}}Attribute", read{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}AttributeInteractionInfo);
{{/unless}}
{{/chip_server_cluster_attributes}}
{{/if_unsupported_attribute_callback}}
{{/zcl_attributes_server}}
readAttributeMap.put("{{asLowerCamelCase name}}", read{{asUpperCamelCase name}}InteractionInfo);
{{/chip_client_clusters}}
return readAttributeMap;
Expand Down
11 changes: 6 additions & 5 deletions src/controller/java/templates/ClusterInfo-write-interaction.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ public class ClusterWriteMapping {
Map<String, Map<String, InteractionInfo>> writeAttributeMap = new HashMap<>();
{{#chip_client_clusters}}
Map<String, InteractionInfo> write{{asUpperCamelCase name}}InteractionInfo = new LinkedHashMap<>();
{{#chip_server_cluster_attributes}}
{{#zcl_attributes_server removeKeys='isOptional'}}
{{! TODO: Add support for struct-typed attributes }}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#if_unsupported_attribute_callback type isArray ../id language='java'}}
{{else}}
{{#if isWritableAttribute}}
{{#unless isArray}}
Map<String, CommandParameterInfo> write{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}CommandParams = new LinkedHashMap<String, CommandParameterInfo>();
Expand All @@ -27,7 +28,7 @@ public class ClusterWriteMapping {
(cluster, callback, commandArguments) -> {
((ChipClusters.{{asUpperCamelCase ../name}}Cluster) cluster).write{{asUpperCamelCase name}}Attribute(
(DefaultClusterCallback) callback,
({{asJavaBoxedType type chipType}})
({{as_underlying_java_zcl_type type ../id boolean="Boolean" isBoxedJavaType=true}})
commandArguments.get("value")
{{#if mustUseTimedWrite}}, 10000{{/if}}
);
Expand All @@ -38,8 +39,8 @@ public class ClusterWriteMapping {
write{{asUpperCamelCase ../name}}InteractionInfo.put("write{{asUpperCamelCase name}}Attribute", write{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}AttributeInteractionInfo);
{{/unless}}
{{/if}}
{{/unless}}
{{/chip_server_cluster_attributes}}
{{/if_unsupported_attribute_callback}}
{{/zcl_attributes_server}}
writeAttributeMap.put("{{asLowerCamelCase name}}", write{{asUpperCamelCase name}}InteractionInfo);
{{/chip_client_clusters}}
return writeAttributeMap;
Expand Down
Loading

0 comments on commit 8ef2aab

Please sign in to comment.