Matter SDK Coverage Report
Current view: top level - app - StatusResponse.cpp (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 100.0 % 28 28
Test Date: 2025-01-17 19:00:11 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /*
       2              :  *
       3              :  *    Copyright (c) 2021 Project CHIP Authors
       4              :  *    All rights reserved.
       5              :  *
       6              :  *    Licensed under the Apache License, Version 2.0 (the "License");
       7              :  *    you may not use this file except in compliance with the License.
       8              :  *    You may obtain a copy of the License at
       9              :  *
      10              :  *        http://www.apache.org/licenses/LICENSE-2.0
      11              :  *
      12              :  *    Unless required by applicable law or agreed to in writing, software
      13              :  *    distributed under the License is distributed on an "AS IS" BASIS,
      14              :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      15              :  *    See the License for the specific language governing permissions and
      16              :  *    limitations under the License.
      17              :  */
      18              : 
      19              : #include <app/InteractionModelTimeout.h>
      20              : #include <app/MessageDef/StatusResponseMessage.h>
      21              : #include <app/StatusResponse.h>
      22              : 
      23              : namespace chip {
      24              : namespace app {
      25         1319 : CHIP_ERROR StatusResponse::Send(Protocols::InteractionModel::Status aStatus, Messaging::ExchangeContext * apExchangeContext,
      26              :                                 bool aExpectResponse)
      27              : {
      28         1319 :     VerifyOrReturnError(apExchangeContext != nullptr, CHIP_ERROR_INCORRECT_STATE);
      29         1319 :     System::PacketBufferHandle msgBuf = System::PacketBufferHandle::New(kMaxSecureSduLengthBytes);
      30         1319 :     VerifyOrReturnError(!msgBuf.IsNull(), CHIP_ERROR_NO_MEMORY);
      31              : 
      32         1319 :     System::PacketBufferTLVWriter writer;
      33         1319 :     writer.Init(std::move(msgBuf));
      34              : 
      35         1319 :     StatusResponseMessage::Builder response;
      36         1319 :     ReturnErrorOnFailure(response.Init(&writer));
      37         1319 :     response.Status(aStatus);
      38         1319 :     ReturnErrorOnFailure(response.GetError());
      39         1319 :     ReturnErrorOnFailure(writer.Finalize(&msgBuf));
      40         1319 :     apExchangeContext->UseSuggestedResponseTimeout(app::kExpectedIMProcessingTime);
      41         1319 :     ReturnErrorOnFailure(apExchangeContext->SendMessage(Protocols::InteractionModel::MsgType::StatusResponse, std::move(msgBuf),
      42              :                                                         aExpectResponse ? Messaging::SendMessageFlags::kExpectResponse
      43              :                                                                         : Messaging::SendMessageFlags::kNone));
      44         1319 :     return CHIP_NO_ERROR;
      45         1319 : }
      46              : 
      47         1247 : CHIP_ERROR StatusResponse::ProcessStatusResponse(System::PacketBufferHandle && aPayload, CHIP_ERROR & aStatusError)
      48              : {
      49         1247 :     StatusResponseMessage::Parser response;
      50         1247 :     System::PacketBufferTLVReader reader;
      51         1247 :     reader.Init(std::move(aPayload));
      52         1247 :     ReturnErrorOnFailure(response.Init(reader));
      53              : #if CHIP_CONFIG_IM_PRETTY_PRINT
      54         1243 :     response.PrettyPrint();
      55              : #endif
      56         1243 :     StatusIB status;
      57         1243 :     ReturnErrorOnFailure(response.GetStatus(status.mStatus));
      58         1243 :     ChipLogProgress(InteractionModel, "Received status response, status is " ChipLogFormatIMStatus,
      59              :                     ChipLogValueIMStatus(status.mStatus));
      60         1243 :     ReturnErrorOnFailure(response.ExitContainer());
      61              : 
      62         1243 :     aStatusError = status.ToChipError();
      63         1243 :     return CHIP_NO_ERROR;
      64         1247 : }
      65              : } // namespace app
      66              : } // namespace chip
        

Generated by: LCOV version 2.0-1