Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2024 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 : #pragma once
19 :
20 : #include <app/ConcreteAttributePath.h>
21 : #include <app/ConcreteClusterPath.h>
22 : #include <app/data-model-provider/MetadataList.h>
23 : #include <app/data-model-provider/MetadataTypes.h>
24 : #include <app/data-model-provider/ProviderMetadataTree.h>
25 : #include <lib/core/DataModelTypes.h>
26 : #include <lib/support/CodeUtils.h>
27 : #include <protocols/interaction_model/StatusCode.h>
28 :
29 : #include <optional>
30 :
31 : namespace chip {
32 : namespace app {
33 : namespace DataModel {
34 :
35 : /// Helps search for a specific server cluster in the given
36 : /// metadata provider.
37 : ///
38 : /// Facilitates the very common operation of "find a cluster on a given cluster path".
39 : class ServerClusterFinder
40 : {
41 : public:
42 4589 : ServerClusterFinder(ProviderMetadataTree * provider) : mProvider(provider) {}
43 :
44 : std::optional<ServerClusterEntry> Find(const ConcreteClusterPath & path);
45 :
46 : private:
47 : ProviderMetadataTree * mProvider;
48 : EndpointId mEndpointId = kInvalidEndpointId;
49 : ReadOnlyBuffer<ServerClusterEntry> mClusterEntries;
50 : };
51 :
52 : /// Helps search for a specific server attribute in the given
53 : /// metadata provider.
54 : ///
55 : /// Facilitates the very common operation of "find an attribute on a given attribute path".
56 : class AttributeFinder
57 : {
58 : public:
59 8970 : AttributeFinder(ProviderMetadataTree * provider) : mProvider(provider), mClusterPath(kInvalidEndpointId, kInvalidClusterId) {}
60 :
61 : std::optional<AttributeEntry> Find(const ConcreteAttributePath & path);
62 :
63 : private:
64 : ProviderMetadataTree * mProvider;
65 : ConcreteClusterPath mClusterPath;
66 : ReadOnlyBuffer<AttributeEntry> mAttributes;
67 : };
68 :
69 : /// Validates that the cluster identified by `path` exists within the given provider.
70 : ///
71 : /// If the endpoint identified by the path does not exist, will return Status::UnsupportedEndpoint.
72 : /// If the endpoint exists but does not have the cluster identified by the path, will return Status::UnsupportedCluster.
73 : ///
74 : /// otherwise, it will return successStatus.
75 : Protocols::InteractionModel::Status ValidateClusterPath(ProviderMetadataTree * provider, const ConcreteClusterPath & path,
76 : Protocols::InteractionModel::Status successStatus);
77 :
78 : /// Validates that the cluster identified by `path` exists within the given provider.
79 : /// If the endpoint does not exist, will return Status::UnsupportedEndpoint.
80 : /// If the endpoint exists but does not have the cluster identified by the path, will return Status::UnsupportedCluster.
81 : ///
82 : /// Otherwise, will return successStatus.
83 : Protocols::InteractionModel::Status ValidateClusterPath(ProviderMetadataTree * provider, const ConcreteClusterPath & path,
84 : Protocols::InteractionModel::Status successStatus);
85 :
86 : } // namespace DataModel
87 : } // namespace app
88 : } // namespace chip
|