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