Line data Source code
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 : * @file
19 : * This file defines WriteRequestMessage parser and builder in CHIP interaction model
20 : *
21 : */
22 :
23 : #pragma once
24 :
25 : #include "AttributeDataIBs.h"
26 : #include "MessageBuilder.h"
27 : #include "MessageParser.h"
28 : #include <app/util/basic-types.h>
29 : #include <lib/core/CHIPCore.h>
30 : #include <lib/core/TLV.h>
31 : #include <lib/support/CodeUtils.h>
32 : #include <lib/support/logging/CHIPLogging.h>
33 :
34 : namespace chip {
35 : namespace app {
36 : namespace WriteRequestMessage {
37 : enum class Tag : uint8_t
38 : {
39 : kSuppressResponse = 0,
40 : kTimedRequest = 1,
41 : kWriteRequests = 2,
42 : kMoreChunkedMessages = 3,
43 : };
44 :
45 : class Parser : public MessageParser
46 : {
47 : public:
48 : #if CHIP_CONFIG_IM_PRETTY_PRINT
49 : CHIP_ERROR PrettyPrint() const;
50 : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
51 : /**
52 : * @brief Get SuppressResponse boolean
53 : *
54 : * @param [in] apSuppressResponse A pointer to apSuppressResponse
55 : *
56 : * @return #CHIP_NO_ERROR on success
57 : * #CHIP_END_OF_TLV if there is no such element
58 : */
59 : CHIP_ERROR GetSuppressResponse(bool * const apSuppressResponse) const;
60 :
61 : /**
62 : * @brief Get TimedRequest boolean
63 : *
64 : * @param [in] apTimedRequest A pointer to apTimedRequest
65 : *
66 : * @return #CHIP_NO_ERROR on success
67 : * #CHIP_END_OF_TLV if there is no such element
68 : */
69 : CHIP_ERROR GetTimedRequest(bool * const apTimedRequest) const;
70 :
71 : /**
72 : * @brief Get a TLVReader for the AttributePathIBs. Next() must be called before accessing them.
73 : *
74 : * @param [in] apAttributeDataIBs A pointer to apAttributeDataIBs
75 : *
76 : * @return #CHIP_NO_ERROR on success
77 : * #CHIP_END_OF_TLV if there is no such element
78 : */
79 : CHIP_ERROR GetWriteRequests(AttributeDataIBs::Parser * const apAttributeDataIBs) const;
80 :
81 : /**
82 : * @brief Get MoreChunkedMessages boolean
83 : *
84 : * @param [in] apMoreChunkedMessages A pointer to apMoreChunkedMessages
85 : *
86 : * @return #CHIP_NO_ERROR on success
87 : * #CHIP_END_OF_TLV if there is no such element
88 : */
89 : CHIP_ERROR GetMoreChunkedMessages(bool * const apMoreChunkedMessages) const;
90 : };
91 :
92 : class Builder : public MessageBuilder
93 : {
94 : public:
95 : /**
96 : * @brief This can be used to optionally signal to the server that no responses are to be sent back.
97 : * @param [in] aSuppressResponse true if client need to signal suppress response
98 : * @return A reference to *this
99 : */
100 : WriteRequestMessage::Builder & SuppressResponse(const bool aSuppressResponse);
101 :
102 : /**
103 : * @brief flag action as part of a timed write transaction
104 : * @param [in] aTimedRequest true if client need to signal this is a timed request
105 : * @return A reference to *this
106 : */
107 : WriteRequestMessage::Builder & TimedRequest(const bool aTimedRequest);
108 :
109 : /**
110 : * @brief Initialize a AttributeDataIBs::Builder for writing into the TLV stream
111 : *
112 : * @return A reference to AttributeDataIBs::Builder
113 : */
114 : AttributeDataIBs::Builder & CreateWriteRequests();
115 :
116 : /**
117 : * @brief Set True if the set of AttributeDataIBs have to be sent across multiple packets in a single transaction
118 : * @param [in] aMoreChunkedMessages true if more chunked messaged is needed
119 : * @return A reference to *this
120 : */
121 : WriteRequestMessage::Builder & MoreChunkedMessages(const bool aMoreChunkedMessages);
122 :
123 0 : AttributeDataIBs::Builder & GetWriteRequests() { return mWriteRequests; };
124 :
125 : /**
126 : * @brief Mark the end of this WriteRequestMessage
127 : *
128 : * @return The builder's final status.
129 : */
130 : CHIP_ERROR EndOfWriteRequestMessage();
131 :
132 : private:
133 : AttributeDataIBs::Builder mWriteRequests;
134 : };
135 : } // namespace WriteRequestMessage
136 : } // namespace app
137 : } // namespace chip
|