Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2025 Project CHIP Authors
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 :
18 : #pragma once
19 :
20 : #include <app-common/zap-generated/cluster-objects.h>
21 : #include <lib/core/CHIPPersistentStorageDelegate.h>
22 : #include <lib/core/CHIPVendorIdentifiers.hpp>
23 : #include <lib/core/DataModelTypes.h>
24 : #include <lib/core/NodeId.h>
25 :
26 : #include <optional>
27 :
28 : namespace chip {
29 : namespace app {
30 :
31 : class JointFabricAdministrator
32 : {
33 : public:
34 : class Delegate
35 : {
36 : public:
37 : Delegate() {}
38 : virtual ~Delegate() {}
39 :
40 : virtual CHIP_ERROR GetIcacCsr(MutableByteSpan & icacCsr) { return CHIP_NO_ERROR; }
41 : };
42 :
43 : static JointFabricAdministrator & GetInstance()
44 : {
45 : static JointFabricAdministrator sInstance;
46 : return sInstance;
47 : }
48 :
49 5 : void SetPeerJFAdminClusterEndpointId(chip::EndpointId peerJFAdminClusterEndpointId)
50 : {
51 5 : mPeerJFAdminClusterEndpointId = peerJFAdminClusterEndpointId;
52 5 : }
53 :
54 : void SetVidVerificationForFabric(chip::FabricIndex fabricIndex) { mVidVerificationFabricIndex = fabricIndex; }
55 : void ClearVidVerificationForFabric() { mVidVerificationFabricIndex.reset(); }
56 :
57 : /**
58 : * Clear cached VID-verification state when its fabric is removed.
59 : */
60 0 : void OnFabricRemoved(chip::FabricIndex removedFabricIndex)
61 : {
62 0 : if (mVidVerificationFabricIndex.has_value() && (mVidVerificationFabricIndex.value() == removedFabricIndex))
63 : {
64 0 : mVidVerificationFabricIndex.reset();
65 : }
66 0 : }
67 : bool WasVidVerificationExecutedForFabric(chip::FabricIndex fabricIndex) const
68 : {
69 : return mVidVerificationFabricIndex.has_value() && (mVidVerificationFabricIndex.value() == fabricIndex);
70 : }
71 :
72 : CHIP_ERROR SetDelegate(JointFabricAdministrator::Delegate * delegate)
73 : {
74 : VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
75 : mDelegate = delegate;
76 :
77 : return CHIP_NO_ERROR;
78 : }
79 :
80 2 : chip::EndpointId GetPeerJFAdminClusterEndpointId() const { return mPeerJFAdminClusterEndpointId; }
81 :
82 : JointFabricAdministrator::Delegate * GetDelegate() { return mDelegate; }
83 :
84 : private:
85 : chip::EndpointId mPeerJFAdminClusterEndpointId = chip::kInvalidEndpointId;
86 : std::optional<chip::FabricIndex> mVidVerificationFabricIndex;
87 : JointFabricAdministrator::Delegate * mDelegate = nullptr;
88 : };
89 :
90 : } // namespace app
91 : } // namespace chip
|