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