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

Generated by: LCOV version 2.0-1