Matter SDK Coverage Report
Current view: top level - app/MessageDef - SubscribeRequestMessage.cpp (source / functions) Coverage Total Hit
Test: SHA:4cbce7f768f16e614f5a8ccb8cd93c92cbeae70d Lines: 97.0 % 132 128
Test Date: 2025-04-26 07:09:35 Functions: 100.0 % 18 18

            Line data    Source code
       1              : /**
       2              :  *
       3              :  *    Copyright (c) 2021 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 "SubscribeRequestMessage.h"
      18              : #include "MessageDefHelper.h"
      19              : 
      20              : namespace chip {
      21              : namespace app {
      22              : #if CHIP_CONFIG_IM_PRETTY_PRINT
      23          308 : CHIP_ERROR SubscribeRequestMessage::Parser::PrettyPrint() const
      24              : {
      25          308 :     CHIP_ERROR err = CHIP_NO_ERROR;
      26          308 :     TLV::TLVReader reader;
      27              : 
      28          308 :     PRETTY_PRINT("SubscribeRequestMessage =");
      29          308 :     PRETTY_PRINT("{");
      30              : 
      31              :     // make a copy of the reader
      32          308 :     reader.Init(mReader);
      33              : 
      34         2235 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      35              :     {
      36         1927 :         if (!TLV::IsContextTag(reader.GetTag()))
      37              :         {
      38            0 :             continue;
      39              :         }
      40         1927 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      41         1927 :         switch (tagNum)
      42              :         {
      43          308 :         case to_underlying(Tag::kKeepSubscriptions):
      44          308 :             VerifyOrReturnError(TLV::kTLVType_Boolean == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      45              : #if CHIP_DETAIL_LOGGING
      46              :             {
      47              :                 bool keepSubscriptions;
      48          308 :                 ReturnErrorOnFailure(reader.Get(keepSubscriptions));
      49          308 :                 PRETTY_PRINT("\tKeepSubscriptions = %s, ", keepSubscriptions ? "true" : "false");
      50              :             }
      51              : #endif // CHIP_DETAIL_LOGGING
      52          308 :             break;
      53          308 :         case to_underlying(Tag::kMinIntervalFloorSeconds):
      54          308 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      55              : #if CHIP_DETAIL_LOGGING
      56              :             {
      57              :                 uint16_t MinIntervalFloorSeconds;
      58          308 :                 ReturnErrorOnFailure(reader.Get(MinIntervalFloorSeconds));
      59          308 :                 PRETTY_PRINT("\tMinIntervalFloorSeconds = 0x%x,", MinIntervalFloorSeconds);
      60              :             }
      61              : #endif // CHIP_DETAIL_LOGGING
      62          308 :             break;
      63          308 :         case to_underlying(Tag::kMaxIntervalCeilingSeconds):
      64          308 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      65              : #if CHIP_DETAIL_LOGGING
      66              :             {
      67              :                 uint16_t MaxIntervalCeilingSeconds;
      68          308 :                 ReturnErrorOnFailure(reader.Get(MaxIntervalCeilingSeconds));
      69          308 :                 PRETTY_PRINT("\tMaxIntervalCeilingSeconds = 0x%x,", MaxIntervalCeilingSeconds);
      70              :             }
      71              : #endif // CHIP_DETAIL_LOGGING
      72          308 :             break;
      73          301 :         case to_underlying(Tag::kAttributeRequests): {
      74          301 :             AttributePathIBs::Parser attributeRequests;
      75          301 :             ReturnErrorOnFailure(attributeRequests.Init(reader));
      76              : 
      77          301 :             PRETTY_PRINT_INCDEPTH();
      78          301 :             ReturnErrorOnFailure(attributeRequests.PrettyPrint());
      79          301 :             PRETTY_PRINT_DECDEPTH();
      80              :         }
      81          301 :         break;
      82           66 :         case to_underlying(Tag::kDataVersionFilters): {
      83           66 :             DataVersionFilterIBs::Parser dataVersionFilters;
      84           66 :             ReturnErrorOnFailure(dataVersionFilters.Init(reader));
      85              : 
      86           66 :             PRETTY_PRINT_INCDEPTH();
      87           66 :             ReturnErrorOnFailure(dataVersionFilters.PrettyPrint());
      88           66 :             PRETTY_PRINT_DECDEPTH();
      89              :         }
      90           66 :         break;
      91           19 :         case to_underlying(Tag::kEventRequests): {
      92           19 :             EventPathIBs::Parser eventRequests;
      93           19 :             ReturnErrorOnFailure(eventRequests.Init(reader));
      94              : 
      95           19 :             PRETTY_PRINT_INCDEPTH();
      96           19 :             ReturnErrorOnFailure(eventRequests.PrettyPrint());
      97           19 :             PRETTY_PRINT_DECDEPTH();
      98              :         }
      99           19 :         break;
     100            1 :         case to_underlying(Tag::kEventFilters): {
     101            1 :             EventFilterIBs::Parser eventFilters;
     102            1 :             ReturnErrorOnFailure(eventFilters.Init(reader));
     103              : 
     104            1 :             PRETTY_PRINT_INCDEPTH();
     105            1 :             ReturnErrorOnFailure(eventFilters.PrettyPrint());
     106            1 :             PRETTY_PRINT_DECDEPTH();
     107              :         }
     108            1 :         break;
     109          308 :         case to_underlying(Tag::kIsFabricFiltered):
     110              : #if CHIP_DETAIL_LOGGING
     111              :         {
     112              :             bool isFabricFiltered;
     113          308 :             ReturnErrorOnFailure(reader.Get(isFabricFiltered));
     114          308 :             PRETTY_PRINT("\tisFabricFiltered = %s, ", isFabricFiltered ? "true" : "false");
     115              :         }
     116              : #endif // CHIP_DETAIL_LOGGING
     117          308 :         break;
     118          308 :         case Revision::kInteractionModelRevisionTag:
     119          308 :             ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
     120          308 :             break;
     121            0 :         default:
     122            0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
     123            0 :             break;
     124              :         }
     125              :     }
     126              : 
     127          308 :     PRETTY_PRINT("},");
     128          308 :     PRETTY_PRINT_BLANK_LINE();
     129              : 
     130          308 :     if (CHIP_END_OF_TLV == err)
     131              :     {
     132          308 :         err = CHIP_NO_ERROR;
     133              :     }
     134              : 
     135          308 :     ReturnErrorOnFailure(err);
     136          308 :     return reader.ExitContainer(mOuterContainerType);
     137              : }
     138              : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
     139              : 
     140          308 : CHIP_ERROR SubscribeRequestMessage::Parser::GetKeepSubscriptions(bool * const apKeepExistingSubscription) const
     141              : {
     142          308 :     return GetSimpleValue(to_underlying(Tag::kKeepSubscriptions), TLV::kTLVType_Boolean, apKeepExistingSubscription);
     143              : }
     144              : 
     145          306 : CHIP_ERROR SubscribeRequestMessage::Parser::GetMinIntervalFloorSeconds(uint16_t * const apMinIntervalFloorSeconds) const
     146              : {
     147          306 :     return GetUnsignedInteger(to_underlying(Tag::kMinIntervalFloorSeconds), apMinIntervalFloorSeconds);
     148              : }
     149              : 
     150          306 : CHIP_ERROR SubscribeRequestMessage::Parser::GetMaxIntervalCeilingSeconds(uint16_t * const apMaxIntervalCeilingSeconds) const
     151              : {
     152          306 :     return GetUnsignedInteger(to_underlying(Tag::kMaxIntervalCeilingSeconds), apMaxIntervalCeilingSeconds);
     153              : }
     154              : 
     155          613 : CHIP_ERROR SubscribeRequestMessage::Parser::GetAttributeRequests(AttributePathIBs::Parser * const apAttributeRequests) const
     156              : {
     157          613 :     TLV::TLVReader reader;
     158          613 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kAttributeRequests), reader));
     159          600 :     return apAttributeRequests->Init(reader);
     160              : }
     161              : 
     162          300 : CHIP_ERROR SubscribeRequestMessage::Parser::GetDataVersionFilters(DataVersionFilterIBs::Parser * const apDataVersionFilters) const
     163              : {
     164          300 :     TLV::TLVReader reader;
     165          300 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kDataVersionFilters), reader));
     166           66 :     return apDataVersionFilters->Init(reader);
     167              : }
     168              : 
     169          613 : CHIP_ERROR SubscribeRequestMessage::Parser::GetEventRequests(EventPathIBs::Parser * const apEventRequests) const
     170              : {
     171          613 :     TLV::TLVReader reader;
     172          613 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kEventRequests), reader));
     173           37 :     return apEventRequests->Init(reader);
     174              : }
     175              : 
     176           19 : CHIP_ERROR SubscribeRequestMessage::Parser::GetEventFilters(EventFilterIBs::Parser * const apEventFilters) const
     177              : {
     178           19 :     TLV::TLVReader reader;
     179           19 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kEventFilters), reader));
     180            1 :     return apEventFilters->Init(reader);
     181              : }
     182              : 
     183          300 : CHIP_ERROR SubscribeRequestMessage::Parser::GetIsFabricFiltered(bool * const apIsFabricFiltered) const
     184              : {
     185          300 :     return GetSimpleValue(to_underlying(Tag::kIsFabricFiltered), TLV::kTLVType_Boolean, apIsFabricFiltered);
     186              : }
     187              : 
     188          316 : SubscribeRequestMessage::Builder & SubscribeRequestMessage::Builder::KeepSubscriptions(const bool aKeepSubscriptions)
     189              : {
     190          316 :     if (mError == CHIP_NO_ERROR)
     191              :     {
     192          316 :         mError = mpWriter->PutBoolean(TLV::ContextTag(Tag::kKeepSubscriptions), aKeepSubscriptions);
     193              :     }
     194          316 :     return *this;
     195              : }
     196              : 
     197              : SubscribeRequestMessage::Builder &
     198          316 : SubscribeRequestMessage::Builder::MinIntervalFloorSeconds(const uint16_t aMinIntervalFloorSeconds)
     199              : {
     200          316 :     if (mError == CHIP_NO_ERROR)
     201              :     {
     202          316 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kMinIntervalFloorSeconds), aMinIntervalFloorSeconds);
     203              :     }
     204          316 :     return *this;
     205              : }
     206              : 
     207              : SubscribeRequestMessage::Builder &
     208          316 : SubscribeRequestMessage::Builder::MaxIntervalCeilingSeconds(const uint16_t aMaxIntervalCeilingSeconds)
     209              : {
     210          316 :     if (mError == CHIP_NO_ERROR)
     211              :     {
     212          316 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kMaxIntervalCeilingSeconds), aMaxIntervalCeilingSeconds);
     213              :     }
     214          316 :     return *this;
     215              : }
     216              : 
     217          309 : AttributePathIBs::Builder & SubscribeRequestMessage::Builder::CreateAttributeRequests()
     218              : {
     219          309 :     if (mError == CHIP_NO_ERROR)
     220              :     {
     221          309 :         mError = mAttributeRequests.Init(mpWriter, to_underlying(Tag::kAttributeRequests));
     222              :     }
     223          309 :     return mAttributeRequests;
     224              : }
     225              : 
     226          312 : DataVersionFilterIBs::Builder & SubscribeRequestMessage::Builder::CreateDataVersionFilters()
     227              : {
     228              :     // skip if error has already been set
     229          312 :     if (mError == CHIP_NO_ERROR)
     230              :     {
     231          312 :         mError = mDataVersionFilters.Init(mpWriter, to_underlying(Tag::kDataVersionFilters));
     232              :     }
     233          312 :     return mDataVersionFilters;
     234              : }
     235              : 
     236           23 : EventPathIBs::Builder & SubscribeRequestMessage::Builder::CreateEventRequests()
     237              : {
     238           23 :     if (mError == CHIP_NO_ERROR)
     239              :     {
     240           23 :         mError = mEventRequests.Init(mpWriter, to_underlying(Tag::kEventRequests));
     241              :     }
     242           23 :     return mEventRequests;
     243              : }
     244              : 
     245            1 : EventFilterIBs::Builder & SubscribeRequestMessage::Builder::CreateEventFilters()
     246              : {
     247            1 :     if (mError == CHIP_NO_ERROR)
     248              :     {
     249            1 :         mError = mEventFilters.Init(mpWriter, to_underlying(Tag::kEventFilters));
     250              :     }
     251            1 :     return mEventFilters;
     252              : }
     253              : 
     254          316 : SubscribeRequestMessage::Builder & SubscribeRequestMessage::Builder::IsFabricFiltered(const bool aIsFabricFiltered)
     255              : {
     256              :     // skip if error has already been set
     257          316 :     if (mError == CHIP_NO_ERROR)
     258              :     {
     259          316 :         mError = mpWriter->PutBoolean(TLV::ContextTag(Tag::kIsFabricFiltered), aIsFabricFiltered);
     260              :     }
     261          316 :     return *this;
     262              : }
     263              : 
     264          316 : CHIP_ERROR SubscribeRequestMessage::Builder::EndOfSubscribeRequestMessage()
     265              : {
     266          316 :     if (mError == CHIP_NO_ERROR)
     267              :     {
     268          316 :         mError = MessageBuilder::EncodeInteractionModelRevision();
     269              :     }
     270          316 :     if (mError == CHIP_NO_ERROR)
     271              :     {
     272          316 :         EndOfContainer();
     273              :     }
     274          316 :     return GetError();
     275              : }
     276              : } // namespace app
     277              : } // namespace chip
        

Generated by: LCOV version 2.0-1