Matter SDK Coverage Report
Current view: top level - app/util - attribute-table.h (source / functions) Coverage Total Hit
Test: SHA:f84fe08d06f240e801b5d923f8a938a9938ca110 Lines: 100.0 % 4 4
Test Date: 2025-02-22 08:08:07 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /**
       2              :  *
       3              :  *    Copyright (c) 2024 Project CHIP Authors
       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              : 
      18              : #pragma once
      19              : 
      20              : #include <app/ConcreteAttributePath.h>
      21              : #include <app/util/AttributesChangedListener.h>
      22              : #include <app/util/MarkAttributeDirty.h>
      23              : #include <app/util/attribute-metadata.h>
      24              : #include <lib/core/DataModelTypes.h>
      25              : #include <protocols/interaction_model/StatusCode.h>
      26              : 
      27              : #include <cstdint>
      28              : 
      29              : struct EmberAfWriteDataInput
      30              : {
      31              :     // Where the input data originates from.
      32              :     //
      33              :     // NOTE: at this time there is no information regarding
      34              :     // input buffer size and it is assumed "correct" for the given data type.
      35              :     //
      36              :     // NOTE: technically this should be `const uint8_t*`, however ember internal logic uses a
      37              :     //       `emAfReadOrWriteAttribute` method and because of the duality of read/write it needs
      38              :     //       a non-const input. This is odd and should probably be fixed.
      39              :     uint8_t * dataPtr;
      40              : 
      41              :     // The data type that dataPtr points to
      42              :     EmberAfAttributeType dataType;
      43              : 
      44              :     // Controls when `changeListener` is called to flag an attribute dirty. It allows for things like:
      45              :     //     kIfChanged - only if the dataPtr contains a different value than what currenty exists
      46              :     //     kNo - never called
      47              :     //     kYes - always called
      48              :     chip::app::MarkAttributeDirty markDirty = chip::app::MarkAttributeDirty::kIfChanged;
      49              : 
      50              :     // Listener called when when the written data is consided changed/dirty.
      51              :     // This being called depends on settings of `markDirty` combined with the actual contents of dataPtr
      52              :     // vs the contents of the current attribute storage.
      53              :     chip::app::AttributesChangedListener * changeListener = nullptr;
      54              : 
      55          116 :     EmberAfWriteDataInput(uint8_t * data, EmberAfAttributeType type) : dataPtr(data), dataType(type) {}
      56              : 
      57              :     EmberAfWriteDataInput & SetMarkDirty(chip::app::MarkAttributeDirty value)
      58              :     {
      59              :         markDirty = value;
      60              :         return *this;
      61              :     }
      62              : 
      63          116 :     EmberAfWriteDataInput & SetChangeListener(chip::app::AttributesChangedListener * listener)
      64              :     {
      65          116 :         changeListener = listener;
      66          116 :         return *this;
      67              :     }
      68              : };
      69              : 
      70              : /**
      71              :  * @brief write an attribute, performing all the checks.
      72              :  *
      73              :  * TODO: what are "all the checks"? There are limitations below
      74              :  *       and generally input data pointer does not even have a size,
      75              :  *       hence data validity check capabilities seem limited.
      76              :  *
      77              :  * This function will attempt to write the attribute value from
      78              :  * the provided pointer. This function will only check that the
      79              :  * attribute exists. If it does it will write the value into
      80              :  * the attribute table for the given attribute.
      81              :  *
      82              :  * This function will not check to see if the attribute is
      83              :  * writable since the read only / writable characteristic
      84              :  * of an attribute only pertains to external devices writing
      85              :  * over the air. Because this function is being called locally
      86              :  * it assumes that the device knows what it is doing and has permission
      87              :  * to perform the given operation.
      88              :  *
      89              :  * This function also does NOT check that the input dataType matches the expected
      90              :  * data type (as Accessors.h/cpp have this correct by default).
      91              :  * TODO: this not checking seems off - what if this is run without Accessors.h ?
      92              :  */
      93              : chip::Protocols::InteractionModel::Status emberAfWriteAttribute(const chip::app::ConcreteAttributePath & path,
      94              :                                                                 const EmberAfWriteDataInput & input);
      95              : 
      96              : /**
      97              :  * Override of emberAfWriteAttribute to reduce code size for calls that default
      98              :  * markDirty/changeListener and any other future customization calls.
      99              :  */
     100              : chip::Protocols::InteractionModel::Status emberAfWriteAttribute(chip::EndpointId endpoint, chip::ClusterId cluster,
     101              :                                                                 chip::AttributeId attributeID, uint8_t * dataPtr,
     102              :                                                                 EmberAfAttributeType dataType);
     103              : 
     104              : /**
     105              :  * @brief Read the attribute value, performing all the checks.
     106              :  *
     107              :  * This function will attempt to read the attribute and store it into the
     108              :  * pointer.
     109              :  *
     110              :  * dataPtr may be NULL, signifying that we don't need the value, just the status
     111              :  * (i.e. whether the attribute can be read).
     112              :  */
     113              : chip::Protocols::InteractionModel::Status emberAfReadAttribute(chip::EndpointId endpoint, chip::ClusterId cluster,
     114              :                                                                chip::AttributeId attributeID, uint8_t * dataPtr,
     115              :                                                                uint16_t readLength);
        

Generated by: LCOV version 2.0-1