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

Create an AAI registry for PwRPC services to allow registration of custom AAI classes #37351

Merged
merged 30 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2376709
Allow custom AAI registration for PwRPC Reads/Writes. Update PwRPC Wr…
sxb427 Feb 2, 2025
209f816
Add succes log
sxb427 Feb 2, 2025
5a361ca
Make TryWriteViaAAI public
sxb427 Feb 2, 2025
5457062
Make TryWriteViaAAI public
sxb427 Feb 2, 2025
008f9bf
Fix compilation errors
sxb427 Feb 2, 2025
f606f4b
Fix compilation errors
sxb427 Feb 2, 2025
a130e5f
Fix compilation errors
sxb427 Feb 2, 2025
4393084
Update examples/common/pigweed/rpc_services/Attributes.h
sxb427 Feb 3, 2025
5fe8146
Add new attribute accessor and registry for PwRPC
sxb427 Feb 4, 2025
38feaad
Fix compilation error
sxb427 Feb 4, 2025
0bb1c43
Fix compilation error
sxb427 Feb 4, 2025
a8bcf87
Fix compilation error
sxb427 Feb 4, 2025
e5c8e4b
Revert changes
sxb427 Feb 4, 2025
95c1d6b
Revert changes
sxb427 Feb 4, 2025
9347c92
Accessors will not be indexed by EndpointId/ClusterId. Caller queries…
sxb427 Feb 4, 2025
a9d9d83
fix compilation bug
sxb427 Feb 5, 2025
1b26dca
Review comments
sxb427 Feb 5, 2025
ac040f3
Fix compilation
sxb427 Feb 5, 2025
892903f
Fix nits
sxb427 Feb 5, 2025
ed08376
Merge branch 'master' into pwrpc-aai
sxb427 Feb 5, 2025
14806c8
Fix ESP32 compilation
sxb427 Feb 6, 2025
222ab01
Update examples/common/pigweed/rpc_services/AccessInterceptor.h
sxb427 Feb 6, 2025
a3e8f15
Update examples/common/pigweed/rpc_services/AccessInterceptor.h
sxb427 Feb 6, 2025
45f54b8
Update examples/common/pigweed/rpc_services/AccessInterceptorRegistry.h
sxb427 Feb 6, 2025
7676386
Merge branch 'master' into pwrpc-aai
sxb427 Feb 6, 2025
38edc19
Review comments
sxb427 Feb 6, 2025
40de86d
Merge branch 'master' into pwrpc-aai
sxb427 Feb 6, 2025
ba38ab0
Update examples/common/pigweed/rpc_services/AccessInterceptor.h
andy31415 Feb 6, 2025
20294c9
Merge branch 'master' into pwrpc-aai
sxb427 Feb 6, 2025
cbcbae7
Merge branch 'master' into pwrpc-aai
sxb427 Feb 6, 2025
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
46 changes: 46 additions & 0 deletions examples/common/pigweed/rpc_services/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <app-common/zap-generated/attribute-type.h>
#include <app/AppConfig.h>
#include <app/AttributeAccessInterfaceRegistry.h>
#include <app/AttributeValueEncoder.h>
#include <app/InteractionModelEngine.h>
#include <app/MessageDef/AttributeReportIBs.h>
Expand All @@ -33,6 +34,7 @@
#include <app/data-model-provider/Provider.h>
#include <app/util/attribute-storage.h>
#include <app/util/attribute-table.h>
#include <data-model-providers/codegen/CodegenDataModelProvider.h>
#include <lib/core/TLV.h>
#include <lib/core/TLVTags.h>
#include <lib/core/TLVTypes.h>
Expand All @@ -41,6 +43,25 @@
namespace chip {
namespace rpc {

/** @brief
* This class is specifically meant for registering custom Attribute Access Interfaces that
* allow to read/modify the state of an attribute at its raw storage location. This should
* not be used in code paths that need to be matter spec compliant. It is meant to be used
* by Pw RPC to add device simulation for tests.
*/
sxb427 marked this conversation as resolved.
Show resolved Hide resolved
class RawAttributeAccessInterfaceRegistry : public chip::app::AttributeAccessInterfaceRegistry
{
public:
/**
* Get the singleton instance.
*/
static RawAttributeAccessInterfaceRegistry & Instance()
{
static RawAttributeAccessInterfaceRegistry instance;
return instance;
}
};

// Implementation class for chip.rpc.Attributes.
class Attributes : public pw_rpc::nanopb::Attributes::Service<Attributes>
{
Expand Down Expand Up @@ -207,6 +228,31 @@ class Attributes : public pw_rpc::nanopb::Attributes::Service<Attributes>
}

app::AttributeValueDecoder decoder(tlvReader.value(), subjectDescriptor);

// Try to write using a custom AAI first
chip::app::AttributeAccessInterface * customAai =
sxb427 marked this conversation as resolved.
Show resolved Hide resolved
RawAttributeAccessInterfaceRegistry::Instance().Get(write_request.path.mEndpointId, write_request.path.mClusterId);
std::optional<CHIP_ERROR> aaiResult = chip::app::TryWriteViaAccessInterface(write_request.path, customAai, decoder);
sxb427 marked this conversation as resolved.
Show resolved Hide resolved
if (aaiResult.has_value())
{
if (*aaiResult == CHIP_NO_ERROR)
{
ChipLogProgress(Support, "Successfully changed attribute value using custom AAI Write.");
// TODO: Call emberAfAttributeChanged here or let AAI decide?
return pw::OkStatus();
}
else
{
ChipLogError(Support, "Failed to write data: %" CHIP_ERROR_FORMAT, (*aaiResult).Format());
return ::pw::Status::Internal();
}
}
else
{
ChipLogProgress(Support, "No custom AAI Write registration found for: endpoint=%u cluster=%u",
sxb427 marked this conversation as resolved.
Show resolved Hide resolved
write_request.path.mEndpointId, write_request.path.mClusterId);
}

app::DataModel::ActionReturnStatus result = provider->WriteAttribute(write_request, decoder);

if (!result.IsSuccess())
Expand Down
3 changes: 3 additions & 0 deletions src/data-model-providers/codegen/CodegenDataModelProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <app/data-model-provider/Provider.h>

#include <app/AttributeAccessInterface.h>
#include <app/CommandHandlerInterface.h>
#include <app/ConcreteCommandPath.h>
#include <app/data-model-provider/ActionReturnStatus.h>
Expand Down Expand Up @@ -121,5 +122,7 @@ class CodegenDataModelProvider : public DataModel::Provider
std::optional<unsigned> TryFindEndpointIndex(EndpointId id) const;
};

std::optional<CHIP_ERROR> TryWriteViaAccessInterface(const ConcreteDataAttributePath & path, AttributeAccessInterface * aai,
sxb427 marked this conversation as resolved.
Show resolved Hide resolved
AttributeValueDecoder & decoder);
} // namespace app
} // namespace chip
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ContextAttributesChangeListener : public AttributesChangedListener
private:
DataModel::ProviderChangeListener * mListener;
};
} // namespace

/// Attempts to write via an attribute access interface (AAI)
///
Expand Down Expand Up @@ -86,8 +87,6 @@ std::optional<CHIP_ERROR> TryWriteViaAccessInterface(const ConcreteDataAttribute
return decoder.TriedDecode() ? std::make_optional(CHIP_NO_ERROR) : std::nullopt;
}

} // namespace

DataModel::ActionReturnStatus CodegenDataModelProvider::WriteAttribute(const DataModel::WriteAttributeRequest & request,
AttributeValueDecoder & decoder)
{
Expand Down
Loading