-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create an AAI registry for PwRPC services to allow registration of cu…
…stom AAI classes (#37351) * Allow custom AAI registration for PwRPC Reads/Writes. Update PwRPC Writes to look for custom AAIs before using datamodel provider * Add succes log * Make TryWriteViaAAI public * Make TryWriteViaAAI public * Fix compilation errors * Fix compilation errors * Fix compilation errors * Update examples/common/pigweed/rpc_services/Attributes.h Co-authored-by: Tennessee Carmel-Veilleux <tennessee.carmelveilleux@gmail.com> * Add new attribute accessor and registry for PwRPC * Fix compilation error * Fix compilation error * Fix compilation error * Revert changes * Revert changes * Accessors will not be indexed by EndpointId/ClusterId. Caller queries all accessors to satisfy the request and returns as soon as a succes/failure is encountered. Accessors will return 'pw::Status::NotFound()' as a way of hinting the caller 'look for an alternative'. If no accessors were registered or all returned 'NotFound' the fallback path is taken. * fix compilation bug * Review comments * Fix compilation * Fix nits * Fix ESP32 compilation * Update examples/common/pigweed/rpc_services/AccessInterceptor.h Nit : rename parameter names. Co-authored-by: Andrei Litvin <andy314@gmail.com> * Update examples/common/pigweed/rpc_services/AccessInterceptor.h Review suggestion. Co-authored-by: Andrei Litvin <andy314@gmail.com> * Update examples/common/pigweed/rpc_services/AccessInterceptorRegistry.h Review suggestion. Co-authored-by: Andrei Litvin <andy314@gmail.com> * Review comments * Update examples/common/pigweed/rpc_services/AccessInterceptor.h --------- Co-authored-by: Tennessee Carmel-Veilleux <tennessee.carmelveilleux@gmail.com> Co-authored-by: Andrei Litvin <andy314@gmail.com>
- Loading branch information
1 parent
cbe17ed
commit ce47e22
Showing
3 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* | ||
* Copyright (c) 2025 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "pw_status/status.h" | ||
#include <app/AttributeReportBuilder.h> | ||
#include <app/AttributeValueDecoder.h> | ||
#include <app/AttributeValueEncoder.h> | ||
|
||
namespace chip { | ||
namespace rpc { | ||
|
||
/** | ||
* Callback class that clusters can implement in order to interpose custom | ||
* interception logic. | ||
*/ | ||
class PigweedDebugAccessInterceptor | ||
{ | ||
public: | ||
PigweedDebugAccessInterceptor() = default; | ||
virtual ~PigweedDebugAccessInterceptor() = default; | ||
|
||
/** | ||
* Callback for writing attributes. | ||
* | ||
* The implementation can do one of three things: | ||
* | ||
* Returns: | ||
* - `std::nullopt` if the `path` was not handled by this Interceptor. | ||
* Interceptor MUST NOT have attepted to decode `decoder`. | ||
* - A `::pw::Status` value that is considered the FINAL result of the | ||
* write (i.e. write handled) either with success or failure. | ||
*/ | ||
virtual std::optional<::pw::Status> Write(const chip::app::ConcreteDataAttributePath & path, | ||
chip::app::AttributeValueDecoder & decoder) = 0; | ||
}; | ||
|
||
} // namespace rpc | ||
} // namespace chip |
73 changes: 73 additions & 0 deletions
73
examples/common/pigweed/rpc_services/AccessInterceptorRegistry.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* | ||
* Copyright (c) 2025 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "pw_status/status.h" | ||
#include <pigweed/rpc_services/AccessInterceptor.h> | ||
#include <set> | ||
|
||
namespace chip { | ||
namespace rpc { | ||
|
||
/** @brief Custom debug request interceptors. | ||
* | ||
* This class is specifically meant for registering custom Accessors that | ||
* allow mini-handlers to process PigweedRPC read/writes separately from the cluster | ||
* code. It is meant to be used by samples using this PigweedRPC services to allow the RPC | ||
* interface to be used in more ways than simply for example, simulating writes from a Matter | ||
* client at the IM level. Handlers registered here by applications should be attempted before any | ||
* standard processing. | ||
*/ | ||
class PigweedDebugAccessInterceptorRegistry | ||
{ | ||
public: | ||
/** | ||
* Registers an attribute access inteceptor within this registry. Use `Unregister` to | ||
* unregister an interceptor that was previously registered. | ||
* @param attrOverride - the interceptor to be registered. | ||
*/ | ||
void Register(PigweedDebugAccessInterceptor * attrOverride) { mAccessors.insert(attrOverride); } | ||
|
||
void Unregister(PigweedDebugAccessInterceptor * attrOverride) | ||
{ | ||
if (mAccessors.find(attrOverride) == mAccessors.end()) | ||
{ | ||
ChipLogError(Support, "Attempt to unregister accessor that is not registered."); | ||
return; | ||
} | ||
mAccessors.erase(attrOverride); | ||
} | ||
|
||
const std::set<PigweedDebugAccessInterceptor *> & GetAllAccessors() const { return mAccessors; } | ||
|
||
/** | ||
* Returns the singleton instance of the attribute accessor registory. | ||
*/ | ||
static PigweedDebugAccessInterceptorRegistry & Instance() | ||
{ | ||
static PigweedDebugAccessInterceptorRegistry instance; | ||
return instance; | ||
} | ||
|
||
private: | ||
std::set<PigweedDebugAccessInterceptor *> mAccessors; | ||
}; | ||
|
||
} // namespace rpc | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters