Hide RadarProductManager implementation detail by using friend class

This commit is contained in:
Dan Paulat 2022-02-28 22:56:18 -06:00
parent c9e312fd54
commit 410eb85d3f
2 changed files with 19 additions and 17 deletions

View file

@ -24,6 +24,9 @@ namespace manager
static const std::string logPrefix_ = static const std::string logPrefix_ =
"[scwx::qt::manager::radar_product_manager] "; "[scwx::qt::manager::radar_product_manager] ";
typedef std::function<std::shared_ptr<wsr88d::NexradFile>()>
CreateNexradFileFunction;
static constexpr uint32_t NUM_RADIAL_GATES_0_5_DEGREE = static constexpr uint32_t NUM_RADIAL_GATES_0_5_DEGREE =
common::MAX_0_5_DEGREE_RADIALS * common::MAX_DATA_MOMENT_GATES; common::MAX_0_5_DEGREE_RADIALS * common::MAX_DATA_MOMENT_GATES;
static constexpr uint32_t NUM_RADIAL_GATES_1_DEGREE = static constexpr uint32_t NUM_RADIAL_GATES_1_DEGREE =
@ -59,6 +62,10 @@ public:
void void
StoreRadarProductRecord(std::shared_ptr<types::RadarProductRecord> record); StoreRadarProductRecord(std::shared_ptr<types::RadarProductRecord> record);
static void
LoadNexradFile(CreateNexradFileFunction load,
std::shared_ptr<request::NexradFileRequest> request);
std::string radarId_; std::string radarId_;
bool initialized_; bool initialized_;
@ -70,8 +77,6 @@ public:
std::map<std::chrono::system_clock::time_point, std::map<std::chrono::system_clock::time_point,
std::shared_ptr<wsr88d::Ar2vFile>> std::shared_ptr<wsr88d::Ar2vFile>>
level2VolumeScans_; level2VolumeScans_;
std::mutex fileLoadMutex_;
}; };
RadarProductManager::RadarProductManager(const std::string& radarId) : RadarProductManager::RadarProductManager(const std::string& radarId) :
@ -208,7 +213,8 @@ void RadarProductManager::Initialize()
void RadarProductManager::LoadData( void RadarProductManager::LoadData(
std::istream& is, std::shared_ptr<request::NexradFileRequest> request) std::istream& is, std::shared_ptr<request::NexradFileRequest> request)
{ {
LoadNexradFile([=, &is]() -> std::shared_ptr<wsr88d::NexradFile> RadarProductManagerImpl::LoadNexradFile(
[=, &is]() -> std::shared_ptr<wsr88d::NexradFile>
{ return wsr88d::NexradFileFactory::Create(is); }, { return wsr88d::NexradFileFactory::Create(is); },
request); request);
} }
@ -217,12 +223,13 @@ void RadarProductManager::LoadFile(
const std::string& filename, const std::string& filename,
std::shared_ptr<request::NexradFileRequest> request) std::shared_ptr<request::NexradFileRequest> request)
{ {
LoadNexradFile([=]() -> std::shared_ptr<wsr88d::NexradFile> RadarProductManagerImpl::LoadNexradFile(
[=]() -> std::shared_ptr<wsr88d::NexradFile>
{ return wsr88d::NexradFileFactory::Create(filename); }, { return wsr88d::NexradFileFactory::Create(filename); },
request); request);
} }
void RadarProductManager::LoadNexradFile( void RadarProductManagerImpl::LoadNexradFile(
CreateNexradFileFunction load, CreateNexradFileFunction load,
std::shared_ptr<request::NexradFileRequest> request) std::shared_ptr<request::NexradFileRequest> request)
{ {
@ -307,7 +314,7 @@ RadarProductManager::GetLevel2Data(wsr88d::rda::DataBlockType dataBlockType,
scwx::util::async( scwx::util::async(
[&]() [&]()
{ {
std::lock_guard<std::mutex> guard(p->fileLoadMutex_); std::unique_lock lock(fileLoadMutex_);
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Start load"; BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Start load";

View file

@ -59,14 +59,9 @@ signals:
void Level2DataLoaded(); void Level2DataLoaded();
private: private:
typedef std::function<std::shared_ptr<wsr88d::NexradFile>()>
CreateNexradFileFunction;
static void
LoadNexradFile(CreateNexradFileFunction load,
std::shared_ptr<request::NexradFileRequest> request);
std::unique_ptr<RadarProductManagerImpl> p; std::unique_ptr<RadarProductManagerImpl> p;
friend class RadarProductManagerImpl;
}; };
} // namespace manager } // namespace manager