From 95e92382d503239bf76e926dce0aec959116a66f Mon Sep 17 00:00:00 2001 From: vng Date: Thu, 18 Oct 2012 19:54:28 +0300 Subject: Emit "end search marker" with cancelled flag. It helps to determine whether the indicator should be shown. --- search/result.hpp | 21 +++++++++++++++++++++ search/search_engine.cpp | 6 ++++++ 2 files changed, 27 insertions(+) (limited to 'search') diff --git a/search/result.hpp b/search/result.hpp index 697e810c19..6a1326b804 100644 --- a/search/result.hpp +++ b/search/result.hpp @@ -57,7 +57,28 @@ class Results { vector m_vec; + enum StatusT { + NONE, // default status + ENDED_CANCELLED, // search ended with canceling + ENDED // search ended itself + }; + StatusT m_status; + + explicit Results(bool isCancelled) + { + m_status = (isCancelled ? ENDED_CANCELLED : ENDED); + } + public: + Results() : m_status(NONE) {} + + /// @name To implement end of search notification. + //@{ + static Results GetEndMarker(bool isCancelled) { return Results(isCancelled); } + bool IsEndMarker() const { return (m_status != NONE); } + bool IsEndedNormal() const { return (m_status == ENDED); } + //@} + inline void AddResult(Result const & r) { m_vec.push_back(r); } void AddResultCheckExisting(Result const & r); diff --git a/search/search_engine.cpp b/search/search_engine.cpp index 4f7b150382..078c845d04 100644 --- a/search/search_engine.cpp +++ b/search/search_engine.cpp @@ -246,6 +246,9 @@ void Engine::SearchAsync() Results res; + // Call m_pQuery->IsCanceled() everywhere it needed without storing return value. + // This flag can be changed from another thread. + try { if (params.m_query.empty()) @@ -291,6 +294,9 @@ void Engine::SearchAsync() if (res.GetCount() > count) params.m_callback(res); } + + // Emit finish marker to client. + params.m_callback(Results::GetEndMarker(m_pQuery->IsCanceled())); } string Engine::GetCountryFile(m2::PointD const & pt) -- cgit v1.2.3