mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 22:10:05 +00:00
Associate product refresh with a uuid
Allows product manager to track which map widgets have enabled which product refreshes
This commit is contained in:
parent
5a353a8139
commit
6e10ca88d5
3 changed files with 91 additions and 9 deletions
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#pragma warning(push, 0)
|
#pragma warning(push, 0)
|
||||||
#include <boost/asio/steady_timer.hpp>
|
#include <boost/asio/steady_timer.hpp>
|
||||||
|
#include <boost/container_hash/hash.hpp>
|
||||||
#include <boost/range/irange.hpp>
|
#include <boost/range/irange.hpp>
|
||||||
#include <boost/timer/timer.hpp>
|
#include <boost/timer/timer.hpp>
|
||||||
#include <fmt/chrono.h>
|
#include <fmt/chrono.h>
|
||||||
|
|
@ -166,7 +167,8 @@ public:
|
||||||
std::shared_ptr<ProviderManager>
|
std::shared_ptr<ProviderManager>
|
||||||
GetLevel3ProviderManager(const std::string& product);
|
GetLevel3ProviderManager(const std::string& product);
|
||||||
|
|
||||||
void EnableRefresh(std::shared_ptr<ProviderManager> providerManager,
|
void EnableRefresh(boost::uuids::uuid uuid,
|
||||||
|
std::shared_ptr<ProviderManager> providerManager,
|
||||||
bool enabled);
|
bool enabled);
|
||||||
void RefreshData(std::shared_ptr<ProviderManager> providerManager);
|
void RefreshData(std::shared_ptr<ProviderManager> providerManager);
|
||||||
|
|
||||||
|
|
@ -218,6 +220,12 @@ public:
|
||||||
|
|
||||||
common::Level3ProductCategoryMap availableCategoryMap_;
|
common::Level3ProductCategoryMap availableCategoryMap_;
|
||||||
std::shared_mutex availableCategoryMutex_;
|
std::shared_mutex availableCategoryMutex_;
|
||||||
|
|
||||||
|
std::unordered_map<boost::uuids::uuid,
|
||||||
|
std::shared_ptr<ProviderManager>,
|
||||||
|
boost::hash<boost::uuids::uuid>>
|
||||||
|
refreshMap_ {};
|
||||||
|
std::mutex refreshMapMutex_ {};
|
||||||
};
|
};
|
||||||
|
|
||||||
RadarProductManager::RadarProductManager(const std::string& radarId) :
|
RadarProductManager::RadarProductManager(const std::string& radarId) :
|
||||||
|
|
@ -248,6 +256,8 @@ std::string ProviderManager::name() const
|
||||||
|
|
||||||
void ProviderManager::Disable()
|
void ProviderManager::Disable()
|
||||||
{
|
{
|
||||||
|
logger_->debug("Disabling refresh: {}", name());
|
||||||
|
|
||||||
std::unique_lock lock(refreshTimerMutex_);
|
std::unique_lock lock(refreshTimerMutex_);
|
||||||
refreshEnabled_ = false;
|
refreshEnabled_ = false;
|
||||||
refreshTimer_.cancel();
|
refreshTimer_.cancel();
|
||||||
|
|
@ -413,11 +423,12 @@ RadarProductManagerImpl::GetLevel3ProviderManager(const std::string& product)
|
||||||
|
|
||||||
void RadarProductManager::EnableRefresh(common::RadarProductGroup group,
|
void RadarProductManager::EnableRefresh(common::RadarProductGroup group,
|
||||||
const std::string& product,
|
const std::string& product,
|
||||||
bool enabled)
|
bool enabled,
|
||||||
|
boost::uuids::uuid uuid)
|
||||||
{
|
{
|
||||||
if (group == common::RadarProductGroup::Level2)
|
if (group == common::RadarProductGroup::Level2)
|
||||||
{
|
{
|
||||||
p->EnableRefresh(p->level2ProviderManager_, enabled);
|
p->EnableRefresh(uuid, p->level2ProviderManager_, enabled);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -437,16 +448,65 @@ void RadarProductManager::EnableRefresh(common::RadarProductGroup group,
|
||||||
availableProducts.cend(),
|
availableProducts.cend(),
|
||||||
product) != availableProducts.cend())
|
product) != availableProducts.cend())
|
||||||
{
|
{
|
||||||
p->EnableRefresh(providerManager, enabled);
|
p->EnableRefresh(uuid, providerManager, enabled);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadarProductManagerImpl::EnableRefresh(
|
void RadarProductManagerImpl::EnableRefresh(
|
||||||
std::shared_ptr<ProviderManager> providerManager, bool enabled)
|
boost::uuids::uuid uuid,
|
||||||
|
std::shared_ptr<ProviderManager> providerManager,
|
||||||
|
bool enabled)
|
||||||
{
|
{
|
||||||
if (providerManager->refreshEnabled_ != enabled)
|
// Lock the refresh map
|
||||||
|
std::unique_lock lock {refreshMapMutex_};
|
||||||
|
|
||||||
|
auto currentProviderManager = refreshMap_.find(uuid);
|
||||||
|
if (currentProviderManager != refreshMap_.cend())
|
||||||
|
{
|
||||||
|
// If the enabling refresh for a different product, or disabling refresh
|
||||||
|
if (currentProviderManager->second != providerManager || !enabled)
|
||||||
|
{
|
||||||
|
// Determine number of entries in the map for the current provider
|
||||||
|
// manager
|
||||||
|
auto currentProviderManagerCount = std::count_if(
|
||||||
|
refreshMap_.cbegin(),
|
||||||
|
refreshMap_.cend(),
|
||||||
|
[&](const auto& provider)
|
||||||
|
{ return provider.second == currentProviderManager->second; });
|
||||||
|
|
||||||
|
// If this is the last reference to the provider in the refresh map
|
||||||
|
if (currentProviderManagerCount == 1)
|
||||||
|
{
|
||||||
|
// Disable current provider
|
||||||
|
currentProviderManager->second->Disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dissociate uuid from current provider manager
|
||||||
|
refreshMap_.erase(currentProviderManager);
|
||||||
|
|
||||||
|
// If we are enabling a new provider manager
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
// Associate uuid to providerManager
|
||||||
|
refreshMap_.emplace(uuid, providerManager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (enabled)
|
||||||
|
{
|
||||||
|
// We are enabling a new provider manager
|
||||||
|
// Associate uuid to provider manager
|
||||||
|
refreshMap_.emplace(uuid, providerManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release the refresh map mutex
|
||||||
|
lock.unlock();
|
||||||
|
|
||||||
|
// We have already handled a disable request by this point. If enabling, and
|
||||||
|
// the provider manager refresh isn't already enabled, enable it.
|
||||||
|
if (enabled && providerManager->refreshEnabled_ != enabled)
|
||||||
{
|
{
|
||||||
providerManager->refreshEnabled_ = enabled;
|
providerManager->refreshEnabled_ = enabled;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <boost/uuid/nil_generator.hpp>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
|
|
@ -38,9 +39,24 @@ public:
|
||||||
std::shared_ptr<config::RadarSite> radar_site() const;
|
std::shared_ptr<config::RadarSite> radar_site() const;
|
||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enables or disables refresh associated with a unique identifier
|
||||||
|
* (UUID) for a given radar product group and product.
|
||||||
|
*
|
||||||
|
* Only a single product refresh can be enabled for a given UUID. If a second
|
||||||
|
* product refresh is enabled for the same UUID, the first product refresh is
|
||||||
|
* disabled (unless still enabled under a different UUID).
|
||||||
|
*
|
||||||
|
* @param [in] group Radar product group
|
||||||
|
* @param [in] product Radar product name
|
||||||
|
* @param [in] enabled Whether to enable refresh
|
||||||
|
* @param [in] uuid Unique identifier. Default is boost::uuids::nil_uuid().
|
||||||
|
*/
|
||||||
void EnableRefresh(common::RadarProductGroup group,
|
void EnableRefresh(common::RadarProductGroup group,
|
||||||
const std::string& product,
|
const std::string& product,
|
||||||
bool enabled);
|
bool enabled,
|
||||||
|
boost::uuids::uuid uuid = boost::uuids::nil_uuid());
|
||||||
|
|
||||||
std::tuple<std::shared_ptr<wsr88d::rda::ElevationScan>,
|
std::tuple<std::shared_ptr<wsr88d::rda::ElevationScan>,
|
||||||
float,
|
float,
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include <backends/imgui_impl_opengl3.h>
|
#include <backends/imgui_impl_opengl3.h>
|
||||||
#include <backends/imgui_impl_qt.hpp>
|
#include <backends/imgui_impl_qt.hpp>
|
||||||
|
#include <boost/uuid/random_generator.hpp>
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
|
@ -58,6 +59,7 @@ class MapWidgetImpl : public QObject
|
||||||
public:
|
public:
|
||||||
explicit MapWidgetImpl(MapWidget* widget,
|
explicit MapWidgetImpl(MapWidget* widget,
|
||||||
const QMapLibreGL::Settings& settings) :
|
const QMapLibreGL::Settings& settings) :
|
||||||
|
uuid_ {boost::uuids::random_generator()()},
|
||||||
context_ {std::make_shared<MapContext>()},
|
context_ {std::make_shared<MapContext>()},
|
||||||
widget_ {widget},
|
widget_ {widget},
|
||||||
settings_(settings),
|
settings_(settings),
|
||||||
|
|
@ -126,6 +128,8 @@ public:
|
||||||
common::Level2Product
|
common::Level2Product
|
||||||
GetLevel2ProductOrDefault(const std::string& productName) const;
|
GetLevel2ProductOrDefault(const std::string& productName) const;
|
||||||
|
|
||||||
|
boost::uuids::uuid uuid_;
|
||||||
|
|
||||||
std::shared_ptr<MapContext> context_;
|
std::shared_ptr<MapContext> context_;
|
||||||
|
|
||||||
MapWidget* widget_;
|
MapWidget* widget_;
|
||||||
|
|
@ -399,7 +403,8 @@ void MapWidget::SelectRadarProduct(common::RadarProductGroup group,
|
||||||
|
|
||||||
if (p->autoRefreshEnabled_)
|
if (p->autoRefreshEnabled_)
|
||||||
{
|
{
|
||||||
p->radarProductManager_->EnableRefresh(group, productName, true);
|
p->radarProductManager_->EnableRefresh(
|
||||||
|
group, productName, true, p->uuid_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -485,7 +490,8 @@ void MapWidget::SetAutoRefresh(bool enabled)
|
||||||
p->radarProductManager_->EnableRefresh(
|
p->radarProductManager_->EnableRefresh(
|
||||||
radarProductView->GetRadarProductGroup(),
|
radarProductView->GetRadarProductGroup(),
|
||||||
radarProductView->GetRadarProductName(),
|
radarProductView->GetRadarProductName(),
|
||||||
true);
|
true,
|
||||||
|
p->uuid_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue