Skip to content

Commit 277f287

Browse files
committedSep 24, 2024
Add AsyncTransferFacilitator to support BDX transfer that uses an event driven approach to interact with the Transfer Session
1 parent 39a9222 commit 277f287

10 files changed

+834
-497
lines changed
 

‎src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ - (MTRDeviceController_Concrete * _Nullable)maybeInitializeOTAProvider:(MTRDevic
874874

875875
// Now that our endpoint exists, go ahead and create the OTA delegate
876876
// bridge. Its constructor relies on the endpoint existing.
877+
_otaProviderDelegate = nil;
877878
_otaProviderDelegateBridge = std::make_unique<MTROTAProviderDelegateBridge>();
878879

879880
auto systemState = _controllerFactory->GetSystemState();
@@ -941,7 +942,6 @@ - (void)controllerShuttingDown:(MTRDeviceController *)controller
941942
if (_controllers.count == 0) {
942943
if (_otaProviderDelegateBridge) {
943944
_otaProviderDelegateBridge->Shutdown();
944-
_otaProviderDelegateBridge.reset();
945945
}
946946

947947
if (_otaProviderEndpoint != nil) {
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)