Line data Source code
1 : /*
2 : * Copyright (c) 2024 Project CHIP Authors
3 : * All rights reserved.
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 : #include <data-model-providers/codegen/EmberMetadata.h>
18 :
19 : #include <app/GlobalAttributes.h>
20 : #include <app/util/attribute-storage.h>
21 : #include <app/util/endpoint-config-api.h>
22 :
23 : namespace chip {
24 : namespace app {
25 : namespace Ember {
26 :
27 : using Protocols::InteractionModel::Status;
28 :
29 : std::variant<const EmberAfCluster *, // global attribute, data from a cluster
30 : const EmberAfAttributeMetadata *, // a specific attribute stored by ember
31 : Status // one of Status::Unsupported*
32 : >
33 5108 : FindAttributeMetadata(const ConcreteAttributePath & aPath)
34 : {
35 5108 : if (IsGlobalAttribute(aPath.mAttributeId))
36 : {
37 : // Global list attribute check first: during path expansion a lot of attributes
38 : // will actually be global attributes (so not too much of a performance hit)
39 2336 : for (auto & attr : GlobalAttributesNotInMetadata)
40 : {
41 2131 : if (attr == aPath.mAttributeId)
42 : {
43 719 : const EmberAfCluster * cluster = emberAfFindServerCluster(aPath.mEndpointId, aPath.mClusterId);
44 719 : if (cluster == nullptr)
45 : {
46 2 : return (emberAfFindEndpointType(aPath.mEndpointId) == nullptr) ? Status::UnsupportedEndpoint
47 2 : : Status::UnsupportedCluster;
48 : }
49 :
50 717 : return cluster;
51 : }
52 : }
53 : }
54 : const EmberAfAttributeMetadata * metadata =
55 4389 : emberAfLocateAttributeMetadata(aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId);
56 :
57 4389 : if (metadata == nullptr)
58 : {
59 6 : const EmberAfEndpointType * type = emberAfFindEndpointType(aPath.mEndpointId);
60 6 : if (type == nullptr)
61 : {
62 2 : return Status::UnsupportedEndpoint;
63 : }
64 :
65 4 : const EmberAfCluster * cluster = emberAfFindClusterInType(type, aPath.mClusterId, CLUSTER_MASK_SERVER);
66 4 : if (cluster == nullptr)
67 : {
68 2 : return Status::UnsupportedCluster;
69 : }
70 :
71 : // Since we know the attribute is unsupported and the endpoint/cluster are
72 : // OK, this is the only option left.
73 2 : return Status::UnsupportedAttribute;
74 : }
75 :
76 4383 : return metadata;
77 : }
78 :
79 : } // namespace Ember
80 : } // namespace app
81 : } // namespace chip
|