Skip to content

Commit 2c98093

Browse files
committed
Add ListNotifications on DataModelProvider
1 parent 952a5d2 commit 2c98093

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

src/app/WriteHandler.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,18 @@ CHIP_ERROR WriteHandler::SendWriteResponse(System::PacketBufferTLVWriter && aMes
258258

259259
void WriteHandler::DeliverListWriteBegin(const ConcreteAttributePath & aPath)
260260
{
261-
if (auto * attrOverride = AttributeAccessInterfaceRegistry::Instance().Get(aPath.mEndpointId, aPath.mClusterId))
261+
if(mDataModelProvider != nullptr)
262262
{
263-
attrOverride->OnListWriteBegin(aPath);
263+
mDataModelProvider->ListAttributeWriteNotification(aPath, DataModel::ListWriteOperation::kListWriteBegin);
264264
}
265265
}
266266

267267
void WriteHandler::DeliverListWriteEnd(const ConcreteAttributePath & aPath, bool writeWasSuccessful)
268268
{
269-
if (auto * attrOverride = AttributeAccessInterfaceRegistry::Instance().Get(aPath.mEndpointId, aPath.mClusterId))
269+
if(mDataModelProvider != nullptr)
270270
{
271-
attrOverride->OnListWriteEnd(aPath, writeWasSuccessful);
271+
mDataModelProvider->ListAttributeWriteNotification(aPath, writeWasSuccessful ?
272+
DataModel::ListWriteOperation::kListWriteEndFinal : DataModel::ListWriteOperation::kListWriteEnd);
272273
}
273274
}
274275

src/app/data-model-provider/OperationTypes.h

+7
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ enum class ReadFlags : uint32_t
7373
kFabricFiltered = 0x0001, // reading is performed fabric-filtered
7474
};
7575

76+
enum class ListWriteOperation : uint8_t
77+
{
78+
kListWriteBegin = 0,
79+
kListWriteEnd,
80+
kListWriteEndFinal
81+
};
82+
7683
struct ReadAttributeRequest : OperationRequest
7784
{
7885
ConcreteAttributePath path;

src/app/data-model-provider/Provider.h

+8
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ class Provider : public ProviderMetadataTree
7979
/// - validation of ACL/timed interaction flags/writability, if those checks are desired.
8080
virtual ActionReturnStatus WriteAttribute(const WriteAttributeRequest & request, AttributeValueDecoder & decoder) = 0;
8181

82+
/// Indicates the start/end of a series of list operations. This function will be called either before the first
83+
/// Write operation or after the last one of a series of consequence attribute data of the same attribute.
84+
///
85+
/// 1) This function will be called if the client tries to set a nullable list attribute to null.
86+
/// 2) This function will only be called once for a series of consequent attribute data (regardless the kind of list operation)
87+
/// of the same attribute.
88+
virtual void ListAttributeWriteNotification(const ConcreteAttributePath & aPath, BitFlags<ListWriteOperation> opType) = 0;
89+
8290
/// `handler` is used to send back the reply.
8391
/// - returning `std::nullopt` means that return value was placed in handler directly.
8492
/// This includes cases where command handling and value return will be done asynchronously.

src/data-model-providers/codegen/CodegenDataModelProvider.h

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class CodegenDataModelProvider : public DataModel::Provider
6363
AttributeValueEncoder & encoder) override;
6464
DataModel::ActionReturnStatus WriteAttribute(const DataModel::WriteAttributeRequest & request,
6565
AttributeValueDecoder & decoder) override;
66+
void ListAttributeWriteNotification(const ConcreteAttributePath & aPath, BitFlags<DataModel::ListWriteOperation> opType) override;
6667
std::optional<DataModel::ActionReturnStatus> Invoke(const DataModel::InvokeRequest & request, TLV::TLVReader & input_arguments,
6768
CommandHandler * handler) override;
6869

src/data-model-providers/codegen/CodegenDataModelProvider_Write.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,28 @@ DataModel::ActionReturnStatus CodegenDataModelProvider::WriteAttribute(const Dat
198198
return CHIP_NO_ERROR;
199199
}
200200

201+
void CodegenDataModelProvider::ListAttributeWriteNotification(const ConcreteAttributePath & aPath, BitFlags<DataModel::ListWriteOperation> opType) {
202+
AttributeAccessInterface * aai =
203+
AttributeAccessInterfaceRegistry::Instance().Get(aPath.mEndpointId, aPath.mClusterId);
204+
205+
if(aai != nullptr)
206+
{
207+
switch(opType)
208+
{
209+
case DataModel::ListWriteOperation::kListWriteBegin:
210+
aai->OnListWriteBegin(aPath);
211+
break;
212+
case DataModel::ListWriteOperation::kListWriteEnd:
213+
aai->OnListWriteEnd(aPath, false);
214+
break;
215+
case DataModel::ListWriteOperation::kListWriteEndFinal:
216+
aai->OnListWriteEnd(aPath, true);
217+
break;
218+
}
219+
}
220+
221+
}
222+
201223
void CodegenDataModelProvider::Temporary_ReportAttributeChanged(const AttributePathParams & path)
202224
{
203225
ContextAttributesChangeListener change_listener(CurrentContext());

0 commit comments

Comments
 (0)