Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / app / MessageDef / AttributePath.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 AttributePath parser and builder in CHIP interaction model
21  *
22  */
23
24 #pragma once
25
26 #ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_PATH_H
27 #define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_PATH_H
28
29 #include "Builder.h"
30 #include "Parser.h"
31 #include <core/CHIPCore.h>
32 #include <core/CHIPTLV.h>
33 #include <support/CodeUtils.h>
34 #include <support/logging/CHIPLogging.h>
35 #include <util/basic-types.h>
36
37 namespace chip {
38 namespace app {
39 namespace AttributePath {
40 enum
41 {
42     kCsTag_NodeId     = 0,
43     kCsTag_EndpointId = 1,
44     kCsTag_ClusterId  = 2,
45     kCsTag_FieldId    = 3,
46     kCsTag_ListIndex  = 4,
47 };
48
49 class Parser : public chip::app::Parser
50 {
51 public:
52     /**
53      *  @brief Initialize the parser object with TLVReader
54      *
55      *  @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this AttributePath
56      *
57      *  @return #CHIP_NO_ERROR on success
58      */
59     CHIP_ERROR Init(const chip::TLV::TLVReader & aReader);
60
61     /**
62      *  @brief Roughly verify the message is correctly formed
63      *   1) all mandatory tags are present
64      *   2) all elements have expected data type
65      *   3) any tag can only appear once
66      *   4) At the top level of the structure, unknown tags are ignored for forward compatibility
67      *  @note The main use of this function is to print out what we're
68      *    receiving during protocol development and debugging.
69      *    The encoding rule has changed in IM encoding spec so this
70      *    check is only "roughly" conformant now.
71      *
72      *  @return #CHIP_NO_ERROR on success
73      */
74     CHIP_ERROR CheckSchemaValidity() const;
75
76     /**
77      *  @brief Get a TLVReader for the NodeId. Next() must be called before accessing them.
78      *
79      *  @param [in] apNodeId    A pointer to apNodeId
80      *
81      *  @return #CHIP_NO_ERROR on success
82      *          #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types
83      *          #CHIP_END_OF_TLV if there is no such element
84      */
85     CHIP_ERROR GetNodeId(chip::NodeId * const apNodeId) const;
86
87     /**
88      *  @brief Get a TLVReader for the EndpointId. Next() must be called before accessing them.
89      *
90      *  @param [in] apEndpointId    A pointer to apEndpointId
91      *
92      *  @return #CHIP_NO_ERROR on success
93      *          #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types
94      *          #CHIP_END_OF_TLV if there is no such element
95      */
96     CHIP_ERROR GetEndpointId(chip::EndpointId * const apEndpointId) const;
97
98     /**
99      *  @brief Get a TLVReader for the ClusterId. Next() must be called before accessing them.
100      *
101      *  @param [in] apClusterId    A pointer to apClusterId
102      *
103      *  @return #CHIP_NO_ERROR on success
104      *          #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types
105      *          #CHIP_END_OF_TLV if there is no such element
106      */
107     CHIP_ERROR GetClusterId(chip::ClusterId * const apClusterId) const;
108
109     /**
110      *  @brief Get a TLVReader for the FieldId. Next() must be called before accessing them.
111      *
112      *  @param [in] apFieldId    A pointer to apFieldId
113      *
114      *  @return #CHIP_NO_ERROR on success
115      *          #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types
116      *          #CHIP_END_OF_TLV if there is no such element
117      */
118     CHIP_ERROR GetFieldId(uint8_t * const apFieldId) const;
119
120     /**
121      *  @brief Get a TLVReader for the ListIndex. Next() must be called before accessing them.
122      *
123      *  @param [in] apListIndex    A pointer to apListIndex
124      *
125      *  @return #CHIP_NO_ERROR on success
126      *          #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types
127      *          #CHIP_END_OF_TLV if there is no such element
128      */
129     CHIP_ERROR GetListIndex(uint16_t * const apListIndex) const;
130 };
131
132 class Builder : public chip::app::Builder
133 {
134 public:
135     /**
136      *  @brief Initialize a AttributePath::Builder for writing into a TLV stream
137      *
138      *  @param [in] apWriter    A pointer to TLVWriter
139      *
140      *  @return #CHIP_NO_ERROR on success
141      */
142     CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter);
143
144     /**
145      * Init the AttributePath container with an particular context tag.
146      * Required to implement arrays of arrays, and to test ListBuilder.
147      *
148      * @param[in]   apWriter    Pointer to the TLVWriter that is encoding the message.
149      * @param[in]   aContextTagToUse    A contextTag to use.
150      *
151      * @return                  CHIP_ERROR codes returned by chip::TLV objects.
152      */
153     CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter, const uint8_t aContextTagToUse);
154
155     /**
156      *  @brief Inject NodeId into the TLV stream.
157      *
158      *  @param [in] aNodeId NodeId for this attribute path
159      *
160      *  @return A reference to *this
161      */
162     AttributePath::Builder & NodeId(const chip::NodeId aNodeId);
163
164     /**
165      *  @brief Inject EndpointId into the TLV stream.
166      *
167      *  @param [in] aEndpointId NodeId for this attribute path
168      *
169      *  @return A reference to *this
170      */
171     AttributePath::Builder & EndpointId(const chip::EndpointId aEndpointId);
172
173     /**
174      *  @brief Inject ClusterId into the TLV stream.
175      *
176      *  @param [in] aClusterId ClusterId for this attribute path
177      *
178      *  @return A reference to *this
179      */
180     AttributePath::Builder & ClusterId(const chip::ClusterId aClusterId);
181
182     /**
183      *  @brief Inject FieldId into the TLV stream.
184      *
185      *  @param [in] aFieldId FieldId for this attribute path
186      *
187      *  @return A reference to *this
188      */
189     AttributePath::Builder & FieldId(const uint8_t aFieldId);
190
191     /**
192      *  @brief Inject NodeId into the TLV stream.
193      *
194      *  @param [in] aListIndex NodeId for this attribute path
195      *
196      *  @return A reference to *this
197      */
198     AttributePath::Builder & ListIndex(const uint16_t aListIndex);
199
200     /**
201      *  @brief Mark the end of this AttributePath
202      *
203      *  @return A reference to *this
204      */
205     AttributePath::Builder & EndOfAttributePath();
206
207 private:
208     CHIP_ERROR _Init(chip::TLV::TLVWriter * const apWriter, const uint64_t aTag);
209 };
210
211 }; // namespace AttributePath
212
213 }; // namespace app
214 }; // namespace chip
215
216 #endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_PATH_H