3 * Copyright (c) 2020 Project CHIP Authors
4 * 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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 * This file defines AttributePath parser and builder in CHIP interaction model
26 #ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_PATH_H
27 #define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_PATH_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>
39 namespace AttributePath {
43 kCsTag_EndpointId = 1,
49 class Parser : public chip::app::Parser
53 * @brief Initialize the parser object with TLVReader
55 * @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this AttributePath
57 * @return #CHIP_NO_ERROR on success
59 CHIP_ERROR Init(const chip::TLV::TLVReader & aReader);
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.
72 * @return #CHIP_NO_ERROR on success
74 CHIP_ERROR CheckSchemaValidity() const;
77 * @brief Get a TLVReader for the NodeId. Next() must be called before accessing them.
79 * @param [in] apNodeId A pointer to apNodeId
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
85 CHIP_ERROR GetNodeId(chip::NodeId * const apNodeId) const;
88 * @brief Get a TLVReader for the EndpointId. Next() must be called before accessing them.
90 * @param [in] apEndpointId A pointer to apEndpointId
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
96 CHIP_ERROR GetEndpointId(chip::EndpointId * const apEndpointId) const;
99 * @brief Get a TLVReader for the ClusterId. Next() must be called before accessing them.
101 * @param [in] apClusterId A pointer to apClusterId
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
107 CHIP_ERROR GetClusterId(chip::ClusterId * const apClusterId) const;
110 * @brief Get a TLVReader for the FieldId. Next() must be called before accessing them.
112 * @param [in] apFieldId A pointer to apFieldId
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
118 CHIP_ERROR GetFieldId(uint8_t * const apFieldId) const;
121 * @brief Get a TLVReader for the ListIndex. Next() must be called before accessing them.
123 * @param [in] apListIndex A pointer to apListIndex
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
129 CHIP_ERROR GetListIndex(uint16_t * const apListIndex) const;
132 class Builder : public chip::app::Builder
136 * @brief Initialize a AttributePath::Builder for writing into a TLV stream
138 * @param [in] apWriter A pointer to TLVWriter
140 * @return #CHIP_NO_ERROR on success
142 CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter);
145 * Init the AttributePath container with an particular context tag.
146 * Required to implement arrays of arrays, and to test ListBuilder.
148 * @param[in] apWriter Pointer to the TLVWriter that is encoding the message.
149 * @param[in] aContextTagToUse A contextTag to use.
151 * @return CHIP_ERROR codes returned by chip::TLV objects.
153 CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter, const uint8_t aContextTagToUse);
156 * @brief Inject NodeId into the TLV stream.
158 * @param [in] aNodeId NodeId for this attribute path
160 * @return A reference to *this
162 AttributePath::Builder & NodeId(const chip::NodeId aNodeId);
165 * @brief Inject EndpointId into the TLV stream.
167 * @param [in] aEndpointId NodeId for this attribute path
169 * @return A reference to *this
171 AttributePath::Builder & EndpointId(const chip::EndpointId aEndpointId);
174 * @brief Inject ClusterId into the TLV stream.
176 * @param [in] aClusterId ClusterId for this attribute path
178 * @return A reference to *this
180 AttributePath::Builder & ClusterId(const chip::ClusterId aClusterId);
183 * @brief Inject FieldId into the TLV stream.
185 * @param [in] aFieldId FieldId for this attribute path
187 * @return A reference to *this
189 AttributePath::Builder & FieldId(const uint8_t aFieldId);
192 * @brief Inject NodeId into the TLV stream.
194 * @param [in] aListIndex NodeId for this attribute path
196 * @return A reference to *this
198 AttributePath::Builder & ListIndex(const uint16_t aListIndex);
201 * @brief Mark the end of this AttributePath
203 * @return A reference to *this
205 AttributePath::Builder & EndOfAttributePath();
208 CHIP_ERROR _Init(chip::TLV::TLVWriter * const apWriter, const uint64_t aTag);
211 }; // namespace AttributePath
216 #endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_ATTRIBUTE_PATH_H