Matter SDK Coverage Report
Current view: top level - app/MessageDef - WriteRequestMessage.cpp (source / functions) Coverage Total Hit
Test: SHA:4cbce7f768f16e614f5a8ccb8cd93c92cbeae70d Lines: 94.6 % 74 70
Test Date: 2025-04-26 07:09:35 Functions: 100.0 % 10 10

            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         3435 : CHIP_ERROR WriteRequestMessage::Parser::PrettyPrint() const
      35              : {
      36         3435 :     CHIP_ERROR err = CHIP_NO_ERROR;
      37         3435 :     TLV::TLVReader reader;
      38              : 
      39         3435 :     PRETTY_PRINT("WriteRequestMessage =");
      40         3435 :     PRETTY_PRINT("{");
      41              : 
      42              :     // make a copy of the reader
      43         3435 :     reader.Init(mReader);
      44              : 
      45        20602 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      46              :     {
      47        17167 :         if (!TLV::IsContextTag(reader.GetTag()))
      48              :         {
      49            0 :             continue;
      50              :         }
      51        17167 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      52        17167 :         switch (tagNum)
      53              :         {
      54         3431 :         case to_underlying(Tag::kSuppressResponse):
      55              : #if CHIP_DETAIL_LOGGING
      56              :         {
      57              :             bool suppressResponse;
      58         3431 :             ReturnErrorOnFailure(reader.Get(suppressResponse));
      59         3431 :             PRETTY_PRINT("\tsuppressResponse = %s, ", suppressResponse ? "true" : "false");
      60              :         }
      61              : #endif // CHIP_DETAIL_LOGGING
      62         3431 :         break;
      63              : 
      64         3435 :         case to_underlying(Tag::kTimedRequest):
      65              : #if CHIP_DETAIL_LOGGING
      66              :         {
      67              :             bool timedRequest;
      68         3435 :             ReturnErrorOnFailure(reader.Get(timedRequest));
      69         3435 :             PRETTY_PRINT("\ttimedRequest = %s, ", timedRequest ? "true" : "false");
      70              :         }
      71              : #endif // CHIP_DETAIL_LOGGING
      72         3435 :         break;
      73         3435 :         case to_underlying(Tag::kWriteRequests): {
      74         3435 :             AttributeDataIBs::Parser writeRequests;
      75         3435 :             ReturnErrorOnFailure(writeRequests.Init(reader));
      76              : 
      77         3435 :             PRETTY_PRINT_INCDEPTH();
      78         3435 :             ReturnErrorOnFailure(writeRequests.PrettyPrint());
      79         3435 :             PRETTY_PRINT_DECDEPTH();
      80              :         }
      81         3435 :         break;
      82         3431 :         case to_underlying(Tag::kMoreChunkedMessages):
      83              : #if CHIP_DETAIL_LOGGING
      84              :         {
      85              :             bool moreChunkedMessages;
      86         3431 :             ReturnErrorOnFailure(reader.Get(moreChunkedMessages));
      87         3431 :             PRETTY_PRINT("\tmoreChunkedMessages = %s, ", moreChunkedMessages ? "true" : "false");
      88              :         }
      89              : #endif // CHIP_DETAIL_LOGGING
      90         3431 :         break;
      91         3435 :         case Revision::kInteractionModelRevisionTag:
      92         3435 :             ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader));
      93         3435 :             break;
      94            0 :         default:
      95            0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      96            0 :             break;
      97              :         }
      98              :     }
      99              : 
     100         3435 :     PRETTY_PRINT("},");
     101         3435 :     PRETTY_PRINT_BLANK_LINE();
     102              : 
     103         3435 :     if (CHIP_END_OF_TLV == err)
     104              :     {
     105         3435 :         err = CHIP_NO_ERROR;
     106              :     }
     107              : 
     108         3435 :     ReturnErrorOnFailure(err);
     109         3435 :     return reader.ExitContainer(mOuterContainerType);
     110              : }
     111              : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
     112              : 
     113         3435 : CHIP_ERROR WriteRequestMessage::Parser::GetSuppressResponse(bool * const apSuppressResponse) const
     114              : {
     115         3435 :     return GetSimpleValue(to_underlying(Tag::kSuppressResponse), TLV::kTLVType_Boolean, apSuppressResponse);
     116              : }
     117              : 
     118         3435 : CHIP_ERROR WriteRequestMessage::Parser::GetTimedRequest(bool * const apTimedRequest) const
     119              : {
     120         3435 :     return GetSimpleValue(to_underlying(Tag::kTimedRequest), TLV::kTLVType_Boolean, apTimedRequest);
     121              : }
     122              : 
     123         3435 : CHIP_ERROR WriteRequestMessage::Parser::GetWriteRequests(AttributeDataIBs::Parser * const apAttributeDataIBs) const
     124              : {
     125         3435 :     TLV::TLVReader reader;
     126         3435 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kWriteRequests), reader));
     127         3435 :     return apAttributeDataIBs->Init(reader);
     128              : }
     129              : 
     130         3435 : CHIP_ERROR WriteRequestMessage::Parser::GetMoreChunkedMessages(bool * const apMoreChunkedMessages) const
     131              : {
     132         3435 :     return GetSimpleValue(to_underlying(Tag::kMoreChunkedMessages), TLV::kTLVType_Boolean, apMoreChunkedMessages);
     133              : }
     134              : 
     135         3717 : WriteRequestMessage::Builder & WriteRequestMessage::Builder::SuppressResponse(const bool aSuppressResponse)
     136              : {
     137              :     // skip if error has already been set
     138         3717 :     if (mError == CHIP_NO_ERROR)
     139              :     {
     140         3717 :         mError = mpWriter->PutBoolean(TLV::ContextTag(Tag::kSuppressResponse), aSuppressResponse);
     141              :     }
     142         3717 :     return *this;
     143              : }
     144              : 
     145         3721 : WriteRequestMessage::Builder & WriteRequestMessage::Builder::TimedRequest(const bool aTimedRequest)
     146              : {
     147              :     // skip if error has already been set
     148         3721 :     if (mError == CHIP_NO_ERROR)
     149              :     {
     150         3721 :         mError = mpWriter->PutBoolean(TLV::ContextTag(Tag::kTimedRequest), aTimedRequest);
     151              :     }
     152         3721 :     return *this;
     153              : }
     154              : 
     155         3721 : AttributeDataIBs::Builder & WriteRequestMessage::Builder::CreateWriteRequests()
     156              : {
     157              :     // skip if error has already been set
     158         3721 :     if (mError == CHIP_NO_ERROR)
     159              :     {
     160         3721 :         mError = mWriteRequests.Init(mpWriter, to_underlying(Tag::kWriteRequests));
     161              :     }
     162         3721 :     return mWriteRequests;
     163              : }
     164              : 
     165         3615 : WriteRequestMessage::Builder & WriteRequestMessage::Builder::MoreChunkedMessages(const bool aMoreChunkedMessages)
     166              : {
     167              :     // skip if error has already been set
     168         3615 :     if (mError == CHIP_NO_ERROR)
     169              :     {
     170         3615 :         mError = mpWriter->PutBoolean(TLV::ContextTag(Tag::kMoreChunkedMessages), aMoreChunkedMessages);
     171              :     }
     172         3615 :     return *this;
     173              : }
     174              : 
     175         3619 : CHIP_ERROR WriteRequestMessage::Builder::EndOfWriteRequestMessage()
     176              : {
     177         3619 :     if (mError == CHIP_NO_ERROR)
     178              :     {
     179         3619 :         mError = MessageBuilder::EncodeInteractionModelRevision();
     180              :     }
     181         3619 :     if (mError == CHIP_NO_ERROR)
     182              :     {
     183         3619 :         EndOfContainer();
     184              :     }
     185         3619 :     return GetError();
     186              : }
     187              : } // namespace app
     188              : } // namespace chip
        

Generated by: LCOV version 2.0-1