diff --git a/src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.mm b/src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.mm index 96da43ad219203..c4ca0caf0238bf 100644 --- a/src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.mm +++ b/src/darwin/Framework/CHIP/MTROTAProviderDelegateBridge.mm @@ -18,6 +18,7 @@ #import "MTROTAProviderDelegateBridge.h" #include +#include static NSInteger const kOtaProviderEndpoint = 0; @@ -30,13 +31,8 @@ void MTROTAProviderDelegateBridge::setDelegate(id delegate, dispatch_queue_t queue) { - if (delegate && queue) { - mDelegate = delegate; - mQueue = queue; - } else { - mDelegate = nil; - mQueue = nil; - } + mDelegate = delegate ?: nil; + mQueue = queue ?: nil; chip::app::Clusters::OTAProvider::SetDelegate(kOtaProviderEndpoint, this); } @@ -60,14 +56,16 @@ [strongDelegate handleQueryImage:commandParams completionHandler:^(MTROtaSoftwareUpdateProviderClusterQueryImageResponseParams * _Nullable data, NSError * _Nullable error) { - chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::QueryImageResponse::Type response; - ConvertFromQueryImageResponseParms(data, response); - - chip::app::CommandHandler * handler = handle.Get(); - if (handler) { - handler->AddResponse(cachedCommandPath, response); - handle.Release(); - } + dispatch_async(chip::DeviceLayer::PlatformMgrImpl().GetWorkQueue(), ^{ + chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::QueryImageResponse::Type response; + ConvertFromQueryImageResponseParms(data, response); + + chip::app::CommandHandler * handler = handle.Get(); + if (handler) { + handler->AddResponse(cachedCommandPath, response); + handle.Release(); + } + }); }]; }); } @@ -94,14 +92,16 @@ handleApplyUpdateRequest:commandParams completionHandler:^(MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data, NSError * _Nullable error) { - chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::ApplyUpdateResponse::Type response; - ConvertFromApplyUpdateRequestResponseParms(data, response); - - chip::app::CommandHandler * handler = handle.Get(); - if (handler) { - handler->AddResponse(cachedCommandPath, response); - handle.Release(); - } + dispatch_async(chip::DeviceLayer::PlatformMgrImpl().GetWorkQueue(), ^{ + chip::app::Clusters::OtaSoftwareUpdateProvider::Commands::ApplyUpdateResponse::Type response; + ConvertFromApplyUpdateRequestResponseParms(data, response); + + chip::app::CommandHandler * handler = handle.Get(); + if (handler) { + handler->AddResponse(cachedCommandPath, response); + handle.Release(); + } + }); }]; }); } @@ -127,11 +127,13 @@ [strongDelegate handleNotifyUpdateApplied:commandParams completionHandler:^(NSError * _Nullable error) { - chip::app::CommandHandler * handler = handle.Get(); - if (handler) { - handler->AddStatus(cachedCommandPath, chip::Protocols::InteractionModel::Status::Success); - handle.Release(); - } + dispatch_async(chip::DeviceLayer::PlatformMgrImpl().GetWorkQueue(), ^{ + chip::app::CommandHandler * handler = handle.Get(); + if (handler) { + handler->AddStatus(cachedCommandPath, chip::Protocols::InteractionModel::Status::Success); + handle.Release(); + } + }); }]; }); }