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 :
19 : #pragma once
20 :
21 : #include <lib/core/DataModelTypes.h>
22 : #include <lib/support/Pool.h>
23 : #include <protocols/bdx/BdxTransferDiagnosticLog.h>
24 : #include <protocols/bdx/BdxTransferServerDelegate.h>
25 : #include <system/SystemLayer.h>
26 :
27 : namespace chip {
28 : namespace bdx {
29 :
30 : class BdxTransferDiagnosticLogPoolDelegate
31 : {
32 : public:
33 0 : virtual ~BdxTransferDiagnosticLogPoolDelegate() {}
34 :
35 : virtual BdxTransferDiagnosticLog * Allocate(BDXTransferServerDelegate * delegate, System::Layer * systemLayer) = 0;
36 :
37 : virtual void Release(BdxTransferDiagnosticLog * client) = 0;
38 : };
39 :
40 : template <size_t N>
41 : class BdxTransferDiagnosticLogPool : public BdxTransferDiagnosticLogPoolDelegate
42 : {
43 : public:
44 0 : ~BdxTransferDiagnosticLogPool() override { mTransferPool.ReleaseAll(); }
45 :
46 0 : BdxTransferDiagnosticLog * Allocate(BDXTransferServerDelegate * delegate, System::Layer * systemLayer) override
47 : {
48 0 : return mTransferPool.CreateObject(delegate, this, systemLayer);
49 : }
50 :
51 0 : void Release(BdxTransferDiagnosticLog * transfer) override { mTransferPool.ReleaseObject(transfer); }
52 :
53 0 : void AbortTransfersForFabric(FabricIndex fabricIndex)
54 : {
55 0 : mTransferPool.ForEachActiveObject([fabricIndex](BdxTransferDiagnosticLog * transfer) {
56 0 : if (transfer->IsForFabric(fabricIndex))
57 : {
58 0 : transfer->AbortTransfer();
59 : }
60 0 : return Loop::Continue;
61 : });
62 0 : }
63 :
64 : private:
65 : ObjectPool<BdxTransferDiagnosticLog, N> mTransferPool;
66 : };
67 :
68 : } // namespace bdx
69 : } // namespace chip
|