LCOV - code coverage report
Current view: top level - app/MessageDef - StatusResponseMessage.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 36 40 90.0 %
Date: 2024-02-15 08:20:41 Functions: 3 3 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 "StatusResponseMessage.h"
      18             : #include "MessageDefHelper.h"
      19             : #include "protocols/interaction_model/Constants.h"
      20             : 
      21             : using namespace chip::Protocols::InteractionModel;
      22             : 
      23             : namespace chip {
      24             : namespace app {
      25             : #if CHIP_CONFIG_IM_PRETTY_PRINT
      26        1239 : CHIP_ERROR StatusResponseMessage::Parser::PrettyPrint() const
      27             : {
      28        1239 :     CHIP_ERROR err = CHIP_NO_ERROR;
      29             :     TLV::TLVReader reader;
      30        1239 :     PRETTY_PRINT("StatusResponseMessage =");
      31        1239 :     PRETTY_PRINT("{");
      32             : 
      33             :     // make a copy of the reader
      34        1239 :     reader.Init(mReader);
      35             : 
      36        3717 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      37             :     {
      38        2478 :         if (!TLV::IsContextTag(reader.GetTag()))
      39             :         {
      40           0 :             continue;
      41             :         }
      42        2478 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      43        2478 :         switch (tagNum)
      44             :         {
      45        1239 :         case to_underlying(Tag::kStatus):
      46        1239 :             VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
      47             : #if CHIP_DETAIL_LOGGING
      48             :             {
      49             :                 uint8_t status;
      50        1239 :                 ReturnErrorOnFailure(reader.Get(status));
      51        1239 :                 PRETTY_PRINT("\tStatus = " ChipLogFormatIMStatus ",", ChipLogValueIMStatus(static_cast<Status>(status)));
      52             :             }
      53             : #endif // CHIP_DETAIL_LOGGING
      54        1239 :             break;
      55        1239 :         case kInteractionModelRevisionTag:
      56        1239 :             ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
      57        1239 :             break;
      58           0 :         default:
      59           0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      60           0 :             break;
      61             :         }
      62             :     }
      63        1239 :     PRETTY_PRINT("}");
      64        1239 :     PRETTY_PRINT_BLANK_LINE();
      65             : 
      66        1239 :     if (CHIP_END_OF_TLV == err)
      67             :     {
      68        1239 :         err = CHIP_NO_ERROR;
      69             :     }
      70        1239 :     ReturnErrorOnFailure(err);
      71        1239 :     return reader.ExitContainer(mOuterContainerType);
      72             : }
      73             : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
      74             : 
      75        1239 : CHIP_ERROR StatusResponseMessage::Parser::GetStatus(Protocols::InteractionModel::Status & aStatus) const
      76             : {
      77        1239 :     uint16_t status = 0;
      78        1239 :     CHIP_ERROR err  = GetUnsignedInteger(to_underlying(Tag::kStatus), &status);
      79        1239 :     aStatus         = static_cast<Protocols::InteractionModel::Status>(status);
      80        1239 :     return err;
      81             : }
      82             : 
      83        1323 : StatusResponseMessage::Builder & StatusResponseMessage::Builder::Status(const Protocols::InteractionModel::Status aStatus)
      84             : {
      85             :     // skip if error has already been set
      86        1323 :     if (mError == CHIP_NO_ERROR)
      87             :     {
      88        1323 :         mError = mpWriter->Put(TLV::ContextTag(Tag::kStatus), aStatus);
      89             :     }
      90        1323 :     if (mError == CHIP_NO_ERROR)
      91             :     {
      92        1323 :         mError = MessageBuilder::EncodeInteractionModelRevision();
      93             :     }
      94        1323 :     if (mError == CHIP_NO_ERROR)
      95             :     {
      96        1323 :         EndOfContainer();
      97             :     }
      98        1323 :     return *this;
      99             : }
     100             : 
     101             : } // namespace app
     102             : } // namespace chip

Generated by: LCOV version 1.14