Line data Source code
1 : /*
2 : * Copyright (c) 2025 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 "SpanEndpoint.h"
18 :
19 : #include <app/ConcreteClusterPath.h>
20 : #include <app/server-cluster/ServerClusterContext.h>
21 : #include <clusters/Descriptor/ClusterId.h>
22 : #include <lib/core/CHIPError.h>
23 : #include <lib/support/Span.h>
24 : #include <lib/support/logging/CHIPLogging.h>
25 :
26 : namespace chip {
27 : namespace app {
28 :
29 : // Builder implementation
30 6 : SpanEndpoint::Builder & SpanEndpoint::Builder::SetClientClusters(Span<const ClusterId> clientClusters)
31 : {
32 6 : mClientClusters = clientClusters;
33 6 : return *this;
34 : }
35 :
36 6 : SpanEndpoint::Builder & SpanEndpoint::Builder::SetDeviceTypes(Span<const DataModel::DeviceTypeEntry> deviceTypes)
37 : {
38 6 : mDeviceTypes = deviceTypes;
39 6 : return *this;
40 : }
41 :
42 : #if CHIP_CONFIG_USE_ENDPOINT_UNIQUE_ID
43 : SpanEndpoint::Builder & SpanEndpoint::Builder::SetEndpointUniqueId(CharSpan endpointUniqueId)
44 : {
45 : mEndpointUniqueId = endpointUniqueId;
46 : return *this;
47 : }
48 : #endif
49 :
50 157 : SpanEndpoint SpanEndpoint::Builder::Build()
51 : {
52 : #if CHIP_CONFIG_USE_ENDPOINT_UNIQUE_ID
53 : return SpanEndpoint(mClientClusters, mDeviceTypes, mEndpointUniqueId);
54 : #else
55 157 : return SpanEndpoint(mClientClusters, mDeviceTypes);
56 : #endif
57 : }
58 :
59 4 : CHIP_ERROR SpanEndpoint::DeviceTypes(ReadOnlyBufferBuilder<DataModel::DeviceTypeEntry> & out) const
60 : {
61 4 : return out.ReferenceExisting(mDeviceTypes);
62 : }
63 :
64 4 : CHIP_ERROR SpanEndpoint::ClientClusters(ReadOnlyBufferBuilder<ClusterId> & out) const
65 : {
66 4 : return out.ReferenceExisting(mClientClusters);
67 : }
68 :
69 : #if CHIP_CONFIG_USE_ENDPOINT_UNIQUE_ID
70 : CharSpan SpanEndpoint::EndpointUniqueId() const
71 : {
72 : return mEndpointUniqueId;
73 : }
74 : #endif
75 :
76 : // Private constructor for Builder
77 : #if CHIP_CONFIG_USE_ENDPOINT_UNIQUE_ID
78 : SpanEndpoint::SpanEndpoint(const Span<const ClusterId> & clientClusters, const Span<const DataModel::DeviceTypeEntry> & deviceTypes,
79 : const CharSpan & uniqueEndpointId) :
80 : mDeviceTypes(deviceTypes),
81 : mClientClusters(clientClusters), mEndpointUniqueId(uniqueEndpointId)
82 : {}
83 : #else
84 157 : SpanEndpoint::SpanEndpoint(const Span<const ClusterId> & clientClusters,
85 157 : const Span<const DataModel::DeviceTypeEntry> & deviceTypes) :
86 157 : mDeviceTypes(deviceTypes),
87 157 : mClientClusters(clientClusters)
88 157 : {}
89 : #endif
90 :
91 : } // namespace app
92 : } // namespace chip
|