13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- /* *
17
- * @file
18
- * This file defines ReadRequestMessage parser and builder in CHIP interaction model
19
- *
20
- */
21
16
22
17
#include " ReadRequestMessage.h"
23
18
#include " MessageDefHelper.h"
28
23
29
24
#include < app/AppBuildConfig.h>
30
25
31
- using namespace chip ;
32
- using namespace chip ::TLV;
33
-
34
26
namespace chip {
35
27
namespace app {
36
28
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
37
29
CHIP_ERROR ReadRequestMessage::Parser::CheckSchemaValidity () const
38
30
{
39
- CHIP_ERROR err = CHIP_NO_ERROR;
40
- uint16_t TagPresenceMask = 0 ;
41
- chip::TLV::TLVReader reader;
42
- AttributePathIBs::Parser AttributePathIBs;
43
- EventPaths::Parser eventPathList;
44
- AttributeDataVersionList::Parser attributeDataVersionList;
31
+ CHIP_ERROR err = CHIP_NO_ERROR;
32
+ int TagPresenceMask = 0 ;
33
+ TLV::TLVReader reader;
34
+
45
35
PRETTY_PRINT (" ReadRequestMessage =" );
46
36
PRETTY_PRINT (" {" );
47
37
@@ -50,206 +40,151 @@ CHIP_ERROR ReadRequestMessage::Parser::CheckSchemaValidity() const
50
40
51
41
while (CHIP_NO_ERROR == (err = reader.Next ()))
52
42
{
53
- const Tag tag = reader.GetTag ();
54
-
55
- if (chip::TLV::ContextTag (kCsTag_AttributePathList ) == tag)
56
- {
57
- VerifyOrExit (!(TagPresenceMask & (1 << kCsTag_AttributePathList )), err = CHIP_ERROR_INVALID_TLV_TAG);
58
- TagPresenceMask |= (1 << kCsTag_AttributePathList );
59
- VerifyOrExit (chip::TLV::kTLVType_Array == reader.GetType (), err = CHIP_ERROR_WRONG_TLV_TYPE);
60
-
61
- AttributePathIBs.Init (reader);
62
-
63
- PRETTY_PRINT_INCDEPTH ();
64
-
65
- err = AttributePathIBs.CheckSchemaValidity ();
66
- SuccessOrExit (err);
67
-
68
- PRETTY_PRINT_DECDEPTH ();
69
- }
70
- else if (chip::TLV::ContextTag (kCsTag_EventPaths ) == tag)
71
- {
72
- VerifyOrExit (!(TagPresenceMask & (1 << kCsTag_EventPaths )), err = CHIP_ERROR_INVALID_TLV_TAG);
73
- TagPresenceMask |= (1 << kCsTag_EventPaths );
74
- VerifyOrExit (chip::TLV::kTLVType_Array == reader.GetType (), err = CHIP_ERROR_WRONG_TLV_TYPE);
75
-
76
- eventPathList.Init (reader);
77
-
78
- PRETTY_PRINT_INCDEPTH ();
79
-
80
- err = eventPathList.CheckSchemaValidity ();
81
- SuccessOrExit (err);
82
-
83
- PRETTY_PRINT_DECDEPTH ();
84
- }
85
- else if (chip::TLV::ContextTag (kCsTag_AttributeDataVersionList ) == tag)
43
+ VerifyOrReturnError (TLV::IsContextTag (reader.GetTag ()), CHIP_ERROR_INVALID_TLV_TAG);
44
+ uint32_t tagNum = TLV::TagNumFromTag (reader.GetTag ());
45
+ switch (tagNum)
86
46
{
87
- VerifyOrExit (!(TagPresenceMask & (1 << kCsTag_AttributeDataVersionList )), err = CHIP_ERROR_INVALID_TLV_TAG);
88
- TagPresenceMask |= (1 << kCsTag_AttributeDataVersionList );
89
- VerifyOrExit (chip::TLV::kTLVType_Array == reader.GetType (), err = CHIP_ERROR_WRONG_TLV_TYPE);
90
-
91
- attributeDataVersionList.Init (reader);
92
-
93
- PRETTY_PRINT_INCDEPTH ();
94
-
95
- err = attributeDataVersionList.CheckSchemaValidity ();
96
- SuccessOrExit (err);
97
-
98
- PRETTY_PRINT_DECDEPTH ();
99
- }
100
- else if (chip::TLV::ContextTag (kCsTag_AttributePathList ) == tag)
101
- {
102
- VerifyOrExit (!(TagPresenceMask & (1 << kCsTag_AttributePathList )), err = CHIP_ERROR_INVALID_TLV_TAG);
103
- TagPresenceMask |= (1 << kCsTag_AttributePathList );
104
- VerifyOrExit (chip::TLV::kTLVType_Array == reader.GetType (), err = CHIP_ERROR_WRONG_TLV_TYPE);
105
-
106
- AttributePathIBs.Init (reader);
47
+ case to_underlying (Tag::kAttributeRequests ):
48
+ // check if this tag has appeared before
49
+ VerifyOrReturnError (!(TagPresenceMask & (1 << to_underlying (Tag::kAttributeRequests ))), CHIP_ERROR_INVALID_TLV_TAG);
50
+ TagPresenceMask |= (1 << to_underlying (Tag::kAttributeRequests ));
51
+ {
52
+ AttributePathIBs::Parser attributeRequests;
53
+ ReturnErrorOnFailure (attributeRequests.Init (reader));
107
54
108
- PRETTY_PRINT_INCDEPTH ();
55
+ PRETTY_PRINT_INCDEPTH ();
56
+ ReturnErrorOnFailure (attributeRequests.CheckSchemaValidity ());
57
+ PRETTY_PRINT_DECDEPTH ();
58
+ }
59
+ break ;
60
+ case to_underlying (Tag::kEventRequests ):
61
+ // check if this tag has appeared before
62
+ VerifyOrReturnError (!(TagPresenceMask & (1 << to_underlying (Tag::kEventRequests ))), CHIP_ERROR_INVALID_TLV_TAG);
63
+ TagPresenceMask |= (1 << to_underlying (Tag::kEventRequests ));
64
+ {
65
+ EventPaths::Parser eventRequests;
66
+ ReturnErrorOnFailure (eventRequests.Init (reader));
109
67
110
- err = AttributePathIBs.CheckSchemaValidity ();
111
- SuccessOrExit (err);
68
+ PRETTY_PRINT_INCDEPTH ();
69
+ ReturnErrorOnFailure (eventRequests.CheckSchemaValidity ());
70
+ PRETTY_PRINT_DECDEPTH ();
71
+ }
72
+ break ;
73
+ case to_underlying (Tag::kEventFilters ):
74
+ // check if this tag has appeared before
75
+ VerifyOrReturnError (!(TagPresenceMask & (1 << to_underlying (Tag::kEventFilters ))), CHIP_ERROR_INVALID_TLV_TAG);
76
+ TagPresenceMask |= (1 << to_underlying (Tag::kEventFilters ));
77
+ {
78
+ EventFilters::Parser eventFilters;
79
+ ReturnErrorOnFailure (eventFilters.Init (reader));
112
80
113
- PRETTY_PRINT_DECDEPTH ();
114
- }
115
- else if (chip::TLV::ContextTag (kCsTag_EventNumber ) == tag)
116
- {
117
- VerifyOrExit (!(TagPresenceMask & (1 << kCsTag_EventNumber )), err = CHIP_ERROR_INVALID_TLV_TAG);
118
- TagPresenceMask |= (1 << kCsTag_EventNumber );
119
- VerifyOrExit (chip::TLV::kTLVType_UnsignedInteger == reader.GetType (), err = CHIP_ERROR_WRONG_TLV_TYPE);
81
+ PRETTY_PRINT_INCDEPTH ();
82
+ ReturnErrorOnFailure (eventFilters.CheckSchemaValidity ());
83
+ PRETTY_PRINT_DECDEPTH ();
84
+ }
85
+ break ;
86
+ case to_underlying (Tag::kIsFabricFiltered ):
87
+ // check if this tag has appeared before
88
+ VerifyOrReturnError (!(TagPresenceMask & (1 << to_underlying (Tag::kIsFabricFiltered ))), CHIP_ERROR_INVALID_TLV_TAG);
89
+ TagPresenceMask |= (1 << to_underlying (Tag::kIsFabricFiltered ));
120
90
#if CHIP_DETAIL_LOGGING
121
91
{
122
- uint64_t eventNumber;
123
- err = reader.Get (eventNumber);
124
- SuccessOrExit (err);
125
- PRETTY_PRINT (" \t EventNumber = 0x%" PRIx64 " ," , eventNumber);
92
+ bool isFabricFiltered;
93
+ ReturnErrorOnFailure (reader.Get (isFabricFiltered));
94
+ PRETTY_PRINT (" \t isFabricFiltered = %s, " , isFabricFiltered ? " true" : " false" );
126
95
}
127
96
#endif // CHIP_DETAIL_LOGGING
97
+ break ;
98
+ default :
99
+ PRETTY_PRINT (" Unknown tag num %" PRIu32, tagNum);
100
+ break ;
128
101
}
129
102
}
130
103
131
- PRETTY_PRINT (" }" );
104
+ PRETTY_PRINT (" }, " );
132
105
PRETTY_PRINT (" " );
133
106
134
- // if we have exhausted this container
135
107
if (CHIP_END_OF_TLV == err)
136
108
{
137
- err = CHIP_NO_ERROR;
138
- }
139
- SuccessOrExit (err);
140
- err = reader.ExitContainer (mOuterContainerType );
109
+ const int RequiredFields = (1 << to_underlying (Tag::kIsFabricFiltered ));
141
110
142
- exit :
111
+ if ((TagPresenceMask & RequiredFields) == RequiredFields)
112
+ {
113
+ err = CHIP_NO_ERROR;
114
+ }
115
+ else
116
+ {
117
+ err = CHIP_ERROR_IM_MALFORMED_READ_REQUEST_MESSAGE;
118
+ }
119
+ }
143
120
144
- return err;
121
+ ReturnErrorOnFailure (err);
122
+ return reader.ExitContainer (mOuterContainerType );
145
123
}
146
124
#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
147
125
148
- CHIP_ERROR ReadRequestMessage::Parser::GetPathList (AttributePathIBs::Parser * const apAttributePathList ) const
126
+ CHIP_ERROR ReadRequestMessage::Parser::GetAttributeRequests (AttributePathIBs::Parser * const apAttributeRequests ) const
149
127
{
150
- CHIP_ERROR err = CHIP_NO_ERROR;
151
- chip::TLV::TLVReader reader;
152
-
153
- err = mReader .FindElementWithTag (chip::TLV::ContextTag (kCsTag_AttributePathList ), reader);
154
- SuccessOrExit (err);
155
-
156
- VerifyOrExit (chip::TLV::kTLVType_Array == reader.GetType (), err = CHIP_ERROR_WRONG_TLV_TYPE);
157
-
158
- err = apAttributePathList->Init (reader);
159
- SuccessOrExit (err);
160
-
161
- exit :
162
- ChipLogIfFalse ((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err));
163
-
164
- return err;
128
+ TLV::TLVReader reader;
129
+ ReturnErrorOnFailure (mReader .FindElementWithTag (TLV::ContextTag (to_underlying (Tag::kAttributeRequests )), reader));
130
+ return apAttributeRequests->Init (reader);
165
131
}
166
132
167
- CHIP_ERROR ReadRequestMessage::Parser::GetEventPaths (EventPaths::Parser * const apEventPaths ) const
133
+ CHIP_ERROR ReadRequestMessage::Parser::GetEventRequests (EventPaths::Parser * const apEventRequests ) const
168
134
{
169
- CHIP_ERROR err = CHIP_NO_ERROR;
170
- chip::TLV::TLVReader reader;
171
-
172
- err = mReader .FindElementWithTag (chip::TLV::ContextTag (kCsTag_EventPaths ), reader);
173
- SuccessOrExit (err);
174
-
175
- VerifyOrExit (chip::TLV::kTLVType_Array == reader.GetType (), err = CHIP_ERROR_WRONG_TLV_TYPE);
176
-
177
- err = apEventPaths->Init (reader);
178
- SuccessOrExit (err);
179
-
180
- exit :
181
- ChipLogIfFalse ((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err));
182
-
183
- return err;
135
+ TLV::TLVReader reader;
136
+ ReturnErrorOnFailure (mReader .FindElementWithTag (TLV::ContextTag (to_underlying (Tag::kEventRequests )), reader));
137
+ return apEventRequests->Init (reader);
184
138
}
185
139
186
- CHIP_ERROR
187
- ReadRequestMessage::Parser::GetAttributeDataVersionList (AttributeDataVersionList::Parser * const apAttributeDataVersionList) const
140
+ CHIP_ERROR ReadRequestMessage::Parser::GetEventFilters (EventFilters::Parser * const apEventFilters) const
188
141
{
189
- CHIP_ERROR err = CHIP_NO_ERROR;
190
- chip::TLV::TLVReader reader;
191
-
192
- err = mReader .FindElementWithTag (chip::TLV::ContextTag (kCsTag_AttributeDataVersionList ), reader);
193
- SuccessOrExit (err);
194
-
195
- VerifyOrExit (chip::TLV::kTLVType_Array == reader.GetType (), err = CHIP_ERROR_WRONG_TLV_TYPE);
196
-
197
- err = apAttributeDataVersionList->Init (reader);
198
- SuccessOrExit (err);
199
-
200
- exit :
201
- ChipLogIfFalse ((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err));
202
-
203
- return err;
142
+ TLV::TLVReader reader;
143
+ ReturnErrorOnFailure (mReader .FindElementWithTag (TLV::ContextTag (to_underlying (Tag::kEventFilters )), reader));
144
+ return apEventFilters->Init (reader);
204
145
}
205
146
206
- CHIP_ERROR ReadRequestMessage::Parser::GetEventNumber ( uint64_t * const apEventNumber ) const
147
+ CHIP_ERROR ReadRequestMessage::Parser::GetIsFabricFiltered ( bool * const apIsFabricFiltered ) const
207
148
{
208
- return GetUnsignedInteger ( kCsTag_EventNumber , apEventNumber );
149
+ return GetSimpleValue ( to_underlying (Tag:: kIsFabricFiltered ), TLV:: kTLVType_Boolean , apIsFabricFiltered );
209
150
}
210
151
211
- AttributePathIBs::Builder & ReadRequestMessage::Builder::CreateAttributePathListBuilder ()
152
+ AttributePathIBs::Builder & ReadRequestMessage::Builder::CreateAttributeRequests ()
212
153
{
213
154
// skip if error has already been set
214
- VerifyOrExit (CHIP_NO_ERROR == mError , mAttributePathListBuilder .ResetError (mError ));
215
-
216
- mError = mAttributePathListBuilder .Init (mpWriter, kCsTag_AttributePathList );
217
-
218
- exit :
219
- // on error, mAttributePathListBuilder would be un-/partial initialized and cannot be used to write anything
220
- return mAttributePathListBuilder ;
155
+ if (mError == CHIP_NO_ERROR)
156
+ {
157
+ mError = mAttributeRequests .Init (mpWriter, to_underlying (Tag::kAttributeRequests ));
158
+ }
159
+ return mAttributeRequests ;
221
160
}
222
161
223
- EventPaths::Builder & ReadRequestMessage::Builder::CreateEventPathsBuilder ()
162
+ EventPaths::Builder & ReadRequestMessage::Builder::CreateEventRequests ()
224
163
{
225
164
// skip if error has already been set
226
- VerifyOrExit (CHIP_NO_ERROR == mError , mEventPathsBuilder .ResetError (mError ));
227
-
228
- mError = mEventPathsBuilder .Init (mpWriter, kCsTag_EventPaths );
229
-
230
- exit :
231
- // on error, mEventPathsBuilder would be un-/partial initialized and cannot be used to write anything
232
- return mEventPathsBuilder ;
165
+ if (mError == CHIP_NO_ERROR)
166
+ {
167
+ mError = mEventRequests .Init (mpWriter, to_underlying (Tag::kEventRequests ));
168
+ }
169
+ return mEventRequests ;
233
170
}
234
171
235
- AttributeDataVersionList ::Builder & ReadRequestMessage::Builder::CreateAttributeDataVersionListBuilder ()
172
+ EventFilters ::Builder & ReadRequestMessage::Builder::CreateEventFilters ()
236
173
{
237
174
// skip if error has already been set
238
- VerifyOrExit (CHIP_NO_ERROR == mError , mAttributeDataVersionListBuilder .ResetError (mError ));
239
-
240
- mError = mAttributeDataVersionListBuilder .Init (mpWriter, kCsTag_AttributeDataVersionList );
241
-
242
- exit :
243
- // on error, mAttributeDataVersionListBuilder would be un-/partial initialized and cannot be used to write anything
244
- return mAttributeDataVersionListBuilder ;
175
+ if (mError == CHIP_NO_ERROR)
176
+ {
177
+ mError = mEventFilters .Init (mpWriter, to_underlying (Tag::kEventFilters ));
178
+ }
179
+ return mEventFilters ;
245
180
}
246
181
247
- ReadRequestMessage::Builder & ReadRequestMessage::Builder::EventNumber (const uint64_t aEventNumber )
182
+ ReadRequestMessage::Builder & ReadRequestMessage::Builder::IsFabricFiltered (const bool aIsFabricFiltered )
248
183
{
249
184
// skip if error has already been set
250
185
if (mError == CHIP_NO_ERROR)
251
186
{
252
- mError = mpWriter->Put ( chip:: TLV::ContextTag (kCsTag_EventNumber ), aEventNumber );
187
+ mError = mpWriter->PutBoolean ( TLV::ContextTag (to_underlying (Tag:: kIsFabricFiltered )), aIsFabricFiltered );
253
188
}
254
189
return *this ;
255
190
}
@@ -259,5 +194,5 @@ ReadRequestMessage::Builder & ReadRequestMessage::Builder::EndOfReadRequestMessa
259
194
EndOfContainer ();
260
195
return *this ;
261
196
}
262
- }; // namespace app
263
- }; // namespace chip
197
+ } // namespace app
198
+ } // namespace chip
0 commit comments