From 0390a8d33b1d1c709fcc4499eab6e132428ad5e2 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Wed, 13 Jul 2022 14:35:21 -0700 Subject: [PATCH] Update OTA queues to use the matter work queue. (#20628) (#20690) Co-authored-by: krypton36 --- .../CHIP/MTROTAProviderDelegateBridge.mm | 58 ++++++++++--------- 1 file changed, 30 insertions(+), 28 deletions(-) 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(); + } + }); }]; }); }