mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 08:10:06 +00:00 
			
		
		
		
	Emit signal from provider manager instead of radar product manager in async callback
Prevents application crash when exiting during refresh due to destroyed object reference
This commit is contained in:
		
							parent
							
								
									1811236cae
								
							
						
					
					
						commit
						254fbbeb67
					
				
					 1 changed files with 61 additions and 48 deletions
				
			
		|  | @ -61,17 +61,18 @@ static std::shared_mutex fileIndexMutex_; | ||||||
| 
 | 
 | ||||||
| static std::mutex fileLoadMutex_; | static std::mutex fileLoadMutex_; | ||||||
| 
 | 
 | ||||||
| class RadarProductManagerImpl | class ProviderManager : public QObject | ||||||
| { | { | ||||||
|  |    Q_OBJECT | ||||||
| public: | public: | ||||||
|    struct ProviderManager |    explicit ProviderManager(RadarProductManager*      self, | ||||||
|    { |                             const std::string&        radarId, | ||||||
|       explicit ProviderManager(const std::string&        radarId, |  | ||||||
|                             common::RadarProductGroup group) : |                             common::RadarProductGroup group) : | ||||||
|           ProviderManager(radarId, group, "???") |        ProviderManager(self, radarId, group, "???") | ||||||
|    { |    { | ||||||
|    } |    } | ||||||
|       explicit ProviderManager(const std::string&        radarId, |    explicit ProviderManager(RadarProductManager*      self, | ||||||
|  |                             const std::string&        radarId, | ||||||
|                             common::RadarProductGroup group, |                             common::RadarProductGroup group, | ||||||
|                             const std::string&        product) : |                             const std::string&        product) : | ||||||
|        radarId_ {radarId}, |        radarId_ {radarId}, | ||||||
|  | @ -82,6 +83,10 @@ public: | ||||||
|        refreshTimerMutex_ {}, |        refreshTimerMutex_ {}, | ||||||
|        provider_ {nullptr} |        provider_ {nullptr} | ||||||
|    { |    { | ||||||
|  |       connect(this, | ||||||
|  |               &ProviderManager::NewDataAvailable, | ||||||
|  |               self, | ||||||
|  |               &RadarProductManager::NewDataAvailable); | ||||||
|    } |    } | ||||||
|    ~ProviderManager() = default; |    ~ProviderManager() = default; | ||||||
| 
 | 
 | ||||||
|  | @ -96,8 +101,16 @@ public: | ||||||
|    boost::asio::steady_timer                     refreshTimer_; |    boost::asio::steady_timer                     refreshTimer_; | ||||||
|    std::mutex                                    refreshTimerMutex_; |    std::mutex                                    refreshTimerMutex_; | ||||||
|    std::shared_ptr<provider::NexradDataProvider> provider_; |    std::shared_ptr<provider::NexradDataProvider> provider_; | ||||||
|  | 
 | ||||||
|  | signals: | ||||||
|  |    void NewDataAvailable(common::RadarProductGroup             group, | ||||||
|  |                          const std::string&                    product, | ||||||
|  |                          std::chrono::system_clock::time_point latestTime); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | class RadarProductManagerImpl | ||||||
|  | { | ||||||
|  | public: | ||||||
|    explicit RadarProductManagerImpl(RadarProductManager* self, |    explicit RadarProductManagerImpl(RadarProductManager* self, | ||||||
|                                     const std::string&   radarId) : |                                     const std::string&   radarId) : | ||||||
|        self_ {self}, |        self_ {self}, | ||||||
|  | @ -112,7 +125,7 @@ public: | ||||||
|        level2ProductRecordMutex_ {}, |        level2ProductRecordMutex_ {}, | ||||||
|        level3ProductRecordMutex_ {}, |        level3ProductRecordMutex_ {}, | ||||||
|        level2ProviderManager_ {std::make_shared<ProviderManager>( |        level2ProviderManager_ {std::make_shared<ProviderManager>( | ||||||
|           radarId_, common::RadarProductGroup::Level2)}, |           self_, radarId_, common::RadarProductGroup::Level2)}, | ||||||
|        level3ProviderManagerMap_ {}, |        level3ProviderManagerMap_ {}, | ||||||
|        level3ProviderManagerMutex_ {}, |        level3ProviderManagerMutex_ {}, | ||||||
|        initializeMutex_ {}, |        initializeMutex_ {}, | ||||||
|  | @ -151,8 +164,7 @@ public: | ||||||
|    std::shared_ptr<ProviderManager> |    std::shared_ptr<ProviderManager> | ||||||
|    GetLevel3ProviderManager(const std::string& product); |    GetLevel3ProviderManager(const std::string& product); | ||||||
| 
 | 
 | ||||||
|    void EnableRefresh( |    void EnableRefresh(std::shared_ptr<ProviderManager> providerManager, | ||||||
|       std::shared_ptr<RadarProductManagerImpl::ProviderManager> providerManager, |  | ||||||
|                       bool                             enabled); |                       bool                             enabled); | ||||||
|    void RefreshData(std::shared_ptr<ProviderManager> providerManager); |    void RefreshData(std::shared_ptr<ProviderManager> providerManager); | ||||||
| 
 | 
 | ||||||
|  | @ -212,7 +224,7 @@ RadarProductManager::RadarProductManager(const std::string& radarId) : | ||||||
| } | } | ||||||
| RadarProductManager::~RadarProductManager() = default; | RadarProductManager::~RadarProductManager() = default; | ||||||
| 
 | 
 | ||||||
| std::string RadarProductManagerImpl::ProviderManager::name() const | std::string ProviderManager::name() const | ||||||
| { | { | ||||||
|    std::string name; |    std::string name; | ||||||
| 
 | 
 | ||||||
|  | @ -232,7 +244,7 @@ std::string RadarProductManagerImpl::ProviderManager::name() const | ||||||
|    return name; |    return name; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void RadarProductManagerImpl::ProviderManager::Disable() | void ProviderManager::Disable() | ||||||
| { | { | ||||||
|    std::unique_lock lock(refreshTimerMutex_); |    std::unique_lock lock(refreshTimerMutex_); | ||||||
|    refreshEnabled_ = false; |    refreshEnabled_ = false; | ||||||
|  | @ -374,7 +386,7 @@ void RadarProductManager::Initialize() | ||||||
|    p->initialized_ = true; |    p->initialized_ = true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| std::shared_ptr<RadarProductManagerImpl::ProviderManager> | std::shared_ptr<ProviderManager> | ||||||
| RadarProductManagerImpl::GetLevel3ProviderManager(const std::string& product) | RadarProductManagerImpl::GetLevel3ProviderManager(const std::string& product) | ||||||
| { | { | ||||||
|    std::unique_lock lock(level3ProviderManagerMutex_); |    std::unique_lock lock(level3ProviderManagerMutex_); | ||||||
|  | @ -384,15 +396,14 @@ RadarProductManagerImpl::GetLevel3ProviderManager(const std::string& product) | ||||||
|       level3ProviderManagerMap_.emplace( |       level3ProviderManagerMap_.emplace( | ||||||
|          std::piecewise_construct, |          std::piecewise_construct, | ||||||
|          std::forward_as_tuple(product), |          std::forward_as_tuple(product), | ||||||
|          std::forward_as_tuple( |          std::forward_as_tuple(std::make_shared<ProviderManager>( | ||||||
|             std::make_shared<RadarProductManagerImpl::ProviderManager>( |             self_, radarId_, common::RadarProductGroup::Level3, product))); | ||||||
|                radarId_, common::RadarProductGroup::Level3, product))); |  | ||||||
|       level3ProviderManagerMap_.at(product)->provider_ = |       level3ProviderManagerMap_.at(product)->provider_ = | ||||||
|          provider::NexradDataProviderFactory::CreateLevel3DataProvider(radarId_, |          provider::NexradDataProviderFactory::CreateLevel3DataProvider(radarId_, | ||||||
|                                                                        product); |                                                                        product); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    std::shared_ptr<RadarProductManagerImpl::ProviderManager> providerManager = |    std::shared_ptr<ProviderManager> providerManager = | ||||||
|       level3ProviderManagerMap_.at(product); |       level3ProviderManagerMap_.at(product); | ||||||
| 
 | 
 | ||||||
|    return providerManager; |    return providerManager; | ||||||
|  | @ -408,8 +419,8 @@ void RadarProductManager::EnableRefresh(common::RadarProductGroup group, | ||||||
|    } |    } | ||||||
|    else |    else | ||||||
|    { |    { | ||||||
|       std::shared_ptr<RadarProductManagerImpl::ProviderManager> |       std::shared_ptr<ProviderManager> providerManager = | ||||||
|          providerManager = p->GetLevel3ProviderManager(product); |          p->GetLevel3ProviderManager(product); | ||||||
| 
 | 
 | ||||||
|       // Only enable refresh on available products
 |       // Only enable refresh on available products
 | ||||||
|       util::async( |       util::async( | ||||||
|  | @ -478,7 +489,7 @@ void RadarProductManagerImpl::RefreshData( | ||||||
|                interval = kRetryInterval_; |                interval = kRetryInterval_; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             emit self_->NewDataAvailable( |             emit providerManager->NewDataAvailable( | ||||||
|                providerManager->group_, providerManager->product_, latestTime); |                providerManager->group_, providerManager->product_, latestTime); | ||||||
|          } |          } | ||||||
|          else if (providerManager->refreshEnabled_ && totalObjects == 0) |          else if (providerManager->refreshEnabled_ && totalObjects == 0) | ||||||
|  | @ -986,6 +997,8 @@ RadarProductManager::Instance(const std::string& radarSite) | ||||||
|    return instance; |    return instance; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | #include "radar_product_manager.moc" | ||||||
|  | 
 | ||||||
| } // namespace manager
 | } // namespace manager
 | ||||||
| } // namespace qt
 | } // namespace qt
 | ||||||
| } // namespace scwx
 | } // namespace scwx
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat