Skip to content

Commit db59df6

Browse files
committed
Add an AsyncTransferFacilitator that supports BDX transfer using an event driven approach rather than polling
- Update the OTA provider darwin implementation to use the AsyncTransferFacilitator to transfer the OTA file using BDX
1 parent b6a1304 commit db59df6

10 files changed

+1016
-474
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
*
3+
* Copyright (c) 2024 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+
#import <Matter/MTROTAProviderDelegate.h>
19+
20+
#include <protocols/bdx/AsyncTransferFacilitator.h>
21+
22+
NS_ASSUME_NONNULL_BEGIN
23+
24+
/**
25+
* This class inherits from the AsyncResponder class and handles the BDX messages for a BDX transfer session.
26+
* It overrides the HandleTransferSessionOutput virtual method and provides an implementation for it to handle
27+
* the OutputEvents that are generated by the BDX transfer session state machine.
28+
*
29+
* An MTROTAImageTransferHandler will be associated with a specific BDX transfer session.
30+
*
31+
* The lifecycle of this class is managed by the AsyncFacilitator class which calls the virtual DestroySelf method
32+
* that is implemented by this class to clean up and destroy itself and the AsyncFacilitator instances.
33+
* Note: An object of this class can't be used after DestroySelf has been called.
34+
*/
35+
class MTROTAImageTransferHandler : public chip::bdx::AsyncResponder
36+
{
37+
public:
38+
MTROTAImageTransferHandler();
39+
~MTROTAImageTransferHandler();
40+
41+
void HandleTransferSessionOutput(chip::bdx::TransferSession::OutputEvent & event) override;
42+
void DestroySelf() override;
43+
44+
protected:
45+
CHIP_ERROR OnMessageReceived(chip::Messaging::ExchangeContext * ec, const chip::PayloadHeader & payloadHeader,
46+
chip::System::PacketBufferHandle && payload) override;
47+
48+
private:
49+
CHIP_ERROR PrepareForTransfer(chip::System::Layer * layer, chip::Messaging::ExchangeContext * exchangeCtx, chip::FabricIndex fabricIndex,
50+
chip::NodeId nodeId);
51+
52+
CHIP_ERROR ConfigureState(chip::FabricIndex fabricIndex, chip::NodeId nodeId);
53+
54+
CHIP_ERROR OnMessageToSend(chip::bdx::TransferSession::OutputEvent & event);
55+
56+
CHIP_ERROR OnTransferSessionBegin(chip::bdx::TransferSession::OutputEvent & event);
57+
58+
CHIP_ERROR OnTransferSessionEnd(chip::bdx::TransferSession::OutputEvent & event);
59+
60+
CHIP_ERROR OnBlockQuery(chip::bdx::TransferSession::OutputEvent & event);
61+
62+
// The fabric index of the node with which the BDX session is established.
63+
chip::Optional<chip::FabricIndex> mFabricIndex;
64+
65+
// The node id of the node with which the BDX session is established.
66+
chip::Optional<chip::NodeId> mNodeId;
67+
68+
// The OTA provider delegate used by the controller.
69+
id<MTROTAProviderDelegate> mDelegate = nil;
70+
chip::System::Layer * mSystemLayer = nil;
71+
72+
// The OTA provider delegate queue used by the controller.
73+
dispatch_queue_t mDelegateNotificationQueue = nil;
74+
};
75+
76+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)