Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions examples/chef/common/DeviceTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using namespace chip::app;

bool DeviceTypes::EndpointHasDeviceType(EndpointId endpoint, DeviceTypeId deviceTypeId)
{
DataModel::ListBuilder<DataModel::DeviceTypeEntry> deviceTypesList;
ReadOnlyBufferBuilder<DataModel::DeviceTypeEntry> deviceTypesList;
CHIP_ERROR err = InteractionModelEngine::GetInstance()->GetDataModelProvider()->DeviceTypes(endpoint, deviceTypesList);
if (err != CHIP_NO_ERROR)
{
Expand All @@ -45,25 +45,34 @@ bool DeviceTypes::EndpointHasDeviceType(EndpointId endpoint, DeviceTypeId device
return false;
}

DataModel::ListBuilder<EndpointId> DeviceTypes::GetAllEndpointsHavingDeviceType(DeviceTypeId deviceTypeId)
ReadOnlyBuffer<EndpointId> DeviceTypes::GetAllEndpointsHavingDeviceType(DeviceTypeId deviceTypeId)
{
DataModel::ListBuilder<DataModel::EndpointEntry> endpointsList;
ReadOnlyBufferBuilder<DataModel::EndpointEntry> endpointsList;
CHIP_ERROR err = InteractionModelEngine::GetInstance()->GetDataModelProvider()->Endpoints(endpointsList);
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "GetDataModelProvider Endpoints returned error: %" CHIP_ERROR_FORMAT, err.Format());
return DataModel::ListBuilder<EndpointId>();
return {};
}
auto allEndpoints = endpointsList.TakeBuffer();

DataModel::ListBuilder<EndpointId> endpoints;
ReadOnlyBufferBuilder<EndpointId> endpoints;
err = endpoints.EnsureAppendCapacity(allEndpoints.size());
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Error ensuring append capacity for endpoints: %" CHIP_ERROR_FORMAT, err.Format());
}

for (const auto & ep : allEndpoints)
{
if (EndpointHasDeviceType(ep.id, deviceTypeId))
{
endpoints.Append(ep.id);
err = endpoints.Append(ep.id);
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Error appending endpoint: %" CHIP_ERROR_FORMAT, err.Format());
}
}
}
return endpoints;
return endpoints.TakeBuffer();
}
4 changes: 2 additions & 2 deletions examples/chef/common/DeviceTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* limitations under the License.
*/

#include <app/data-model-provider/MetadataList.h>
#include <lib/core/CHIPError.h>
#include <lib/core/DataModelTypes.h>
#include <lib/support/ReadOnlyBuffer.h>

