Skip to content

Commit 36ec44c

Browse files
tersalrestyled-commitsbzbarsky-apple
authored andcommitted
Add ListNotifications on DataModelProvider (project-chip#37526)
* Add ListNotifications on DataModelProvider * Restyled by whitespace * Restyled by clang-format * Rename enum values and add more information in comments. * Update src/app/data-model-provider/Provider.h Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Remove BitFlags from Provider --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent 6ae2b9c commit 36ec44c

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

src/app/WriteHandler.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,19 @@ 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,
272+
writeWasSuccessful ? DataModel::ListWriteOperation::kListWriteSuccess
273+
: DataModel::ListWriteOperation::kListWriteFailure);
272274
}
273275
}
274276

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+
kListWriteSuccess,
80+
kListWriteFailure
81+
};
82+
7683
struct ReadAttributeRequest : OperationRequest
7784
{
7885
ConcreteAttributePath path;

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

+9
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ 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 consecutive 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 at the beginning and end of a series of consecutive attribute data
87+
/// blocks for the same attribute, no matter what list operations those data blocks represent.
88+
/// 3) The opType argument indicates the type of notification (Start, Failure, Success).
89+
virtual void ListAttributeWriteNotification(const ConcreteAttributePath & aPath, ListWriteOperation opType) = 0;
90+
8291
/// `handler` is used to send back the reply.
8392
/// - returning `std::nullopt` means that return value was placed in handler directly.
8493
/// 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, 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,
202+
DataModel::ListWriteOperation opType)
203+
{
204+
AttributeAccessInterface * aai = AttributeAccessInterfaceRegistry::Instance().Get(aPath.mEndpointId, aPath.mClusterId);
205+
206+
if (aai != nullptr)
207+
{
208+
switch (opType)
209+
{
210+
case DataModel::ListWriteOperation::kListWriteBegin:
211+
aai->OnListWriteBegin(aPath);
212+
break;
213+
case DataModel::ListWriteOperation::kListWriteFailure:
214+
aai->OnListWriteEnd(aPath, false);
215+
break;
216+
case DataModel::ListWriteOperation::kListWriteSuccess:
217+
aai->OnListWriteEnd(aPath, true);
218+
break;
219+
}
220+
}
221+
}
222+
201223
void CodegenDataModelProvider::Temporary_ReportAttributeChanged(const AttributePathParams & path)
202224
{
203225
ContextAttributesChangeListener change_listener(CurrentContext());

0 commit comments

Comments
 (0)