yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 1 | /** |
| 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 Spang | c6b6fb3 | 2023-11-17 02:21:20 -0500 | [diff] [blame] | 26 | #include <app/AppConfig.h> |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 27 | #include <app/util/basic-types.h> |
| 28 | #include <lib/core/CHIPCore.h> |
Martin Turon | 82bfcd5 | 2023-01-09 13:30:38 -0800 | [diff] [blame] | 29 | #include <lib/core/TLV.h> |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 30 | #include <lib/support/CodeUtils.h> |
| 31 | #include <lib/support/logging/CHIPLogging.h> |
| 32 | |
| 33 | namespace chip { |
| 34 | namespace app { |
| 35 | namespace CommandStatusIB { |
| 36 | enum class Tag : uint8_t |
| 37 | { |
| 38 | kPath = 0, |
| 39 | kErrorStatus = 1, |
Terence Hampson | 4e2d489 | 2023-11-21 23:16:42 -0500 | [diff] [blame] | 40 | kRef = 2, |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | class Parser : public StructParser |
| 44 | { |
| 45 | public: |
yunhanw-google | 751d0dd | 2022-11-16 19:09:58 -0800 | [diff] [blame] | 46 | #if CHIP_CONFIG_IM_PRETTY_PRINT |
| 47 | CHIP_ERROR PrettyPrint() const; |
| 48 | #endif // CHIP_CONFIG_IM_PRETTY_PRINT |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 49 | |
| 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 Hampson | 4e2d489 | 2023-11-21 23:16:42 -0500 | [diff] [blame] | 71 | |
| 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-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | class Builder : public StructBuilder |
| 85 | { |
| 86 | public: |
| 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 Hampson | 4e2d489 | 2023-11-21 23:16:42 -0500 | [diff] [blame] | 102 | * @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-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 111 | * @brief Mark the end of this CommandStatusIB |
| 112 | * |
Boris Zbarsky | df1f7a8 | 2023-05-29 11:24:25 -0400 | [diff] [blame] | 113 | * @return The builder's final status. |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 114 | */ |
Boris Zbarsky | df1f7a8 | 2023-05-29 11:24:25 -0400 | [diff] [blame] | 115 | CHIP_ERROR EndOfCommandStatusIB(); |
yunhanw-google | 36e61e3 | 2021-11-02 08:31:34 -0700 | [diff] [blame] | 116 | |
| 117 | private: |
| 118 | CommandPathIB::Builder mPath; |
| 119 | StatusIB::Builder mErrorStatus; |
| 120 | }; |
| 121 | } // namespace CommandStatusIB |
| 122 | } // namespace app |
| 123 | } // namespace chip |