Matter SDK Coverage Report
Current view: top level - app/MessageDef - EventReportIB.cpp (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 93.9 % 66 62
Test Date: 2025-01-17 19:00:11 Functions: 100.0 % 7 7

            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 "EventReportIB.h"
      18              : #include "EventDataIB.h"
      19              : #include "MessageDefHelper.h"
      20              : #include "StructBuilder.h"
      21              : #include "StructParser.h"
      22              : 
      23              : #include <inttypes.h>
      24              : #include <stdarg.h>
      25              : #include <stdio.h>
      26              : 
      27              : #include <app/AppConfig.h>
      28              : 
      29              : namespace chip {
      30              : namespace app {
      31              : #if CHIP_CONFIG_IM_PRETTY_PRINT
      32         1582 : CHIP_ERROR EventReportIB::Parser::PrettyPrint() const
      33              : {
      34         1582 :     CHIP_ERROR err = CHIP_NO_ERROR;
      35         1582 :     TLV::TLVReader reader;
      36              : 
      37         1582 :     PRETTY_PRINT("EventReportIB =");
      38         1582 :     PRETTY_PRINT("{");
      39              : 
      40              :     // make a copy of the reader
      41         1582 :     reader.Init(mReader);
      42              : 
      43         3164 :     while (CHIP_NO_ERROR == (err = reader.Next()))
      44              :     {
      45         1582 :         if (!TLV::IsContextTag(reader.GetTag()))
      46              :         {
      47            0 :             continue;
      48              :         }
      49         1582 :         uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
      50         1582 :         switch (tagNum)
      51              :         {
      52            4 :         case to_underlying(Tag::kEventStatus): {
      53            4 :             EventStatusIB::Parser eventStatus;
      54            4 :             ReturnErrorOnFailure(eventStatus.Init(reader));
      55              : 
      56            4 :             PRETTY_PRINT_INCDEPTH();
      57            4 :             ReturnErrorOnFailure(eventStatus.PrettyPrint());
      58            4 :             PRETTY_PRINT_DECDEPTH();
      59              :         }
      60            4 :         break;
      61         1578 :         case to_underlying(Tag::kEventData): {
      62         1578 :             EventDataIB::Parser eventData;
      63         1578 :             ReturnErrorOnFailure(eventData.Init(reader));
      64              : 
      65         1578 :             PRETTY_PRINT_INCDEPTH();
      66         1578 :             ReturnErrorOnFailure(eventData.PrettyPrint());
      67         1578 :             PRETTY_PRINT_DECDEPTH();
      68              :         }
      69         1578 :         break;
      70            0 :         default:
      71            0 :             PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
      72            0 :             break;
      73              :         }
      74              :     }
      75              : 
      76         1582 :     PRETTY_PRINT("},");
      77         1582 :     PRETTY_PRINT_BLANK_LINE();
      78              : 
      79         1582 :     if (CHIP_END_OF_TLV == err)
      80              :     {
      81         1582 :         err = CHIP_NO_ERROR;
      82              :     }
      83              : 
      84         1582 :     ReturnErrorOnFailure(err);
      85         1582 :     return reader.ExitContainer(mOuterContainerType);
      86              : }
      87              : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
      88              : 
      89            4 : CHIP_ERROR EventReportIB::Parser::GetEventStatus(EventStatusIB::Parser * const apEventStatus) const
      90              : {
      91            4 :     TLV::TLVReader reader;
      92            4 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kEventStatus), reader));
      93            4 :     return apEventStatus->Init(reader);
      94              : }
      95              : 
      96         1580 : CHIP_ERROR EventReportIB::Parser::GetEventData(EventDataIB::Parser * const apEventData) const
      97              : {
      98         1580 :     TLV::TLVReader reader;
      99         1580 :     ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kEventData), reader));
     100         1576 :     return apEventData->Init(reader);
     101              : }
     102              : 
     103            4 : EventStatusIB::Builder & EventReportIB::Builder::CreateEventStatus()
     104              : {
     105            4 :     if (mError == CHIP_NO_ERROR)
     106              :     {
     107            4 :         mError = mEventStatus.Init(mpWriter, to_underlying(Tag::kEventStatus));
     108              :     }
     109            4 :     return mEventStatus;
     110              : }
     111              : 
     112         1327 : EventDataIB::Builder & EventReportIB::Builder::CreateEventData()
     113              : {
     114         1327 :     if (mError == CHIP_NO_ERROR)
     115              :     {
     116         1327 :         mError = mEventData.Init(mpWriter, to_underlying(Tag::kEventData));
     117              :     }
     118         1327 :     return mEventData;
     119              : }
     120              : 
     121         1331 : CHIP_ERROR EventReportIB::Builder::EndOfEventReportIB()
     122              : {
     123         1331 :     EndOfContainer();
     124         1331 :     return GetError();
     125              : }
     126              : 
     127            4 : CHIP_ERROR EventReportIB::ConstructEventStatusIB(TLV::TLVWriter & aWriter, const ConcreteEventPath & aEvent, StatusIB aStatus)
     128              : {
     129            4 :     Builder eventReportIBBuilder;
     130            4 :     ReturnErrorOnFailure(eventReportIBBuilder.Init(&aWriter));
     131            4 :     EventStatusIB::Builder & eventStatusIBBuilder = eventReportIBBuilder.CreateEventStatus();
     132            4 :     ReturnErrorOnFailure(eventReportIBBuilder.GetError());
     133            4 :     EventPathIB::Builder & eventPathIBBuilder = eventStatusIBBuilder.CreatePath();
     134            4 :     ReturnErrorOnFailure(eventStatusIBBuilder.GetError());
     135            4 :     ReturnErrorOnFailure(
     136              :         eventPathIBBuilder.Endpoint(aEvent.mEndpointId).Cluster(aEvent.mClusterId).Event(aEvent.mEventId).EndOfEventPathIB());
     137              : 
     138            4 :     ReturnErrorOnFailure(eventStatusIBBuilder.CreateErrorStatus().EncodeStatusIB(aStatus).GetError());
     139              : 
     140            4 :     ReturnErrorOnFailure(eventStatusIBBuilder.EndOfEventStatusIB());
     141            4 :     ReturnErrorOnFailure(eventReportIBBuilder.EndOfEventReportIB());
     142            4 :     ReturnErrorOnFailure(aWriter.Finalize());
     143            4 :     return CHIP_NO_ERROR;
     144              : }
     145              : } // namespace app
     146              : } // namespace chip
        

Generated by: LCOV version 2.0-1