|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) 2025 Project CHIP Authors |
| 4 | + * All rights reserved. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +#pragma once |
| 20 | + |
| 21 | +#include "pw_status/status.h" |
| 22 | +#include <pigweed/rpc_services/AccessInterceptor.h> |
| 23 | +#include <set> |
| 24 | + |
| 25 | +namespace chip { |
| 26 | +namespace rpc { |
| 27 | + |
| 28 | +/** @brief Custom debug request interceptors. |
| 29 | + * |
| 30 | + * This class is specifically meant for registering custom Accessors that |
| 31 | + * allow mini-handlers to process PigweedRPC read/writes separately from the cluster |
| 32 | + * code. It is meant to be used by samples using this PigweedRPC services to allow the RPC |
| 33 | + * interface to be used in more ways than simply for example, simulating writes from a Matter |
| 34 | + * client at the IM level. Handlers registered here by applications should be attempted before any |
| 35 | + * standard processing. |
| 36 | + */ |
| 37 | +class PigweedDebugAccessInterceptorRegistry |
| 38 | +{ |
| 39 | +public: |
| 40 | + /** |
| 41 | + * Registers an attribute access inteceptor within this registry. Use `Unregister` to |
| 42 | + * unregister an interceptor that was previously registered. |
| 43 | + * @param attrOverride - the interceptor to be registered. |
| 44 | + */ |
| 45 | + void Register(PigweedDebugAccessInterceptor * attrOverride) { mAccessors.insert(attrOverride); } |
| 46 | + |
| 47 | + void Unregister(PigweedDebugAccessInterceptor * attrOverride) |
| 48 | + { |
| 49 | + if (mAccessors.find(attrOverride) == mAccessors.end()) |
| 50 | + { |
| 51 | + ChipLogError(Support, "Attempt to unregister accessor that is not registered."); |
| 52 | + return; |
| 53 | + } |
| 54 | + mAccessors.erase(attrOverride); |
| 55 | + } |
| 56 | + |
| 57 | + const std::set<PigweedDebugAccessInterceptor *> & GetAllAccessors() const { return mAccessors; } |
| 58 | + |
| 59 | + /** |
| 60 | + * Returns the singleton instance of the attribute accessor registory. |
| 61 | + */ |
| 62 | + static PigweedDebugAccessInterceptorRegistry & Instance() |
| 63 | + { |
| 64 | + static PigweedDebugAccessInterceptorRegistry instance; |
| 65 | + return instance; |
| 66 | + } |
| 67 | + |
| 68 | +private: |
| 69 | + std::set<PigweedDebugAccessInterceptor *> mAccessors; |
| 70 | +}; |
| 71 | + |
| 72 | +} // namespace rpc |
| 73 | +} // namespace chip |
0 commit comments