From 104841d706a6c2018f303f1652a17ef3d0d17bd5 Mon Sep 17 00:00:00 2001 From: Albert Chaulk Date: Mon, 22 Aug 2022 15:53:59 -0400 Subject: [PATCH] Split generated files out Updates userinput backend to run commands on matter thread --- examples/bridge-app/linux/BUILD.gn | 2 +- examples/bridge-app/linux/Device.cpp | 6 +- .../bridge-app/linux/UserInputBackend.cpp | 45 ++- examples/bridge-app/linux/include/Clusters.h | 2 +- examples/bridge-app/linux/main.cpp | 1 - scripts/codegen.py | 10 +- scripts/idl/BUILD.gn | 20 +- .../bridge/BridgeClustersCommon.jinja | 61 ++++ .../{cpp => bridge}/BridgeClustersCpp.jinja | 92 +---- .../bridge/BridgeClustersGlobalStructs.jinja | 38 ++ .../generators/{cpp => bridge}/__init__.py | 28 +- .../bridge/BridgeClustersImpl.h | 44 +++ .../bridge/BridgeGlobalStructs.h | 10 + .../DemoCluster.h} | 47 +-- .../bridge/BridgeClustersImpl.h | 44 +++ .../bridge/BridgeGlobalStructs.h | 33 ++ .../DemoCluster.h} | 70 +--- .../bridge/BridgeClustersImpl.h | 67 ++++ .../bridge/BridgeGlobalStructs.h | 10 + .../outputs/several_clusters/bridge/First.h | 96 +++++ .../outputs/several_clusters/bridge/Second.h | 96 +++++ .../outputs/several_clusters/bridge/Third.h | 96 +++++ .../several_clusters/cpp/BridgeClustersImpl.h | 334 ------------------ .../bridge/BridgeClustersImpl.h | 43 +++ .../bridge/BridgeGlobalStructs.h | 10 + .../MyCluster.h} | 42 +-- 26 files changed, 760 insertions(+), 587 deletions(-) create mode 100644 scripts/idl/generators/bridge/BridgeClustersCommon.jinja rename scripts/idl/generators/{cpp => bridge}/BridgeClustersCpp.jinja (66%) create mode 100644 scripts/idl/generators/bridge/BridgeClustersGlobalStructs.jinja rename scripts/idl/generators/{cpp => bridge}/__init__.py (87%) create mode 100644 scripts/idl/tests/outputs/cluster_struct_attribute/bridge/BridgeClustersImpl.h create mode 100644 scripts/idl/tests/outputs/cluster_struct_attribute/bridge/BridgeGlobalStructs.h rename scripts/idl/tests/outputs/cluster_struct_attribute/{cpp/BridgeClustersImpl.h => bridge/DemoCluster.h} (77%) create mode 100644 scripts/idl/tests/outputs/global_struct_attribute/bridge/BridgeClustersImpl.h create mode 100644 scripts/idl/tests/outputs/global_struct_attribute/bridge/BridgeGlobalStructs.h rename scripts/idl/tests/outputs/global_struct_attribute/{cpp/BridgeClustersImpl.h => bridge/DemoCluster.h} (66%) create mode 100644 scripts/idl/tests/outputs/several_clusters/bridge/BridgeClustersImpl.h create mode 100644 scripts/idl/tests/outputs/several_clusters/bridge/BridgeGlobalStructs.h create mode 100644 scripts/idl/tests/outputs/several_clusters/bridge/First.h create mode 100644 scripts/idl/tests/outputs/several_clusters/bridge/Second.h create mode 100644 scripts/idl/tests/outputs/several_clusters/bridge/Third.h delete mode 100644 scripts/idl/tests/outputs/several_clusters/cpp/BridgeClustersImpl.h create mode 100644 scripts/idl/tests/outputs/simple_attribute/bridge/BridgeClustersImpl.h create mode 100644 scripts/idl/tests/outputs/simple_attribute/bridge/BridgeGlobalStructs.h rename scripts/idl/tests/outputs/simple_attribute/{cpp/BridgeClustersImpl.h => bridge/MyCluster.h} (77%) diff --git a/examples/bridge-app/linux/BUILD.gn b/examples/bridge-app/linux/BUILD.gn index fadf198709d7a8..2bf6bf7988f91b 100644 --- a/examples/bridge-app/linux/BUILD.gn +++ b/examples/bridge-app/linux/BUILD.gn @@ -27,7 +27,7 @@ action("chip-bridge-codegen") { args = [ "--generator", - "cpp", + "bridge", "--output-dir", rebase_path(target_gen_dir, root_build_dir), rebase_path( diff --git a/examples/bridge-app/linux/Device.cpp b/examples/bridge-app/linux/Device.cpp index 490297f22ccc4e..31d8b5c960fb0c 100644 --- a/examples/bridge-app/linux/Device.cpp +++ b/examples/bridge-app/linux/Device.cpp @@ -27,7 +27,11 @@ Device::Device(chip::Span dataVersions, chip::Span + #include #include +#include #include #include #include @@ -343,6 +346,28 @@ void ParseValue(std::vector * data, uint16_t size, const std::string & case ZCL_DOUBLE_ATTRIBUTE_TYPE: wr.Put(chip::TLV::Tag(), atof(str.c_str())); break; + case ZCL_INT8S_ATTRIBUTE_TYPE: + case ZCL_INT16S_ATTRIBUTE_TYPE: + case ZCL_INT24S_ATTRIBUTE_TYPE: + case ZCL_INT32S_ATTRIBUTE_TYPE: + case ZCL_INT40S_ATTRIBUTE_TYPE: + case ZCL_INT48S_ATTRIBUTE_TYPE: + case ZCL_INT56S_ATTRIBUTE_TYPE: + case ZCL_INT64S_ATTRIBUTE_TYPE: + wr.Put(chip::TLV::Tag(), (int64_t) strtoll(str.c_str(), nullptr, 10)); + break; + + case ZCL_INT8U_ATTRIBUTE_TYPE: + case ZCL_INT16U_ATTRIBUTE_TYPE: + case ZCL_INT24U_ATTRIBUTE_TYPE: + case ZCL_INT32U_ATTRIBUTE_TYPE: + case ZCL_INT40U_ATTRIBUTE_TYPE: + case ZCL_INT48U_ATTRIBUTE_TYPE: + case ZCL_INT56U_ATTRIBUTE_TYPE: + case ZCL_INT64U_ATTRIBUTE_TYPE: + wr.Put(chip::TLV::Tag(), (uint64_t) strtoll(str.c_str(), nullptr, 10)); + break; + default: // Assume integer wr.Put(chip::TLV::Tag(), (int64_t) strtoll(str.c_str(), nullptr, 10)); @@ -401,6 +426,7 @@ void SetValue(const std::vector & tokens) chip::TLV::TLVReader rd; rd.Init(data.data(), data.size()); + rd.Next(); if (!cluster->Push(attr->attributeId, rd)) { @@ -547,6 +573,19 @@ void Help(const std::vector & tokens) } } +struct Op +{ + std::vector * tokens; + const Command * command; + std::promise lock; +}; +void ProcessLineOnMatterThread(intptr_t arg) +{ + Op * op = reinterpret_cast(arg); + op->command->fn(*op->tokens); + op->lock.set_value(); +} + void ProcessLine(std::vector & tokens) { for (auto & cmd : commands) @@ -554,7 +593,11 @@ void ProcessLine(std::vector & tokens) if (tokens[0] == cmd.name) { tokens.erase(tokens.begin()); - cmd.fn(tokens); + + Op op{ &tokens, &cmd }; + chip::DeviceLayer::PlatformMgr().ScheduleWork(&ProcessLineOnMatterThread, reinterpret_cast(&op)); + // Wait for command completion + op.lock.get_future().wait(); return; } } diff --git a/examples/bridge-app/linux/include/Clusters.h b/examples/bridge-app/linux/include/Clusters.h index e6791985d0c927..171b3c869fb124 100644 --- a/examples/bridge-app/linux/include/Clusters.h +++ b/examples/bridge-app/linux/include/Clusters.h @@ -261,7 +261,7 @@ struct CommonAttributeAccessInterface : public chip::app::AttributeAccessInterfa static CommonCluster * FindCluster(const chip::app::ConcreteClusterPath & path); }; -#include "cpp/BridgeClustersImpl.h" +#include "bridge/BridgeClustersImpl.h" namespace clusters { struct BridgedDeviceBasicCluster : public CommonCluster diff --git a/examples/bridge-app/linux/main.cpp b/examples/bridge-app/linux/main.cpp index 867d89838abcec..3f8c42104c05c3 100644 --- a/examples/bridge-app/linux/main.cpp +++ b/examples/bridge-app/linux/main.cpp @@ -96,7 +96,6 @@ int AddDeviceEndpoint(Device * dev) while (1) { // Todo: Update this to schedule the work rather than use this lock - DeviceLayer::StackLock lock; dev->SetEndpointId(gCurrentEndpointId); ret = emberAfSetDynamicEndpoint(index, gCurrentEndpointId, dev->endpointType(), dev->versions(), dev->deviceTypes()); diff --git a/scripts/codegen.py b/scripts/codegen.py index 26c2ad3dc8eac2..3eb6acd047f760 100755 --- a/scripts/codegen.py +++ b/scripts/codegen.py @@ -28,7 +28,7 @@ from idl.generators import FileSystemGeneratorStorage, GeneratorStorage from idl.generators.java import JavaGenerator -from idl.generators.cpp import CppGenerator +from idl.generators.bridge import BridgeGenerator class CodeGeneratorTypes(enum.Enum): @@ -38,13 +38,13 @@ class CodeGeneratorTypes(enum.Enum): into underlying generators. """ JAVA = enum.auto() - CPP = enum.auto() + BRIDGE = enum.auto() def CreateGenerator(self, *args, **kargs): if self == CodeGeneratorTypes.JAVA: return JavaGenerator(*args, **kargs) - elif self == CodeGeneratorTypes.CPP: - return CppGenerator(*args, **kargs) + elif self == CodeGeneratorTypes.BRIDGE: + return BridgeGenerator(*args, **kargs) else: raise Error("Unknown code generator type") @@ -72,7 +72,7 @@ def write_new_data(self, relative_path: str, content: str): __GENERATORS__ = { 'java': CodeGeneratorTypes.JAVA, - 'cpp': CodeGeneratorTypes.CPP, + 'bridge': CodeGeneratorTypes.BRIDGE, } diff --git a/scripts/idl/BUILD.gn b/scripts/idl/BUILD.gn index 28dba784fe5413..d9616391c3baa4 100644 --- a/scripts/idl/BUILD.gn +++ b/scripts/idl/BUILD.gn @@ -25,7 +25,9 @@ pw_python_package("idl") { "matter_grammar.lark", # Templates used for generation - "generators/cpp/BridgeClustersCpp.jinja", + "generators/bridge/BridgeClustersCpp.jinja", + "generators/bridge/BridgeClustersCommon.jinja", + "generators/bridge/BridgeClustersGlobalStructs.jinja", "generators/java/ChipClustersCpp.jinja", "generators/java/ChipClustersRead.jinja", @@ -36,18 +38,32 @@ pw_python_package("idl") { "tests/inputs/optional_argument.matter", "tests/inputs/several_clusters.matter", "tests/inputs/simple_attribute.matter", + "tests/outputs/cluster_struct_attribute/bridge/BridgeClustersImpl.h", + "tests/outputs/cluster_struct_attribute/bridge/BridgeGlobalStructs.h", + "tests/outputs/cluster_struct_attribute/bridge/DemoCluster.h", "tests/outputs/cluster_struct_attribute/jni/DemoClusterClient-ReadImpl.cpp", "tests/outputs/cluster_struct_attribute/jni/DemoClusterClient-InvokeSubscribeImpl.cpp", + "tests/outputs/global_struct_attribute/bridge/BridgeClustersImpl.h", + "tests/outputs/global_struct_attribute/bridge/BridgeGlobalStructs.h", + "tests/outputs/global_struct_attribute/bridge/DemoCluster.h", "tests/outputs/global_struct_attribute/jni/DemoClusterClient-ReadImpl.cpp", "tests/outputs/global_struct_attribute/jni/DemoClusterClient-InvokeSubscribeImpl.cpp", "tests/outputs/optional_argument/jni/MyClusterClient-ReadImpl.cpp", "tests/outputs/optional_argument/jni/MyClusterClient-InvokeSubscribeImpl.cpp", + "tests/outputs/several_clusters/bridge/BridgeClustersImpl.h", + "tests/outputs/several_clusters/bridge/BridgeGlobalStructs.h", + "tests/outputs/several_clusters/bridge/First.h", + "tests/outputs/several_clusters/bridge/Second.h", + "tests/outputs/several_clusters/bridge/Third.h", "tests/outputs/several_clusters/jni/FirstClient-ReadImpl.cpp", "tests/outputs/several_clusters/jni/SecondClient-ReadImpl.cpp", "tests/outputs/several_clusters/jni/ThirdClient-ReadImpl.cpp", "tests/outputs/several_clusters/jni/FirstClient-InvokeSubscribeImpl.cpp", "tests/outputs/several_clusters/jni/SecondClient-InvokeSubscribeImpl.cpp", "tests/outputs/several_clusters/jni/ThirdClient-InvokeSubscribeImpl.cpp", + "tests/outputs/simple_attribute/bridge/BridgeClustersImpl.h", + "tests/outputs/simple_attribute/bridge/BridgeGlobalStructs.h", + "tests/outputs/simple_attribute/bridge/MyCluster.h", "tests/outputs/simple_attribute/jni/MyClusterClient-ReadImpl.cpp", "tests/outputs/simple_attribute/jni/MyClusterClient-InvokeSubscribeImpl.cpp", ] @@ -55,7 +71,7 @@ pw_python_package("idl") { sources = [ "__init__.py", "generators/__init__.py", - "generators/cpp/__init__.py", + "generators/bridge/__init__.py", "generators/filters.py", "generators/java/__init__.py", "generators/types.py", diff --git a/scripts/idl/generators/bridge/BridgeClustersCommon.jinja b/scripts/idl/generators/bridge/BridgeClustersCommon.jinja new file mode 100644 index 00000000000000..0631595d380ebd --- /dev/null +++ b/scripts/idl/generators/bridge/BridgeClustersCommon.jinja @@ -0,0 +1,61 @@ +#pragma once + +#include + +{%- for cluster in clusters %} +{%- if cluster | dynamicCluster(idl) %} +#include "bridge/{{cluster.name}}.h" +{%- endif %} +{%- endfor %} + +namespace clusters { + +struct ClusterInfo +{ + chip::ClusterId id; + const char *name; + uint16_t size; + CommonCluster* (*ctor)(void*); +} static const kKnownClusters[] = { +{% for cluster in clusters %} +{%- if cluster | dynamicCluster(idl) %} + { + {{cluster.code}}, + "{{cluster.name}}", + sizeof({{cluster.name}}Cluster), + [](void *mem) -> CommonCluster* { + return new(mem) {{cluster.name}}Cluster(); + }, + }, +{%- endif %} +{%- endfor %} +}; + +inline void BridgeRegisterAllAttributeOverrides() +{ +{% for cluster in clusters %} +{%- if cluster | dynamicCluster(idl) %} + static {{cluster.name}}Access {{cluster.name}}; + registerAttributeAccessOverride(&{{cluster.name}}); +{%- endif %} +{%- endfor %} +} + +struct AttrInfo +{ + chip::ClusterId cluster; + chip::AttributeId attr; + const char *name; +} static const kKnownAttributes[] = { +{% for cluster in clusters %} +{%- if cluster | dynamicCluster(idl) %} + +{%- for attr in cluster.attributes %} + { {{cluster.code}}, {{attr.definition.code}}, "{{attr.definition.name | capitalcase}}" }, +{%- endfor %} + +{%- endif %} +{%- endfor %} +}; + +} diff --git a/scripts/idl/generators/cpp/BridgeClustersCpp.jinja b/scripts/idl/generators/bridge/BridgeClustersCpp.jinja similarity index 66% rename from scripts/idl/generators/cpp/BridgeClustersCpp.jinja rename to scripts/idl/generators/bridge/BridgeClustersCpp.jinja index f3f3746e10dfbd..51b9383e956551 100644 --- a/scripts/idl/generators/cpp/BridgeClustersCpp.jinja +++ b/scripts/idl/generators/bridge/BridgeClustersCpp.jinja @@ -1,41 +1,8 @@ -#include -#include +#pragma once -#include +#include "BridgeGlobalStructs.h" namespace clusters { -{% for struct in structs %} -struct {{struct.name}} -{ - CHIP_ERROR Decode(chip::TLV::TLVReader & reader) - { - chip::app::Clusters::detail::Structs::{{struct.name}}::DecodableType t; - CHIP_ERROR err = t.Decode(reader); - if(err == CHIP_NO_ERROR) { - {%- for field in struct.fields %} - {{field.name}} = t.{{field.name}}; - {%- endfor %} - } - return err; - } - - CHIP_ERROR Encode(chip::TLV::TLVWriter & writer, chip::TLV::Tag tag) const - { - chip::app::Clusters::detail::Structs::{{struct.name}}::Type t; - {%- for field in struct.fields %} - t.{{field.name}} = {{field.name}}; - {%- endfor %} - return t.Encode(writer, tag); - } - - {%- for field in struct.fields %} - {{field | getField(None, idl)}} {{field.name}}; - {%- endfor %} -}; -{%- endfor %} - -{%- for cluster in clusters %} -{%- if cluster | dynamicCluster(idl) %} struct {{cluster.name}}Cluster : public CommonCluster { {%- for struct in cluster.structs %} @@ -158,7 +125,7 @@ struct {{cluster.name}}Access : public CommonAttributeAccessInterface {%- if attr.is_writable %} {%- if attr.definition.is_list %} case {{attr.definition.code}}: - m{{attr.definition.name | capitalcase}}.ListWriteBegin(aPath); + c->m{{attr.definition.name | capitalcase}}.ListWriteBegin(aPath); return; {%- endif %} {%- endif %} @@ -177,7 +144,7 @@ struct {{cluster.name}}Access : public CommonAttributeAccessInterface {%- if attr.is_writable %} {%- if attr.definition.is_list %} case {{attr.definition.code}}: - m{{attr.definition.name | capitalcase}}.ListWriteEnd(aPath, aWriteWasSuccessful); + c->m{{attr.definition.name | capitalcase}}.ListWriteEnd(aPath, aWriteWasSuccessful); return; {%- endif %} {%- endif %} @@ -185,56 +152,5 @@ struct {{cluster.name}}Access : public CommonAttributeAccessInterface } } }; -{%- endif %} -{%- endfor %} - -struct ClusterInfo -{ - chip::ClusterId id; - const char *name; - uint16_t size; - CommonCluster* (*ctor)(void*); -} static const kKnownClusters[] = { -{% for cluster in clusters %} -{%- if cluster | dynamicCluster(idl) %} - { - {{cluster.code}}, - "{{cluster.name}}", - sizeof({{cluster.name}}Cluster), - [](void *mem) -> CommonCluster* { - return new(mem) {{cluster.name}}Cluster(); - }, - }, -{%- endif %} -{%- endfor %} -}; - -inline void BridgeRegisterAllAttributeOverrides() -{ -{% for cluster in clusters %} -{%- if cluster | dynamicCluster(idl) %} - static {{cluster.name}}Access {{cluster.name}}; - registerAttributeAccessOverride(&{{cluster.name}}); -{%- endif %} -{%- endfor %} -} - -struct AttrInfo -{ - chip::ClusterId cluster; - chip::AttributeId attr; - const char *name; -} static const kKnownAttributes[] = { -{% for cluster in clusters %} -{%- if cluster | dynamicCluster(idl) %} - -{%- for attr in cluster.attributes %} - { {{cluster.code}}, {{attr.definition.code}}, "{{attr.definition.name | capitalcase}}" }, -{%- endfor %} - -{%- endif %} -{%- endfor %} - -}; } diff --git a/scripts/idl/generators/bridge/BridgeClustersGlobalStructs.jinja b/scripts/idl/generators/bridge/BridgeClustersGlobalStructs.jinja new file mode 100644 index 00000000000000..ccad20e0b5336c --- /dev/null +++ b/scripts/idl/generators/bridge/BridgeClustersGlobalStructs.jinja @@ -0,0 +1,38 @@ +#pragma once + +#include +#include + +namespace clusters { + +{% for struct in structs %} +struct {{struct.name}} +{ + CHIP_ERROR Decode(chip::TLV::TLVReader & reader) + { + chip::app::Clusters::detail::Structs::{{struct.name}}::DecodableType t; + CHIP_ERROR err = t.Decode(reader); + if(err == CHIP_NO_ERROR) { + {%- for field in struct.fields %} + {{field.name}} = t.{{field.name}}; + {%- endfor %} + } + return err; + } + + CHIP_ERROR Encode(chip::TLV::TLVWriter & writer, chip::TLV::Tag tag) const + { + chip::app::Clusters::detail::Structs::{{struct.name}}::Type t; + {%- for field in struct.fields %} + t.{{field.name}} = {{field.name}}; + {%- endfor %} + return t.Encode(writer, tag); + } + + {%- for field in struct.fields %} + {{field | getField(None, idl)}} {{field.name}}; + {%- endfor %} +}; +{%- endfor %} + +} diff --git a/scripts/idl/generators/cpp/__init__.py b/scripts/idl/generators/bridge/__init__.py similarity index 87% rename from scripts/idl/generators/cpp/__init__.py rename to scripts/idl/generators/bridge/__init__.py index 19545ef3bb099e..b955a4a8cedbce 100644 --- a/scripts/idl/generators/cpp/__init__.py +++ b/scripts/idl/generators/bridge/__init__.py @@ -141,9 +141,9 @@ def is_dynamic_cluster(cluster: Cluster, idl: Idl): return False -class CppGenerator(CodeGenerator): +class BridgeGenerator(CodeGenerator): """ - Generation of cpp code for matter. + Generation of bridge cpp code for matter. """ def __init__(self, storage: GeneratorStorage, idl: Idl): @@ -167,13 +167,33 @@ def internal_render_all(self): """ Renders C++ """ + for cluster in self.idl.clusters: + if not is_dynamic_cluster(cluster, self.idl): + continue + + self.internal_render_one_output( + template_path="bridge/BridgeClustersCpp.jinja", + output_file_name="bridge/%s.h" % cluster.name, + vars={ + 'cluster': cluster, + 'idl': self.idl, + } + ) self.internal_render_one_output( - template_path="cpp/BridgeClustersCpp.jinja", - output_file_name="cpp/BridgeClustersImpl.h", + template_path="bridge/BridgeClustersCommon.jinja", + output_file_name="bridge/BridgeClustersImpl.h", vars={ 'clusters': self.idl.clusters, 'idl': self.idl, + } + ) + + self.internal_render_one_output( + template_path="bridge/BridgeClustersGlobalStructs.jinja", + output_file_name="bridge/BridgeGlobalStructs.h", + vars={ + 'idl': self.idl, 'structs': self.idl.structs, } ) diff --git a/scripts/idl/tests/outputs/cluster_struct_attribute/bridge/BridgeClustersImpl.h b/scripts/idl/tests/outputs/cluster_struct_attribute/bridge/BridgeClustersImpl.h new file mode 100644 index 00000000000000..8a3b84eeea5281 --- /dev/null +++ b/scripts/idl/tests/outputs/cluster_struct_attribute/bridge/BridgeClustersImpl.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include "bridge/DemoCluster.h" + +namespace clusters { + +struct ClusterInfo +{ + chip::ClusterId id; + const char *name; + uint16_t size; + CommonCluster* (*ctor)(void*); +} static const kKnownClusters[] = { + + { + 10, + "DemoCluster", + sizeof(DemoClusterCluster), + [](void *mem) -> CommonCluster* { + return new(mem) DemoClusterCluster(); + }, + }, +}; + +inline void BridgeRegisterAllAttributeOverrides() +{ + + static DemoClusterAccess DemoCluster; + registerAttributeAccessOverride(&DemoCluster); +} + +struct AttrInfo +{ + chip::ClusterId cluster; + chip::AttributeId attr; + const char *name; +} static const kKnownAttributes[] = { + + { 10, 5, "SingleFailSafe" }, + { 10, 100, "ArmFailsafes" }, +}; + +} \ No newline at end of file diff --git a/scripts/idl/tests/outputs/cluster_struct_attribute/bridge/BridgeGlobalStructs.h b/scripts/idl/tests/outputs/cluster_struct_attribute/bridge/BridgeGlobalStructs.h new file mode 100644 index 00000000000000..9dc0e1e1dec340 --- /dev/null +++ b/scripts/idl/tests/outputs/cluster_struct_attribute/bridge/BridgeGlobalStructs.h @@ -0,0 +1,10 @@ +#pragma once + +#include +#include + +namespace clusters { + + + +} \ No newline at end of file diff --git a/scripts/idl/tests/outputs/cluster_struct_attribute/cpp/BridgeClustersImpl.h b/scripts/idl/tests/outputs/cluster_struct_attribute/bridge/DemoCluster.h similarity index 77% rename from scripts/idl/tests/outputs/cluster_struct_attribute/cpp/BridgeClustersImpl.h rename to scripts/idl/tests/outputs/cluster_struct_attribute/bridge/DemoCluster.h index 78ec3c5ab7be5e..19bbf08dd098f2 100644 --- a/scripts/idl/tests/outputs/cluster_struct_attribute/cpp/BridgeClustersImpl.h +++ b/scripts/idl/tests/outputs/cluster_struct_attribute/bridge/DemoCluster.h @@ -1,10 +1,8 @@ -#include -#include +#pragma once -#include +#include "BridgeGlobalStructs.h" namespace clusters { - struct DemoClusterCluster : public CommonCluster { @@ -89,7 +87,7 @@ struct DemoClusterAccess : public CommonAttributeAccessInterface switch(aPath.mAttributeId) { case 100: - mArmFailsafes.ListWriteBegin(aPath); + c->mArmFailsafes.ListWriteBegin(aPath); return; } } @@ -102,47 +100,10 @@ struct DemoClusterAccess : public CommonAttributeAccessInterface switch(aPath.mAttributeId) { case 100: - mArmFailsafes.ListWriteEnd(aPath, aWriteWasSuccessful); + c->mArmFailsafes.ListWriteEnd(aPath, aWriteWasSuccessful); return; } } }; -struct ClusterInfo -{ - chip::ClusterId id; - const char *name; - uint16_t size; - CommonCluster* (*ctor)(void*); -} static const kKnownClusters[] = { - - { - 10, - "DemoCluster", - sizeof(DemoClusterCluster), - [](void *mem) -> CommonCluster* { - return new(mem) DemoClusterCluster(); - }, - }, -}; - -inline void BridgeRegisterAllAttributeOverrides() -{ - - static DemoClusterAccess DemoCluster; - registerAttributeAccessOverride(&DemoCluster); -} - -struct AttrInfo -{ - chip::ClusterId cluster; - chip::AttributeId attr; - const char *name; -} static const kKnownAttributes[] = { - - { 10, 5, "SingleFailSafe" }, - { 10, 100, "ArmFailsafes" }, - -}; - } \ No newline at end of file diff --git a/scripts/idl/tests/outputs/global_struct_attribute/bridge/BridgeClustersImpl.h b/scripts/idl/tests/outputs/global_struct_attribute/bridge/BridgeClustersImpl.h new file mode 100644 index 00000000000000..3b102344a117c4 --- /dev/null +++ b/scripts/idl/tests/outputs/global_struct_attribute/bridge/BridgeClustersImpl.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include "bridge/DemoCluster.h" + +namespace clusters { + +struct ClusterInfo +{ + chip::ClusterId id; + const char *name; + uint16_t size; + CommonCluster* (*ctor)(void*); +} static const kKnownClusters[] = { + + { + 18, + "DemoCluster", + sizeof(DemoClusterCluster), + [](void *mem) -> CommonCluster* { + return new(mem) DemoClusterCluster(); + }, + }, +}; + +inline void BridgeRegisterAllAttributeOverrides() +{ + + static DemoClusterAccess DemoCluster; + registerAttributeAccessOverride(&DemoCluster); +} + +struct AttrInfo +{ + chip::ClusterId cluster; + chip::AttributeId attr; + const char *name; +} static const kKnownAttributes[] = { + + { 18, 32, "SingleLabel" }, + { 18, 33, "SomeLabels" }, +}; + +} \ No newline at end of file diff --git a/scripts/idl/tests/outputs/global_struct_attribute/bridge/BridgeGlobalStructs.h b/scripts/idl/tests/outputs/global_struct_attribute/bridge/BridgeGlobalStructs.h new file mode 100644 index 00000000000000..82d6f174b2e95e --- /dev/null +++ b/scripts/idl/tests/outputs/global_struct_attribute/bridge/BridgeGlobalStructs.h @@ -0,0 +1,33 @@ +#pragma once + +#include +#include + +namespace clusters { + + +struct LabelStruct +{ + CHIP_ERROR Decode(chip::TLV::TLVReader & reader) + { + chip::app::Clusters::detail::Structs::LabelStruct::DecodableType t; + CHIP_ERROR err = t.Decode(reader); + if(err == CHIP_NO_ERROR) { + label = t.label; + value = t.value; + } + return err; + } + + CHIP_ERROR Encode(chip::TLV::TLVWriter & writer, chip::TLV::Tag tag) const + { + chip::app::Clusters::detail::Structs::LabelStruct::Type t; + t.label = label; + t.value = value; + return t.Encode(writer, tag); + } + OctetString<16, ZCL_CHAR_STRING_ATTRIBUTE_TYPE> label; + OctetString<16, ZCL_CHAR_STRING_ATTRIBUTE_TYPE> value; +}; + +} \ No newline at end of file diff --git a/scripts/idl/tests/outputs/global_struct_attribute/cpp/BridgeClustersImpl.h b/scripts/idl/tests/outputs/global_struct_attribute/bridge/DemoCluster.h similarity index 66% rename from scripts/idl/tests/outputs/global_struct_attribute/cpp/BridgeClustersImpl.h rename to scripts/idl/tests/outputs/global_struct_attribute/bridge/DemoCluster.h index f92843f069280f..2293e82818ef63 100644 --- a/scripts/idl/tests/outputs/global_struct_attribute/cpp/BridgeClustersImpl.h +++ b/scripts/idl/tests/outputs/global_struct_attribute/bridge/DemoCluster.h @@ -1,33 +1,8 @@ -#include -#include +#pragma once -#include +#include "BridgeGlobalStructs.h" namespace clusters { - -struct LabelStruct -{ - CHIP_ERROR Decode(chip::TLV::TLVReader & reader) - { - chip::app::Clusters::detail::Structs::LabelStruct::DecodableType t; - CHIP_ERROR err = t.Decode(reader); - if(err == CHIP_NO_ERROR) { - label = t.label; - value = t.value; - } - return err; - } - - CHIP_ERROR Encode(chip::TLV::TLVWriter & writer, chip::TLV::Tag tag) const - { - chip::app::Clusters::detail::Structs::LabelStruct::Type t; - t.label = label; - t.value = value; - return t.Encode(writer, tag); - } - OctetString<16, ZCL_CHAR_STRING_ATTRIBUTE_TYPE> label; - OctetString<16, ZCL_CHAR_STRING_ATTRIBUTE_TYPE> value; -}; struct DemoClusterCluster : public CommonCluster { @@ -112,7 +87,7 @@ struct DemoClusterAccess : public CommonAttributeAccessInterface switch(aPath.mAttributeId) { case 33: - mSomeLabels.ListWriteBegin(aPath); + c->mSomeLabels.ListWriteBegin(aPath); return; } } @@ -125,47 +100,10 @@ struct DemoClusterAccess : public CommonAttributeAccessInterface switch(aPath.mAttributeId) { case 33: - mSomeLabels.ListWriteEnd(aPath, aWriteWasSuccessful); + c->mSomeLabels.ListWriteEnd(aPath, aWriteWasSuccessful); return; } } }; -struct ClusterInfo -{ - chip::ClusterId id; - const char *name; - uint16_t size; - CommonCluster* (*ctor)(void*); -} static const kKnownClusters[] = { - - { - 18, - "DemoCluster", - sizeof(DemoClusterCluster), - [](void *mem) -> CommonCluster* { - return new(mem) DemoClusterCluster(); - }, - }, -}; - -inline void BridgeRegisterAllAttributeOverrides() -{ - - static DemoClusterAccess DemoCluster; - registerAttributeAccessOverride(&DemoCluster); -} - -struct AttrInfo -{ - chip::ClusterId cluster; - chip::AttributeId attr; - const char *name; -} static const kKnownAttributes[] = { - - { 18, 32, "SingleLabel" }, - { 18, 33, "SomeLabels" }, - -}; - } \ No newline at end of file diff --git a/scripts/idl/tests/outputs/several_clusters/bridge/BridgeClustersImpl.h b/scripts/idl/tests/outputs/several_clusters/bridge/BridgeClustersImpl.h new file mode 100644 index 00000000000000..b008f6743cf09d --- /dev/null +++ b/scripts/idl/tests/outputs/several_clusters/bridge/BridgeClustersImpl.h @@ -0,0 +1,67 @@ +#pragma once + +#include +#include "bridge/First.h" +#include "bridge/Second.h" +#include "bridge/Third.h" + +namespace clusters { + +struct ClusterInfo +{ + chip::ClusterId id; + const char *name; + uint16_t size; + CommonCluster* (*ctor)(void*); +} static const kKnownClusters[] = { + + { + 1, + "First", + sizeof(FirstCluster), + [](void *mem) -> CommonCluster* { + return new(mem) FirstCluster(); + }, + }, + { + 2, + "Second", + sizeof(SecondCluster), + [](void *mem) -> CommonCluster* { + return new(mem) SecondCluster(); + }, + }, + { + 3, + "Third", + sizeof(ThirdCluster), + [](void *mem) -> CommonCluster* { + return new(mem) ThirdCluster(); + }, + }, +}; + +inline void BridgeRegisterAllAttributeOverrides() +{ + + static FirstAccess First; + registerAttributeAccessOverride(&First); + static SecondAccess Second; + registerAttributeAccessOverride(&Second); + static ThirdAccess Third; + registerAttributeAccessOverride(&Third); +} + +struct AttrInfo +{ + chip::ClusterId cluster; + chip::AttributeId attr; + const char *name; +} static const kKnownAttributes[] = { + + { 1, 1, "SomeInteger" }, + { 2, 123, "SomeBytes" }, + { 3, 10, "SomeEnum" }, +}; + +} \ No newline at end of file diff --git a/scripts/idl/tests/outputs/several_clusters/bridge/BridgeGlobalStructs.h b/scripts/idl/tests/outputs/several_clusters/bridge/BridgeGlobalStructs.h new file mode 100644 index 00000000000000..9dc0e1e1dec340 --- /dev/null +++ b/scripts/idl/tests/outputs/several_clusters/bridge/BridgeGlobalStructs.h @@ -0,0 +1,10 @@ +#pragma once + +#include +#include + +namespace clusters { + + + +} \ No newline at end of file diff --git a/scripts/idl/tests/outputs/several_clusters/bridge/First.h b/scripts/idl/tests/outputs/several_clusters/bridge/First.h new file mode 100644 index 00000000000000..c5bae7b40c51bc --- /dev/null +++ b/scripts/idl/tests/outputs/several_clusters/bridge/First.h @@ -0,0 +1,96 @@ +#pragma once + +#include "BridgeGlobalStructs.h" + +namespace clusters { +struct FirstCluster : public CommonCluster +{ + + + static constexpr chip::ClusterId kClusterId = 1; + + chip::ClusterId GetClusterId() override { return kClusterId; } + + CHIP_ERROR WriteFromBridge(const chip::app::ConcreteDataAttributePath & aPath, chip::app::AttributeValueDecoder & aDecoder) override + { + switch(aPath.mAttributeId) + { + case 1: + return mSomeInteger.Write(aPath, aDecoder); + default: + return CHIP_ERROR_NOT_IMPLEMENTED; + } + } + + template + void AddAllAttributes(T *list) + { + list->Add(mSomeInteger); + } + + chip::Span GetAllAttributes() override + { + static constexpr const EmberAfAttributeMetadata kAllAttributes[] = { + { 1, ZCL_INT16U_ATTRIBUTE_TYPE, 2, ATTRIBUTE_MASK_WRITABLE | ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE), ZAP_EMPTY_DEFAULT() }, + }; + return chip::Span(kAllAttributes); + } + + + Attribute<1, ATTRIBUTE_MASK_WRITABLE, PrimitiveType> mSomeInteger; +}; + +struct FirstAccess : public CommonAttributeAccessInterface +{ + FirstAccess() : CommonAttributeAccessInterface(chip::Optional(), FirstCluster::kClusterId) {} + + FirstCluster* GetCluster(const chip::app::ConcreteClusterPath & aPath) + { + CommonCluster * cluster = FindCluster(aPath); + return cluster ? static_cast(cluster) : nullptr; + } + + CHIP_ERROR Read(const chip::app::ConcreteReadAttributePath & aPath, chip::app::AttributeValueEncoder & aEncoder) override + { + auto * c = GetCluster(aPath); + if (!c) + return CHIP_ERROR_NOT_IMPLEMENTED; + + switch(aPath.mAttributeId) { + case 1: + return c->mSomeInteger.Read(aPath, aEncoder); + default: + return CHIP_ERROR_NOT_IMPLEMENTED; + } + } + + CHIP_ERROR Write(const chip::app::ConcreteDataAttributePath & aPath, chip::app::AttributeValueDecoder & aDecoder) override + { + auto * c = GetCluster(aPath); + if (!c) + return CHIP_ERROR_NOT_IMPLEMENTED; + return c->ForwardWriteToBridge(aPath, aDecoder); + } + + void OnListWriteBegin(const chip::app::ConcreteAttributePath & aPath) override + { + auto * c = GetCluster(aPath); + if (!c) + return; + + switch(aPath.mAttributeId) { + } + } + + void OnListWriteEnd(const chip::app::ConcreteAttributePath & aPath, bool aWriteWasSuccessful) override + { + auto * c = GetCluster(aPath); + if (!c) + return; + + switch(aPath.mAttributeId) { + } + } +}; + +} \ No newline at end of file diff --git a/scripts/idl/tests/outputs/several_clusters/bridge/Second.h b/scripts/idl/tests/outputs/several_clusters/bridge/Second.h new file mode 100644 index 00000000000000..6b0b74e5021897 --- /dev/null +++ b/scripts/idl/tests/outputs/several_clusters/bridge/Second.h @@ -0,0 +1,96 @@ +#pragma once + +#include "BridgeGlobalStructs.h" + +namespace clusters { +struct SecondCluster : public CommonCluster +{ + + + static constexpr chip::ClusterId kClusterId = 2; + + chip::ClusterId GetClusterId() override { return kClusterId; } + + CHIP_ERROR WriteFromBridge(const chip::app::ConcreteDataAttributePath & aPath, chip::app::AttributeValueDecoder & aDecoder) override + { + switch(aPath.mAttributeId) + { + case 123: + return mSomeBytes.Write(aPath, aDecoder); + default: + return CHIP_ERROR_NOT_IMPLEMENTED; + } + } + + template + void AddAllAttributes(T *list) + { + list->Add(mSomeBytes); + } + + chip::Span GetAllAttributes() override + { + static constexpr const EmberAfAttributeMetadata kAllAttributes[] = { + { 123, ZCL_OCTET_STRING_ATTRIBUTE_TYPE, 32, 0 | ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE), ZAP_EMPTY_DEFAULT() }, + }; + return chip::Span(kAllAttributes); + } + + + Attribute<123, 0, OctetString<32, ZCL_OCTET_STRING_ATTRIBUTE_TYPE>> mSomeBytes; +}; + +struct SecondAccess : public CommonAttributeAccessInterface +{ + SecondAccess() : CommonAttributeAccessInterface(chip::Optional(), SecondCluster::kClusterId) {} + + SecondCluster* GetCluster(const chip::app::ConcreteClusterPath & aPath) + { + CommonCluster * cluster = FindCluster(aPath); + return cluster ? static_cast(cluster) : nullptr; + } + + CHIP_ERROR Read(const chip::app::ConcreteReadAttributePath & aPath, chip::app::AttributeValueEncoder & aEncoder) override + { + auto * c = GetCluster(aPath); + if (!c) + return CHIP_ERROR_NOT_IMPLEMENTED; + + switch(aPath.mAttributeId) { + case 123: + return c->mSomeBytes.Read(aPath, aEncoder); + default: + return CHIP_ERROR_NOT_IMPLEMENTED; + } + } + + CHIP_ERROR Write(const chip::app::ConcreteDataAttributePath & aPath, chip::app::AttributeValueDecoder & aDecoder) override + { + auto * c = GetCluster(aPath); + if (!c) + return CHIP_ERROR_NOT_IMPLEMENTED; + return c->ForwardWriteToBridge(aPath, aDecoder); + } + + void OnListWriteBegin(const chip::app::ConcreteAttributePath & aPath) override + { + auto * c = GetCluster(aPath); + if (!c) + return; + + switch(aPath.mAttributeId) { + } + } + + void OnListWriteEnd(const chip::app::ConcreteAttributePath & aPath, bool aWriteWasSuccessful) override + { + auto * c = GetCluster(aPath); + if (!c) + return; + + switch(aPath.mAttributeId) { + } + } +}; + +} \ No newline at end of file diff --git a/scripts/idl/tests/outputs/several_clusters/bridge/Third.h b/scripts/idl/tests/outputs/several_clusters/bridge/Third.h new file mode 100644 index 00000000000000..18833218b504a1 --- /dev/null +++ b/scripts/idl/tests/outputs/several_clusters/bridge/Third.h @@ -0,0 +1,96 @@ +#pragma once + +#include "BridgeGlobalStructs.h" + +namespace clusters { +struct ThirdCluster : public CommonCluster +{ + + + static constexpr chip::ClusterId kClusterId = 3; + + chip::ClusterId GetClusterId() override { return kClusterId; } + + CHIP_ERROR WriteFromBridge(const chip::app::ConcreteDataAttributePath & aPath, chip::app::AttributeValueDecoder & aDecoder) override + { + switch(aPath.mAttributeId) + { + case 10: + return mSomeEnum.Write(aPath, aDecoder); + default: + return CHIP_ERROR_NOT_IMPLEMENTED; + } + } + + template + void AddAllAttributes(T *list) + { + list->Add(mSomeEnum); + } + + chip::Span GetAllAttributes() override + { + static constexpr const EmberAfAttributeMetadata kAllAttributes[] = { + { 10, ZCL_ENUM8_ATTRIBUTE_TYPE, 1, ATTRIBUTE_MASK_WRITABLE | ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE), ZAP_EMPTY_DEFAULT() }, + }; + return chip::Span(kAllAttributes); + } + + + Attribute<10, ATTRIBUTE_MASK_WRITABLE, PrimitiveType> mSomeEnum; +}; + +struct ThirdAccess : public CommonAttributeAccessInterface +{ + ThirdAccess() : CommonAttributeAccessInterface(chip::Optional(), ThirdCluster::kClusterId) {} + + ThirdCluster* GetCluster(const chip::app::ConcreteClusterPath & aPath) + { + CommonCluster * cluster = FindCluster(aPath); + return cluster ? static_cast(cluster) : nullptr; + } + + CHIP_ERROR Read(const chip::app::ConcreteReadAttributePath & aPath, chip::app::AttributeValueEncoder & aEncoder) override + { + auto * c = GetCluster(aPath); + if (!c) + return CHIP_ERROR_NOT_IMPLEMENTED; + + switch(aPath.mAttributeId) { + case 10: + return c->mSomeEnum.Read(aPath, aEncoder); + default: + return CHIP_ERROR_NOT_IMPLEMENTED; + } + } + + CHIP_ERROR Write(const chip::app::ConcreteDataAttributePath & aPath, chip::app::AttributeValueDecoder & aDecoder) override + { + auto * c = GetCluster(aPath); + if (!c) + return CHIP_ERROR_NOT_IMPLEMENTED; + return c->ForwardWriteToBridge(aPath, aDecoder); + } + + void OnListWriteBegin(const chip::app::ConcreteAttributePath & aPath) override + { + auto * c = GetCluster(aPath); + if (!c) + return; + + switch(aPath.mAttributeId) { + } + } + + void OnListWriteEnd(const chip::app::ConcreteAttributePath & aPath, bool aWriteWasSuccessful) override + { + auto * c = GetCluster(aPath); + if (!c) + return; + + switch(aPath.mAttributeId) { + } + } +}; + +} \ No newline at end of file diff --git a/scripts/idl/tests/outputs/several_clusters/cpp/BridgeClustersImpl.h b/scripts/idl/tests/outputs/several_clusters/cpp/BridgeClustersImpl.h deleted file mode 100644 index 6cea2430bd0c86..00000000000000 --- a/scripts/idl/tests/outputs/several_clusters/cpp/BridgeClustersImpl.h +++ /dev/null @@ -1,334 +0,0 @@ -#include -#include - -#include - -namespace clusters { - -struct FirstCluster : public CommonCluster -{ - - - static constexpr chip::ClusterId kClusterId = 1; - - chip::ClusterId GetClusterId() override { return kClusterId; } - - CHIP_ERROR WriteFromBridge(const chip::app::ConcreteDataAttributePath & aPath, chip::app::AttributeValueDecoder & aDecoder) override - { - switch(aPath.mAttributeId) - { - case 1: - return mSomeInteger.Write(aPath, aDecoder); - default: - return CHIP_ERROR_NOT_IMPLEMENTED; - } - } - - template - void AddAllAttributes(T *list) - { - list->Add(mSomeInteger); - } - - chip::Span GetAllAttributes() override - { - static constexpr const EmberAfAttributeMetadata kAllAttributes[] = { - { 1, ZCL_INT16U_ATTRIBUTE_TYPE, 2, ATTRIBUTE_MASK_WRITABLE | ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE), ZAP_EMPTY_DEFAULT() }, - }; - return chip::Span(kAllAttributes); - } - - - Attribute<1, ATTRIBUTE_MASK_WRITABLE, PrimitiveType> mSomeInteger; -}; - -struct FirstAccess : public CommonAttributeAccessInterface -{ - FirstAccess() : CommonAttributeAccessInterface(chip::Optional(), FirstCluster::kClusterId) {} - - FirstCluster* GetCluster(const chip::app::ConcreteClusterPath & aPath) - { - CommonCluster * cluster = FindCluster(aPath); - return cluster ? static_cast(cluster) : nullptr; - } - - CHIP_ERROR Read(const chip::app::ConcreteReadAttributePath & aPath, chip::app::AttributeValueEncoder & aEncoder) override - { - auto * c = GetCluster(aPath); - if (!c) - return CHIP_ERROR_NOT_IMPLEMENTED; - - switch(aPath.mAttributeId) { - case 1: - return c->mSomeInteger.Read(aPath, aEncoder); - default: - return CHIP_ERROR_NOT_IMPLEMENTED; - } - } - - CHIP_ERROR Write(const chip::app::ConcreteDataAttributePath & aPath, chip::app::AttributeValueDecoder & aDecoder) override - { - auto * c = GetCluster(aPath); - if (!c) - return CHIP_ERROR_NOT_IMPLEMENTED; - return c->ForwardWriteToBridge(aPath, aDecoder); - } - - void OnListWriteBegin(const chip::app::ConcreteAttributePath & aPath) override - { - auto * c = GetCluster(aPath); - if (!c) - return; - - switch(aPath.mAttributeId) { - } - } - - void OnListWriteEnd(const chip::app::ConcreteAttributePath & aPath, bool aWriteWasSuccessful) override - { - auto * c = GetCluster(aPath); - if (!c) - return; - - switch(aPath.mAttributeId) { - } - } -}; -struct SecondCluster : public CommonCluster -{ - - - static constexpr chip::ClusterId kClusterId = 2; - - chip::ClusterId GetClusterId() override { return kClusterId; } - - CHIP_ERROR WriteFromBridge(const chip::app::ConcreteDataAttributePath & aPath, chip::app::AttributeValueDecoder & aDecoder) override - { - switch(aPath.mAttributeId) - { - case 123: - return mSomeBytes.Write(aPath, aDecoder); - default: - return CHIP_ERROR_NOT_IMPLEMENTED; - } - } - - template - void AddAllAttributes(T *list) - { - list->Add(mSomeBytes); - } - - chip::Span GetAllAttributes() override - { - static constexpr const EmberAfAttributeMetadata kAllAttributes[] = { - { 123, ZCL_OCTET_STRING_ATTRIBUTE_TYPE, 32, 0 | ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE), ZAP_EMPTY_DEFAULT() }, - }; - return chip::Span(kAllAttributes); - } - - - Attribute<123, 0, OctetString<32, ZCL_OCTET_STRING_ATTRIBUTE_TYPE>> mSomeBytes; -}; - -struct SecondAccess : public CommonAttributeAccessInterface -{ - SecondAccess() : CommonAttributeAccessInterface(chip::Optional(), SecondCluster::kClusterId) {} - - SecondCluster* GetCluster(const chip::app::ConcreteClusterPath & aPath) - { - CommonCluster * cluster = FindCluster(aPath); - return cluster ? static_cast(cluster) : nullptr; - } - - CHIP_ERROR Read(const chip::app::ConcreteReadAttributePath & aPath, chip::app::AttributeValueEncoder & aEncoder) override - { - auto * c = GetCluster(aPath); - if (!c) - return CHIP_ERROR_NOT_IMPLEMENTED; - - switch(aPath.mAttributeId) { - case 123: - return c->mSomeBytes.Read(aPath, aEncoder); - default: - return CHIP_ERROR_NOT_IMPLEMENTED; - } - } - - CHIP_ERROR Write(const chip::app::ConcreteDataAttributePath & aPath, chip::app::AttributeValueDecoder & aDecoder) override - { - auto * c = GetCluster(aPath); - if (!c) - return CHIP_ERROR_NOT_IMPLEMENTED; - return c->ForwardWriteToBridge(aPath, aDecoder); - } - - void OnListWriteBegin(const chip::app::ConcreteAttributePath & aPath) override - { - auto * c = GetCluster(aPath); - if (!c) - return; - - switch(aPath.mAttributeId) { - } - } - - void OnListWriteEnd(const chip::app::ConcreteAttributePath & aPath, bool aWriteWasSuccessful) override - { - auto * c = GetCluster(aPath); - if (!c) - return; - - switch(aPath.mAttributeId) { - } - } -}; -struct ThirdCluster : public CommonCluster -{ - - - static constexpr chip::ClusterId kClusterId = 3; - - chip::ClusterId GetClusterId() override { return kClusterId; } - - CHIP_ERROR WriteFromBridge(const chip::app::ConcreteDataAttributePath & aPath, chip::app::AttributeValueDecoder & aDecoder) override - { - switch(aPath.mAttributeId) - { - case 10: - return mSomeEnum.Write(aPath, aDecoder); - default: - return CHIP_ERROR_NOT_IMPLEMENTED; - } - } - - template - void AddAllAttributes(T *list) - { - list->Add(mSomeEnum); - } - - chip::Span GetAllAttributes() override - { - static constexpr const EmberAfAttributeMetadata kAllAttributes[] = { - { 10, ZCL_ENUM8_ATTRIBUTE_TYPE, 1, ATTRIBUTE_MASK_WRITABLE | ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE), ZAP_EMPTY_DEFAULT() }, - }; - return chip::Span(kAllAttributes); - } - - - Attribute<10, ATTRIBUTE_MASK_WRITABLE, PrimitiveType> mSomeEnum; -}; - -struct ThirdAccess : public CommonAttributeAccessInterface -{ - ThirdAccess() : CommonAttributeAccessInterface(chip::Optional(), ThirdCluster::kClusterId) {} - - ThirdCluster* GetCluster(const chip::app::ConcreteClusterPath & aPath) - { - CommonCluster * cluster = FindCluster(aPath); - return cluster ? static_cast(cluster) : nullptr; - } - - CHIP_ERROR Read(const chip::app::ConcreteReadAttributePath & aPath, chip::app::AttributeValueEncoder & aEncoder) override - { - auto * c = GetCluster(aPath); - if (!c) - return CHIP_ERROR_NOT_IMPLEMENTED; - - switch(aPath.mAttributeId) { - case 10: - return c->mSomeEnum.Read(aPath, aEncoder); - default: - return CHIP_ERROR_NOT_IMPLEMENTED; - } - } - - CHIP_ERROR Write(const chip::app::ConcreteDataAttributePath & aPath, chip::app::AttributeValueDecoder & aDecoder) override - { - auto * c = GetCluster(aPath); - if (!c) - return CHIP_ERROR_NOT_IMPLEMENTED; - return c->ForwardWriteToBridge(aPath, aDecoder); - } - - void OnListWriteBegin(const chip::app::ConcreteAttributePath & aPath) override - { - auto * c = GetCluster(aPath); - if (!c) - return; - - switch(aPath.mAttributeId) { - } - } - - void OnListWriteEnd(const chip::app::ConcreteAttributePath & aPath, bool aWriteWasSuccessful) override - { - auto * c = GetCluster(aPath); - if (!c) - return; - - switch(aPath.mAttributeId) { - } - } -}; - -struct ClusterInfo -{ - chip::ClusterId id; - const char *name; - uint16_t size; - CommonCluster* (*ctor)(void*); -} static const kKnownClusters[] = { - - { - 1, - "First", - sizeof(FirstCluster), - [](void *mem) -> CommonCluster* { - return new(mem) FirstCluster(); - }, - }, - { - 2, - "Second", - sizeof(SecondCluster), - [](void *mem) -> CommonCluster* { - return new(mem) SecondCluster(); - }, - }, - { - 3, - "Third", - sizeof(ThirdCluster), - [](void *mem) -> CommonCluster* { - return new(mem) ThirdCluster(); - }, - }, -}; - -inline void BridgeRegisterAllAttributeOverrides() -{ - - static FirstAccess First; - registerAttributeAccessOverride(&First); - static SecondAccess Second; - registerAttributeAccessOverride(&Second); - static ThirdAccess Third; - registerAttributeAccessOverride(&Third); -} - -struct AttrInfo -{ - chip::ClusterId cluster; - chip::AttributeId attr; - const char *name; -} static const kKnownAttributes[] = { - - { 1, 1, "SomeInteger" }, - { 2, 123, "SomeBytes" }, - { 3, 10, "SomeEnum" }, - -}; - -} \ No newline at end of file diff --git a/scripts/idl/tests/outputs/simple_attribute/bridge/BridgeClustersImpl.h b/scripts/idl/tests/outputs/simple_attribute/bridge/BridgeClustersImpl.h new file mode 100644 index 00000000000000..3375275f87ee02 --- /dev/null +++ b/scripts/idl/tests/outputs/simple_attribute/bridge/BridgeClustersImpl.h @@ -0,0 +1,43 @@ +#pragma once + +#include +#include "bridge/MyCluster.h" + +namespace clusters { + +struct ClusterInfo +{ + chip::ClusterId id; + const char *name; + uint16_t size; + CommonCluster* (*ctor)(void*); +} static const kKnownClusters[] = { + + { + 123, + "MyCluster", + sizeof(MyClusterCluster), + [](void *mem) -> CommonCluster* { + return new(mem) MyClusterCluster(); + }, + }, +}; + +inline void BridgeRegisterAllAttributeOverrides() +{ + + static MyClusterAccess MyCluster; + registerAttributeAccessOverride(&MyCluster); +} + +struct AttrInfo +{ + chip::ClusterId cluster; + chip::AttributeId attr; + const char *name; +} static const kKnownAttributes[] = { + + { 123, 1, "ClusterAttr" }, +}; + +} \ No newline at end of file diff --git a/scripts/idl/tests/outputs/simple_attribute/bridge/BridgeGlobalStructs.h b/scripts/idl/tests/outputs/simple_attribute/bridge/BridgeGlobalStructs.h new file mode 100644 index 00000000000000..9dc0e1e1dec340 --- /dev/null +++ b/scripts/idl/tests/outputs/simple_attribute/bridge/BridgeGlobalStructs.h @@ -0,0 +1,10 @@ +#pragma once + +#include +#include + +namespace clusters { + + + +} \ No newline at end of file diff --git a/scripts/idl/tests/outputs/simple_attribute/cpp/BridgeClustersImpl.h b/scripts/idl/tests/outputs/simple_attribute/bridge/MyCluster.h similarity index 77% rename from scripts/idl/tests/outputs/simple_attribute/cpp/BridgeClustersImpl.h rename to scripts/idl/tests/outputs/simple_attribute/bridge/MyCluster.h index e276240132a6fa..813f722913c412 100644 --- a/scripts/idl/tests/outputs/simple_attribute/cpp/BridgeClustersImpl.h +++ b/scripts/idl/tests/outputs/simple_attribute/bridge/MyCluster.h @@ -1,10 +1,8 @@ -#include -#include +#pragma once -#include +#include "BridgeGlobalStructs.h" namespace clusters { - struct MyClusterCluster : public CommonCluster { @@ -95,40 +93,4 @@ struct MyClusterAccess : public CommonAttributeAccessInterface } }; -struct ClusterInfo -{ - chip::ClusterId id; - const char *name; - uint16_t size; - CommonCluster* (*ctor)(void*); -} static const kKnownClusters[] = { - - { - 123, - "MyCluster", - sizeof(MyClusterCluster), - [](void *mem) -> CommonCluster* { - return new(mem) MyClusterCluster(); - }, - }, -}; - -inline void BridgeRegisterAllAttributeOverrides() -{ - - static MyClusterAccess MyCluster; - registerAttributeAccessOverride(&MyCluster); -} - -struct AttrInfo -{ - chip::ClusterId cluster; - chip::AttributeId attr; - const char *name; -} static const kKnownAttributes[] = { - - { 123, 1, "ClusterAttr" }, - -}; - } \ No newline at end of file