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 ReadRequest parser and builder in CHIP interaction model
26 #ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_READ_REQUEST_H
27 #define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_READ_REQUEST_H
29 #include "AttributeDataVersionList.h"
30 #include "AttributePathList.h"
32 #include "EventPathList.h"
35 #include <core/CHIPCore.h>
36 #include <core/CHIPTLV.h>
37 #include <support/CodeUtils.h>
38 #include <support/logging/CHIPLogging.h>
39 #include <util/basic-types.h>
43 namespace ReadRequest {
46 kCsTag_AttributePathList = 0,
47 kCsTag_EventPathList = 1,
48 kCsTag_AttributeDataVersionList = 2,
49 kCsTag_EventNumber = 3,
52 class Parser : public chip::app::Parser
56 * @brief Initialize the parser object with TLVReader
58 * @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this request
60 * @return #CHIP_NO_ERROR on success
62 CHIP_ERROR Init(const chip::TLV::TLVReader & aReader);
65 * @brief Roughly verify the message is correctly formed
66 * 1) all mandatory tags are present
67 * 2) all elements have expected data type
68 * 3) any tag can only appear once
69 * 4) At the top level of the structure, unknown tags are ignored for forward compatibility
70 * @note The main use of this function is to print out what we're
71 * receiving during protocol development and debugging.
72 * The encoding rule has changed in IM encoding spec so this
73 * check is only "roughly" conformant now.
75 * @return #CHIP_NO_ERROR on success
77 CHIP_ERROR CheckSchemaValidity() const;
80 * @brief Get a TLVReader for the AttributePathList. Next() must be called before accessing them.
82 * @param [in] apAttributePath A pointer to apAttributePath
84 * @return #CHIP_NO_ERROR on success
85 * #CHIP_END_OF_TLV if there is no such element
87 CHIP_ERROR GetAttributePathList(AttributePathList::Parser * const apAttributePathList) const;
90 * @brief Get a TLVReader for the EventPathList. Next() must be called before accessing them.
92 * @param [in] apEventPathList A pointer to apEventPathList
94 * @return #CHIP_NO_ERROR on success
95 * #CHIP_END_OF_TLV if there is no such element
97 CHIP_ERROR GetEventPathList(EventPathList::Parser * const apEventPathList) const;
100 * @brief Get a parser for the AttributeDataVersionList. Next() must be called before accessing them.
102 * @param [in] apAttributeDataVersionList A pointer to apAttributeDataVersionList
104 * @return #CHIP_NO_ERROR on success
105 * #CHIP_END_OF_TLV if there is no such element
107 CHIP_ERROR GetAttributeDataVersionList(AttributeDataVersionList::Parser * const apAttributeDataVersionList) const;
110 * @brief Get Event Number. Next() must be called before accessing them.
112 * @param [in] apEventNumber A pointer to apEventNumber
114 * @return #CHIP_NO_ERROR on success
115 * #CHIP_END_OF_TLV if there is no such element
117 CHIP_ERROR GetEventNumber(uint64_t * const apEventNumber) const;
120 class Builder : public chip::app::Builder
124 * @brief Initialize a ReadRequest::Builder for writing into a TLV stream
126 * @param [in] apWriter A pointer to TLVWriter
128 * @return #CHIP_NO_ERROR on success
130 CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter);
133 * @brief Initialize a AttributePathList::Builder for writing into the TLV stream
135 * @return A reference to AttributePathList::Builder
137 AttributePathList::Builder & CreateAttributePathListBuilder();
140 * @brief Initialize a EventPathList::Builder for writing into the TLV stream
142 * @return A reference to EventPathList::Builder
144 EventPathList::Builder & CreateEventPathListBuilder();
147 * @brief Initialize a AttributeDataVersionList::Builder for writing into the TLV stream
149 * @return A reference to AttributeDataVersionList::Builder
151 AttributeDataVersionList::Builder & CreateAttributeDataVersionListBuilder();
154 * @brief An initiator can optionally specify an EventNumber it has already to limit the
155 * set of retrieved events on the server for optimization purposes.
156 * @param [in] aEventNumber The event number
157 * @return A reference to *this
159 ReadRequest::Builder & EventNumber(const uint64_t aEventNumber);
161 * @brief Mark the end of this ReadRequest
163 * @return A reference to *this
165 ReadRequest::Builder & EndOfReadRequest();
168 AttributePathList::Builder mAttributePathListBuilder;
169 EventPathList::Builder mEventPathListBuilder;
170 AttributeDataVersionList::Builder mAttributeDataVersionListBuilder;
172 }; // namespace ReadRequest
176 #endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_READ_REQUEST_H