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 <protocols/bdx/BdxTransferProxyDiagnosticLog.h>
23 : #include <protocols/bdx/BdxTransferServerDelegate.h>
24 : #include <protocols/bdx/TransferFacilitator.h>
25 : #include <system/SystemLayer.h>
26 :
27 : namespace chip {
28 : namespace bdx {
29 :
30 : class BdxTransferDiagnosticLogPoolDelegate;
31 :
32 : class BdxTransferDiagnosticLog : public Responder
33 : {
34 : public:
35 0 : BdxTransferDiagnosticLog(BDXTransferServerDelegate * delegate, BdxTransferDiagnosticLogPoolDelegate * poolDelegate,
36 0 : System::Layer * systemLayer) :
37 0 : mSystemLayer(systemLayer),
38 0 : mDelegate(delegate), mPoolDelegate(poolDelegate){};
39 :
40 0 : ~BdxTransferDiagnosticLog() { Reset(); };
41 :
42 : /**
43 : * This method handles BDX messages and other TransferSession events.
44 : *
45 : * @param[in] event An OutputEvent that contains output from the TransferSession object.
46 : */
47 : void HandleTransferSessionOutput(TransferSession::OutputEvent & event) override;
48 :
49 : void OnExchangeClosing(Messaging::ExchangeContext * ec) override;
50 :
51 : /**
52 : * Lifetime management, to allow us to abort transfers when a fabric
53 : * identity is being shut down.
54 : */
55 : bool IsForFabric(FabricIndex fabricIndex) const;
56 : void AbortTransfer();
57 :
58 : protected:
59 : /**
60 : * Called when a BDX message is received over the exchange context
61 : *
62 : * @param[in] ec The exchange context
63 : *
64 : * @param[in] payloadHeader The payload header of the message
65 : *
66 : * @param[in] payload The payload of the message
67 : */
68 : CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * ec, const PayloadHeader & payloadHeader,
69 : System::PacketBufferHandle && payload) override;
70 :
71 : private:
72 : /**
73 : * Called to send a BDX MsgToSend message over the exchange
74 : *
75 : *
76 : * @param[in] event The output event to be send
77 : */
78 : CHIP_ERROR OnMessageToSend(TransferSession::OutputEvent & event);
79 :
80 : /**
81 : * Called to begin the transfer session when an init message has been received
82 : *
83 : * @param[in] event The output event received
84 : */
85 : CHIP_ERROR OnTransferSessionBegin(TransferSession::OutputEvent & event);
86 :
87 : /**
88 : * Called to end the transfer session when a BlockAckEOF message has been sent over the exchange
89 : * or an error has occurred during the BDX session
90 : *
91 : * @param[in] error The error type
92 : */
93 : CHIP_ERROR OnTransferSessionEnd(CHIP_ERROR error);
94 :
95 : /**
96 : * Called when a block has been received from the Sender. The block is processed
97 : * and written to a file and a block ack is sent back to the sender.
98 : *
99 : * @param[in] event The output event received
100 : */
101 : CHIP_ERROR OnBlockReceived(TransferSession::OutputEvent & event);
102 :
103 : /**
104 : * This method is called to reset state. It resets the transfer and cleans up the
105 : * exchange and the fabric index and peer node id.
106 : */
107 : void Reset();
108 :
109 : void AbortTransferOnFailure(CHIP_ERROR error);
110 :
111 : BDXTransferProxyDiagnosticLog mTransferProxy;
112 : bool mIsExchangeClosing = false;
113 :
114 : System::Layer * mSystemLayer;
115 :
116 : BDXTransferServerDelegate * mDelegate;
117 : BdxTransferDiagnosticLogPoolDelegate * mPoolDelegate;
118 : };
119 :
120 : } // namespace bdx
121 : } // namespace chip
|