16
16
*/
17
17
#pragma once
18
18
19
+ #include < access/SubjectDescriptor.h>
20
+ #include < app/AttributeEncodeState.h>
19
21
#include < app/AttributeReportBuilder.h>
20
22
#include < app/ConcreteAttributePath.h>
21
23
#include < app/MessageDef/AttributeReportIBs.h>
@@ -51,9 +53,9 @@ class AttributeValueEncoder
51
53
// If we are encoding for a fabric filtered attribute read and the fabric index does not match that present in the
52
54
// request, skip encoding this list item.
53
55
VerifyOrReturnError (!mAttributeValueEncoder .mIsFabricFiltered ||
54
- aArg.GetFabricIndex () == mAttributeValueEncoder .mAccessingFabricIndex ,
56
+ aArg.GetFabricIndex () == mAttributeValueEncoder .AccessingFabricIndex () ,
55
57
CHIP_NO_ERROR);
56
- return mAttributeValueEncoder .EncodeListItem (mAttributeValueEncoder .mAccessingFabricIndex , std::forward<T>(aArg));
58
+ return mAttributeValueEncoder .EncodeListItem (mAttributeValueEncoder .AccessingFabricIndex () , std::forward<T>(aArg));
57
59
}
58
60
59
61
template <typename T, std::enable_if_t <!DataModel::IsFabricScoped<T>::value, bool > = true >
@@ -66,42 +68,11 @@ class AttributeValueEncoder
66
68
AttributeValueEncoder & mAttributeValueEncoder ;
67
69
};
68
70
69
- class AttributeEncodeState
70
- {
71
- public:
72
- AttributeEncodeState () : mAllowPartialData (false ), mCurrentEncodingListIndex (kInvalidListIndex ) {}
73
- bool AllowPartialData () const { return mAllowPartialData ; }
74
-
75
- private:
76
- friend class AttributeValueEncoder ;
77
- /* *
78
- * When an attempt to encode an attribute returns an error, the buffer may contain tailing dirty data
79
- * (since the put was aborted). The report engine normally rolls back the buffer to right before encoding
80
- * of the attribute started on errors.
81
- *
82
- * When chunking a list, EncodeListItem will atomically encode list items, ensuring that the
83
- * state of the buffer is valid to send (i.e. contains no trailing garbage), and return an error
84
- * if the list doesn't entirely fit. In this situation, mAllowPartialData is set to communicate to the
85
- * report engine that it should not roll back the list items.
86
- *
87
- * TODO: There might be a better name for this variable.
88
- */
89
- bool mAllowPartialData = false ;
90
- /* *
91
- * If set to kInvalidListIndex, indicates that we have not encoded any data for the list yet and
92
- * need to start by encoding an empty list before we start encoding any list items.
93
- *
94
- * When set to a valid ListIndex value, indicates the index of the next list item that needs to be
95
- * encoded (i.e. the count of items encoded so far).
96
- */
97
- ListIndex mCurrentEncodingListIndex = kInvalidListIndex ;
98
- };
99
-
100
- AttributeValueEncoder (AttributeReportIBs::Builder & aAttributeReportIBsBuilder, FabricIndex aAccessingFabricIndex,
71
+ AttributeValueEncoder (AttributeReportIBs::Builder & aAttributeReportIBsBuilder, Access::SubjectDescriptor subjectDescriptor,
101
72
const ConcreteAttributePath & aPath, DataVersion aDataVersion, bool aIsFabricFiltered = false ,
102
73
const AttributeEncodeState & aState = AttributeEncodeState()) :
103
74
mAttributeReportIBsBuilder (aAttributeReportIBsBuilder),
104
- mAccessingFabricIndex (aAccessingFabricIndex ), mPath (aPath.mEndpointId , aPath.mClusterId , aPath.mAttributeId ),
75
+ mSubjectDescriptor (subjectDescriptor ), mPath (aPath.mEndpointId , aPath.mClusterId , aPath.mAttributeId ),
105
76
mDataVersion (aDataVersion), mIsFabricFiltered (aIsFabricFiltered), mEncodeState (aState)
106
77
{}
107
78
@@ -169,17 +140,19 @@ class AttributeValueEncoder
169
140
if (err == CHIP_NO_ERROR)
170
141
{
171
142
// The Encode procedure finished without any error, clear the state.
172
- mEncodeState = AttributeEncodeState ();
143
+ mEncodeState . Reset ();
173
144
}
174
145
return err;
175
146
}
176
147
177
148
bool TriedEncode () const { return mTriedEncode ; }
178
149
150
+ const Access::SubjectDescriptor & GetSubjectDescriptor () const { return mSubjectDescriptor ; }
151
+
179
152
/* *
180
153
* The accessing fabric index for this read or subscribe interaction.
181
154
*/
182
- FabricIndex AccessingFabricIndex () const { return mAccessingFabricIndex ; }
155
+ FabricIndex AccessingFabricIndex () const { return GetSubjectDescriptor (). fabricIndex ; }
183
156
184
157
/* *
185
158
* AttributeValueEncoder is a short lived object, and the state is persisted by mEncodeState and restored by constructor.
@@ -195,7 +168,7 @@ class AttributeValueEncoder
195
168
{
196
169
// EncodeListItem must be called after EnsureListStarted(), thus mCurrentEncodingListIndex and
197
170
// mEncodeState.mCurrentEncodingListIndex are not invalid values.
198
- if (mCurrentEncodingListIndex < mEncodeState .mCurrentEncodingListIndex )
171
+ if (mCurrentEncodingListIndex < mEncodeState .CurrentEncodingListIndex () )
199
172
{
200
173
// We have encoded this element in previous chunks, skip it.
201
174
mCurrentEncodingListIndex ++;
@@ -226,7 +199,7 @@ class AttributeValueEncoder
226
199
}
227
200
228
201
mCurrentEncodingListIndex ++;
229
- mEncodeState .mCurrentEncodingListIndex ++ ;
202
+ mEncodeState .SetCurrentEncodingListIndex ( mCurrentEncodingListIndex ) ;
230
203
mEncodedAtLeastOneListItem = true ;
231
204
return CHIP_NO_ERROR;
232
205
}
@@ -266,20 +239,20 @@ class AttributeValueEncoder
266
239
*/
267
240
void EnsureListEnded ();
268
241
269
- bool mTriedEncode = false ;
270
242
AttributeReportIBs::Builder & mAttributeReportIBsBuilder ;
271
- const FabricIndex mAccessingFabricIndex ;
243
+ const Access::SubjectDescriptor mSubjectDescriptor ;
272
244
ConcreteDataAttributePath mPath ;
273
245
DataVersion mDataVersion ;
246
+ bool mTriedEncode = false ;
274
247
bool mIsFabricFiltered = false ;
275
248
// mEncodingInitialList is true if we're encoding a list and we have not
276
249
// started chunking it yet, so we're encoding a single attribute report IB
277
250
// for the whole list, not one per item.
278
251
bool mEncodingInitialList = false ;
279
252
// mEncodedAtLeastOneListItem becomes true once we successfully encode a list item.
280
- bool mEncodedAtLeastOneListItem = false ;
281
- AttributeEncodeState mEncodeState ;
253
+ bool mEncodedAtLeastOneListItem = false ;
282
254
ListIndex mCurrentEncodingListIndex = kInvalidListIndex ;
255
+ AttributeEncodeState mEncodeState ;
283
256
};
284
257
285
258
} // namespace app
0 commit comments