From d5166aed5779e9ffbd751ba3837a65a391512483 Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Wed, 31 Oct 2018 15:09:05 +0300 Subject: [PATCH] Notification manager review fixes + eye unsubscribe fix --- coding/serdes_json.hpp | 32 ++++++++++++++++++---- map/framework.cpp | 4 ++- map/notifications/notification_manager.cpp | 1 + map/notifications/notification_queue.hpp | 2 +- metrics/eye.cpp | 13 +++++---- metrics/eye.hpp | 2 ++ 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/coding/serdes_json.hpp b/coding/serdes_json.hpp index 4541bfb2ee..e6af971567 100644 --- a/coding/serdes_json.hpp +++ b/coding/serdes_json.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -34,10 +35,22 @@ auto is_iterable_checker(int) -> decltype( template std::false_type is_iterable_checker(...); + +template +auto is_dynamic_sequence_checker(int) -> decltype( + std::declval().resize(0), + std::declval()[0], + std::true_type {}); + +template +std::false_type is_dynamic_sequence_checker(...); } // namespace impl template using is_iterable = decltype(impl::is_iterable_checker(0)); + +template +using is_dynamic_sequence = decltype(impl::is_dynamic_sequence_checker(0)); } // namespace traits template @@ -52,6 +65,13 @@ using EnableIfEnum = std::enable_if_t::value>; template using EnableIfNotEnum = std::enable_if_t::value>; +template +using EnableIfVectorOrDeque = std::enable_if_t::value && + !std::is_same::value>; + +template +using EnableIfNotVectorOrDeque = std::enable_if_t::value>; + template class SerializerJson { @@ -218,20 +238,20 @@ public: void operator()(double & d, char const * name = nullptr) { FromJsonObjectOrValue(d, name); } void operator()(std::string & s, char const * name = nullptr) { FromJsonObjectOrValue(s, name); } - template - void operator()(std::vector & vs, char const * name = nullptr) + template * = nullptr> + void operator()(T & dest, char const * name = nullptr) { json_t * outerContext = SaveContext(name); if (!json_is_array(m_json)) MYTHROW(base::Json::Exception, ("The field", name, "must contain a json array.")); - vs.resize(json_array_size(m_json)); - for (size_t index = 0; index < vs.size(); ++index) + dest.resize(json_array_size(m_json)); + for (size_t index = 0; index < dest.size(); ++index) { json_t * context = SaveContext(); m_json = json_array_get(context, index); - (*this)(vs[index]); + (*this)(dest[index]); RestoreContext(context); } @@ -287,7 +307,7 @@ public: RestoreContext(outerContext); } - template * = nullptr> + template * = nullptr, EnableIfNotVectorOrDeque * = nullptr> void operator()(R & r, char const * name = nullptr) { json_t * context = SaveContext(name); diff --git a/map/framework.cpp b/map/framework.cpp index c2b405534f..5d7732450b 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -511,11 +511,14 @@ Framework::Framework(FrameworkParams const & params) InitTransliteration(); LOG(LDEBUG, ("Transliterators initialized")); + eye::Eye::Instance().TrimExpired(); eye::Eye::Instance().Subscribe(&m_notificationManager); } Framework::~Framework() { + eye::Eye::Instance().UnsubscribeAll(); + m_threadRunner.reset(); // Must be destroyed implicitly at the start of destruction, @@ -535,7 +538,6 @@ Framework::~Framework() m_user.ClearSubscribers(); // Must be destroyed implicitly, since it stores reference to m_user. m_bmManager.reset(); - eye::Eye::Instance().UnsubscribeAll(); } booking::Api * Framework::GetBookingApi(platform::NetworkPolicy const & policy) diff --git a/map/notifications/notification_manager.cpp b/map/notifications/notification_manager.cpp index 6d0ada4c1e..58caeaeba5 100644 --- a/map/notifications/notification_manager.cpp +++ b/map/notifications/notification_manager.cpp @@ -1,4 +1,5 @@ #include "map/notifications/notification_manager.hpp" + #include "map/notifications/notification_queue_serdes.hpp" #include "map/notifications/notification_queue_storage.hpp" diff --git a/map/notifications/notification_queue.hpp b/map/notifications/notification_queue.hpp index 38993738ba..6f13b8c276 100644 --- a/map/notifications/notification_queue.hpp +++ b/map/notifications/notification_queue.hpp @@ -22,7 +22,7 @@ struct Notification std::unique_ptr m_mapObject; }; -using Candidates = std::vector; +using Candidates = std::deque; enum class Version : int8_t { diff --git a/metrics/eye.cpp b/metrics/eye.cpp index 5d0e3c6fa2..20d7160e1b 100644 --- a/metrics/eye.cpp +++ b/metrics/eye.cpp @@ -79,11 +79,6 @@ Eye::Eye() Info info; Load(info); m_info.Set(std::make_shared(info)); - - GetPlatform().RunTask(Platform::Thread::File, [this] - { - TrimExpiredMapObjectEvents(); - }); } // static @@ -108,6 +103,14 @@ void Eye::UnsubscribeAll() m_subscribers.clear(); } +void Eye::TrimExpired() +{ + GetPlatform().RunTask(Platform::Thread::File, [this] + { + TrimExpiredMapObjectEvents(); + }); +} + bool Eye::Save(InfoType const & info) { if (!::Save(*info)) diff --git a/metrics/eye.hpp b/metrics/eye.hpp index 03dd2ca3c6..a41399cbc7 100644 --- a/metrics/eye.hpp +++ b/metrics/eye.hpp @@ -64,6 +64,8 @@ public: void Subscribe(Subscriber * subscriber); void UnsubscribeAll(); + void TrimExpired(); + private: Eye();