Skip to content

Commit

Permalink
Start moving CHIPCallbackTypes JNI to jinja-based codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
andy31415 committed Mar 23, 2023
1 parent bf14eb2 commit 4a9a2b6
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2,243 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
*
* Copyright (c) 2022 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.
*/

#include <app-common/zap-generated/cluster-objects.h>
#include <app/util/af-enums.h>

typedef void (*CHIPDefaultSuccessCallbackType)(void *, const chip::app::DataModel::NullObjectType &);
typedef void (*CHIPDefaultWriteSuccessCallbackType)(void *);
typedef void (*CHIPDefaultFailureCallbackType)(void *, CHIP_ERROR);

{% for cluster in clientClusters | sort(attribute='code') %}
{%- for response in cluster.structs | select('is_response_struct') -%}
typedef void (*CHIP{{cluster.name}}Cluster{{response.name}}CallbackType)(void *, const chip::app::Clusters::{{cluster.name}}::Commands::{{response.name}}::DecodableType &);
{%- endfor -%}

{#- TODO: global response types? #}
{% for attribute in cluster.attributes | sort(attribute='name') %}
{%- if attribute.definition.is_list %}
typedef void (*CHIP{{cluster.name}}Cluster{{attribute.definition.name | upfirst}}AttributeCallbackType)(void *, const chip::app::Clusters::{{cluster.name}}::Attributes::{{attribute.definition.name | upfirst}}::TypeInfo::DecodableType &);
{%- else %}
typedef void (*CHIP{{cluster.name}}Cluster{{attribute.definition.name | upfirst}}AttributeCallbackType)(void *, chip::app::Clusters::{{cluster.name}}::Attributes::{{attribute.definition.name | upfirst}}::TypeInfo::DecodableArgType);
{%- endif %}
{%- endfor %}
{% endfor %}

16 changes: 15 additions & 1 deletion scripts/py_matter_idl/matter_idl/generators/java/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from matter_idl.generators import CodeGenerator, GeneratorStorage
from matter_idl.generators.types import (BasicInteger, BasicString, FundamentalType, IdlBitmapType, IdlEnumType, IdlType,
ParseDataType, TypeLookupContext)
from matter_idl.matter_idl_types import Attribute, Cluster, ClusterSide, Command, DataType, Field, FieldQuality, Idl
from matter_idl.matter_idl_types import Attribute, Cluster, ClusterSide, Command, DataType, Field, FieldQuality, Idl, Struct, StructTag
from stringcase import capitalcase


Expand Down Expand Up @@ -355,6 +355,9 @@ def CanGenerateSubscribe(attr: Attribute, lookup: TypeLookupContext) -> bool:

return not lookup.is_struct_type(attr.definition.data_type.name)

def IsResponseStruct(s: Struct) -> bool:
return s.tag == StructTag.RESPONSE


class __JavaCodeGenerator(CodeGenerator):
"""
Expand All @@ -380,6 +383,8 @@ def __init__(self, storage: GeneratorStorage, idl: Idl, **kargs):
self.jinja_env.filters['createLookupContext'] = CreateLookupContext
self.jinja_env.filters['canGenerateSubscribe'] = CanGenerateSubscribe

self.jinja_env.tests['is_response_struct'] = IsResponseStruct


class JavaJNIGenerator(__JavaCodeGenerator):
"""Generates JNI java files (i.e. C++ source/headers)."""
Expand All @@ -392,6 +397,15 @@ def internal_render_all(self):
Renders .CPP files required for JNI support.
"""

self.internal_render_one_output(
template_path="java/CHIPCallbackTypes.jinja",
output_file_name="jni/CHIPCallbackTypes.h",
vars= {
'idl': self.idl,
'clientClusters': [c for c in self.idl.clusters if c.side == ClusterSide.CLIENT],
}
)

# Every cluster has its own impl, to avoid
# very large compilations (running out of RAM)
for cluster in self.idl.clusters:
Expand Down
25 changes: 0 additions & 25 deletions src/controller/java/templates/CHIPCallbackTypes.zapt

This file was deleted.

5 changes: 0 additions & 5 deletions src/controller/java/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@
"name": "CHIP cluster invoke callbacks for Java (native code)",
"output": "src/controller/java/zap-generated/CHIPInvokeCallbacks.cpp"
},
{
"path": "CHIPCallbackTypes.zapt",
"name": "CHIP cluster callback types",
"output": "src/controller/java/zap-generated/CHIPCallbackTypes.h"
},
{
"path": "CHIPClustersWrite-JNI.zapt",
"name": "CHIP ZCL API for Java (native code for writes)",
Expand Down
Loading

0 comments on commit 4a9a2b6

Please sign in to comment.