diff --git a/android/jni/com/mapswithme/maps/LightFramework.cpp b/android/jni/com/mapswithme/maps/LightFramework.cpp index 2fbf100704..bd165309ae 100644 --- a/android/jni/com/mapswithme/maps/LightFramework.cpp +++ b/android/jni/com/mapswithme/maps/LightFramework.cpp @@ -13,14 +13,14 @@ JNIEXPORT jboolean JNICALL Java_com_mapswithme_maps_LightFramework_nativeIsAuthenticated(JNIEnv * env, jclass clazz) { Framework const framework(REQUEST_TYPE_USER_AUTH_STATUS); - return static_cast(framework.Get()); + return static_cast(framework.IsUserAuthenticated()); } JNIEXPORT jint JNICALL Java_com_mapswithme_maps_LightFramework_nativeGetNumberUnsentUGC(JNIEnv * env, jclass clazz) { Framework const framework(REQUEST_TYPE_NUMBER_OF_UNSENT_UGC); - return static_cast(framework.Get()); + return static_cast(framework.GetNumberOfUnsentUGC()); } JNIEXPORT jobjectArray JNICALL @@ -30,8 +30,7 @@ Java_com_mapswithme_maps_LightFramework_nativeGetLocalAdsFeatures(JNIEnv * env, jint maxCount) { Framework framework(REQUEST_TYPE_LOCAL_ADS_FEATURES); - auto const features = framework.GetNonConst( - lat, lon, radiusInMeters, maxCount); + auto const features = framework.GetLocalAdsFeatures(lat, lon, radiusInMeters, maxCount); static jclass const geoFenceFeatureClazz = jni::GetGlobalClassRef(env, "com/mapswithme/maps/geofence/GeoFenceFeature"); @@ -66,14 +65,14 @@ Java_com_mapswithme_maps_LightFramework_nativeLogLocalAdsEvent(JNIEnv * env, jcl static_cast(1) /* zoom level */, local_ads::Clock::now(), static_cast(lat), static_cast(lon), static_cast(accuracyInMeters)); - framework.GetNonConst()->RegisterEvent(std::move(event)); + framework.GetLocalAdsStatistics()->RegisterEvent(std::move(event)); } JNIEXPORT jobject JNICALL Java_com_mapswithme_maps_LightFramework_nativeGetNotification(JNIEnv * env, jclass clazz) { Framework framework(REQUEST_TYPE_NOTIFICATION); - auto const notification = framework.Get(); + auto const notification = framework.GetNotification(); if (!notification) return nullptr; diff --git a/iphone/Maps/Core/Notifications/LocalNotificationManager.mm b/iphone/Maps/Core/Notifications/LocalNotificationManager.mm index d4b7ff675a..aa7cda69f8 100644 --- a/iphone/Maps/Core/Notifications/LocalNotificationManager.mm +++ b/iphone/Maps/Core/Notifications/LocalNotificationManager.mm @@ -79,7 +79,7 @@ using namespace storage; using namespace lightweight; lightweight::Framework const f(REQUEST_TYPE_NUMBER_OF_UNSENT_UGC | REQUEST_TYPE_USER_AUTH_STATUS); - if (f.Get() || f.Get() < 2) + if (f.IsUserAuthenticated() || f.GetNumberOfUnsentUGC() < 2) return NO; return YES; diff --git a/map/CMakeLists.txt b/map/CMakeLists.txt index ca3be83014..b86200e00f 100644 --- a/map/CMakeLists.txt +++ b/map/CMakeLists.txt @@ -55,6 +55,7 @@ set( feature_vec_model.hpp framework.cpp framework.hpp + framework_light.cpp framework_light.hpp ge0_parser.cpp ge0_parser.hpp diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index 62fd4785a2..0a63459617 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -2704,8 +2704,11 @@ void BookmarkManager::EditSession::NotifyChanges() namespace lightweight { +namespace impl +{ bool IsBookmarksCloudEnabled() { return Cloud::GetCloudState(kBookmarkCloudSettingsParam) == Cloud::State::Enabled; } +} // namespace impl } // namespace lightweight diff --git a/map/bookmark_manager.hpp b/map/bookmark_manager.hpp index c2fc0a0c0f..8285e36c5f 100644 --- a/map/bookmark_manager.hpp +++ b/map/bookmark_manager.hpp @@ -576,5 +576,8 @@ private: namespace lightweight { +namespace impl +{ bool IsBookmarksCloudEnabled(); +} // namespace impl } //namespace lightweight diff --git a/map/framework_light.cpp b/map/framework_light.cpp new file mode 100644 index 0000000000..d54dd3c6bf --- /dev/null +++ b/map/framework_light.cpp @@ -0,0 +1,118 @@ +#include "map/framework_light.hpp" + +namespace lightweight +{ +Framework::Framework(RequestTypeMask request) : m_request(request) +{ + CHECK_NOT_EQUAL(request, REQUEST_TYPE_EMPTY, ("Mask is empty")); + + if (request & REQUEST_TYPE_NUMBER_OF_UNSENT_UGC) + { + m_numberOfUnsentUGC = impl::GetNumberOfUnsentUGC(); + request ^= REQUEST_TYPE_NUMBER_OF_UNSENT_UGC; + } + + if (request & REQUEST_TYPE_USER_AUTH_STATUS) + { + m_userAuthStatus = impl::IsUserAuthenticated(); + request ^= REQUEST_TYPE_USER_AUTH_STATUS; + } + + if (request & REQUEST_TYPE_NUMBER_OF_UNSENT_EDITS) + { + // TODO: Hasn't implemented yet. + request ^= REQUEST_TYPE_NUMBER_OF_UNSENT_EDITS; + } + + if (request & REQUEST_TYPE_BOOKMARKS_CLOUD_ENABLED) + { + m_bookmarksCloudEnabled = impl::IsBookmarksCloudEnabled(); + request ^= REQUEST_TYPE_BOOKMARKS_CLOUD_ENABLED; + } + + if (request & REQUEST_TYPE_LOCATION) + { + m_countryInfoReader = std::make_unique(); + request ^= REQUEST_TYPE_LOCATION; + } + + if (request & REQUEST_TYPE_LOCAL_ADS_FEATURES) + { + m_localAdsFeaturesReader = std::make_unique(); + request ^= REQUEST_TYPE_LOCAL_ADS_FEATURES; + } + + if (request & REQUEST_TYPE_LOCAL_ADS_STATISTICS) + { + m_localAdsStatistics = std::make_unique(); + request ^= REQUEST_TYPE_LOCAL_ADS_STATISTICS; + } + + if (request & REQUEST_TYPE_NOTIFICATION) + { + m_notificationManager = std::make_unique(); + request ^= REQUEST_TYPE_NOTIFICATION; + } + + CHECK_EQUAL(request, REQUEST_TYPE_EMPTY, ("Incorrect mask type:", request)); +} + +bool Framework::IsUserAuthenticated() const +{ + ASSERT(m_request & REQUEST_TYPE_USER_AUTH_STATUS, (m_request)); + return m_userAuthStatus; +} + +size_t Framework::GetNumberOfUnsentUGC() const +{ + ASSERT(m_request & REQUEST_TYPE_NUMBER_OF_UNSENT_UGC, (m_request)); + return m_numberOfUnsentUGC; +} + + +size_t Framework::GetNumberOfUnsentEdits() const +{ + ASSERT(m_request & REQUEST_TYPE_NUMBER_OF_UNSENT_EDITS, (m_request)); + return m_numberOfUnsentEdits; +} + +bool Framework::IsBookmarksCloudEnabled() const +{ + ASSERT(m_request & REQUEST_TYPE_BOOKMARKS_CLOUD_ENABLED, (m_request)); + return m_bookmarksCloudEnabled; +} + +CountryInfoReader::Info Framework::GetLocation(m2::PointD const & pt) const +{ + ASSERT(m_request & REQUEST_TYPE_LOCATION, (m_request)); + + CHECK(m_countryInfoReader, ()); + + return m_countryInfoReader->GetMwmInfo(pt); +} + +std::vector Framework::GetLocalAdsFeatures(double lat, double lon, + double radiusInMeters, uint32_t maxCount) +{ + ASSERT(m_request & REQUEST_TYPE_LOCAL_ADS_FEATURES, (m_request)); + + CHECK(m_localAdsFeaturesReader, ()); + + return m_localAdsFeaturesReader->GetCampaignFeatures(lat, lon, radiusInMeters, maxCount); +} + +Statistics * Framework::GetLocalAdsStatistics() +{ + ASSERT(m_request & REQUEST_TYPE_LOCAL_ADS_STATISTICS, (m_request)); + + CHECK(m_localAdsStatistics, ()); + + return m_localAdsStatistics.get(); +} + +boost::optional Framework::GetNotification() const +{ + return m_notificationManager->GetNotification(); +} +} // namespace lightweight + diff --git a/map/framework_light.hpp b/map/framework_light.hpp index 9d8487fb27..c0cc9ba286 100644 --- a/map/framework_light.hpp +++ b/map/framework_light.hpp @@ -46,72 +46,17 @@ class Framework public: friend struct LightFrameworkTest; - explicit Framework(RequestTypeMask request) : m_request(request) - { - CHECK_NOT_EQUAL(request, REQUEST_TYPE_EMPTY, ("Mask is empty")); + explicit Framework(RequestTypeMask request); - if (request & REQUEST_TYPE_NUMBER_OF_UNSENT_UGC) - { - m_numberOfUnsentUGC = GetNumberOfUnsentUGC(); - request ^= REQUEST_TYPE_NUMBER_OF_UNSENT_UGC; - } - - if (request & REQUEST_TYPE_USER_AUTH_STATUS) - { - m_userAuthStatus = IsUserAuthenticated(); - request ^= REQUEST_TYPE_USER_AUTH_STATUS; - } - - if (request & REQUEST_TYPE_NUMBER_OF_UNSENT_EDITS) - { - // TODO: Hasn't implemented yet. - request ^= REQUEST_TYPE_NUMBER_OF_UNSENT_EDITS; - } - - if (request & REQUEST_TYPE_BOOKMARKS_CLOUD_ENABLED) - { - m_bookmarksCloudEnabled = IsBookmarksCloudEnabled(); - request ^= REQUEST_TYPE_BOOKMARKS_CLOUD_ENABLED; - } - - if (request & REQUEST_TYPE_LOCATION) - { - m_countryInfoReader = std::make_unique(); - request ^= REQUEST_TYPE_LOCATION; - } - - if (request & REQUEST_TYPE_LOCAL_ADS_FEATURES) - { - m_localAdsFeaturesReader = std::make_unique(); - request ^= REQUEST_TYPE_LOCAL_ADS_FEATURES; - } - - if (request & REQUEST_TYPE_LOCAL_ADS_STATISTICS) - { - m_localAdsStatistics = std::make_unique(); - request ^= REQUEST_TYPE_LOCAL_ADS_STATISTICS; - } - - if (request & REQUEST_TYPE_NOTIFICATION) - { - m_notificationManager = std::make_unique(); - request ^= REQUEST_TYPE_NOTIFICATION; - } - - CHECK_EQUAL(request, REQUEST_TYPE_EMPTY, ("Incorrect mask type:", request)); - } - - template - auto Get() const; - - template - auto Get(m2::PointD const & pt) const; - - template - auto GetNonConst(double lat, double lon, double radiusInMeters, uint32_t maxCount); - - template - auto GetNonConst(); + bool IsUserAuthenticated() const; + size_t GetNumberOfUnsentUGC() const; + size_t GetNumberOfUnsentEdits() const; + bool IsBookmarksCloudEnabled() const; + CountryInfoReader::Info GetLocation(m2::PointD const & pt) const; + std::vector GetLocalAdsFeatures(double lat, double lon, double radiusInMeters, + uint32_t maxCount); + Statistics * GetLocalAdsStatistics(); + boost::optional GetNotification() const; private: RequestTypeMask m_request; @@ -124,69 +69,4 @@ private: std::unique_ptr m_localAdsStatistics; std::unique_ptr m_notificationManager; }; - -template<> -auto Framework::Get() const -{ - ASSERT(m_request & REQUEST_TYPE_USER_AUTH_STATUS, (m_request)); - return m_userAuthStatus; -} - -template<> -auto Framework::Get() const -{ - ASSERT(m_request & REQUEST_TYPE_NUMBER_OF_UNSENT_UGC, (m_request)); - return m_numberOfUnsentUGC; -} - -template<> -auto Framework::Get() const -{ - ASSERT(m_request & REQUEST_TYPE_NUMBER_OF_UNSENT_EDITS, (m_request)); - return m_numberOfUnsentEdits; -} - -template<> -auto Framework::Get() const -{ - ASSERT(m_request & REQUEST_TYPE_BOOKMARKS_CLOUD_ENABLED, (m_request)); - return m_bookmarksCloudEnabled; -} - -template <> -auto Framework::Get(m2::PointD const & pt) const -{ - ASSERT(m_request & REQUEST_TYPE_LOCATION, (m_request)); - - CHECK(m_countryInfoReader, ()); - - return m_countryInfoReader->GetMwmInfo(pt); -} - -template <> -auto Framework::GetNonConst(double lat, double lon, - double radiusInMeters, uint32_t maxCount) -{ - ASSERT(m_request & REQUEST_TYPE_LOCAL_ADS_FEATURES, (m_request)); - - CHECK(m_localAdsFeaturesReader, ()); - - return m_localAdsFeaturesReader->GetCampaignFeatures(lat, lon, radiusInMeters, maxCount); -} - -template <> -auto Framework::GetNonConst() -{ - ASSERT(m_request & REQUEST_TYPE_LOCAL_ADS_STATISTICS, (m_request)); - - CHECK(m_localAdsStatistics, ()); - - return m_localAdsStatistics.get(); -} - -template <> -auto Framework::Get() const -{ - return m_notificationManager->GetNotification(); -} } // namespace lightweight diff --git a/map/map_tests/framework_light_tests.cpp b/map/map_tests/framework_light_tests.cpp index b74f4cfb0e..9440a5edb5 100644 --- a/map/map_tests/framework_light_tests.cpp +++ b/map/map_tests/framework_light_tests.cpp @@ -12,8 +12,8 @@ struct LightFrameworkTest Framework f(REQUEST_TYPE_NUMBER_OF_UNSENT_UGC | REQUEST_TYPE_USER_AUTH_STATUS); f.m_userAuthStatus = true; f.m_numberOfUnsentUGC = 30; - TEST_EQUAL(f.Get(), 30, ()); - TEST(f.Get(), ()); + TEST_EQUAL(f.GetNumberOfUnsentUGC(), 30, ()); + TEST(f.IsUserAuthenticated(), ()); } { @@ -22,17 +22,17 @@ struct LightFrameworkTest REQUEST_TYPE_NUMBER_OF_UNSENT_UGC); f.m_numberOfUnsentEdits = 10; - TEST_EQUAL(f.Get(), 10, ()); - TEST_EQUAL(f.Get(), 0, ()); - TEST(!f.Get(), ()); + TEST_EQUAL(f.GetNumberOfUnsentEdits(), 10, ()); + TEST_EQUAL(f.GetNumberOfUnsentUGC(), 0, ()); + TEST(!f.IsUserAuthenticated(), ()); } { Framework f(REQUEST_TYPE_LOCAL_ADS_FEATURES | REQUEST_TYPE_LOCAL_ADS_STATISTICS); - auto const features = f.GetNonConst(0.0 /* lat */, 0.0 /* lon */, + auto const features = f.GetLocalAdsFeatures(0.0 /* lat */, 0.0 /* lon */, 100 /* radiusInMeters */, 0 /* maxCount */); - auto stats = f.GetNonConst(); + auto stats = f.GetLocalAdsStatistics(); TEST(stats != nullptr, ()); TEST_EQUAL(features.size(), 0, ()); } diff --git a/map/user.cpp b/map/user.cpp index 89becd999e..d69addb280 100644 --- a/map/user.cpp +++ b/map/user.cpp @@ -714,6 +714,8 @@ void User::RequestImpl(std::string const & url, BuildRequestHandler const & onBu namespace lightweight { +namespace impl +{ bool IsUserAuthenticated() { std::string token; @@ -722,4 +724,5 @@ bool IsUserAuthenticated() return false; } +} // namespace impl } // namespace lightweight diff --git a/map/user.hpp b/map/user.hpp index e01610a477..171668b81f 100644 --- a/map/user.hpp +++ b/map/user.hpp @@ -105,5 +105,8 @@ private: namespace lightweight { +namespace impl +{ bool IsUserAuthenticated(); +} // namespace impl } //namespace lightweight diff --git a/ugc/storage.cpp b/ugc/storage.cpp index d6eedaf446..2ec5cd4815 100644 --- a/ugc/storage.cpp +++ b/ugc/storage.cpp @@ -544,6 +544,8 @@ void Storage::LoadForTesting(std::string const & testIndexFilePath) namespace lightweight { +namespace impl +{ size_t GetNumberOfUnsentUGC() { auto const indexFilePath = GetIndexFilePath(); @@ -573,4 +575,5 @@ size_t GetNumberOfUnsentUGC() return number; } +} // namespace impl } // namespace lightweight diff --git a/ugc/storage.hpp b/ugc/storage.hpp index a578e25e4b..113d82a53c 100644 --- a/ugc/storage.hpp +++ b/ugc/storage.hpp @@ -76,5 +76,8 @@ inline std::string DebugPrint(Storage::SettingResult const & result) namespace lightweight { +namespace impl +{ size_t GetNumberOfUnsentUGC(); +} // namespace impl } //namespace lightweight