Skip to content

Commit

Permalink
Moving zap templates away from zap helpers which use State (eg. ensur…
Browse files Browse the repository at this point in the history
…eClusters, etc) and other cleanup

- Switching to zcl_attributes_server from chip_server_cluster_attributes
- Using if_unsupported_attribute_type instead of  unless (isStrEqual chipCallback.name Unsupported)
- Using if_attribute_complex instead of if_basic_global_response
- Updating the zap repo
- Logic behind the diff in the applications: Some templates have the following hierarchy
{{#chip_client_clusters}}
{{#chip_server_cluster_attributes}}
In here we are going through the enabled client clusters and then the enabled server attributes for that cluster. However chip_server_cluster_attributes does not check if the server side cluster is actually enabled or not. The way zap is designed is to store user settings so a user may enable server cluster, enable server attribute and then disable server cluster. The backend saves user's enabled server attributes such that if in the future the user enables the server side cluster again then they get their old selections back. However that does not mean the server side attribute is enabled.
Switching to the following:
{#chip_client_clusters}}
{{#zcl_attributes_server}}
Gets all available server side attributes for the cluster. I believe this will give a better and consistent representation and ease of use for a user building the app. App developers do not need to worry if they enabled the server side cluster and attribute or not. Also they do not have to enable the server side attribute if not needed.
- Github: ZAP#682
  • Loading branch information
brdandu committed Nov 4, 2022
1 parent 237a869 commit 4f4fe15
Show file tree
Hide file tree
Showing 15 changed files with 17,748 additions and 8,427 deletions.
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}}
{{#if_unsupported_attribute_type type isArray}}
{{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_type}}
{{/zcl_attributes_server}}
{{/chip_client_clusters}}
{{/if}}

Expand Down
19 changes: 9 additions & 10 deletions src/controller/java/templates/CHIPReadCallbacks-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +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}}
{{! TODO: Add support for struct-typed attributes }}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}

{{#if_basic_global_response}}
{{#if_unsupported_attribute_type type isArray}}
{{else}}

{{#if_attribute_complex type}}
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 +116,7 @@ CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback::
}
env->DeleteGlobalRef(javaCallbackRef);
}
{{/if_basic_global_response}}
{{/if_attribute_complex}}

{{#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,8 +144,7 @@ void CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallb
env->CallVoidMethod(javaCallbackRef, javaMethod, arrayListObj);
}
{{else}}
{{#if_basic_global_response}}
{{else}}
{{#if_attribute_complex type}}
void CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback::CallbackFn(void * context, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} value)
{
chip::DeviceLayer::StackUnlock unlock;
Expand All @@ -168,10 +167,10 @@ void CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallb

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

{{/if}}
12 changes: 6 additions & 6 deletions src/controller/java/templates/CHIPReadCallbacks.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +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}}
{{#if_unsupported_attribute_type type isArray}}
{{else}}
{{#if_attribute_complex type}}
class CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback : public chip::Callback::Callback<CHIP{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}AttributeCallbackType>
{
public:
Expand All @@ -65,10 +65,10 @@ private:
jobject javaCallbackRef;
bool keepAlive;
};
{{/if_basic_global_response}}
{{/if_attribute_complex}}

{{/unless}}
{{/chip_server_cluster_attributes}}
{{/if_unsupported_attribute_type}}
{{/zcl_attributes_server}}
{{/chip_client_clusters}}

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

{{/chip_cluster_responses}}

{{#chip_server_cluster_attributes}}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#if_basic_global_response}}
{{#zcl_attributes_server}}
{{#if_unsupported_attribute_type type isArray}}
{{else}}
{{#if_attribute_complex type}}
{{! NOTE: asJavaType ends up sniffing for isArray on the context. Since we want the type of our _entry_, force isArray to
false. }}
{{~#*inline "asJavaTypeForEntry"}}{{asJavaType type null parent.name forceNotList=true}}{{/inline~}}
Expand All @@ -161,19 +161,20 @@ public class ChipClusters {
default void onSubscriptionEstablished() {}
}
{{/if}}
{{/if_basic_global_response}}
{{/unless}}
{{/chip_server_cluster_attributes}}
{{#chip_server_cluster_attributes}}
{{/if_attribute_complex}}
{{/if_unsupported_attribute_type}}
{{/zcl_attributes_server}}
{{#zcl_attributes_server}}
{{! TODO: Add support for struct-typed attributes }}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#if_unsupported_attribute_type type isArray}}
{{else}}

public void read{{asUpperCamelCase name}}Attribute(
{{#if_basic_global_response}}
{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback callback
{{else}}
{{#if_attribute_complex type}}
{{asUpperCamelCase name}}AttributeCallback callback
{{/if_basic_global_response}}
{{else}}
{{get_underlying_language_specific_zcl_type type language="java" boolean="Boolean"}}AttributeCallback callback
{{/if_attribute_complex}}
) {
read{{asUpperCamelCase name}}Attribute(chipClusterPtr, callback);
}
Expand All @@ -190,42 +191,43 @@ public class ChipClusters {
{{/if}}
{{#if isReportableAttribute}}
public void subscribe{{asCamelCased name false}}Attribute(
{{#if_basic_global_response}}
{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback callback
{{else}}
{{#if_attribute_complex type}}
{{asUpperCamelCase name}}AttributeCallback callback
{{/if_basic_global_response}},
{{else}}
{{get_underlying_language_specific_zcl_type type language="java" boolean="Boolean"}}AttributeCallback callback
{{/if_attribute_complex}},
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_type}}
{{/zcl_attributes_server}}
{{#zcl_attributes_server}}
{{! TODO: Add support for struct-typed attributes }}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#if_unsupported_attribute_type type isArray}}
{{else}}

private native void read{{asUpperCamelCase name}}Attribute(long chipClusterPtr,
{{#if_basic_global_response}}
{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback callback
{{else}}
{{#if_attribute_complex type}}
{{asUpperCamelCase name}}AttributeCallback callback
{{/if_basic_global_response}}
{{else}}
{{get_underlying_language_specific_zcl_type type language="java" boolean="Boolean"}}AttributeCallback callback
{{/if_attribute_complex}}
);
{{#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
{{else}}
{{#if_attribute_complex type}}
{{asUpperCamelCase name}}AttributeCallback callback
{{/if_basic_global_response}}, int minInterval, int maxInterval);
{{else}}
{{get_underlying_language_specific_zcl_type type language="java" boolean="Boolean"}}AttributeCallback callback
{{/if_attribute_complex}}, int minInterval, int maxInterval);
{{/if}}
{{/unless}}
{{/chip_server_cluster_attributes}}
{{/if_unsupported_attribute_type}}
{{/zcl_attributes_server}}
}
{{#not_last}}

Expand Down
15 changes: 8 additions & 7 deletions src/controller/java/templates/ClusterInfo-read-interaction.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,28 @@ public class ClusterReadMapping {
Map<String, InteractionInfo> read{{asUpperCamelCase name}}InteractionInfo = new LinkedHashMap<>();
{{#chip_server_cluster_attributes}}
{{! TODO: Add support for struct-typed attributes }}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#if_unsupported_attribute_type type isArray}}
{{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
{{else}}
({{#if_attribute_complex type}}
ChipClusters.{{asUpperCamelCase ../name}}Cluster.{{asUpperCamelCase name}}AttributeCallback
{{/if_basic_global_response}}) callback
{{else}}
ChipClusters.{{get_underlying_language_specific_zcl_type type language="java" boolean="Boolean"}}AttributeCallback
{{/if_attribute_complex}}) callback
);
},
{{#if isArray}}
() -> new ClusterInfoMapping.Delegated{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}AttributeCallback(),
{{else}}
() -> new ClusterInfoMapping.Delegated{{convertAttributeCallbackTypeToJavaName chipCallback.type}}AttributeCallback(),
() -> new ClusterInfoMapping.Delegated{{get_underlying_language_specific_zcl_type type language="java" boolean="Boolean"}}AttributeCallback(),
{{/if}}
read{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}CommandParams
);
read{{asUpperCamelCase ../name}}InteractionInfo.put("read{{asUpperCamelCase name}}Attribute", read{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}AttributeInteractionInfo);
{{/unless}}
{{/if_unsupported_attribute_type}}
{{/chip_server_cluster_attributes}}
readAttributeMap.put("{{asLowerCamelCase name}}", read{{asUpperCamelCase name}}InteractionInfo);
{{/chip_client_clusters}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class ClusterWriteMapping {
Map<String, InteractionInfo> write{{asUpperCamelCase name}}InteractionInfo = new LinkedHashMap<>();
{{#chip_server_cluster_attributes}}
{{! TODO: Add support for struct-typed attributes }}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
{{#if_unsupported_attribute_type type isArray}}
{{else}}
{{#if isWritableAttribute}}
{{#unless isArray}}
Map<String, CommandParameterInfo> write{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}CommandParams = new LinkedHashMap<String, CommandParameterInfo>();
Expand All @@ -38,7 +39,7 @@ public class ClusterWriteMapping {
write{{asUpperCamelCase ../name}}InteractionInfo.put("write{{asUpperCamelCase name}}Attribute", write{{asUpperCamelCase ../name}}{{asUpperCamelCase name}}AttributeInteractionInfo);
{{/unless}}
{{/if}}
{{/unless}}
{{/if_unsupported_attribute_type}}
{{/chip_server_cluster_attributes}}
writeAttributeMap.put("{{asLowerCamelCase name}}", write{{asUpperCamelCase name}}InteractionInfo);
{{/chip_client_clusters}}
Expand Down
Loading

0 comments on commit 4f4fe15

Please sign in to comment.