LCOV - code coverage report
Current view: top level - app/MessageDef - SubscribeResponseMessage.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 46 50 92.0 %
Date: 2024-02-15 08:20:41 Functions: 6 6 100.0 %

          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 "SubscribeResponseMessage.h"
      18             : #include "MessageDefHelper.h"
      19             : 
      20             : namespace chip {
      21             : namespace app {
      22             : #if CHIP_CONFIG_IM_PRETTY_PRINT
      23         212 : CHIP_ERROR SubscribeResponseMessage::Parser::PrettyPrint() const
      24             : {
      25         212 :     CHIP_ERROR err = CHIP_NO_ERROR;
      26             :     TLV::TLVReader reader;
      27         212 :     PRETTY_PRINT("SubscribeResponseMessage =");
      28         212 :     PRETTY_PRINT("{");
      29             : 
      30             :     // make a copy of the reader
      31         212 :     reader.Init(mReader);
      32             : 
      33         848 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      34             :     {
      35         636 :         if (!TLV::IsContextTag(reader.GetTag()))
      36             :         {
      37           0 :             continue;
      38             :         }
      39         636 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      40         636 :         switch (tagNum)
      41             :         {
      42         212 :         case to_underlying(Tag::kSubscriptionId):
      43         212 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      44             : #if CHIP_DETAIL_LOGGING
      45             :             {
      46             :                 SubscriptionId subscriptionId;
      47         212 :                 ReturnErrorOnFailure(reader.Get(subscriptionId));
      48         212 :                 PRETTY_PRINT("\tSubscriptionId = 0x%" PRIx32 ",", subscriptionId);
      49             :             }
      50             : #endif // CHIP_DETAIL_LOGGING
      51         212 :             break;
      52         212 :         case to_underlying(Tag::kMaxInterval):
      53         212 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      54             : #if CHIP_DETAIL_LOGGING
      55             :             {
      56             :                 uint16_t maxInterval;
      57         212 :                 ReturnErrorOnFailure(reader.Get(maxInterval));
      58         212 :                 PRETTY_PRINT("\tMaxInterval = 0x%x,", maxInterval);
      59             :             }
      60             : #endif // CHIP_DETAIL_LOGGING
      61         212 :             break;
      62         212 :         case kInteractionModelRevisionTag:
      63         212 :             ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
      64         212 :             break;
      65           0 :         default:
      66           0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      67           0 :             break;
      68             :         }
      69             :     }
      70         212 :     PRETTY_PRINT("}");
      71         212 :     PRETTY_PRINT_BLANK_LINE();
      72             : 
      73         212 :     if (CHIP_END_OF_TLV == err)
      74             :     {
      75         212 :         err = CHIP_NO_ERROR;
      76             :     }
      77         212 :     ReturnErrorOnFailure(err);
      78         212 :     return reader.ExitContainer(mOuterContainerType);
      79             : }
      80             : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
      81             : 
      82         212 : CHIP_ERROR SubscribeResponseMessage::Parser::GetSubscriptionId(SubscriptionId * const apSubscribeId) const
      83             : {
      84         212 :     return GetUnsignedInteger(to_underlying(Tag::kSubscriptionId), apSubscribeId);
      85             : }
      86             : 
      87         210 : CHIP_ERROR SubscribeResponseMessage::Parser::GetMaxInterval(uint16_t * const apMaxInterval) const
      88             : {
      89         210 :     return GetUnsignedInteger(to_underlying(Tag::kMaxInterval), apMaxInterval);
      90             : }
      91             : 
      92         214 : SubscribeResponseMessage::Builder & SubscribeResponseMessage::Builder::SubscriptionId(const chip::SubscriptionId aSubscribeId)
      93             : {
      94         214 :     if (mError == CHIP_NO_ERROR)
      95             :     {
      96         214 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kSubscriptionId), aSubscribeId);
      97             :     }
      98         214 :     return *this;
      99             : }
     100             : 
     101         214 : SubscribeResponseMessage::Builder & SubscribeResponseMessage::Builder::MaxInterval(const uint16_t aMaxInterval)
     102             : {
     103         214 :     if (mError == CHIP_NO_ERROR)
     104             :     {
     105         214 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kMaxInterval), aMaxInterval);
     106             :     }
     107         214 :     return *this;
     108             : }
     109             : 
     110         214 : CHIP_ERROR SubscribeResponseMessage::Builder::EndOfSubscribeResponseMessage()
     111             : {
     112         214 :     if (mError == CHIP_NO_ERROR)
     113             :     {
     114         214 :         mError = MessageBuilder::EncodeInteractionModelRevision();
     115             :     }
     116         214 :     if (mError == CHIP_NO_ERROR)
     117             :     {
     118         214 :         EndOfContainer();
     119             :     }
     120         214 :     return GetError();
     121             : }
     122             : } // namespace app
     123             : } // namespace chip

Generated by: LCOV version 1.14