-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Centralize codegen integration #40553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f0adceb
924553a
91cb98f
cf9c67e
c66614a
cf639b5
37d84a0
df42029
6a9a706
0e03026
9c32d7c
337fec7
15236e6
45d9995
2832aa2
7000db5
d08eff6
4eddafe
5c25b46
ec2021e
2c24c44
fe2e5e3
b2be556
a2f96d0
e7cad9c
aba4279
a77b9cc
d3ded91
7bd86ff
440b198
8c0f5c2
28fd918
23de75e
9443e7d
b41ed02
03f5e31
7618be8
02f289d
cf8de98
07f36bb
f889687
9d5a5f3
88e08a8
010d26c
46f3ef4
ed9ed60
0fc0f85
29d9b75
afd0981
cfc0156
dcc1a00
779bc59
74ab244
ac1b359
2f19eb1
e6c634f
b98fc29
0ce0363
f9c47a1
f8c7751
fcfa5f9
2f86de2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,10 +16,9 @@ | |
| */ | ||
| #include <app/clusters/administrator-commissioning-server/AdministratorCommissioningCluster.h> | ||
| #include <app/static-cluster-config/AdministratorCommissioning.h> | ||
| #include <data-model-providers/codegen/CodegenDataModelProvider.h> | ||
| #include <data-model-providers/codegen/ClusterIntegration.h> | ||
|
|
||
| #include <app-common/zap-generated/attributes/Accessors.h> | ||
| #include <app/util/attribute-storage.h> | ||
| #include <app/util/config.h> // REQUIRED for ifdefs for commands | ||
|
|
||
| using namespace chip; | ||
| using namespace chip::app; | ||
|
|
@@ -51,43 +50,52 @@ using ClusterImpl = AdministratorCommissioningCluster; | |
|
|
||
| LazyRegisteredServerCluster<ClusterImpl> gServer; | ||
|
|
||
| } // namespace | ||
|
|
||
| void emberAfAdministratorCommissioningClusterServerInitCallback(EndpointId endpointId) | ||
| class IntegrationDelegate : public CodegenClusterIntegration::Delegate | ||
| { | ||
| if (endpointId != kRootEndpointId) | ||
| public: | ||
| ServerClusterRegistration & CreateRegistration(EndpointId endpointId, unsigned emberEndpointIndex, | ||
| uint32_t optionalAttributeBits, uint32_t featureMap) override | ||
| { | ||
| return; | ||
| gServer.Create(endpointId, BitFlags<AdministratorCommissioning::Feature>(featureMap)); | ||
| return gServer.Registration(); | ||
| } | ||
|
|
||
| uint32_t rawFeatureMap; | ||
| if (FeatureMap::Get(endpointId, &rawFeatureMap) != Status::Success) | ||
| { | ||
| ChipLogError(AppServer, "Failed to get feature map for endpoint %u", endpointId); | ||
| rawFeatureMap = 0; | ||
| } | ||
| ServerClusterInterface & FindRegistration(unsigned emberEndpointIndex) override { return gServer.Cluster(); } | ||
| void ReleaseRegistration(unsigned emberEndpointIndex) override { gServer.Destroy(); } | ||
| }; | ||
|
|
||
| gServer.Create(endpointId, BitFlags<AdministratorCommissioning::Feature>(rawFeatureMap)); | ||
| CHIP_ERROR err = CodegenDataModelProvider::Instance().Registry().Register(gServer.Registration()); | ||
| if (err != CHIP_NO_ERROR) | ||
| { | ||
| ChipLogError(AppServer, "Admin Commissioning register error: endpoint %u, %" CHIP_ERROR_FORMAT, endpointId, err.Format()); | ||
| } | ||
| } // namespace | ||
|
|
||
| void emberAfAdministratorCommissioningClusterServerInitCallback(EndpointId endpointId) | ||
| { | ||
| IntegrationDelegate integrationDelegate; | ||
|
|
||
| // register a singleton server (root endpoint only) | ||
| CodegenClusterIntegration::RegisterServer( | ||
| { | ||
| .endpointId = endpointId, | ||
| .clusterId = AdministratorCommissioning::Id, | ||
| .fixedClusterServerEndpointCount = 1, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you know it's 1? What if endpoint 0 is a dynamic endpoint? This could be 0. Or potentially more than 1 in the presence of fabric sync, but see below. This needs to use the right |
||
| .maxEndpointCount = 1, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks wrong a priori; fabric sync allows multiple Administrator Commissioning clusters on multiple endpoints, right? Now I know the existing code does not work with that, so you can't use codegen for fabric sync, but this is at least worth documentation explaining why this value is 1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case we claim that "the implementation here only handles the root node global instance administrator commissioning" hence the value of 1: we only ever support root endpoint. For the rest, we would error out if codegen requests it. AdministratorCommissioning logic in fabric sync installs its own versions of this cluster and it is not this cluster in particular. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My point is we should document that here. |
||
| .fetchFeatureMap = true, | ||
| .fetchOptionalAttributes = false, | ||
| }, | ||
| integrationDelegate); | ||
| } | ||
|
|
||
| void MatterAdministratorCommissioningClusterServerShutdownCallback(EndpointId endpointId) | ||
| { | ||
| if (endpointId != kRootEndpointId) | ||
| { | ||
| return; | ||
| } | ||
| IntegrationDelegate integrationDelegate; | ||
|
|
||
| CHIP_ERROR err = CodegenDataModelProvider::Instance().Registry().Unregister(&gServer.Cluster()); | ||
| if (err != CHIP_NO_ERROR) | ||
| { | ||
| ChipLogError(AppServer, "Admin Commissioning unregister error: endpoint %u, %" CHIP_ERROR_FORMAT, endpointId, err.Format()); | ||
| } | ||
| gServer.Destroy(); | ||
| // register a singleton server (root endpoint only) | ||
| CodegenClusterIntegration::UnregisterServer( | ||
| { | ||
| .endpointId = endpointId, | ||
| .clusterId = AdministratorCommissioning::Id, | ||
| .fixedClusterServerEndpointCount = 1, | ||
| .maxEndpointCount = 1, | ||
|
Comment on lines
+95
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, these counts look off. |
||
| }, | ||
| integrationDelegate); | ||
| } | ||
|
|
||
| void MatterAdministratorCommissioningPluginServerInitCallback() {} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,7 @@ | |
| #include <app/static-cluster-config/BasicInformation.h> | ||
| #include <app/util/attribute-storage.h> | ||
| #include <app/util/endpoint-config-api.h> | ||
| #include <data-model-providers/codegen/CodegenDataModelProvider.h> | ||
| #include <lib/support/BitFlags.h> | ||
| #include <data-model-providers/codegen/ClusterIntegration.h> | ||
|
|
||
| using namespace chip; | ||
| using namespace chip::app; | ||
|
|
@@ -46,44 +45,60 @@ static_assert((kBasicInformationFixedClusterCount == 0) || | |
|
|
||
| ServerClusterRegistration gRegistration(BasicInformationCluster::Instance()); | ||
|
|
||
| class IntegrationDelegate : public CodegenClusterIntegration::Delegate | ||
| { | ||
| public: | ||
| ServerClusterRegistration & CreateRegistration(EndpointId endpointId, unsigned emberEndpointIndex, | ||
| uint32_t optionalAttributeBits, uint32_t featureMap) override | ||
| { | ||
|
|
||
| BasicInformationCluster::Instance().OptionalAttributes() = | ||
| BasicInformationCluster::OptionalAttributesSet(optionalAttributeBits); | ||
|
|
||
| return gRegistration; | ||
| } | ||
|
|
||
| ServerClusterInterface & FindRegistration(unsigned emberEndpointIndex) override { return BasicInformationCluster::Instance(); } | ||
|
|
||
| // Nothing to destroy: separate singleton class without constructor/destructor is used | ||
| void ReleaseRegistration(unsigned emberEndpointIndex) override {} | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| void emberAfBasicInformationClusterServerInitCallback(EndpointId endpointId) | ||
| { | ||
| VerifyOrReturn(endpointId == kRootEndpointId); | ||
|
|
||
| BasicInformationCluster::OptionalAttributesSet & attrs = BasicInformationCluster::Instance().OptionalAttributes(); | ||
| IntegrationDelegate integrationDelegate; | ||
|
|
||
| attrs.Set<ManufacturingDate::Id>(emberAfContainsAttribute(endpointId, BasicInformation::Id, ManufacturingDate::Id)) | ||
| .Set<PartNumber::Id>(emberAfContainsAttribute(endpointId, BasicInformation::Id, PartNumber::Id)) | ||
| .Set<ProductURL::Id>(emberAfContainsAttribute(endpointId, BasicInformation::Id, ProductURL::Id)) | ||
| .Set<ProductLabel::Id>(emberAfContainsAttribute(endpointId, BasicInformation::Id, ProductLabel::Id)) | ||
| .Set<SerialNumber::Id>(emberAfContainsAttribute(endpointId, BasicInformation::Id, SerialNumber::Id)) | ||
| .Set<LocalConfigDisabled::Id>(emberAfContainsAttribute(endpointId, BasicInformation::Id, LocalConfigDisabled::Id)) | ||
| .Set<Reachable::Id>(emberAfContainsAttribute(endpointId, BasicInformation::Id, Reachable::Id)) | ||
| .Set<ProductAppearance::Id>(emberAfContainsAttribute(endpointId, BasicInformation::Id, ProductAppearance::Id)) | ||
|
|
||
| // This is NOT typical, however we try to respect ZAP here. MCORE_FS tests require this: | ||
| // Specifically builds need to support the "do not build with unique id (make it optional)" | ||
| // to emulate the test case where UniqueID is missing as it was optional in previous versions of the spec | ||
| .Set<UniqueID::Id>(emberAfContainsAttribute(endpointId, BasicInformation::Id, UniqueID::Id)); | ||
|
|
||
| CHIP_ERROR err = CodegenDataModelProvider::Instance().Registry().Register(gRegistration); | ||
| if (err != CHIP_NO_ERROR) | ||
| { | ||
| ChipLogError(AppServer, "Basic Information register error: endpoint %u, %" CHIP_ERROR_FORMAT, endpointId, err.Format()); | ||
| } | ||
| // register a singleton server (root endpoint only) | ||
| CodegenClusterIntegration::RegisterServer( | ||
| { | ||
| .endpointId = endpointId, | ||
| .clusterId = BasicInformation::Id, | ||
| .fixedClusterServerEndpointCount = 1, | ||
| .maxEndpointCount = 1, | ||
|
Comment on lines
+80
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above: the first 1 looks wrong, the second 1 needs documentation (i.e: there is only one Basic Information instance on a node; this one is simpler than Administrator Commissioning). |
||
| .fetchFeatureMap = false, | ||
| .fetchOptionalAttributes = true, | ||
| }, | ||
| integrationDelegate); | ||
| } | ||
|
|
||
| void MatterBasicInformationClusterServerShutdownCallback(EndpointId endpointId) | ||
| { | ||
| VerifyOrReturn(endpointId == kRootEndpointId); | ||
|
|
||
| CHIP_ERROR err = CodegenDataModelProvider::Instance().Registry().Unregister(&BasicInformationCluster::Instance()); | ||
| if (err != CHIP_NO_ERROR) | ||
| { | ||
| ChipLogError(AppServer, "Basic Information unregister error: endpoint %u, %" CHIP_ERROR_FORMAT, endpointId, err.Format()); | ||
| } | ||
| IntegrationDelegate integrationDelegate; | ||
|
|
||
| CodegenClusterIntegration::UnregisterServer( | ||
| { | ||
| .endpointId = endpointId, | ||
| .clusterId = BasicInformation::Id, | ||
| .fixedClusterServerEndpointCount = 1, | ||
| .maxEndpointCount = 1, | ||
tcarmelveilleux marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+98
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to stop commenting on these, but they all need fixing. |
||
| }, | ||
| integrationDelegate); | ||
| } | ||
|
|
||
| void MatterBasicInformationPluginServerInitCallback() {} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.