-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make global attributes be part of IM instead of part of DataModel::Pr…
…ovider (#37345) * A first pass to add global attributes as part of IME instead of datamodel::provider * Some updates * Update some tests and reformat... the checks were PAINFUL,kept debug logs * Bump test: we now support the extra 3 global attributes not in metadata * More fixes * Fix compile error about parameter shadowing * More updates on casts to make xtensa compile happy * Restyled by clang-format * Fix tests * Make the test for unsupported write consistent with #37322 * Fix includes * Smaller delta * Attribute metadata is now guaranteed * Update src/app/data-model-provider/MetadataLookup.h Co-authored-by: Boris Zbarsky <[email protected]> * Update src/app/data-model-provider/MetadataLookup.h Co-authored-by: Boris Zbarsky <[email protected]> * Update src/app/reporting/Engine.cpp Co-authored-by: Boris Zbarsky <[email protected]> * Update src/app/reporting/Engine.cpp Co-authored-by: Boris Zbarsky <[email protected]> * Address some code review comments * Remove the ember metadata public cluster path validation as it is not needed anymore as a public API * Do not enforce ordering in attribute list encoding * Comment about items returned or not returned in various calls * Correct the unsupported attribute call * Restyle * Update order dependent test in java ... this is somewhat broken... * Fix indent * Fix include * Fix typo * Allow TODO comment: I am not willing to re-build the kotlin code right now for this PR * Using uint64_t for encoding saves some flash * Fix test ... although this is NOT ok as we need order independent test * Fix the real list now * Switch the basic information constraints as a set compare (use python) * Remove extra space * Restyled by prettier-yaml * Fix asserts in DGWIFI - wrong method used * Restyled by autopep8 * Update src/app/data-model-provider/Provider.h Co-authored-by: Boris Zbarsky <[email protected]> * Update src/app/data-model-provider/ProviderMetadataTree.h Co-authored-by: Boris Zbarsky <[email protected]> * Update src/data-model-providers/codegen/CodegenDataModelProvider_Write.cpp Co-authored-by: Boris Zbarsky <[email protected]> * Update src/app/data-model-provider/ProviderMetadataTree.h Co-authored-by: Boris Zbarsky <[email protected]> * Undo DFWIFI changes, leave it up to #37382. * Update ordering of attribute list to match unsorted (and smaller) implementation in the SDK * Update src/app/GlobalAttributes.cpp Co-authored-by: Terence Hampson <[email protected]> * Update src/app/GlobalAttributes.h Co-authored-by: Terence Hampson <[email protected]> * Add comment about oddify in path validation * Added comments about why we do the casts ... it is ugly * Add integration test for writing read only attributes and getting the correct error * Restyled by isort * Fix unused imports --------- Co-authored-by: Andrei Litvin <[email protected]> Co-authored-by: Restyled.io <[email protected]> Co-authored-by: Boris Zbarsky <[email protected]> Co-authored-by: Terence Hampson <[email protected]>
- Loading branch information
1 parent
48fc426
commit 09833eb
Showing
31 changed files
with
562 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright (c) 2022-2025 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* 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/GlobalAttributes.h> | ||
#include <app/data-model-provider/MetadataLookup.h> | ||
#include <protocols/interaction_model/StatusCode.h> | ||
|
||
using chip::Protocols::InteractionModel::Status; | ||
|
||
namespace chip { | ||
namespace app { | ||
|
||
bool IsSupportedGlobalAttributeNotInMetadata(AttributeId attributeId) | ||
{ | ||
for (auto & attr : GlobalAttributesNotInMetadata) | ||
{ | ||
if (attr == attributeId) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
DataModel::ActionReturnStatus ReadGlobalAttributeFromMetadata(DataModel::Provider * provider, const ConcreteAttributePath & path, | ||
AttributeValueEncoder & encoder) | ||
{ | ||
CHIP_ERROR err; | ||
|
||
switch (path.mAttributeId) | ||
{ | ||
case Clusters::Globals::Attributes::GeneratedCommandList::Id: { | ||
DataModel::ListBuilder<CommandId> builder; | ||
err = provider->GeneratedCommands(path, builder); | ||
if (err != CHIP_NO_ERROR) | ||
{ | ||
break; | ||
} | ||
auto buffer = builder.TakeBuffer(); | ||
|
||
return encoder.EncodeList([&buffer](const auto & listEncodeHelper) { | ||
for (auto id : buffer) | ||
{ | ||
// NOTE: cast to u64 because TLV encodes all numbers the same (no TLV sideffects) | ||
// and this reduces template variants for Encode, saving flash. | ||
ReturnErrorOnFailure(listEncodeHelper.Encode(static_cast<uint64_t>(id))); | ||
} | ||
return CHIP_NO_ERROR; | ||
}); | ||
} | ||
case Clusters::Globals::Attributes::AcceptedCommandList::Id: { | ||
DataModel::ListBuilder<DataModel::AcceptedCommandEntry> builder; | ||
err = provider->AcceptedCommands(path, builder); | ||
if (err != CHIP_NO_ERROR) | ||
{ | ||
break; | ||
} | ||
auto buffer = builder.TakeBuffer(); | ||
|
||
return encoder.EncodeList([&buffer](const auto & listEncodeHelper) { | ||
for (auto entry : buffer) | ||
{ | ||
// NOTE: cast to u64 because TLV encodes all numbers the same (no TLV sideffects) | ||
// and this reduces template variants for Encode, saving flash. | ||
ReturnErrorOnFailure(listEncodeHelper.Encode(static_cast<uint64_t>(entry.commandId))); | ||
} | ||
return CHIP_NO_ERROR; | ||
}); | ||
} | ||
case Clusters::Globals::Attributes::AttributeList::Id: { | ||
DataModel::ListBuilder<DataModel::AttributeEntry> builder; | ||
err = provider->Attributes(path, builder); | ||
if (err != CHIP_NO_ERROR) | ||
{ | ||
break; | ||
} | ||
auto buffer = builder.TakeBuffer(); | ||
|
||
return encoder.EncodeList([&buffer](const auto & listEncodeHelper) { | ||
for (auto entry : buffer) | ||
{ | ||
// NOTE: cast to u64 because TLV encodes all numbers the same (no TLV sideffects) | ||
// and this reduces template variants for Encode, saving flash. | ||
ReturnErrorOnFailure(listEncodeHelper.Encode(static_cast<uint64_t>(entry.attributeId))); | ||
} | ||
|
||
for (auto id : GlobalAttributesNotInMetadata) | ||
{ | ||
// NOTE: cast to u64 because TLV encodes all numbers the same (no TLV sideffects) | ||
// and this reduces template variants for Encode, saving flash. | ||
ReturnErrorOnFailure(listEncodeHelper.Encode(static_cast<uint64_t>(id))); | ||
} | ||
|
||
return CHIP_NO_ERROR; | ||
}); | ||
} | ||
default: | ||
return CHIP_ERROR_INVALID_ARGUMENT; | ||
} | ||
|
||
// if we get here, the path was NOT valid | ||
if (err == CHIP_ERROR_NOT_FOUND) | ||
{ | ||
// The `Failure` here is arbitrary: we expect ReadGlobalAttributeFromMetadata to be | ||
// an internal API used for global attributes only and call preconditions say that | ||
// should never happen. | ||
// | ||
// Code only takes this path if one of | ||
// `GeneratedCommands`/`AcceptedCommands`/`Attribute` return a NOT_FOUND and | ||
// that would indicate an invalid cluster (which should have been pre-validated by | ||
// the caller). | ||
return DataModel::ValidateClusterPath(provider, path, Status::Failure); | ||
} | ||
return err; | ||
} | ||
|
||
} // namespace app | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.