Matter SDK Coverage Report
Current view: top level - app/MessageDef - SubscribeRequestMessage.cpp (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 97.0 % 132 128
Test Date: 2025-01-17 19:00:11 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          236 : CHIP_ERROR SubscribeRequestMessage::Parser::PrettyPrint() const
      24              : {
      25          236 :     CHIP_ERROR err = CHIP_NO_ERROR;
      26          236 :     TLV::TLVReader reader;
      27              : 
      28          236 :     PRETTY_PRINT("SubscribeRequestMessage =");
      29          236 :     PRETTY_PRINT("{");
      30              : 
      31              :     // make a copy of the reader
      32          236 :     reader.Init(mReader);
      33              : 
      34         1731 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      35              :     {
      36         1495 :         if (!TLV::IsContextTag(reader.GetTag()))
      37              :         {
      38            0 :             continue;
      39              :         }
      40         1495 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      41         1495 :         switch (tagNum)
      42              :         {
      43          236 :         case to_underlying(Tag::kKeepSubscriptions):
      44          236 :             VerifyOrReturnError(TLV::kTLVType_Boolean == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      45              : #if CHIP_DETAIL_LOGGING
      46              :             {
      47              :                 bool keepSubscriptions;
      48          236 :                 ReturnErrorOnFailure(reader.Get(keepSubscriptions));
      49          236 :                 PRETTY_PRINT("\tKeepSubscriptions = %s, ", keepSubscriptions ? "true" : "false");
      50              :             }
      51              : #endif // CHIP_DETAIL_LOGGING
      52          236 :             break;
      53          236 :         case to_underlying(Tag::kMinIntervalFloorSeconds):
      54          236 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      55              : #if CHIP_DETAIL_LOGGING
      56              :             {
      57              :                 uint16_t MinIntervalFloorSeconds;
      58          236 :                 ReturnErrorOnFailure(reader.Get(MinIntervalFloorSeconds));
      59          236 :                 PRETTY_PRINT("\tMinIntervalFloorSeconds = 0x%x,", MinIntervalFloorSeconds);
      60              :             }
      61              : #endif // CHIP_DETAIL_LOGGING
      62          236 :             break;
      63          236 :         case to_underlying(Tag::kMaxIntervalCeilingSeconds):
      64          236 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      65              : #if CHIP_DETAIL_LOGGING
      66              :             {
      67              :                 uint16_t MaxIntervalCeilingSeconds;
      68          236 :                 ReturnErrorOnFailure(reader.Get(MaxIntervalCeilingSeconds));
      69          236 :                 PRETTY_PRINT("\tMaxIntervalCeilingSeconds = 0x%x,", MaxIntervalCeilingSeconds);
      70              :             }
      71              : #endif // CHIP_DETAIL_LOGGING
      72          236 :             break;
      73          229 :         case to_underlying(Tag::kAttributeRequests): {
      74          229 :             AttributePathIBs::Parser attributeRequests;
      75          229 :             ReturnErrorOnFailure(attributeRequests.Init(reader));
      76              : 
      77          229 :             PRETTY_PRINT_INCDEPTH();
      78          229 :             ReturnErrorOnFailure(attributeRequests.PrettyPrint());
      79          229 :             PRETTY_PRINT_DECDEPTH();
      80              :         }
      81          229 :         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          236 :         case to_underlying(Tag::kIsFabricFiltered):
     110              : #if CHIP_DETAIL_LOGGING
     111              :         {
     112              :             bool isFabricFiltered;
     113          236 :             ReturnErrorOnFailure(reader.Get(isFabricFiltered));
     114          236 :             PRETTY_PRINT("\tisFabricFiltered = %s, ", isFabricFiltered ? "true" : "false");
     115              :         }
     116              : #endif // CHIP_DETAIL_LOGGING
     117          236 :         break;
     118          236 :         case Revision::kInteractionModelRevisionTag:
     119          236 :             ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
     120          236 :             break;
     121            0 :         default:
     122            0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
     123            0 :             break;
     124              :         }
     125              :     }
     126              : 
     127          236 :     PRETTY_PRINT("},");
     128          236 :     PRETTY_PRINT_BLANK_LINE();
     129              : 
     130          236 :     if (CHIP_END_OF_TLV == err)
     131              :     {
     132          236 :         err = CHIP_NO_ERROR;
     133              :     }
     134              : 
     135          236 :     ReturnErrorOnFailure(err);
     136          236 :     return reader.ExitContainer(mOuterContainerType);
     137              : }
     138              : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
     139              : 
     140          236 : CHIP_ERROR SubscribeRequestMessage::Parser::GetKeepSubscriptions(bool * const apKeepExistingSubscription) const
     141              : {
     142          236 :     return GetSimpleValue(to_underlying(Tag::kKeepSubscriptions), TLV::kTLVType_Boolean, apKeepExistingSubscription);
     143              : }
     144              : 
     145          234 : CHIP_ERROR SubscribeRequestMessage::Parser::GetMinIntervalFloorSeconds(uint16_t * const apMinIntervalFloorSeconds) const
     146              : {
     147          234 :     return GetUnsignedInteger(to_underlying(Tag::kMinIntervalFloorSeconds), apMinIntervalFloorSeconds);
     148              : }
     149              : 
     150          234 : CHIP_ERROR SubscribeRequestMessage::Parser::GetMaxIntervalCeilingSeconds(uint16_t * const apMaxIntervalCeilingSeconds) const
     151              : {
     152          234 :     return GetUnsignedInteger(to_underlying(Tag::kMaxIntervalCeilingSeconds), apMaxIntervalCeilingSeconds);
     153              : }
     154              : 
     155          469 : CHIP_ERROR SubscribeRequestMessage::Parser::GetAttributeRequests(AttributePathIBs::Parser * const apAttributeRequests) const
     156              : {
     157          469 :     TLV::TLVReader reader;
     158          469 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kAttributeRequests), reader));
     159          456 :     return apAttributeRequests->Init(reader);
     160              : }
     161              : 
     162          228 : CHIP_ERROR SubscribeRequestMessage::Parser::GetDataVersionFilters(DataVersionFilterIBs::Parser * const apDataVersionFilters) const
     163              : {
     164          228 :     TLV::TLVReader reader;
     165          228 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kDataVersionFilters), reader));
     166           66 :     return apDataVersionFilters->Init(reader);
     167              : }
     168              : 
     169          469 : CHIP_ERROR SubscribeRequestMessage::Parser::GetEventRequests(EventPathIBs::Parser * const apEventRequests) const
     170              : {
     171          469 :     TLV::TLVReader reader;
     172          469 :     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          228 : CHIP_ERROR SubscribeRequestMessage::Parser::GetIsFabricFiltered(bool * const apIsFabricFiltered) const
     184              : {
     185          228 :     return GetSimpleValue(to_underlying(Tag::kIsFabricFiltered), TLV::kTLVType_Boolean, apIsFabricFiltered);
     186              : }
     187              : 
     188          244 : SubscribeRequestMessage::Builder & SubscribeRequestMessage::Builder::KeepSubscriptions(const bool aKeepSubscriptions)
     189              : {
     190          244 :     if (mError == CHIP_NO_ERROR)
     191              :     {
     192          244 :         mError = mpWriter->PutBoolean(TLV::ContextTag(Tag::kKeepSubscriptions), aKeepSubscriptions);
     193              :     }
     194          244 :     return *this;
     195              : }
     196              : 
     197              : SubscribeRequestMessage::Builder &
     198          244 : SubscribeRequestMessage::Builder::MinIntervalFloorSeconds(const uint16_t aMinIntervalFloorSeconds)
     199              : {
     200          244 :     if (mError == CHIP_NO_ERROR)
     201              :     {
     202          244 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kMinIntervalFloorSeconds), aMinIntervalFloorSeconds);
     203              :     }
     204          244 :     return *this;
     205              : }
     206              : 
     207              : SubscribeRequestMessage::Builder &
     208          244 : SubscribeRequestMessage::Builder::MaxIntervalCeilingSeconds(const uint16_t aMaxIntervalCeilingSeconds)
     209              : {
     210          244 :     if (mError == CHIP_NO_ERROR)
     211              :     {
     212          244 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kMaxIntervalCeilingSeconds), aMaxIntervalCeilingSeconds);
     213              :     }
     214          244 :     return *this;
     215              : }
     216              : 
     217          237 : AttributePathIBs::Builder & SubscribeRequestMessage::Builder::CreateAttributeRequests()
     218              : {
     219          237 :     if (mError == CHIP_NO_ERROR)
     220              :     {
     221          237 :         mError = mAttributeRequests.Init(mpWriter, to_underlying(Tag::kAttributeRequests));
     222              :     }
     223          237 :     return mAttributeRequests;
     224              : }
     225              : 
     226          240 : DataVersionFilterIBs::Builder & SubscribeRequestMessage::Builder::CreateDataVersionFilters()
     227              : {
     228              :     // skip if error has already been set
     229          240 :     if (mError == CHIP_NO_ERROR)
     230              :     {
     231          240 :         mError = mDataVersionFilters.Init(mpWriter, to_underlying(Tag::kDataVersionFilters));
     232              :     }
     233          240 :     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          244 : SubscribeRequestMessage::Builder & SubscribeRequestMessage::Builder::IsFabricFiltered(const bool aIsFabricFiltered)
     255              : {
     256              :     // skip if error has already been set
     257          244 :     if (mError == CHIP_NO_ERROR)
     258              :     {
     259          244 :         mError = mpWriter->PutBoolean(TLV::ContextTag(Tag::kIsFabricFiltered), aIsFabricFiltered);
     260              :     }
     261          244 :     return *this;
     262              : }
     263              : 
     264          244 : CHIP_ERROR SubscribeRequestMessage::Builder::EndOfSubscribeRequestMessage()
     265              : {
     266          244 :     if (mError == CHIP_NO_ERROR)
     267              :     {
     268          244 :         mError = MessageBuilder::EncodeInteractionModelRevision();
     269              :     }
     270          244 :     if (mError == CHIP_NO_ERROR)
     271              :     {
     272          244 :         EndOfContainer();
     273              :     }
     274          244 :     return GetError();
     275              : }
     276              : } // namespace app
     277              : } // namespace chip
        

Generated by: LCOV version 2.0-1