Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / app / MessageDef / StatusElement.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 StatusElement parser and builder in CHIP interaction model
21  *
22  */
23
24 #pragma once
25
26 #ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_STATUS_ELEMENT_H
27 #define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_STATUS_ELEMENT_H
28
29 #include "ListBuilder.h"
30 #include "ListParser.h"
31
32 #include <core/CHIPCore.h>
33 #include <core/CHIPTLV.h>
34 #include <protocols/secure_channel/Constants.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 StatusElement {
42 enum
43 {
44     kCsTag_GeneralCode  = 1,
45     kCsTag_ProtocolId   = 2,
46     kCsTag_ProtocolCode = 3,
47     kCsTag_ClusterId    = 4
48 };
49
50 class Parser : public ListParser
51 {
52 public:
53     /**
54      *  @brief Initialize the parser object with TLVReader
55      *
56      *  @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this StatusElement
57      *
58      *  @return #CHIP_NO_ERROR on success
59      */
60     CHIP_ERROR Init(const chip::TLV::TLVReader & aReader);
61
62     /**
63      *  @brief Roughly verify the message is correctly formed
64      *   1) all mandatory tags are present
65      *   2) all elements have expected data type
66      *   3) any tag can only appear once
67      *   4) At the top level of the structure, unknown tags are ignored for forward compatibility
68      *  @note The main use of this function is to print out what we're
69      *    receiving during protocol development and debugging.
70      *    The encoding rule has changed in IM encoding spec so this
71      *    check is only "roughly" conformant now.
72      *
73      *  @return #CHIP_NO_ERROR on success
74      */
75     CHIP_ERROR CheckSchemaValidity() const;
76
77     /**
78     `* Read the GeneralCode, ProtocolId, ProtocolCode, ClusterId
79      *
80      * @param[out]   apGeneralCode     Pointer to the storage for the GeneralCode
81      * @param[out]   apProtocolId     Pointer to the storage for the ProtocolId
82      * @param[out]   apProtocolCode   Pointer to the storage for the ProtocolCode
83      * @param[out]   apClusterId     Pointer to the storage for the ClusterId
84      *
85      * @return       CHIP_ERROR codes returned by chip::TLV objects. CHIP_END_OF_TLV if either
86      *               element is missing. CHIP_ERROR_WRONG_TLV_TYPE if the elements are of the wrong
87      *               type.
88      */
89     CHIP_ERROR DecodeStatusElement(Protocols::SecureChannel::GeneralStatusCode * apGeneralCode, uint32_t * apProtocolId,
90                                    uint16_t * apProtocolCode) const;
91 };
92
93 class Builder : public ListBuilder
94 {
95 public:
96     /**
97      *  @brief Initialize a StatusElement::Builder for writing into a TLV stream
98      *
99      *  @param [in] apWriter    A pointer to TLVWriter
100      *
101      *  @return #CHIP_NO_ERROR on success
102      */
103     CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter);
104
105     /**
106      * Init the StatusElement container with an particular context tag.
107      * Required to implement arrays of arrays, and to test ListBuilder.
108      *
109      * @param[in]   apWriter    Pointer to the TLVWriter that is encoding the message.
110      * @param[in]   aContextTagToUse    A contextTag to use.
111      *
112      * @return                  CHIP_ERROR codes returned by chip::TLV objects.
113      */
114     CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter, const uint8_t aContextTagToUse);
115
116     /**
117     `* Read the GeneralCode, ProtocolId, ProtocolCode, ClusterId
118      *
119      * @param[in]   aGeneralCode    General status code
120      * @param[in]   aProtocolId     A protocol ID (32-bit integer composed of a 16-bit vendor id and 16-bit Scoped id)
121      * @param[in]   aProtocolCode   16-bit protocol-specific error code
122      *
123      * @return       CHIP_ERROR codes returned by chip::TLV objects. CHIP_END_OF_TLV if either
124      *               element is missing. CHIP_ERROR_WRONG_TLV_TYPE if the elements are of the wrong
125      *               type.
126      */
127     StatusElement::Builder & EncodeStatusElement(const Protocols::SecureChannel::GeneralStatusCode aGeneralCode,
128                                                  const uint32_t aProtocolId, const uint16_t aProtocolCode);
129
130     /**
131      *  @brief Mark the end of this StatusElement
132      *
133      *  @return A reference to *this
134      */
135     StatusElement::Builder & EndOfStatusElement();
136 };
137 }; // namespace StatusElement
138
139 }; // namespace app
140 }; // namespace chip
141
142 #endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_STATUS_ELEMENT_H