Matter SDK Coverage Report
Current view: top level - app - CommandResponseHelper.h (source / functions) Coverage Total Hit
Test: SHA:6c8f029dd2432dc900f1c9245c324e69bd79e40a Lines: 100.0 % 7 7
Test Date: 2026-08-08 07:40:09 Functions: 80.0 % 5 4

            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              : #pragma once
      20              : 
      21              : #include <app/CommandHandler.h>
      22              : #include <app/ConcreteCommandPath.h>
      23              : #include <protocols/interaction_model/Constants.h>
      24              : #include <protocols/interaction_model/StatusCode.h>
      25              : 
      26              : namespace chip {
      27              : namespace app {
      28              : 
      29              : template <typename CommandData>
      30              : class CommandResponseHelper
      31              : {
      32              : public:
      33            4 :     CommandResponseHelper(app::CommandHandler * command, const app::ConcreteCommandPath & commandPath) :
      34            4 :         mCommandHandler(command), mCommandPath(commandPath), mSentResponse(false)
      35            4 :     {}
      36              : 
      37            2 :     CHIP_ERROR Success(const CommandData & aResponse)
      38              :     {
      39            2 :         mCommandHandler->AddResponse(mCommandPath, aResponse);
      40            2 :         mSentResponse = true;
      41            2 :         return CHIP_NO_ERROR;
      42              :     }
      43              : 
      44              :     CHIP_ERROR Success()
      45              :     {
      46              :         CHIP_ERROR err = mCommandHandler->FallibleAddStatus(mCommandPath, Protocols::InteractionModel::Status::Success);
      47              :         mSentResponse  = (err == CHIP_NO_ERROR);
      48              :         return err;
      49              :     }
      50              : 
      51              :     CHIP_ERROR Failure(Protocols::InteractionModel::Status aStatus)
      52              :     {
      53              :         CHIP_ERROR err = mCommandHandler->FallibleAddStatus(mCommandPath, aStatus);
      54              :         mSentResponse  = (err == CHIP_NO_ERROR);
      55              :         return err;
      56              :     }
      57              : 
      58              :     CHIP_ERROR Failure(ClusterStatus aClusterStatus)
      59              :     {
      60              :         CHIP_ERROR err = mCommandHandler->FallibleAddStatus(
      61              :             mCommandPath, Protocols::InteractionModel::ClusterStatusCode::ClusterSpecificFailure(aClusterStatus));
      62              :         mSentResponse = (err == CHIP_NO_ERROR);
      63              :         return err;
      64              :     }
      65              : 
      66              :     bool HasSentResponse() const { return mSentResponse; }
      67              : 
      68              : private:
      69              :     app::CommandHandler * mCommandHandler;
      70              :     app::ConcreteCommandPath mCommandPath;
      71              :     bool mSentResponse;
      72              : };
      73              : 
      74              : } // namespace app
      75              : } // namespace chip
        

Generated by: LCOV version 2.0-1