LCOV - code coverage report
Current view: top level - app/MessageDef - ReadRequestMessage.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 90 94 95.7 %
Date: 2024-02-15 08:20:41 Functions: 12 12 100.0 %

          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         727 : CHIP_ERROR ReadRequestMessage::Parser::PrettyPrint() const
      30             : {
      31         727 :     CHIP_ERROR err = CHIP_NO_ERROR;
      32             :     TLV::TLVReader reader;
      33             : 
      34         727 :     PRETTY_PRINT("ReadRequestMessage =");
      35         727 :     PRETTY_PRINT("{");
      36             : 
      37             :     // make a copy of the reader
      38         727 :     reader.Init(mReader);
      39             : 
      40        3430 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      41             :     {
      42        2703 :         if (!TLV::IsContextTag(reader.GetTag()))
      43             :         {
      44           0 :             continue;
      45             :         }
      46        2703 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      47        2703 :         switch (tagNum)
      48             :         {
      49         602 :         case to_underlying(Tag::kAttributeRequests): {
      50         602 :             AttributePathIBs::Parser attributeRequests;
      51         602 :             ReturnErrorOnFailure(attributeRequests.Init(reader));
      52             : 
      53         602 :             PRETTY_PRINT_INCDEPTH();
      54         602 :             ReturnErrorOnFailure(attributeRequests.PrettyPrint());
      55         602 :             PRETTY_PRINT_DECDEPTH();
      56             :         }
      57         602 :         break;
      58          12 :         case to_underlying(Tag::kDataVersionFilters): {
      59          12 :             DataVersionFilterIBs::Parser dataVersionFilters;
      60          12 :             ReturnErrorOnFailure(dataVersionFilters.Init(reader));
      61             : 
      62          12 :             PRETTY_PRINT_INCDEPTH();
      63          12 :             ReturnErrorOnFailure(dataVersionFilters.PrettyPrint());
      64          12 :             PRETTY_PRINT_DECDEPTH();
      65             :         }
      66          12 :         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         725 :         case to_underlying(Tag::kIsFabricFiltered):
      86             : #if CHIP_DETAIL_LOGGING
      87             :         {
      88             :             bool isFabricFiltered;
      89         725 :             ReturnErrorOnFailure(reader.Get(isFabricFiltered));
      90         725 :             PRETTY_PRINT("\tisFabricFiltered = %s, ", isFabricFiltered ? "true" : "false");
      91             :         }
      92             : #endif // CHIP_DETAIL_LOGGING
      93         725 :         break;
      94         727 :         case kInteractionModelRevisionTag:
      95         727 :             ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
      96         727 :             break;
      97           0 :         default:
      98           0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      99           0 :             break;
     100             :         }
     101             :     }
     102             : 
     103         727 :     PRETTY_PRINT("},");
     104         727 :     PRETTY_PRINT_BLANK_LINE();
     105             : 
     106         727 :     if (CHIP_END_OF_TLV == err)
     107             :     {
     108         727 :         err = CHIP_NO_ERROR;
     109             :     }
     110             : 
     111         727 :     ReturnErrorOnFailure(err);
     112         727 :     return reader.ExitContainer(mOuterContainerType);
     113             : }
     114             : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
     115             : 
     116        1443 : CHIP_ERROR ReadRequestMessage::Parser::GetAttributeRequests(AttributePathIBs::Parser * const apAttributeRequests) const
     117             : {
     118             :     TLV::TLVReader reader;
     119        1443 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kAttributeRequests), reader));
     120        1201 :     return apAttributeRequests->Init(reader);
     121             : }
     122             : 
     123         600 : CHIP_ERROR ReadRequestMessage::Parser::GetDataVersionFilters(DataVersionFilterIBs::Parser * const apDataVersionFilters) const
     124             : {
     125             :     TLV::TLVReader reader;
     126         600 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kDataVersionFilters), reader));
     127          12 :     return apDataVersionFilters->Init(reader);
     128             : }
     129             : 
     130        1443 : CHIP_ERROR ReadRequestMessage::Parser::GetEventRequests(EventPathIBs::Parser * const apEventRequests) const
     131             : {
     132             :     TLV::TLVReader reader;
     133        1443 :     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             :     TLV::TLVReader reader;
     140         318 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kEventFilters), reader));
     141         315 :     return apEventFilters->Init(reader);
     142             : }
     143             : 
     144         721 : CHIP_ERROR ReadRequestMessage::Parser::GetIsFabricFiltered(bool * const apIsFabricFiltered) const
     145             : {
     146         721 :     return GetSimpleValue(to_underlying(Tag::kIsFabricFiltered), TLV::kTLVType_Boolean, apIsFabricFiltered);
     147             : }
     148             : 
     149         614 : AttributePathIBs::Builder & ReadRequestMessage::Builder::CreateAttributeRequests()
     150             : {
     151             :     // skip if error has already been set
     152         614 :     if (mError == CHIP_NO_ERROR)
     153             :     {
     154         614 :         mError = mAttributeRequests.Init(mpWriter, to_underlying(Tag::kAttributeRequests));
     155             :     }
     156         614 :     return mAttributeRequests;
     157             : }
     158             : 
     159         724 : DataVersionFilterIBs::Builder & ReadRequestMessage::Builder::CreateDataVersionFilters()
     160             : {
     161             :     // skip if error has already been set
     162         724 :     if (mError == CHIP_NO_ERROR)
     163             :     {
     164         724 :         mError = mDataVersionFilters.Init(mpWriter, to_underlying(Tag::kDataVersionFilters));
     165             :     }
     166         724 :     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         731 : ReadRequestMessage::Builder & ReadRequestMessage::Builder::IsFabricFiltered(const bool aIsFabricFiltered)
     190             : {
     191             :     // skip if error has already been set
     192         731 :     if (mError == CHIP_NO_ERROR)
     193             :     {
     194         731 :         mError = mpWriter->PutBoolean(TLV::ContextTag(Tag::kIsFabricFiltered), aIsFabricFiltered);
     195             :     }
     196         731 :     return *this;
     197             : }
     198             : 
     199         735 : CHIP_ERROR ReadRequestMessage::Builder::EndOfReadRequestMessage()
     200             : {
     201         735 :     if (mError == CHIP_NO_ERROR)
     202             :     {
     203         735 :         mError = MessageBuilder::EncodeInteractionModelRevision();
     204             :     }
     205         735 :     if (mError == CHIP_NO_ERROR)
     206             :     {
     207         735 :         EndOfContainer();
     208             :     }
     209         735 :     return GetError();
     210             : }
     211             : } // namespace app
     212             : } // namespace chip

Generated by: LCOV version 1.14