Matter SDK Coverage Report
Current view: top level - app/MessageDef - ReadRequestMessage.cpp (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 96.0 % 99 95
Test Date: 2025-01-17 19:00:11 Functions: 100.0 % 12 12

            Line data    Source code
       1              : /**
       2              :  *
       3              :  *    Copyright (c) 2020 Project CHIP Authors
       4              :  *    Licensed under the Apache License, Version 2.0 (the "License");
       5              :  *    you may not use this file except in compliance with the License.
       6              :  *    You may obtain a copy of the License at
       7              :  *
       8              :  *        http://www.apache.org/licenses/LICENSE-2.0
       9              :  *
      10              :  *    Unless required by applicable law or agreed to in writing, software
      11              :  *    distributed under the License is distributed on an "AS IS" BASIS,
      12              :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13              :  *    See the License for the specific language governing permissions and
      14              :  *    limitations under the License.
      15              :  */
      16              : 
      17              : #include "ReadRequestMessage.h"
      18              : #include "MessageDefHelper.h"
      19              : 
      20              : #include <inttypes.h>
      21              : #include <stdarg.h>
      22              : #include <stdio.h>
      23              : 
      24              : #include <app/AppConfig.h>
      25              : 
      26              : namespace chip {
      27              : namespace app {
      28              : #if CHIP_CONFIG_IM_PRETTY_PRINT
      29          796 : CHIP_ERROR ReadRequestMessage::Parser::PrettyPrint() const
      30              : {
      31          796 :     CHIP_ERROR err = CHIP_NO_ERROR;
      32          796 :     TLV::TLVReader reader;
      33              : 
      34          796 :     PRETTY_PRINT("ReadRequestMessage =");
      35          796 :     PRETTY_PRINT("{");
      36              : 
      37              :     // make a copy of the reader
      38          796 :     reader.Init(mReader);
      39              : 
      40         3775 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      41              :     {
      42         2979 :         if (!TLV::IsContextTag(reader.GetTag()))
      43              :         {
      44            0 :             continue;
      45              :         }
      46         2979 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      47         2979 :         switch (tagNum)
      48              :         {
      49          671 :         case to_underlying(Tag::kAttributeRequests): {
      50          671 :             AttributePathIBs::Parser attributeRequests;
      51          671 :             ReturnErrorOnFailure(attributeRequests.Init(reader));
      52              : 
      53          671 :             PRETTY_PRINT_INCDEPTH();
      54          671 :             ReturnErrorOnFailure(attributeRequests.PrettyPrint());
      55          671 :             PRETTY_PRINT_DECDEPTH();
      56              :         }
      57          671 :         break;
      58           81 :         case to_underlying(Tag::kDataVersionFilters): {
      59           81 :             DataVersionFilterIBs::Parser dataVersionFilters;
      60           81 :             ReturnErrorOnFailure(dataVersionFilters.Init(reader));
      61              : 
      62           81 :             PRETTY_PRINT_INCDEPTH();
      63           81 :             ReturnErrorOnFailure(dataVersionFilters.PrettyPrint());
      64           81 :             PRETTY_PRINT_DECDEPTH();
      65              :         }
      66           81 :         break;
      67          322 :         case to_underlying(Tag::kEventRequests): {
      68          322 :             EventPathIBs::Parser eventRequests;
      69          322 :             ReturnErrorOnFailure(eventRequests.Init(reader));
      70              : 
      71          322 :             PRETTY_PRINT_INCDEPTH();
      72          322 :             ReturnErrorOnFailure(eventRequests.PrettyPrint());
      73          322 :             PRETTY_PRINT_DECDEPTH();
      74              :         }
      75          322 :         break;
      76          315 :         case to_underlying(Tag::kEventFilters): {
      77          315 :             EventFilterIBs::Parser eventFilters;
      78          315 :             ReturnErrorOnFailure(eventFilters.Init(reader));
      79              : 
      80          315 :             PRETTY_PRINT_INCDEPTH();
      81          315 :             ReturnErrorOnFailure(eventFilters.PrettyPrint());
      82          315 :             PRETTY_PRINT_DECDEPTH();
      83              :         }
      84          315 :         break;
      85          794 :         case to_underlying(Tag::kIsFabricFiltered):
      86              : #if CHIP_DETAIL_LOGGING
      87              :         {
      88              :             bool isFabricFiltered;
      89          794 :             ReturnErrorOnFailure(reader.Get(isFabricFiltered));
      90          794 :             PRETTY_PRINT("\tisFabricFiltered = %s, ", isFabricFiltered ? "true" : "false");
      91              :         }
      92              : #endif // CHIP_DETAIL_LOGGING
      93          794 :         break;
      94          796 :         case Revision::kInteractionModelRevisionTag:
      95          796 :             ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
      96          796 :             break;
      97            0 :         default:
      98            0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      99            0 :             break;
     100              :         }
     101              :     }
     102              : 
     103          796 :     PRETTY_PRINT("},");
     104          796 :     PRETTY_PRINT_BLANK_LINE();
     105              : 
     106          796 :     if (CHIP_END_OF_TLV == err)
     107              :     {
     108          796 :         err = CHIP_NO_ERROR;
     109              :     }
     110              : 
     111          796 :     ReturnErrorOnFailure(err);
     112          796 :     return reader.ExitContainer(mOuterContainerType);
     113              : }
     114              : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
     115              : 
     116         1581 : CHIP_ERROR ReadRequestMessage::Parser::GetAttributeRequests(AttributePathIBs::Parser * const apAttributeRequests) const
     117              : {
     118         1581 :     TLV::TLVReader reader;
     119         1581 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kAttributeRequests), reader));
     120         1339 :     return apAttributeRequests->Init(reader);
     121              : }
     122              : 
     123          669 : CHIP_ERROR ReadRequestMessage::Parser::GetDataVersionFilters(DataVersionFilterIBs::Parser * const apDataVersionFilters) const
     124              : {
     125          669 :     TLV::TLVReader reader;
     126          669 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kDataVersionFilters), reader));
     127           81 :     return apDataVersionFilters->Init(reader);
     128              : }
     129              : 
     130         1581 : CHIP_ERROR ReadRequestMessage::Parser::GetEventRequests(EventPathIBs::Parser * const apEventRequests) const
     131              : {
     132         1581 :     TLV::TLVReader reader;
     133         1581 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kEventRequests), reader));
     134          635 :     return apEventRequests->Init(reader);
     135              : }
     136              : 
     137          318 : CHIP_ERROR ReadRequestMessage::Parser::GetEventFilters(EventFilterIBs::Parser * const apEventFilters) const
     138              : {
     139          318 :     TLV::TLVReader reader;
     140          318 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kEventFilters), reader));
     141          315 :     return apEventFilters->Init(reader);
     142              : }
     143              : 
     144          790 : CHIP_ERROR ReadRequestMessage::Parser::GetIsFabricFiltered(bool * const apIsFabricFiltered) const
     145              : {
     146          790 :     return GetSimpleValue(to_underlying(Tag::kIsFabricFiltered), TLV::kTLVType_Boolean, apIsFabricFiltered);
     147              : }
     148              : 
     149          683 : AttributePathIBs::Builder & ReadRequestMessage::Builder::CreateAttributeRequests()
     150              : {
     151              :     // skip if error has already been set
     152          683 :     if (mError == CHIP_NO_ERROR)
     153              :     {
     154          683 :         mError = mAttributeRequests.Init(mpWriter, to_underlying(Tag::kAttributeRequests));
     155              :     }
     156          683 :     return mAttributeRequests;
     157              : }
     158              : 
     159          793 : DataVersionFilterIBs::Builder & ReadRequestMessage::Builder::CreateDataVersionFilters()
     160              : {
     161              :     // skip if error has already been set
     162          793 :     if (mError == CHIP_NO_ERROR)
     163              :     {
     164          793 :         mError = mDataVersionFilters.Init(mpWriter, to_underlying(Tag::kDataVersionFilters));
     165              :     }
     166          793 :     return mDataVersionFilters;
     167              : }
     168              : 
     169          322 : EventPathIBs::Builder & ReadRequestMessage::Builder::CreateEventRequests()
     170              : {
     171              :     // skip if error has already been set
     172          322 :     if (mError == CHIP_NO_ERROR)
     173              :     {
     174          322 :         mError = mEventRequests.Init(mpWriter, to_underlying(Tag::kEventRequests));
     175              :     }
     176          322 :     return mEventRequests;
     177              : }
     178              : 
     179          315 : EventFilterIBs::Builder & ReadRequestMessage::Builder::CreateEventFilters()
     180              : {
     181              :     // skip if error has already been set
     182          315 :     if (mError == CHIP_NO_ERROR)
     183              :     {
     184          315 :         mError = mEventFilters.Init(mpWriter, to_underlying(Tag::kEventFilters));
     185              :     }
     186          315 :     return mEventFilters;
     187              : }
     188              : 
     189          800 : ReadRequestMessage::Builder & ReadRequestMessage::Builder::IsFabricFiltered(const bool aIsFabricFiltered)
     190              : {
     191              :     // skip if error has already been set
     192          800 :     if (mError == CHIP_NO_ERROR)
     193              :     {
     194          800 :         mError = mpWriter->PutBoolean(TLV::ContextTag(Tag::kIsFabricFiltered), aIsFabricFiltered);
     195              :     }
     196          800 :     return *this;
     197              : }
     198              : 
     199          804 : CHIP_ERROR ReadRequestMessage::Builder::EndOfReadRequestMessage()
     200              : {
     201          804 :     if (mError == CHIP_NO_ERROR)
     202              :     {
     203          804 :         mError = MessageBuilder::EncodeInteractionModelRevision();
     204              :     }
     205          804 :     if (mError == CHIP_NO_ERROR)
     206              :     {
     207          804 :         EndOfContainer();
     208              :     }
     209          804 :     return GetError();
     210              : }
     211              : } // namespace app
     212              : } // namespace chip
        

Generated by: LCOV version 2.0-1