Skip to content

Commit

Permalink
Restyle
Browse files Browse the repository at this point in the history
  • Loading branch information
nivi-apple committed Oct 24, 2024
1 parent 4029261 commit d3713d7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
19 changes: 7 additions & 12 deletions src/darwin/Framework/CHIP/MTROTAImageTransferHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@

@interface MTROTAImageTransferHandlerWrapper : NSObject
- (instancetype)initWithMTROTAImageTransferHandler:(MTROTAImageTransferHandler *)otaImageTransferHandler;
@property(nonatomic, nullable, readwrite, assign) MTROTAImageTransferHandler * otaImageTransferHandler;
@property (nonatomic, nullable, readwrite, assign) MTROTAImageTransferHandler * otaImageTransferHandler;
@end

@implementation MTROTAImageTransferHandlerWrapper

- (instancetype)initWithMTROTAImageTransferHandler:(MTROTAImageTransferHandler *)otaImageTransferHandler
{
if (self = [super init])
{
_otaImageTransferHandler = otaImageTransferHandler;
if (self = [super init]) {
_otaImageTransferHandler = otaImageTransferHandler;
}
return self;
}
Expand Down Expand Up @@ -108,18 +107,16 @@ - (instancetype)initWithMTROTAImageTransferHandler:(MTROTAImageTransferHandler *
auto * controller = [[MTRDeviceControllerFactory sharedInstance] runningControllerForFabricIndex:mFabricIndex.Value()];
VerifyOrReturnError(controller != nil, CHIP_ERROR_INCORRECT_STATE);

MTROTAImageTransferHandlerWrapper * __weak weakWrapper = mOTAImageTransferHandlerWrapper;
MTROTAImageTransferHandlerWrapper * __weak weakWrapper = mOTAImageTransferHandlerWrapper;

auto completionHandler = ^(NSError * _Nullable error) {

[controller
asyncDispatchToMatterQueue:^() {
assertChipStackLockedByCurrentThread();

// Check if the OTA image transfer handler is still valid. If not, return from the completion handler.
MTROTAImageTransferHandlerWrapper * strongWrapper = weakWrapper;
if (!strongWrapper || !strongWrapper.otaImageTransferHandler)
{
if (!strongWrapper || !strongWrapper.otaImageTransferHandler) {
return;
}

Expand Down Expand Up @@ -233,18 +230,16 @@ - (instancetype)initWithMTROTAImageTransferHandler:(MTROTAImageTransferHandler *
auto * controller = [[MTRDeviceControllerFactory sharedInstance] runningControllerForFabricIndex:mFabricIndex.Value()];
VerifyOrReturnError(controller != nil, CHIP_ERROR_INCORRECT_STATE);

MTROTAImageTransferHandlerWrapper * __weak weakWrapper = mOTAImageTransferHandlerWrapper;
MTROTAImageTransferHandlerWrapper * __weak weakWrapper = mOTAImageTransferHandlerWrapper;

auto completionHandler = ^(NSData * _Nullable data, BOOL isEOF) {

[controller
asyncDispatchToMatterQueue:^() {
assertChipStackLockedByCurrentThread();

// Check if the OTA image transfer handler is still valid. If not, return from the completion handler.
MTROTAImageTransferHandlerWrapper * strongWrapper = weakWrapper;
if (!strongWrapper || !strongWrapper.otaImageTransferHandler)
{
if (!strongWrapper || !strongWrapper.otaImageTransferHandler) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/

#import <Foundation/Foundation.h>
#import "MTROTAImageTransferHandler.h"
#import <Foundation/Foundation.h>

#include <lib/core/CHIPError.h>
#include <messaging/ExchangeMgr.h>
Expand All @@ -42,7 +42,7 @@ class MTROTAUnsolicitedBDXMessageHandler : public chip::Messaging::UnsolicitedMe
sInstance = this;
}

~MTROTAUnsolicitedBDXMessageHandler() { mExchangeMgr = nullptr;}
~MTROTAUnsolicitedBDXMessageHandler() { mExchangeMgr = nullptr; }

static MTROTAUnsolicitedBDXMessageHandler * GetInstance();

Expand All @@ -51,7 +51,6 @@ class MTROTAUnsolicitedBDXMessageHandler : public chip::Messaging::UnsolicitedMe
// Returns the number of delegates that are currently handling BDX transfers.
static uint8_t GetNumberOfDelegates();


static void IncrementNumberOfDelegates();

// Decrease the number of delegates handling BDX transfers by 1.
Expand Down Expand Up @@ -79,7 +78,6 @@ class MTROTAUnsolicitedBDXMessageHandler : public chip::Messaging::UnsolicitedMe
static inline uint8_t mNumberOfDelegates = 0;

static MTROTAUnsolicitedBDXMessageHandler * sInstance;

};

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@
mExchangeMgr->UnregisterUnsolicitedMessageHandlerForProtocol(Protocols::BDX::Id);
MTROTAUnsolicitedBDXMessageHandler::mNumberOfDelegates = 0;

if (mOTAImageTransferHandler != nullptr)
{
if (mOTAImageTransferHandler != nullptr) {
mOTAImageTransferHandler->DestroySelf();
delete mOTAImageTransferHandler;
}

}

void MTROTAUnsolicitedBDXMessageHandler::ControllerShuttingDown(MTRDeviceController * controller)
Expand Down Expand Up @@ -137,8 +135,7 @@
assertChipStackLockedByCurrentThread();

// TODO: #36181 - Remove the object matching imageTransferHandler in the set of MTROTAImageTransferHandler objects.
if (mOTAImageTransferHandler == static_cast<MTROTAImageTransferHandler *>(imageTransferHandler))
{
if (mOTAImageTransferHandler == static_cast<MTROTAImageTransferHandler *>(imageTransferHandler)) {
mOTAImageTransferHandler = nullptr;
}
MTROTAUnsolicitedBDXMessageHandler::DecrementNumberOfDelegates();
Expand Down
7 changes: 4 additions & 3 deletions src/protocols/bdx/AsyncTransferFacilitator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ CHIP_ERROR AsyncTransferFacilitator::Init(System::Layer * layer, Messaging::Exch

mSystemLayer = layer;
mExchange.Grab(exchangeCtx);
mTimeout = timeout;
mTimeout = timeout;
mProcessingOutputEvents = false;
mDestroySelf = false;
mDestroySelf = false;
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -178,7 +178,8 @@ CHIP_ERROR AsyncResponder::Init(System::Layer * layer, Messaging::ExchangeContex

void AsyncResponder::NotifyEventHandled(const TransferSession::OutputEvent & event, CHIP_ERROR status)
{
ChipLogDetail(BDX, "NotifyEventHandled : Event %s Error %" CHIP_ERROR_FORMAT, TransferSession::OutputEvent::TypeToString(event.EventType), status.Format());
ChipLogDetail(BDX, "NotifyEventHandled : Event %s Error %" CHIP_ERROR_FORMAT,
TransferSession::OutputEvent::TypeToString(event.EventType), status.Format());

// If it's a message indicating either the end of the transfer or a timeout reported by the transfer session
// or an error occured, we need to call DestroySelf().
Expand Down

0 comments on commit d3713d7

Please sign in to comment.