@@ -28,12 +28,13 @@ namespace bdx {
28
28
29
29
/* *
30
30
* An abstract class with methods for handling BDX messages received from an ExchangeContext. Once a message is received, this
31
- * class passes the message to the TransferSession to process the received message and gets the resulting output events from the
32
- * TransferSession state machine and either sends a message accross the exchange or calls the HandleTransferSessionOutput virtual
33
- * method to notify the subclass of the event generated. It keeps getting the next output event until it recieves an output event
34
- * of type TransferSession::OutputEventType::kNone. For events that are handled via the HandleTransferSessionOutput method, the
35
- * subclass must call the NotifyEventHandled to notify the AsyncTransferFacilitator that the event has been handled and returns an
36
- * error code for error cases or success.
31
+ * class passes the message to the TransferSession to process the received messages and calls ProcessOutputEvents to get the next
32
+ * output events generated by the TransferSession state machine until it receives an output event of type TransferSession::OutputEventType::kNone.
33
+ * For each output event it receives, it either sends a message accross the exchange if the TransferSession generated an event of
34
+ * type TransferSession::OutputEventType::kMsgToSend or calls the HandleTransferSessionOutput method to notify the subclass of the output event
35
+ * which has the business logic of handling the BDX message and calling the TransferSession API to proceed with the BDX transfer. For e.g.,
36
+ * If this class received a ReceiveInit message and passed it to the HandleTransferSessionOutput method, the subclass would call the
37
+ * AcceptTransfer on the TransferSession object to negotiate params and prepare a ReceiveAccept message.
37
38
*
38
39
* This class does not define any methods for beginning a transfer or initializing the underlying TransferSession object.
39
40
* See AsyncResponder for a class that does.
@@ -47,6 +48,18 @@ class AsyncTransferFacilitator : public Messaging::ExchangeDelegate
47
48
AsyncTransferFacilitator () : mExchange (*this ) {}
48
49
~AsyncTransferFacilitator () override ;
49
50
51
+ protected:
52
+ CHIP_ERROR Init (System::Layer * layer, Messaging::ExchangeContext * exchangeCtx,
53
+ System::Clock::Timeout timeout);
54
+ CHIP_ERROR OnMessageReceived (Messaging::ExchangeContext * ec, const PayloadHeader & payloadHeader,
55
+ System::PacketBufferHandle && payload) override ;
56
+ void OnResponseTimeout (Messaging::ExchangeContext * ec) override ;
57
+ void OnExchangeClosing (Messaging::ExchangeContext * ec) override ;
58
+
59
+ CHIP_ERROR SendMessage (const TransferSession::MessageTypeData msgTypeData, System::PacketBufferHandle & msgBuf);
60
+
61
+ static bdx::StatusCode GetBdxStatusCodeFromChipError (CHIP_ERROR err);
62
+
50
63
/* *
51
64
* This method should be implemented to contain business-logic handling of BDX messages
52
65
* and other TransferSession events.
@@ -60,23 +73,16 @@ class AsyncTransferFacilitator : public Messaging::ExchangeDelegate
60
73
*/
61
74
virtual void DestroySelf () = 0;
62
75
63
- protected:
64
- CHIP_ERROR OnMessageReceived (Messaging::ExchangeContext * ec, const PayloadHeader & payloadHeader,
65
- System::PacketBufferHandle && payload) override ;
66
- void OnResponseTimeout (Messaging::ExchangeContext * ec) override ;
67
- void OnExchangeClosing (Messaging::ExchangeContext * ec) override ;
68
-
69
- CHIP_ERROR SendMessage (const TransferSession::MessageTypeData msgTypeData, System::PacketBufferHandle & msgBuf);
70
-
71
- static bdx::StatusCode GetBdxStatusCodeFromChipError (CHIP_ERROR err);
76
+ void ProcessOutputEvents ();
72
77
73
78
void CleanUp ();
74
79
75
- void HandleNextOutputEvents ();
76
-
77
80
// The transfer session coresponding to this AsyncTransferFacilitator object.
78
81
TransferSession mTransfer ;
79
82
83
+ private:
84
+ bool mProcessingOutputEvents = false ;
85
+
80
86
// The Exchange holder that holds the exchange context used for sending and receiving BDX messages.
81
87
Messaging::ExchangeHolder mExchange ;
82
88
@@ -85,12 +91,11 @@ class AsyncTransferFacilitator : public Messaging::ExchangeDelegate
85
91
86
92
System::Layer * mSystemLayer ;
87
93
88
- private:
89
- bool mHandlingOutputEvents ;
90
94
};
91
95
92
96
/* *
93
97
* An AsyncTransferFacilitator that is initialized to respond to an incoming BDX transfer request.
98
+ * An AsyncResponder object is associated with an exchange and handles all BDX messages sent over that exchange.
94
99
*
95
100
* Provides a method for initializing the TransferSession members but still needs to be extended to implement
96
101
* HandleTransferSessionOutput.
@@ -109,21 +114,24 @@ class AsyncResponder : public AsyncTransferFacilitator
109
114
* @param[in] maxBlockSize The maximum supported size of BDX Block data
110
115
* @param[in] timeout The chosen timeout delay for the BDX transfer
111
116
*/
112
- CHIP_ERROR PrepareForTransfer (System::Layer * layer, Messaging::ExchangeContext * exchangeCtx, TransferRole role,
117
+ CHIP_ERROR Init (System::Layer * layer, Messaging::ExchangeContext * exchangeCtx, TransferRole role,
113
118
BitFlags<TransferControlFlags> xferControlOpts, uint16_t maxBlockSize,
114
119
System::Clock::Timeout timeout);
115
120
116
121
/* *
117
- * This is called by the subclass implementing HandleTransferSessionOutput to notify the AsyncTransferFacilitator
122
+ * This is called by the subclass implementing HandleTransferSessionOutput to notify the AsyncResponder
118
123
* that it has handled the OutputEvent specified in "event" and "status" is the result of handling the event.
119
- * Once this is called the AsyncTransferFacilitator either aborts the transfer if an error has ocurred or drives the
120
- * TransferSession state machine to generate the next output events to establish and continue the BDX session further.
121
- *
124
+ * If the OutputEvent was handled successfully by the subclass that means the TransferSession API call to handle the output event
125
+ * was successful and the TransferSession has the next message prepared. In that case, the "status" is set to CHIP_NO_ERROR and the
126
+ * AsyncResponder should call ProcessOutputEvents to get and process the next output events from the TransferSession to proceed with
127
+ * the BDX transfer. Otherwise if the output event indicates the end of BDX transfer (like EOF receieved or transfer timeout), it will
128
+ * clean up and destroy itself and the subclass. If the "status" is set to an error code, the AsyncResponder should abort the transfer
129
+ * and clean up once the status report is sent over the exchange.
122
130
*
123
131
* @param[in] event The OutputEvent that was handled by the subclass.
124
132
* @param[in] status The error code that occured when handling the event if an error occurs. Otherwise CHIP_NO_ERROR.
125
133
*/
126
- void NotifyEventHandled (TransferSession::OutputEvent & event, CHIP_ERROR error );
134
+ void NotifyEventHandled (TransferSession::OutputEvent & event, CHIP_ERROR status );
127
135
};
128
136
129
137
} // namespace bdx
0 commit comments