Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ListNotifications on DataModelProvider #37526

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/app/WriteHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,19 @@ CHIP_ERROR WriteHandler::SendWriteResponse(System::PacketBufferTLVWriter && aMes

void WriteHandler::DeliverListWriteBegin(const ConcreteAttributePath & aPath)
{
if (auto * attrOverride = AttributeAccessInterfaceRegistry::Instance().Get(aPath.mEndpointId, aPath.mClusterId))
if (mDataModelProvider != nullptr)
{
attrOverride->OnListWriteBegin(aPath);
mDataModelProvider->ListAttributeWriteNotification(aPath, DataModel::ListWriteOperation::kListWriteBegin);
}
}

void WriteHandler::DeliverListWriteEnd(const ConcreteAttributePath & aPath, bool writeWasSuccessful)
{
if (auto * attrOverride = AttributeAccessInterfaceRegistry::Instance().Get(aPath.mEndpointId, aPath.mClusterId))
if (mDataModelProvider != nullptr)
{
attrOverride->OnListWriteEnd(aPath, writeWasSuccessful);
mDataModelProvider->ListAttributeWriteNotification(aPath,
writeWasSuccessful ? DataModel::ListWriteOperation::kListWriteSuccess
: DataModel::ListWriteOperation::kListWriteFailure);
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/app/data-model-provider/OperationTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ enum class ReadFlags : uint32_t
kFabricFiltered = 0x0001, // reading is performed fabric-filtered
};

enum class ListWriteOperation : uint8_t
{
kListWriteBegin = 0,
kListWriteSuccess,
kListWriteFailure
};

struct ReadAttributeRequest : OperationRequest
{
ConcreteAttributePath path;
Expand Down
9 changes: 9 additions & 0 deletions src/app/data-model-provider/Provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ class Provider : public ProviderMetadataTree
/// - validation of ACL/timed interaction flags/writability, if those checks are desired.
virtual ActionReturnStatus WriteAttribute(const WriteAttributeRequest & request, AttributeValueDecoder & decoder) = 0;

/// Indicates the start/end of a series of list operations. This function will be called either before the first
/// Write operation or after the last one of a series of consecutive attribute data of the same attribute.
///
/// 1) This function will be called if the client tries to set a nullable list attribute to null.
/// 2) This function will only be called at the beginning and end of a series of consecutive attribute data
/// blocks for the same attribute, no matter what list operations those data blocks represent.
/// 3) The opType argument indicates the type of notification (Start, Failure, Success).
virtual void ListAttributeWriteNotification(const ConcreteAttributePath & aPath, ListWriteOperation opType) = 0;

/// `handler` is used to send back the reply.
/// - returning `std::nullopt` means that return value was placed in handler directly.
/// This includes cases where command handling and value return will be done asynchronously.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class CodegenDataModelProvider : public DataModel::Provider
AttributeValueEncoder & encoder) override;
DataModel::ActionReturnStatus WriteAttribute(const DataModel::WriteAttributeRequest & request,
AttributeValueDecoder & decoder) override;
void ListAttributeWriteNotification(const ConcreteAttributePath & aPath, DataModel::ListWriteOperation opType) override;
std::optional<DataModel::ActionReturnStatus> Invoke(const DataModel::InvokeRequest & request, TLV::TLVReader & input_arguments,
CommandHandler * handler) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,28 @@ DataModel::ActionReturnStatus CodegenDataModelProvider::WriteAttribute(const Dat
return CHIP_NO_ERROR;
}

void CodegenDataModelProvider::ListAttributeWriteNotification(const ConcreteAttributePath & aPath,
DataModel::ListWriteOperation opType)
{
AttributeAccessInterface * aai = AttributeAccessInterfaceRegistry::Instance().Get(aPath.mEndpointId, aPath.mClusterId);

if (aai != nullptr)
{
switch (opType)
{
case DataModel::ListWriteOperation::kListWriteBegin:
aai->OnListWriteBegin(aPath);
break;
case DataModel::ListWriteOperation::kListWriteFailure:
aai->OnListWriteEnd(aPath, false);
break;
case DataModel::ListWriteOperation::kListWriteSuccess:
aai->OnListWriteEnd(aPath, true);
break;
}
}
}

void CodegenDataModelProvider::Temporary_ReportAttributeChanged(const AttributePathParams & path)
{
ContextAttributesChangeListener change_listener(CurrentContext());
Expand Down
Loading