LCOV - code coverage report
Current view: top level - app/MessageDef - WriteRequestMessage.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 68 72 94.4 %
Date: 2024-02-15 08:20:41 Functions: 10 10 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             :  *    @file
      18             :  *      This file defines WriteRequestMessage parser and builder in CHIP interaction model
      19             :  *
      20             :  */
      21             : 
      22             : #include "WriteRequestMessage.h"
      23             : #include "MessageDefHelper.h"
      24             : 
      25             : #include <inttypes.h>
      26             : #include <stdarg.h>
      27             : #include <stdio.h>
      28             : 
      29             : #include <app/AppConfig.h>
      30             : 
      31             : namespace chip {
      32             : namespace app {
      33             : #if CHIP_CONFIG_IM_PRETTY_PRINT
      34        1736 : CHIP_ERROR WriteRequestMessage::Parser::PrettyPrint() const
      35             : {
      36        1736 :     CHIP_ERROR err = CHIP_NO_ERROR;
      37             :     TLV::TLVReader reader;
      38             : 
      39        1736 :     PRETTY_PRINT("WriteRequestMessage =");
      40        1736 :     PRETTY_PRINT("{");
      41             : 
      42             :     // make a copy of the reader
      43        1736 :     reader.Init(mReader);
      44             : 
      45       10408 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      46             :     {
      47        8672 :         if (!TLV::IsContextTag(reader.GetTag()))
      48             :         {
      49           0 :             continue;
      50             :         }
      51        8672 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      52        8672 :         switch (tagNum)
      53             :         {
      54        1732 :         case to_underlying(Tag::kSuppressResponse):
      55             : #if CHIP_DETAIL_LOGGING
      56             :         {
      57             :             bool suppressResponse;
      58        1732 :             ReturnErrorOnFailure(reader.Get(suppressResponse));
      59        1732 :             PRETTY_PRINT("\tsuppressResponse = %s, ", suppressResponse ? "true" : "false");
      60             :         }
      61             : #endif // CHIP_DETAIL_LOGGING
      62        1732 :         break;
      63             : 
      64        1736 :         case to_underlying(Tag::kTimedRequest):
      65             : #if CHIP_DETAIL_LOGGING
      66             :         {
      67             :             bool timedRequest;
      68        1736 :             ReturnErrorOnFailure(reader.Get(timedRequest));
      69        1736 :             PRETTY_PRINT("\ttimedRequest = %s, ", timedRequest ? "true" : "false");
      70             :         }
      71             : #endif // CHIP_DETAIL_LOGGING
      72        1736 :         break;
      73        1736 :         case to_underlying(Tag::kWriteRequests): {
      74        1736 :             AttributeDataIBs::Parser writeRequests;
      75        1736 :             ReturnErrorOnFailure(writeRequests.Init(reader));
      76             : 
      77        1736 :             PRETTY_PRINT_INCDEPTH();
      78        1736 :             ReturnErrorOnFailure(writeRequests.PrettyPrint());
      79        1736 :             PRETTY_PRINT_DECDEPTH();
      80             :         }
      81        1736 :         break;
      82        1732 :         case to_underlying(Tag::kMoreChunkedMessages):
      83             : #if CHIP_DETAIL_LOGGING
      84             :         {
      85             :             bool moreChunkedMessages;
      86        1732 :             ReturnErrorOnFailure(reader.Get(moreChunkedMessages));
      87        1732 :             PRETTY_PRINT("\tmoreChunkedMessages = %s, ", moreChunkedMessages ? "true" : "false");
      88             :         }
      89             : #endif // CHIP_DETAIL_LOGGING
      90        1732 :         break;
      91        1736 :         case kInteractionModelRevisionTag:
      92        1736 :             ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
      93        1736 :             break;
      94           0 :         default:
      95           0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      96           0 :             break;
      97             :         }
      98             :     }
      99             : 
     100        1736 :     PRETTY_PRINT("},");
     101        1736 :     PRETTY_PRINT_BLANK_LINE();
     102             : 
     103        1736 :     if (CHIP_END_OF_TLV == err)
     104             :     {
     105        1736 :         err = CHIP_NO_ERROR;
     106             :     }
     107             : 
     108        1736 :     ReturnErrorOnFailure(err);
     109        1736 :     return reader.ExitContainer(mOuterContainerType);
     110             : }
     111             : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
     112             : 
     113        1736 : CHIP_ERROR WriteRequestMessage::Parser::GetSuppressResponse(bool * const apSuppressResponse) const
     114             : {
     115        1736 :     return GetSimpleValue(to_underlying(Tag::kSuppressResponse), TLV::kTLVType_Boolean, apSuppressResponse);
     116             : }
     117             : 
     118        1736 : CHIP_ERROR WriteRequestMessage::Parser::GetTimedRequest(bool * const apTimedRequest) const
     119             : {
     120        1736 :     return GetSimpleValue(to_underlying(Tag::kTimedRequest), TLV::kTLVType_Boolean, apTimedRequest);
     121             : }
     122             : 
     123        1736 : CHIP_ERROR WriteRequestMessage::Parser::GetWriteRequests(AttributeDataIBs::Parser * const apAttributeDataIBs) const
     124             : {
     125             :     TLV::TLVReader reader;
     126        1736 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kWriteRequests), reader));
     127        1736 :     return apAttributeDataIBs->Init(reader);
     128             : }
     129             : 
     130        1736 : CHIP_ERROR WriteRequestMessage::Parser::GetMoreChunkedMessages(bool * const apMoreChunkedMessages) const
     131             : {
     132        1736 :     return GetSimpleValue(to_underlying(Tag::kMoreChunkedMessages), TLV::kTLVType_Boolean, apMoreChunkedMessages);
     133             : }
     134             : 
     135        1842 : WriteRequestMessage::Builder & WriteRequestMessage::Builder::SuppressResponse(const bool aSuppressResponse)
     136             : {
     137             :     // skip if error has already been set
     138        1842 :     if (mError == CHIP_NO_ERROR)
     139             :     {
     140        1842 :         mError = mpWriter->PutBoolean(TLV::ContextTag(Tag::kSuppressResponse), aSuppressResponse);
     141             :     }
     142        1842 :     return *this;
     143             : }
     144             : 
     145        1846 : WriteRequestMessage::Builder & WriteRequestMessage::Builder::TimedRequest(const bool aTimedRequest)
     146             : {
     147             :     // skip if error has already been set
     148        1846 :     if (mError == CHIP_NO_ERROR)
     149             :     {
     150        1846 :         mError = mpWriter->PutBoolean(TLV::ContextTag(Tag::kTimedRequest), aTimedRequest);
     151             :     }
     152        1846 :     return *this;
     153             : }
     154             : 
     155        1846 : AttributeDataIBs::Builder & WriteRequestMessage::Builder::CreateWriteRequests()
     156             : {
     157             :     // skip if error has already been set
     158        1846 :     if (mError == CHIP_NO_ERROR)
     159             :     {
     160        1846 :         mError = mWriteRequests.Init(mpWriter, to_underlying(Tag::kWriteRequests));
     161             :     }
     162        1846 :     return mWriteRequests;
     163             : }
     164             : 
     165        1789 : WriteRequestMessage::Builder & WriteRequestMessage::Builder::MoreChunkedMessages(const bool aMoreChunkedMessages)
     166             : {
     167             :     // skip if error has already been set
     168        1789 :     if (mError == CHIP_NO_ERROR)
     169             :     {
     170        1789 :         mError = mpWriter->PutBoolean(TLV::ContextTag(Tag::kMoreChunkedMessages), aMoreChunkedMessages);
     171             :     }
     172        1789 :     return *this;
     173             : }
     174             : 
     175        1793 : CHIP_ERROR WriteRequestMessage::Builder::EndOfWriteRequestMessage()
     176             : {
     177        1793 :     if (mError == CHIP_NO_ERROR)
     178             :     {
     179        1793 :         mError = MessageBuilder::EncodeInteractionModelRevision();
     180             :     }
     181        1793 :     if (mError == CHIP_NO_ERROR)
     182             :     {
     183        1793 :         EndOfContainer();
     184             :     }
     185        1793 :     return GetError();
     186             : }
     187             : } // namespace app
     188             : } // namespace chip

Generated by: LCOV version 1.14