Skip to content

Commit

Permalink
Add AsyncFacilitator to enable an async, event-driven, non-polling me… (
Browse files Browse the repository at this point in the history
project-chip#29364)

* 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

* Editorial fixes

* Restyled by whitespace

* Restyled by clang-format

* Apply suggestions from code review

Co-authored-by: Boris Zbarsky <[email protected]>

* Addresssed review comments

* Restyle

* Apply suggestions from code review

Co-authored-by: Boris Zbarsky <[email protected]>

* Address review comments

* More fixes

* Restyle

* Apply suggestions from code review

Co-authored-by: Boris Zbarsky <[email protected]>

* Apply suggestions from code review

Co-authored-by: Boris Zbarsky <[email protected]>

* Address more review comments

* Apply suggestions from code review

Co-authored-by: Boris Zbarsky <[email protected]>

* Address review comments

* Apply suggestions from code review

Co-authored-by: Boris Zbarsky <[email protected]>

* Fix restyled issues.

* Add missing header

* Address review comments.

---------

Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
3 people authored Nov 22, 2024
1 parent 048227b commit 7df9b14
Show file tree
Hide file tree
Showing 12 changed files with 1,088 additions and 473 deletions.
79 changes: 79 additions & 0 deletions src/darwin/Framework/CHIP/MTROTAImageTransferHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
*
* 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

@class MTROTAImageTransferHandlerWrapper;

/**
* This class handles the BDX events for a BDX transfer session.
*
* This object may be destroyed directly, when not processing some call it made, to interrupt the BDX
* transfer. Specifically, this has to be done if the fabric it's associated with is shut down. This
* method of interrupting the BDX transfer will not notify the peer that we are interrupting and it will
* keep waiting until it times out.
*
* If not otherwise destroyed, this object will destroy itself when the transfer completes.
*/
class MTROTAImageTransferHandler : public chip::bdx::AsyncResponder {
public:
MTROTAImageTransferHandler(chip::System::Layer * layer);
~MTROTAImageTransferHandler();

chip::FabricIndex GetPeerFabricIndex() { return mPeer.GetFabricIndex(); }

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

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

private:
CHIP_ERROR Init(chip::Messaging::ExchangeContext * exchangeCtx);

CHIP_ERROR OnTransferSessionBegin(const chip::bdx::TransferSession::OutputEventType event);

CHIP_ERROR OnTransferSessionEnd(const chip::bdx::TransferSession::OutputEventType eventType);

CHIP_ERROR OnBlockQuery(const chip::bdx::TransferSession::OutputEventType eventType, uint64_t bytesToSkip);

chip::ScopedNodeId GetPeerScopedNodeId(chip::Messaging::ExchangeContext * exchangeCtx);

void InvokeTransferSessionEndCallback(CHIP_ERROR error);

void DestroySelf() override;

// The scoped node id of the node with which the BDX session is established.
chip::ScopedNodeId mPeer;

// The OTA provider delegate that is responding to the BDX transfer request.
id<MTROTAProviderDelegate> mDelegate = nil;
chip::System::Layer * mSystemLayer = nil;

// The queue mDelegate must be called on.
dispatch_queue_t mDelegateNotificationQueue = nil;

MTROTAImageTransferHandlerWrapper * mOTAImageTransferHandlerWrapper;

bool mNeedToCallTransferSessionEnd = false;
};

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 7df9b14

Please sign in to comment.