Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / app / MessageDef / AttributeStatusElement.h
1 /**
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2016-2017 Nest Labs, Inc.
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  *    @file
20  *      This file defines AttributeStatusElement parser and builder in CHIP interaction model
21  *
22  */
23
24 #pragma once
25
26 #ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_STATUS_ELEMENT_H
27 #define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_STATUS_ELEMENT_H
28
29 #include "AttributePath.h"
30 #include "Builder.h"
31 #include "Parser.h"
32 #include "StatusElement.h"
33 #include <core/CHIPCore.h>
34 #include <core/CHIPTLV.h>
35 #include <support/CodeUtils.h>
36 #include <support/logging/CHIPLogging.h>
37 #include <util/basic-types.h>
38
39 namespace chip {
40 namespace app {
41 namespace AttributeStatusElement {
42 enum
43 {
44     kCsTag_AttributePath = 0,
45     kCsTag_StatusElement = 1,
46 };
47
48 class Builder : public chip::app::Builder
49 {
50 public:
51     /**
52      *  @brief Initialize a AttributeStatusElement::Builder for writing into a TLV stream
53      *
54      *  @param [in] apWriter    A pointer to TLVWriter
55      *
56      *  @return #CHIP_NO_ERROR on success
57      */
58     CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter);
59
60     /**
61      *  @brief Initialize a AttributePath::Builder for writing into the TLV stream
62      *
63      *  @return A reference to AttributePath::Builder
64      */
65     AttributePath::Builder & CreateAttributePathBuilder();
66
67     /**
68      *  @brief Initialize a StatusElement::Builder for writing into the TLV stream
69      *
70      *  @return A reference to StatusElement::Builder
71      */
72     StatusElement::Builder & CreateStatusElementBuilder();
73
74     /**
75      *  @brief Mark the end of this AttributeStatusElement
76      *
77      *  @return A reference to *this
78      */
79     AttributeStatusElement::Builder & EndOfAttributeStatusElement();
80
81 private:
82     AttributePath::Builder mAttributePathBuilder;
83     StatusElement::Builder mStatusElementBuilder;
84 };
85
86 class Parser : public chip::app::Parser
87 {
88 public:
89     /**
90      *  @brief Initialize the parser object with TLVReader
91      *
92      *  @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this AttributeStatusElement
93      *
94      *  @return #CHIP_NO_ERROR on success
95      */
96     CHIP_ERROR Init(const chip::TLV::TLVReader & aReader);
97
98     /**
99      *  @brief Roughly verify the message is correctly formed
100      *   1) all mandatory tags are present
101      *   2) all elements have expected data type
102      *   3) any tag can only appear once
103      *   4) At the top level of the structure, unknown tags are ignored for forward compatibility
104      *  @note The main use of this function is to print out what we're
105      *    receiving during protocol development and debugging.
106      *    The encoding rule has changed in IM encoding spec so this
107      *    check is only "roughly" conformant now.
108      *
109      *  @return #CHIP_NO_ERROR on success
110      */
111     CHIP_ERROR CheckSchemaValidity() const;
112
113     /**
114      *  @brief Get a TLVReader for the AttributePath. Next() must be called before accessing them.
115      *
116      *  @param [in] apAttributePath    A pointer to apAttributePath
117      *
118      *  @return #CHIP_NO_ERROR on success
119      *          #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not a Path
120      *          #CHIP_END_OF_TLV if there is no such element
121      */
122     CHIP_ERROR GetAttributePath(AttributePath::Parser * const apAttributePath) const;
123
124     /**
125      *  @brief Get a TLVReader for the StatusElement. Next() must be called before accessing them.
126      *
127      *  @param [in] apStatusElement    A pointer to apStatusElement
128      *
129      *  @return #CHIP_NO_ERROR on success
130      *          #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not a Path
131      *          #CHIP_END_OF_TLV if there is no such element
132      */
133     CHIP_ERROR GetStatusElement(StatusElement::Parser * const apStatusElement) const;
134 };
135 }; // namespace AttributeStatusElement
136
137 }; // namespace app
138 }; // namespace chip
139
140 #endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_STATUS_ELEMENT_H