Matter SDK Coverage Report
Current view: top level - app/server-cluster - DefaultServerCluster.cpp (source / functions) Coverage Total Hit
Test: SHA:4cbce7f768f16e614f5a8ccb8cd93c92cbeae70d Lines: 100.0 % 28 28
Test Date: 2025-04-26 07:09:35 Functions: 100.0 % 11 11

            Line data    Source code
       1              : /*
       2              :  *    Copyright (c) 2025 Project CHIP Authors
       3              :  *    All rights reserved.
       4              :  *
       5              :  *    Licensed under the Apache License, Version 2.0 (the "License");
       6              :  *    you may not use this file except in compliance with the License.
       7              :  *    You may obtain a copy of the License at
       8              :  *
       9              :  *        http://www.apache.org/licenses/LICENSE-2.0
      10              :  *
      11              :  *    Unless required by applicable law or agreed to in writing, software
      12              :  *    distributed under the License is distributed on an "AS IS" BASIS,
      13              :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14              :  *    See the License for the specific language governing permissions and
      15              :  *    limitations under the License.
      16              :  */
      17              : #include <app/server-cluster/DefaultServerCluster.h>
      18              : 
      19              : #include <access/Privilege.h>
      20              : #include <app-common/zap-generated/ids/Attributes.h>
      21              : #include <app/ConcreteClusterPath.h>
      22              : #include <app/data-model-provider/MetadataTypes.h>
      23              : #include <crypto/RandUtils.h>
      24              : #include <lib/support/BitFlags.h>
      25              : #include <optional>
      26              : #include <protocols/interaction_model/StatusCode.h>
      27              : 
      28              : namespace chip {
      29              : namespace app {
      30              : namespace {
      31              : 
      32              : using namespace chip::app::Clusters;
      33              : using namespace chip::app::DataModel;
      34              : 
      35              : constexpr std::array<AttributeEntry, 5> kGlobalAttributeEntries{ {
      36              :     {
      37              :         Globals::Attributes::ClusterRevision::Id,
      38              :         BitFlags<AttributeQualityFlags>(),
      39              :         Access::Privilege::kView,
      40              :         std::nullopt,
      41              :     },
      42              :     {
      43              :         Globals::Attributes::FeatureMap::Id,
      44              :         BitFlags<AttributeQualityFlags>(),
      45              :         Access::Privilege::kView,
      46              :         std::nullopt,
      47              :     },
      48              :     {
      49              :         Globals::Attributes::AttributeList::Id,
      50              :         BitFlags<AttributeQualityFlags>(AttributeQualityFlags::kListAttribute),
      51              :         Access::Privilege::kView,
      52              :         std::nullopt,
      53              :     },
      54              :     {
      55              :         Globals::Attributes::AcceptedCommandList::Id,
      56              :         BitFlags<AttributeQualityFlags>(AttributeQualityFlags::kListAttribute),
      57              :         Access::Privilege::kView,
      58              :         std::nullopt,
      59              :     },
      60              :     {
      61              :         Globals::Attributes::GeneratedCommandList::Id,
      62              :         BitFlags<AttributeQualityFlags>(AttributeQualityFlags::kListAttribute),
      63              :         Access::Privilege::kView,
      64              :         std::nullopt,
      65              :     },
      66              : } };
      67              : 
      68              : } // namespace
      69              : 
      70            3 : Span<const DataModel::AttributeEntry> DefaultServerCluster::GlobalAttributes()
      71              : {
      72            3 :     return { kGlobalAttributeEntries.data(), kGlobalAttributeEntries.size() };
      73              : }
      74              : 
      75          425 : DefaultServerCluster::DefaultServerCluster(const ConcreteClusterPath & path) : mPath(path)
      76              : {
      77              :     // SPEC - 7.10.3. Cluster Data Version
      78              :     //   A cluster data version SHALL be initialized randomly when it is first published.
      79          425 :     mDataVersion = Crypto::GetRandU32();
      80          425 : }
      81              : 
      82            2 : CHIP_ERROR DefaultServerCluster::Attributes(const ConcreteClusterPath & path, ReadOnlyBufferBuilder<AttributeEntry> & builder)
      83              : {
      84              : 
      85            2 :     return builder.ReferenceExisting(GlobalAttributes());
      86              : }
      87              : 
      88           11 : CHIP_ERROR DefaultServerCluster::Startup(ServerClusterContext & context)
      89              : {
      90           11 :     VerifyOrReturnError(mContext == nullptr, CHIP_ERROR_ALREADY_INITIALIZED);
      91           11 :     mContext = &context;
      92           11 :     return CHIP_NO_ERROR;
      93              : }
      94              : 
      95           11 : void DefaultServerCluster::Shutdown()
      96              : {
      97           11 :     mContext = nullptr;
      98           11 : }
      99              : 
     100            2 : void DefaultServerCluster::NotifyAttributeChanged(AttributeId attributeId)
     101              : {
     102            2 :     IncreaseDataVersion();
     103              : 
     104            2 :     VerifyOrReturn(mContext != nullptr);
     105            1 :     mContext->interactionContext->dataModelChangeListener->MarkDirty({ mPath.mEndpointId, mPath.mClusterId, attributeId });
     106              : }
     107              : 
     108            1 : BitFlags<ClusterQualityFlags> DefaultServerCluster::GetClusterFlags(const ConcreteClusterPath &) const
     109              : {
     110            1 :     return {};
     111              : }
     112              : 
     113            1 : ActionReturnStatus DefaultServerCluster::WriteAttribute(const WriteAttributeRequest & request, AttributeValueDecoder & decoder)
     114              : {
     115            1 :     return Protocols::InteractionModel::Status::UnsupportedWrite;
     116              : }
     117              : 
     118              : std::optional<ActionReturnStatus>
     119            1 : DefaultServerCluster::InvokeCommand(const InvokeRequest & request, chip::TLV::TLVReader & input_arguments, CommandHandler * handler)
     120              : {
     121            1 :     return Protocols::InteractionModel::Status::UnsupportedCommand;
     122              : }
     123              : 
     124            1 : CHIP_ERROR DefaultServerCluster::AcceptedCommands(const ConcreteClusterPath & path,
     125              :                                                   ReadOnlyBufferBuilder<AcceptedCommandEntry> & builder)
     126              : {
     127            1 :     return CHIP_NO_ERROR;
     128              : }
     129              : 
     130            1 : CHIP_ERROR DefaultServerCluster::GeneratedCommands(const ConcreteClusterPath & path, ReadOnlyBufferBuilder<CommandId> & builder)
     131              : {
     132            1 :     return CHIP_NO_ERROR;
     133              : }
     134              : 
     135              : } // namespace app
     136              : } // namespace chip
        

Generated by: LCOV version 2.0-1