Skip to content

Commit

Permalink
Move CHIPCallbackTypes.h into codegen.py generated (build time gene…
Browse files Browse the repository at this point in the history
…ration) (#25788)

* Start moving CHIPCallbackTypes JNI to jinja-based codegen

* Restyle

* Updated build rules ... deps not yet working, but a starting point exists

* Fix include naming for the new path, add/update unit tests

* Add missing files, restyle

* Remove some newlines that seemed extra

* Undo gdbgui comment out - this was for local bootstrap only

* Simplify the generator script a bit, without any deltas in output

* Updated copyright time
  • Loading branch information
andy31415 authored and pull[bot] committed Oct 3, 2023
1 parent b933e94 commit 1135128
Show file tree
Hide file tree
Showing 30 changed files with 229 additions and 2,573 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
*
* 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.
*/

#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') %}
typedef void (*CHIP{{cluster.name}}Cluster{{attribute.definition.name | upfirst}}AttributeCallbackType)(void *, {##}
{%- if attribute.definition.is_list -%}
const chip::app::Clusters::{{cluster.name}}::Attributes::{{attribute.definition.name | upfirst}}::TypeInfo::DecodableType &);
{%- else -%}
chip::app::Clusters::{{cluster.name}}::Attributes::{{attribute.definition.name | upfirst}}::TypeInfo::DecodableArgType);
{%- endif -%}
{%- endfor -%}
{% endfor %}

Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
{% endif -%}
{% endmacro -%}

#include <controller/java/zap-generated/CHIPCallbackTypes.h>
#include <jni/CHIPCallbackTypes.h>
#include <controller/java/zap-generated/CHIPInvokeCallbacks.h>
#include <controller/java/zap-generated/CHIPReadCallbacks.h>

Expand Down
21 changes: 19 additions & 2 deletions 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,8 @@
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 @@ -388,6 +389,10 @@ 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):
"""
Code generation for java-specific files.
Expand All @@ -414,6 +419,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 @@ -426,6 +433,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 Expand Up @@ -462,7 +478,8 @@ def internal_render_all(self):
Renders .java files required for java matter support
"""

clientClusters = [c for c in self.idl.clusters if c.side == ClusterSide.CLIENT]
clientClusters = [
c for c in self.idl.clusters if c.side == ClusterSide.CLIENT]

