Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / app / MessageDef / AttributeDataList.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 AttributeDataList parser and builder in CHIP interaction model
21  *
22  */
23
24 #include "AttributeDataList.h"
25
26 #include "MessageDefHelper.h"
27
28 #include <inttypes.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31
32 using namespace chip;
33 using namespace chip::TLV;
34
35 namespace chip {
36 namespace app {
37 #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
38 CHIP_ERROR AttributeDataList::Parser::CheckSchemaValidity() const
39 {
40     CHIP_ERROR err        = CHIP_NO_ERROR;
41     size_t NumDataElement = 0;
42     chip::TLV::TLVReader reader;
43
44     PRETTY_PRINT("AttributeDataList =");
45     PRETTY_PRINT("[");
46
47     // make a copy of the reader
48     reader.Init(mReader);
49
50     while (CHIP_NO_ERROR == (err = reader.Next()))
51     {
52         VerifyOrExit(chip::TLV::AnonymousTag == reader.GetTag(), err = CHIP_ERROR_INVALID_TLV_TAG);
53         VerifyOrExit(chip::TLV::kTLVType_Structure == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE);
54
55         {
56             AttributeDataElement::Parser data;
57             err = data.Init(reader);
58             SuccessOrExit(err);
59
60             PRETTY_PRINT_INCDEPTH();
61             err = data.CheckSchemaValidity();
62             SuccessOrExit(err);
63             PRETTY_PRINT_DECDEPTH();
64         }
65
66         ++NumDataElement;
67     }
68
69     PRETTY_PRINT("],");
70     PRETTY_PRINT("");
71
72     // if we have exhausted this container
73     if (CHIP_END_OF_TLV == err)
74     {
75         // if we have at least one data element
76         if (NumDataElement > 0)
77         {
78             err = CHIP_NO_ERROR;
79         }
80     }
81
82 exit:
83     ChipLogFunctError(err);
84
85     return err;
86 }
87 #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
88
89 AttributeDataElement::Builder & AttributeDataList::Builder::CreateAttributeDataElementBuilder()
90 {
91     // skip if error has already been set
92     VerifyOrExit(CHIP_NO_ERROR == mError, mAttributeDataElementBuilder.ResetError(mError));
93
94     mError = mAttributeDataElementBuilder.Init(mpWriter);
95     ChipLogFunctError(mError);
96
97 exit:
98
99     // on error, mAttributeDataElementBuilder would be un-/partial initialized and cannot be used to write anything
100     return mAttributeDataElementBuilder;
101 }
102
103 AttributeDataList::Builder & AttributeDataList::Builder::EndOfAttributeDataList()
104 {
105     EndOfContainer();
106
107     return *this;
108 }
109
110 }; // namespace app
111 }; // namespace chip