From f24e31c866fb045238ecf29ecb739749a161a9f9 Mon Sep 17 00:00:00 2001 From: Lukas Zeller Date: Fri, 19 Aug 2022 12:07:59 +0200 Subject: [PATCH 1/2] chip_data_model.gni: add option for custom-implemented clusters Add `zap_clusters_with_custom_implementation` option to `chip_data_model()` template, which allows to list clusters that need to be available in a device, but don't use the standard implementation in `src/app/clusters//.cpp`. # Usage To exclude a particular cluster's standard implementation in favor of an application level implementation: - in the BUILD.gn file for the application specific `.zap` file - in the instantiation of the `chip_data_model` template - add a variable `zap_clusters_with_custom_implementation` - assign it a list of strings with cluster names, corresponding to directories in the `src/app/clusters` directory. - this causes the cluster implementation file(s) not to be included in the build, allowing re-implementation at the application level. Example, excluding standard implementation of level-control: ``` chip_data_model("zap") { zap_file = "myproject.zap" zap_clusters_with_custom_implementation = [ "level-control" ] zap_pregenerated_dir = "//zap-generated" } ``` # Background Some clusters, for example Level Control, are implemented with the assumption of direct low-level access to the device hardware. For bridged devices, the actual interface might be much more high level, as in my case where I have lights which are fully capable of performing parametrized smooth transitions but are NOT capable of receiving output changes in millisecond intervals. In such cases, a cluster might need application-specific re-implementation. This changeset allows, from the application's ZAP BUILD.gn, to exclude the standard cluster implementation file, allowing re-implementation of the needed ember callbacks in a application specific file outside the connectedhomeip repo. --- src/app/chip_data_model.gni | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/app/chip_data_model.gni b/src/app/chip_data_model.gni index a7627cb678ebff..0edc23038031c0 100644 --- a/src/app/chip_data_model.gni +++ b/src/app/chip_data_model.gni @@ -84,6 +84,7 @@ template("chip_data_model") { "*", [ "zap_pregenerated_dir", + "zap_clusters_with_custom_implementation", "zap_file", "is_server", ]) @@ -137,8 +138,22 @@ template("chip_data_model") { [ invoker.zap_file ]) } + _cust_impl_clusters = [] + if (defined(invoker.zap_clusters_with_custom_implementation)) { + _cust_impl_clusters = invoker.zap_clusters_with_custom_implementation + } + foreach(cluster, _cluster_sources) { - if (cluster == "door-lock-server") { + _cust_impl = false + foreach(ci, _cust_impl_clusters) { + if (cluster == ci) { + _cust_impl = true + } + } + + if (_cust_impl) { + # do not include any sources, we have a custom implementation for this cluster + } else if (cluster == "door-lock-server") { sources += [ "${_app_root}/clusters/${cluster}/door-lock-server-callback.cpp", "${_app_root}/clusters/${cluster}/door-lock-server.cpp", From 693174d41da97f708ddfd717cc7f080eeffbb6ce Mon Sep 17 00:00:00 2001 From: Lukas Zeller Date: Thu, 26 Jan 2023 11:31:22 +0100 Subject: [PATCH 2/2] Include suggestions from @bzbarsky-apple --- src/app/chip_data_model.gni | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/chip_data_model.gni b/src/app/chip_data_model.gni index 0edc23038031c0..739e8a7caa5709 100644 --- a/src/app/chip_data_model.gni +++ b/src/app/chip_data_model.gni @@ -138,20 +138,20 @@ template("chip_data_model") { [ invoker.zap_file ]) } - _cust_impl_clusters = [] + _custom_impl_clusters = [] if (defined(invoker.zap_clusters_with_custom_implementation)) { - _cust_impl_clusters = invoker.zap_clusters_with_custom_implementation + _custom_impl_clusters = invoker.zap_clusters_with_custom_implementation } foreach(cluster, _cluster_sources) { - _cust_impl = false - foreach(ci, _cust_impl_clusters) { + _custom_impl = false + foreach(ci, _custom_impl_clusters) { if (cluster == ci) { - _cust_impl = true + _custom_impl = true } } - if (_cust_impl) { + if (_custom_impl) { # do not include any sources, we have a custom implementation for this cluster } else if (cluster == "door-lock-server") { sources += [