Skip to content

Commit

Permalink
Add AsyncTransferFacilitator to support BDX transfer that uses an eve…
Browse files Browse the repository at this point in the history
…nt driven approach to interact with the Transfer Session
  • Loading branch information
nivi-apple committed Sep 24, 2024
1 parent 39a9222 commit 277f287
Show file tree
Hide file tree
Showing 10 changed files with 834 additions and 497 deletions.
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ - (MTRDeviceController_Concrete * _Nullable)maybeInitializeOTAProvider:(MTRDevic

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

auto systemState = _controllerFactory->GetSystemState();
Expand Down Expand Up @@ -941,7 +942,6 @@ - (void)controllerShuttingDown:(MTRDeviceController *)controller
if (_controllers.count == 0) {
if (_otaProviderDelegateBridge) {
_otaProviderDelegateBridge->Shutdown();
_otaProviderDelegateBridge.reset();
}

if (_otaProviderEndpoint != nil) {
Expand Down
76 changes: 76 additions & 0 deletions src/darwin/Framework/CHIP/MTROTAImageTransferHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
*
* Copyright (c) 2024 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Matter/MTROTAProviderDelegate.h>

#include <protocols/bdx/AsyncTransferFacilitator.h>

NS_ASSUME_NONNULL_BEGIN

/**
* This class inherits from the AsyncResponder class and handles the BDX messages for a BDX transfer session.
* It overrides the HandleTransferSessionOutput virtual method and provides an implementation for it to handle
* the OutputEvents that are generated by the BDX transfer session state machine.
*
* An MTROTAImageTransferHandler will be associated with a specific BDX transfer session.
*
* The lifecycle of this class is managed by the AsyncFacilitator class which calls the virtual DestroySelf method
* that is implemented by this class to clean up and destroy itself and the AsyncFacilitator instances.
* Note: An object of this class can't be used after DestroySelf has been called.
*/
class MTROTAImageTransferHandler : public chip::bdx::AsyncResponder
{
public:
MTROTAImageTransferHandler();
~MTROTAImageTransferHandler();

void HandleTransferSessionOutput(chip::bdx::TransferSession::OutputEvent & event) override;
void DestroySelf() override;

protected:
CHIP_ERROR OnMessageReceived(chip::Messaging::ExchangeContext * ec, const chip::PayloadHeader & payloadHeader,
chip::System::PacketBufferHandle && payload) override;

private:
CHIP_ERROR PrepareForTransfer(chip::System::Layer * layer, chip::Messaging::ExchangeContext * exchangeCtx, chip::FabricIndex fabricIndex,
chip::NodeId nodeId);

CHIP_ERROR ConfigureState(chip::FabricIndex fabricIndex, chip::NodeId nodeId);

CHIP_ERROR OnMessageToSend(chip::bdx::TransferSession::OutputEvent & event);

CHIP_ERROR OnTransferSessionBegin(chip::bdx::TransferSession::OutputEvent & event);

CHIP_ERROR OnTransferSessionEnd(chip::bdx::TransferSession::OutputEvent & event);

CHIP_ERROR OnBlockQuery(chip::bdx::TransferSession::OutputEvent & event);

// The fabric index of the node with which the BDX session is established.
chip::Optional<chip::FabricIndex> mFabricIndex;

// The node id of the node with which the BDX session is established.
chip::Optional<chip::NodeId> mNodeId;

// The OTA provider delegate used by the controller.
id<MTROTAProviderDelegate> mDelegate = nil;
chip::System::Layer * mSystemLayer = nil;

// The OTA provider delegate queue used by the controller.
dispatch_queue_t mDelegateNotificationQueue = nil;
};

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 277f287

Please sign in to comment.