namespace chef {
namespace DeviceTypes {
Expand Down Expand Up @@ -63,7 +63,7 @@ bool EndpointHasDeviceType(chip::EndpointId endpoint, chip::DeviceTypeId deviceT
* Returns a list of all endpoints that have the specified device type in their respective device types list.
* Endpoints list is fetched using DataModelProvider. Device type match is checked using EndpointHasDeviceType.
*/
chip::app::DataModel::ListBuilder<chip::EndpointId> GetAllEndpointsHavingDeviceType(chip::DeviceTypeId deviceTypeId);
chip::ReadOnlyBuffer<chip::EndpointId> GetAllEndpointsHavingDeviceType(chip::DeviceTypeId deviceTypeId);

} // namespace DeviceTypes
} // namespace chef
4 changes: 2 additions & 2 deletions src/access/ProviderDeviceTypeResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#pragma once

#include <access/AccessControl.h>
#include <app/data-model-provider/MetadataList.h>
#include <app/data-model-provider/MetadataTypes.h>
#include <app/data-model-provider/Provider.h>
#include <lib/support/ReadOnlyBuffer.h>

namespace chip {
namespace Access {
Expand All @@ -33,7 +33,7 @@ class DynamicProviderDeviceTypeResolver : public chip::Access::AccessControl::De

bool IsDeviceTypeOnEndpoint(chip::DeviceTypeId deviceType, chip::EndpointId endpoint) override
{
app::DataModel::ListBuilder<app::DataModel::DeviceTypeEntry> builder;
ReadOnlyBufferBuilder<app::DataModel::DeviceTypeEntry> builder;
(void) mModelGetter()->DeviceTypes(endpoint, builder);
for (auto & type : builder.TakeBuffer())
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/AttributePathExpandIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
#include <app/AttributePathExpandIterator.h>

#include <app/GlobalAttributes.h>
#include <app/data-model-provider/MetadataList.h>
#include <app/data-model-provider/MetadataLookup.h>
#include <app/data-model-provider/MetadataTypes.h>
#include <lib/core/DataModelTypes.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/ReadOnlyBuffer.h>

#include <optional>

Expand Down
8 changes: 4 additions & 4 deletions src/app/AttributePathExpandIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

#include <app/AttributePathParams.h>
#include <app/ConcreteAttributePath.h>
#include <app/data-model-provider/MetadataList.h>
#include <app/data-model-provider/MetadataTypes.h>
#include <app/data-model-provider/Provider.h>
#include <lib/core/DataModelTypes.h>
#include <lib/support/LinkedList.h>
#include <lib/support/ReadOnlyBuffer.h>
#include <lib/support/Span.h>

#include <limits>
Expand Down Expand Up @@ -121,13 +121,13 @@ class AttributePathExpandIterator
DataModel::Provider * mDataModelProvider;
Position & mPosition;

DataModel::ReadOnlyBuffer<DataModel::EndpointEntry> mEndpoints; // all endpoints
ReadOnlyBuffer<DataModel::EndpointEntry> mEndpoints; // all endpoints
size_t mEndpointIndex = kInvalidIndex;

DataModel::ReadOnlyBuffer<DataModel::ServerClusterEntry> mClusters; // all clusters ON THE CURRENT endpoint
ReadOnlyBuffer<DataModel::ServerClusterEntry> mClusters; // all clusters ON THE CURRENT endpoint
size_t mClusterIndex = kInvalidIndex;

DataModel::ReadOnlyBuffer<DataModel::AttributeEntry> mAttributes; // all attributes ON THE CURRENT cluster
ReadOnlyBuffer<DataModel::AttributeEntry> mAttributes; // all attributes ON THE CURRENT cluster
size_t mAttributeIndex = kInvalidIndex;

/// Move to the next endpoint/cluster/attribute triplet that is valid given
Expand Down
6 changes: 3 additions & 3 deletions src/app/GlobalAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ DataModel::ActionReturnStatus ReadGlobalAttributeFromMetadata(DataModel::Provide
switch (path.mAttributeId)
{
case Clusters::Globals::Attributes::GeneratedCommandList::Id: {
DataModel::ListBuilder<CommandId> builder;
ReadOnlyBufferBuilder<CommandId> builder;
err = provider->GeneratedCommands(path, builder);
if (err != CHIP_NO_ERROR)
{
Expand All @@ -63,7 +63,7 @@ DataModel::ActionReturnStatus ReadGlobalAttributeFromMetadata(DataModel::Provide
});
}
case Clusters::Globals::Attributes::AcceptedCommandList::Id: {
DataModel::ListBuilder<DataModel::AcceptedCommandEntry> builder;
ReadOnlyBufferBuilder<DataModel::AcceptedCommandEntry> builder;
err = provider->AcceptedCommands(path, builder);
if (err != CHIP_NO_ERROR)
{
Expand All @@ -82,7 +82,7 @@ DataModel::ActionReturnStatus ReadGlobalAttributeFromMetadata(DataModel::Provide
});
}
case Clusters::Globals::Attributes::AttributeList::Id: {
DataModel::ListBuilder<DataModel::AttributeEntry> builder;
ReadOnlyBufferBuilder<DataModel::AttributeEntry> builder;
err = provider->Attributes(path, builder);
if (err != CHIP_NO_ERROR)
{
Expand Down
4 changes: 2 additions & 2 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include <app/EventPathParams.h>
#include <app/RequiredPrivilege.h>
#include <app/data-model-provider/ActionReturnStatus.h>
#include <app/data-model-provider/MetadataList.h>
#include <app/data-model-provider/MetadataLookup.h>
#include <app/data-model-provider/MetadataTypes.h>
#include <app/data-model-provider/OperationTypes.h>
Expand All @@ -52,6 +51,7 @@
#include <lib/support/CHIPFaultInjection.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/FibonacciUtils.h>
#include <lib/support/ReadOnlyBuffer.h>
#include <protocols/interaction_model/StatusCode.h>

namespace chip {
Expand Down Expand Up @@ -1848,7 +1848,7 @@ Protocols::InteractionModel::Status InteractionModelEngine::CheckCommandExistenc
{
auto provider = GetDataModelProvider();

DataModel::ListBuilder<DataModel::AcceptedCommandEntry> acceptedCommands;
ReadOnlyBufferBuilder<DataModel::AcceptedCommandEntry> acceptedCommands;
(void) provider->AcceptedCommands(aCommandPath, acceptedCommands);
for (auto & existing : acceptedCommands.TakeBuffer())
{
Expand Down
12 changes: 6 additions & 6 deletions src/app/clusters/descriptor/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
#include <app/AttributeAccessInterface.h>
#include <app/AttributeAccessInterfaceRegistry.h>
#include <app/InteractionModelEngine.h>
#include <app/data-model-provider/MetadataList.h>
#include <app/data-model-provider/MetadataTypes.h>
#include <app/data-model/List.h>
#include <app/util/attribute-storage.h>
#include <app/util/endpoint-config-api.h>
#include <lib/core/CHIPError.h>
#include <lib/core/DataModelTypes.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/ReadOnlyBuffer.h>
#include <lib/support/logging/CHIPLogging.h>

using namespace chip;
Expand Down Expand Up @@ -106,7 +106,7 @@ CHIP_ERROR DescriptorAttrAccess::ReadFeatureMap(EndpointId endpoint, AttributeVa

CHIP_ERROR DescriptorAttrAccess::ReadTagListAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder)
{
DataModel::ListBuilder<DataModel::Provider::SemanticTag> semanticTagsList;
ReadOnlyBufferBuilder<DataModel::Provider::SemanticTag> semanticTagsList;
ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->GetDataModelProvider()->SemanticTags(endpoint, semanticTagsList));

return aEncoder.EncodeList([&semanticTagsList](const auto & encoder) -> CHIP_ERROR {
Expand All @@ -120,7 +120,7 @@ CHIP_ERROR DescriptorAttrAccess::ReadTagListAttribute(EndpointId endpoint, Attri

CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder)
{
DataModel::ListBuilder<DataModel::EndpointEntry> endpointsList;
ReadOnlyBufferBuilder<DataModel::EndpointEntry> endpointsList;
ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->GetDataModelProvider()->Endpoints(endpointsList));
auto endpoints = endpointsList.TakeBuffer();
if (endpoint == 0x00)
Expand Down Expand Up @@ -191,7 +191,7 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu

CHIP_ERROR DescriptorAttrAccess::ReadDeviceAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder)
{
DataModel::ListBuilder<DataModel::DeviceTypeEntry> deviceTypesList;
ReadOnlyBufferBuilder<DataModel::DeviceTypeEntry> deviceTypesList;
ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->GetDataModelProvider()->DeviceTypes(endpoint, deviceTypesList));

auto deviceTypes = deviceTypesList.TakeBuffer();
Expand All @@ -213,7 +213,7 @@ CHIP_ERROR DescriptorAttrAccess::ReadDeviceAttribute(EndpointId endpoint, Attrib

CHIP_ERROR DescriptorAttrAccess::ReadServerClusters(EndpointId endpoint, AttributeValueEncoder & aEncoder)
{
DataModel::ListBuilder<DataModel::ServerClusterEntry> builder;
ReadOnlyBufferBuilder<DataModel::ServerClusterEntry> builder;
ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->GetDataModelProvider()->ServerClusters(endpoint, builder));
return aEncoder.EncodeList([&builder](const auto & encoder) -> CHIP_ERROR {
for (const auto & cluster : builder.TakeBuffer())
Expand All @@ -226,7 +226,7 @@ CHIP_ERROR DescriptorAttrAccess::ReadServerClusters(EndpointId endpoint, Attribu

CHIP_ERROR DescriptorAttrAccess::ReadClientClusters(EndpointId endpoint, AttributeValueEncoder & aEncoder)
{
DataModel::ListBuilder<ClusterId> clusterIdList;
ReadOnlyBufferBuilder<ClusterId> clusterIdList;
ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->GetDataModelProvider()->ClientClusters(endpoint, clusterIdList));
return aEncoder.EncodeList([&clusterIdList](const auto & encoder) -> CHIP_ERROR {
for (const auto & id : clusterIdList.TakeBuffer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*
*/

#include "app/data-model-provider/MetadataList.h"
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app/AttributeAccessInterfaceRegistry.h>
#include <app/CommandHandlerInterfaceRegistry.h>
Expand All @@ -27,6 +26,7 @@
#include <app/data-model-provider/MetadataTypes.h>
#include <app/reporting/reporting.h>
#include <app/util/attribute-storage.h>
#include <lib/support/ReadOnlyBuffer.h>

using namespace chip;
using namespace chip::app;
Expand Down Expand Up @@ -251,7 +251,7 @@ void Instance::HandleSetCookingParameters(HandlerContext & ctx, const Commands::
if (startAfterSetting.HasValue())
{

DataModel::ListBuilder<DataModel::AcceptedCommandEntry> acceptedCommandsList;
ReadOnlyBufferBuilder<DataModel::AcceptedCommandEntry> acceptedCommandsList;

InteractionModelEngine::GetInstance()->GetDataModelProvider()->AcceptedCommands(
ConcreteClusterPath(mEndpointId, OperationalState::Id), acceptedCommandsList);
Expand Down
2 changes: 0 additions & 2 deletions src/app/data-model-provider/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ source_set("data-model-provider") {
"ActionReturnStatus.h",
"Context.h",
"EventsGenerator.h",
"MetadataList.cpp",
"MetadataList.h",
"MetadataLookup.cpp",
"MetadataLookup.h",
"OperationTypes.h",
Expand Down
2 changes: 1 addition & 1 deletion src/app/data-model-provider/MetadataLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
#include <app/data-model-provider/MetadataLookup.h>

#include <app/data-model-provider/MetadataList.h>
#include <lib/support/ReadOnlyBuffer.h>

namespace chip {
namespace app {
Expand Down
2 changes: 1 addition & 1 deletion src/app/data-model-provider/MetadataLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

#include <app/ConcreteAttributePath.h>
#include <app/ConcreteClusterPath.h>
#include <app/data-model-provider/MetadataList.h>
#include <app/data-model-provider/MetadataTypes.h>
#include <app/data-model-provider/ProviderMetadataTree.h>
#include <lib/core/DataModelTypes.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/ReadOnlyBuffer.h>
#include <protocols/interaction_model/StatusCode.h>

#include <optional>
Expand Down
8 changes: 4 additions & 4 deletions src/app/data-model-provider/ProviderMetadataTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include <app/data-model-provider/ProviderMetadataTree.h>

#include <app/data-model-provider/MetadataList.h>
#include <lib/support/ReadOnlyBuffer.h>

namespace chip {
namespace app {
Expand All @@ -26,22 +26,22 @@ namespace DataModel {
ReadOnlyBuffer<EndpointEntry> ProviderMetadataTree::EndpointsIgnoreError()
{

ListBuilder<EndpointEntry> builder;
ReadOnlyBufferBuilder<EndpointEntry> builder;
(void) Endpoints(builder);
return builder.TakeBuffer();
}

ReadOnlyBuffer<ServerClusterEntry> ProviderMetadataTree::ServerClustersIgnoreError(EndpointId endpointId)
{

ListBuilder<ServerClusterEntry> builder;
ReadOnlyBufferBuilder<ServerClusterEntry> builder;
(void) ServerClusters(endpointId, builder);
return builder.TakeBuffer();
}

ReadOnlyBuffer<AttributeEntry> ProviderMetadataTree::AttributesIgnoreError(const ConcreteClusterPath & path)
{
ListBuilder<AttributeEntry> builder;
ReadOnlyBufferBuilder<AttributeEntry> builder;
(void) Attributes(path, builder);
return builder.TakeBuffer();
}
Expand Down
21 changes: 11 additions & 10 deletions src/app/data-model-provider/ProviderMetadataTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#include <app/ConcreteAttributePath.h>
#include <app/ConcreteClusterPath.h>
#include <app/ConcreteCommandPath.h>
#include <app/data-model-provider/MetadataList.h>
#include <app/data-model-provider/MetadataTypes.h>
#include <app/data-model/List.h>
#include <lib/support/ReadOnlyBuffer.h>
#include <lib/support/Span.h>

namespace chip {
Expand Down Expand Up @@ -53,12 +53,12 @@ class ProviderMetadataTree

using SemanticTag = Clusters::Descriptor::Structs::SemanticTagStruct::Type;

virtual CHIP_ERROR Endpoints(ListBuilder<EndpointEntry> & builder) = 0;
virtual CHIP_ERROR Endpoints(ReadOnlyBufferBuilder<EndpointEntry> & builder) = 0;

virtual CHIP_ERROR SemanticTags(EndpointId endpointId, ListBuilder<SemanticTag> & builder) = 0;
virtual CHIP_ERROR DeviceTypes(EndpointId endpointId, ListBuilder<DeviceTypeEntry> & builder) = 0;
virtual CHIP_ERROR ClientClusters(EndpointId endpointId, ListBuilder<ClusterId> & builder) = 0;
virtual CHIP_ERROR ServerClusters(EndpointId endpointId, ListBuilder<ServerClusterEntry> & builder) = 0;
virtual CHIP_ERROR SemanticTags(EndpointId endpointId, ReadOnlyBufferBuilder<SemanticTag> & builder) = 0;
virtual CHIP_ERROR DeviceTypes(EndpointId endpointId, ReadOnlyBufferBuilder<DeviceTypeEntry> & builder) = 0;
virtual CHIP_ERROR ClientClusters(EndpointId endpointId, ReadOnlyBufferBuilder<ClusterId> & builder) = 0;
virtual CHIP_ERROR ServerClusters(EndpointId endpointId, ReadOnlyBufferBuilder<ServerClusterEntry> & builder) = 0;

/// Attribute lists contain all attributes. This MUST include all global
/// attributes (See SPEC 7.13 Global Elements / Global Attributes Table).
Expand All @@ -68,9 +68,10 @@ class ProviderMetadataTree
/// - ClusterRevision::Id
/// - FeatureMap::Id
/// - GeneratedCommandList::Id
virtual CHIP_ERROR Attributes(const ConcreteClusterPath & path, ListBuilder<AttributeEntry> & builder) = 0;
virtual CHIP_ERROR GeneratedCommands(const ConcreteClusterPath & path, ListBuilder<CommandId> & builder) = 0;
virtual CHIP_ERROR AcceptedCommands(const ConcreteClusterPath & path, ListBuilder<AcceptedCommandEntry> & builder) = 0;
virtual CHIP_ERROR Attributes(const ConcreteClusterPath & path, ReadOnlyBufferBuilder<AttributeEntry> & builder) = 0;
virtual CHIP_ERROR GeneratedCommands(const ConcreteClusterPath & path, ReadOnlyBufferBuilder<CommandId> & builder) = 0;
virtual CHIP_ERROR AcceptedCommands(const ConcreteClusterPath & path,
ReadOnlyBufferBuilder<AcceptedCommandEntry> & builder) = 0;

/// Workaround function to report attribute change.
///
Expand All @@ -91,7 +92,7 @@ class ProviderMetadataTree
virtual void Temporary_ReportAttributeChanged(const AttributePathParams & path) = 0;

// "convenience" functions that just return the data and ignore the error
// This returns the `ListBuilder<..>::TakeBuffer` from their equivalent fuctions as-is,
// This returns the `ReadOnlyBufferBuilder<..>::TakeBuffer` from their equivalent fuctions as-is,
// even after an error (e.g. not found would return empty data).
//
// Usage of these indicates no error handling (not even logging) and code should
Expand Down
1 change: 0 additions & 1 deletion src/app/data-model-provider/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ chip_test_suite("tests") {
test_sources = [
"TestActionReturnStatus.cpp",
"TestEventEmitting.cpp",
"TestMetadataList.cpp",
]

cflags = [ "-Wconversion" ]
Expand Down
Loading
Loading