Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / app / MessageDef / AttributeStatusList.cpp
1 /**
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2018 Google LLC.
5  *    Copyright (c) 2016-2017 Nest Labs, Inc.
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  *    @file
20  *      This file defines AttributeStatusList parser and builder in CHIP interaction model
21  *
22  */
23
24 #include "AttributeStatusList.h"
25 #include "AttributeStatusElement.h"
26
27 #include "MessageDefHelper.h"
28
29 #include <inttypes.h>
30 #include <stdarg.h>
31 #include <stdio.h>
32
33 using namespace chip;
34 using namespace chip::TLV;
35
36 namespace chip {
37 namespace app {
38 AttributeStatusElement::Builder & AttributeStatusList::Builder::CreateAttributeStatusBuilder()
39 {
40     // skip if error has already been set
41     VerifyOrExit(CHIP_NO_ERROR == mError, mAttributeStatusBuilder.ResetError(mError));
42
43     mError = mAttributeStatusBuilder.Init(mpWriter);
44     ChipLogFunctError(mError);
45
46 exit:
47     // on error, mAttributeStatusBuilder would be un-/partial initialized and cannot be used to write anything
48     return mAttributeStatusBuilder;
49 }
50
51 AttributeStatusList::Builder & AttributeStatusList::Builder::EndOfAttributeStatusList()
52 {
53     EndOfContainer();
54     return *this;
55 }
56
57 CHIP_ERROR AttributeStatusList::Parser::CheckSchemaValidity() const
58 {
59     CHIP_ERROR err                  = CHIP_NO_ERROR;
60     size_t NumAttributeStateElement = 0;
61     chip::TLV::TLVReader reader;
62
63     PRETTY_PRINT("AttributeStatusList =");
64     PRETTY_PRINT("[");
65
66     // make a copy of the EventList reader
67     reader.Init(mReader);
68
69     while (CHIP_NO_ERROR == (err = reader.Next()))
70     {
71         VerifyOrExit(chip::TLV::AnonymousTag == reader.GetTag(), err = CHIP_ERROR_INVALID_TLV_TAG);
72         VerifyOrExit(chip::TLV::kTLVType_Structure == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE);
73
74         {
75             AttributeStatusElement::Parser status;
76             err = status.Init(reader);
77             SuccessOrExit(err);
78
79             PRETTY_PRINT_INCDEPTH();
80             err = status.CheckSchemaValidity();
81             SuccessOrExit(err);
82             PRETTY_PRINT_DECDEPTH();
83         }
84
85         ++NumAttributeStateElement;
86     }
87
88     PRETTY_PRINT("],");
89     PRETTY_PRINT("");
90     // if we have exhausted this container
91     if (CHIP_END_OF_TLV == err)
92     {
93         // if we have at least one data element
94         if (NumAttributeStateElement > 0)
95         {
96             err = CHIP_NO_ERROR;
97         }
98         // NOTE: temporarily disable this check, to allow test to continue
99         else
100         {
101             ChipLogError(DataManagement, "PROTOCOL ERROR: Empty attribute status list");
102             err = CHIP_NO_ERROR;
103         }
104     }
105
106 exit:
107     ChipLogFunctError(err);
108
109     return err;
110 }
111 }; // namespace app
112 }; // namespace chip