self.internal_render_one_output(
template_path="java/ClusterReadMapping.jinja",
Expand Down
5 changes: 5 additions & 0 deletions scripts/py_matter_idl/matter_idl/tests/available_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ java-jni:
inputs/simple_attribute.matter:
jni/MyClusterClient-ReadImpl.cpp: outputs/simple_attribute/jni/MyClusterClient-ReadImpl.cpp
jni/MyClusterClient-InvokeSubscribeImpl.cpp: outputs/simple_attribute/jni/MyClusterClient-InvokeSubscribeImpl.cpp
jni/CHIPCallbackTypes.h: outputs/simple_attribute/jni/CHIPCallbackTypes.h

inputs/global_struct_attribute.matter:
jni/DemoClusterClient-ReadImpl.cpp: outputs/global_struct_attribute/jni/DemoClusterClient-ReadImpl.cpp
jni/DemoClusterClient-InvokeSubscribeImpl.cpp: outputs/global_struct_attribute/jni/DemoClusterClient-InvokeSubscribeImpl.cpp
jni/CHIPCallbackTypes.h: outputs/global_struct_attribute/jni/CHIPCallbackTypes.h

inputs/cluster_struct_attribute.matter:
jni/DemoClusterClient-ReadImpl.cpp: outputs/cluster_struct_attribute/jni/DemoClusterClient-ReadImpl.cpp
jni/DemoClusterClient-InvokeSubscribeImpl.cpp: outputs/cluster_struct_attribute/jni/DemoClusterClient-InvokeSubscribeImpl.cpp
jni/CHIPCallbackTypes.h: outputs/cluster_struct_attribute/jni/CHIPCallbackTypes.h

inputs/several_clusters.matter:
jni/FirstClient-ReadImpl.cpp: outputs/several_clusters/jni/FirstClient-ReadImpl.cpp
Expand All @@ -30,10 +33,12 @@ java-jni:
jni/FirstClient-InvokeSubscribeImpl.cpp: outputs/several_clusters/jni/FirstClient-InvokeSubscribeImpl.cpp
jni/SecondClient-InvokeSubscribeImpl.cpp: outputs/several_clusters/jni/SecondClient-InvokeSubscribeImpl.cpp
jni/ThirdClient-InvokeSubscribeImpl.cpp: outputs/several_clusters/jni/ThirdClient-InvokeSubscribeImpl.cpp
jni/CHIPCallbackTypes.h: outputs/several_clusters/jni/CHIPCallbackTypes.h

inputs/optional_argument.matter:
jni/MyClusterClient-ReadImpl.cpp: outputs/optional_argument/jni/MyClusterClient-ReadImpl.cpp
jni/MyClusterClient-InvokeSubscribeImpl.cpp: outputs/optional_argument/jni/MyClusterClient-InvokeSubscribeImpl.cpp
jni/CHIPCallbackTypes.h: outputs/optional_argument/jni/CHIPCallbackTypes.h

java-class:
inputs/several_clusters.matter:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
*
* 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.
*/

#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);


typedef void (*CHIPDemoClusterClusterSingleFailSafeAttributeCallbackType)(void *, chip::app::Clusters::DemoCluster::Attributes::SingleFailSafe::TypeInfo::DecodableArgType);
typedef void (*CHIPDemoClusterClusterArmFailsafesAttributeCallbackType)(void *, const chip::app::Clusters::DemoCluster::Attributes::ArmFailsafes::TypeInfo::DecodableType &);

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <controller/java/zap-generated/CHIPCallbackTypes.h>
#include <jni/CHIPCallbackTypes.h>
#include <controller/java/zap-generated/CHIPInvokeCallbacks.h>
#include <controller/java/zap-generated/CHIPReadCallbacks.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
*
* 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.
*/

#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);


typedef void (*CHIPDemoClusterClusterSingleLabelAttributeCallbackType)(void *, chip::app::Clusters::DemoCluster::Attributes::SingleLabel::TypeInfo::DecodableArgType);
typedef void (*CHIPDemoClusterClusterSomeLabelsAttributeCallbackType)(void *, const chip::app::Clusters::DemoCluster::Attributes::SomeLabels::TypeInfo::DecodableType &);

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <controller/java/zap-generated/CHIPCallbackTypes.h>
#include <jni/CHIPCallbackTypes.h>
#include <controller/java/zap-generated/CHIPInvokeCallbacks.h>
#include <controller/java/zap-generated/CHIPReadCallbacks.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
*
* 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.
*/

#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);



Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <controller/java/zap-generated/CHIPCallbackTypes.h>
#include <jni/CHIPCallbackTypes.h>
#include <controller/java/zap-generated/CHIPInvokeCallbacks.h>
#include <controller/java/zap-generated/CHIPReadCallbacks.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
*
* 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.
*/

#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);


typedef void (*CHIPFirstClusterSomeIntegerAttributeCallbackType)(void *, chip::app::Clusters::First::Attributes::SomeInteger::TypeInfo::DecodableArgType);
typedef void (*CHIPSecondClusterSomeBytesAttributeCallbackType)(void *, chip::app::Clusters::Second::Attributes::SomeBytes::TypeInfo::DecodableArgType);
typedef void (*CHIPThirdClusterSomeEnumAttributeCallbackType)(void *, chip::app::Clusters::Third::Attributes::SomeEnum::TypeInfo::DecodableArgType);
typedef void (*CHIPThirdClusterOptionsAttributeCallbackType)(void *, chip::app::Clusters::Third::Attributes::Options::TypeInfo::DecodableArgType);

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <controller/java/zap-generated/CHIPCallbackTypes.h>
#include <jni/CHIPCallbackTypes.h>
#include <controller/java/zap-generated/CHIPInvokeCallbacks.h>
#include <controller/java/zap-generated/CHIPReadCallbacks.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <controller/java/zap-generated/CHIPCallbackTypes.h>
#include <jni/CHIPCallbackTypes.h>
#include <controller/java/zap-generated/CHIPInvokeCallbacks.h>
#include <controller/java/zap-generated/CHIPReadCallbacks.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <controller/java/zap-generated/CHIPCallbackTypes.h>
#include <jni/CHIPCallbackTypes.h>
#include <controller/java/zap-generated/CHIPInvokeCallbacks.h>
#include <controller/java/zap-generated/CHIPReadCallbacks.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
*
* 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.
*/

#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);


typedef void (*CHIPMyClusterClusterClusterAttrAttributeCallbackType)(void *, chip::app::Clusters::MyCluster::Attributes::ClusterAttr::TypeInfo::DecodableArgType);

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <controller/java/zap-generated/CHIPCallbackTypes.h>
#include <jni/CHIPCallbackTypes.h>
#include <controller/java/zap-generated/CHIPInvokeCallbacks.h>
#include <controller/java/zap-generated/CHIPReadCallbacks.h>

Expand Down
2 changes: 2 additions & 0 deletions src/controller/data_model/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ if (current_os == "android" || build_java_matter_controller) {
generator = "java-jni"

outputs = [
"jni/CHIPCallbackTypes.h",
"jni/IdentifyClient-ReadImpl.cpp",
"jni/IdentifyClient-InvokeSubscribeImpl.cpp",
"jni/GroupsClient-ReadImpl.cpp",
Expand Down Expand Up @@ -187,6 +188,7 @@ if (current_os == "android" || build_java_matter_controller) {
source_set("java-jni-sources") {
public_configs = [
":java-build-config",
":java-jni-generate_config",
"${chip_root}/src:includes",
]

Expand Down
4 changes: 4 additions & 0 deletions src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ shared_library("jni") {
output_extension = "dylib"
}

# Temporary while we have circular dependencies between codegen.py and zap
# generated files
check_includes = false

sources = [
"AndroidCallbacks-JNI.cpp",
"AndroidCallbacks.cpp",
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/CHIPDefaultCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <lib/core/CHIPError.h>
#include <zap-generated/CHIPClientCallbacks.h>

#include "zap-generated/CHIPCallbackTypes.h"
#include <jni/CHIPCallbackTypes.h>

namespace chip {

Expand Down
25 changes: 0 additions & 25 deletions src/controller/java/templates/CHIPCallbackTypes.zapt

This file was deleted.

2 changes: 1 addition & 1 deletion src/controller/java/templates/CHIPClustersWrite-JNI.zapt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{> header}}
{{#if (chip_has_client_clusters)}}
#include "CHIPCallbackTypes.h"
#include <jni/CHIPCallbackTypes.h>
#include "CHIPInvokeCallbacks.h"
#include "CHIPReadCallbacks.h"

Expand Down
Loading

0 comments on commit 1135128

Please sign in to comment.