blob: a780e02683eec081f871f245ebcbb90861932612 [file] [log] [blame]
yunhanw-google36e61e32021-11-02 08:31:34 -07001/**
2 *
3 * Copyright (c) 2021 Project CHIP Authors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
20#include "CommandPathIB.h"
21#include "StructBuilder.h"
22
23#include "StatusIB.h"
24#include "StructParser.h"
25
Michael Spangc6b6fb32023-11-17 02:21:20 -050026#include <app/AppConfig.h>
yunhanw-google36e61e32021-11-02 08:31:34 -070027#include <app/util/basic-types.h>
28#include <lib/core/CHIPCore.h>
Martin Turon82bfcd52023-01-09 13:30:38 -080029#include <lib/core/TLV.h>
yunhanw-google36e61e32021-11-02 08:31:34 -070030#include <lib/support/CodeUtils.h>
31#include <lib/support/logging/CHIPLogging.h>
32
33namespace chip {
34namespace app {
35namespace CommandStatusIB {
36enum class Tag : uint8_t
37{
38 kPath = 0,
39 kErrorStatus = 1,
Terence Hampson4e2d4892023-11-21 23:16:42 -050040 kRef = 2,
yunhanw-google36e61e32021-11-02 08:31:34 -070041};
42
43class Parser : public StructParser
44{
45public:
yunhanw-google751d0dd2022-11-16 19:09:58 -080046#if CHIP_CONFIG_IM_PRETTY_PRINT
47 CHIP_ERROR PrettyPrint() const;
48#endif // CHIP_CONFIG_IM_PRETTY_PRINT
yunhanw-google36e61e32021-11-02 08:31:34 -070049
50 /**
51 * @brief Get a TLVReader for the CommandPathIB. Next() must be called before accessing them.
52 *
53 * @param [in] apPath A pointer to apPath
54 *
55 * @return #CHIP_NO_ERROR on success
56 * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not a Path
57 * #CHIP_END_OF_TLV if there is no such element
58 */
59 CHIP_ERROR GetPath(CommandPathIB::Parser * const apPath) const;
60
61 /**
62 * @brief Get a TLVReader for the StatusIB. Next() must be called before accessing them.
63 *
64 * @param [in] apErrorStatus A pointer to apErrorStatus
65 *
66 * @return #CHIP_NO_ERROR on success
67 * # CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not a structure
68 * #CHIP_END_OF_TLV if there is no such element
69 */
70 CHIP_ERROR GetErrorStatus(StatusIB::Parser * const apErrorStatus) const;
Terence Hampson4e2d4892023-11-21 23:16:42 -050071
72 /**
73 * @brief Get the provided command reference associated with the CommandStatus
74 *
75 * @param [out] apRef A pointer to apRef
76 *
77 * @return #CHIP_NO_ERROR on success
78 * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types
79 * #CHIP_END_OF_TLV if there is no such element
80 */
81 CHIP_ERROR GetRef(uint16_t * const apRef) const;
yunhanw-google36e61e32021-11-02 08:31:34 -070082};
83
84class Builder : public StructBuilder
85{
86public:
87 /**
88 * @brief Initialize a CommandPathIB::Builder for writing into the TLV stream
89 *
90 * @return A reference to CommandPathIB::Builder
91 */
92 CommandPathIB::Builder & CreatePath();
93
94 /**
95 * @brief Initialize a StatusIB::Builder for writing into the TLV stream
96 *
97 * @return A reference to StatusIB::Builder
98 */
99 StatusIB::Builder & CreateErrorStatus();
100
101 /**
Terence Hampson4e2d4892023-11-21 23:16:42 -0500102 * @brief Inject Command Ref into the TLV stream.
103 *
104 * @param [in] aRef refer to the CommandRef to set in CommandStatusIB.
105 *
106 * @return #CHIP_NO_ERROR on success
107 */
108 CHIP_ERROR Ref(const uint16_t aRef);
109
110 /**
yunhanw-google36e61e32021-11-02 08:31:34 -0700111 * @brief Mark the end of this CommandStatusIB
112 *
Boris Zbarskydf1f7a82023-05-29 11:24:25 -0400113 * @return The builder's final status.
yunhanw-google36e61e32021-11-02 08:31:34 -0700114 */
Boris Zbarskydf1f7a82023-05-29 11:24:25 -0400115 CHIP_ERROR EndOfCommandStatusIB();
yunhanw-google36e61e32021-11-02 08:31:34 -0700116
117private:
118 CommandPathIB::Builder mPath;
119 StatusIB::Builder mErrorStatus;
120};
121} // namespace CommandStatusIB
122} // namespace app
123} // namespace chip