Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArsentiy Milchakov <milcars@mapswithme.com>2017-08-14 14:16:42 +0300
committerYuri Gorshenin <mipt.vi002@gmail.com>2017-08-14 15:37:42 +0300
commit6bf8b07db5e8f594407973ab336f2e118321f4ac (patch)
tree7e89d836def728f82df2eea623897431f1c875a0
parent580e23357cac94b080cebf90910bfef0ce9991f0 (diff)
[partners_api] use single network thread for all api
-rw-r--r--partners_api/booking_api.cpp8
-rw-r--r--partners_api/cian_api.cpp7
-rw-r--r--partners_api/cian_api.hpp2
-rw-r--r--partners_api/uber_api.cpp10
-rw-r--r--partners_api/viator_api.cpp5
-rw-r--r--partners_api/yandex_api.cpp5
6 files changed, 17 insertions, 20 deletions
diff --git a/partners_api/booking_api.cpp b/partners_api/booking_api.cpp
index e877ad738a..4d2447c223 100644
--- a/partners_api/booking_api.cpp
+++ b/partners_api/booking_api.cpp
@@ -311,7 +311,7 @@ string Api::GetSearchUrl(string const & city, string const & name) const
void Api::GetMinPrice(string const & hotelId, string const & currency,
GetMinPriceCallback const & fn)
{
- threads::SimpleThread([hotelId, currency, fn]()
+ GetPlatform().RunOnNetworkThread([hotelId, currency, fn]()
{
string minPrice;
string priceCurrency;
@@ -333,12 +333,12 @@ void Api::GetMinPrice(string const & hotelId, string const & currency,
priceCurrency.clear();
}
fn(hotelId, minPrice, priceCurrency);
- }).detach();
+ });
}
void Api::GetHotelInfo(string const & hotelId, string const & lang, GetHotelInfoCallback const & fn)
{
- threads::SimpleThread([hotelId, lang, fn]()
+ GetPlatform().RunOnNetworkThread([hotelId, lang, fn]()
{
HotelInfo info;
info.m_hotelId = hotelId;
@@ -361,7 +361,7 @@ void Api::GetHotelInfo(string const & hotelId, string const & lang, GetHotelInfo
}
fn(info);
- }).detach();
+ });
}
void SetBookingUrlForTesting(string const & url)
diff --git a/partners_api/cian_api.cpp b/partners_api/cian_api.cpp
index f7e65e89e0..65121de75d 100644
--- a/partners_api/cian_api.cpp
+++ b/partners_api/cian_api.cpp
@@ -114,11 +114,6 @@ http::Result RawApi::GetRentNearby(m2::RectD const & rect,
Api::Api(std::string const & baseUrl /* = kBaseUrl */) : m_baseUrl(baseUrl) {}
-Api::~Api()
-{
- m_worker.Shutdown(base::WorkerThread::Exit::SkipPending);
-}
-
uint64_t Api::GetRentNearby(ms::LatLon const & latlon, RentNearbyCallback const & onSuccess,
ErrorCallback const & onError)
{
@@ -129,7 +124,7 @@ uint64_t Api::GetRentNearby(ms::LatLon const & latlon, RentNearbyCallback const
auto const mercatorRect = MercatorBounds::MetresToXY(latlon.lat, latlon.lon, kSearchRadius);
auto const rect = MercatorBounds::ToLatLonRect(mercatorRect);
- m_worker.Push([reqId, rect, onSuccess, onError, baseUrl]() {
+ GetPlatform().RunOnNetworkThread([reqId, rect, onSuccess, onError, baseUrl]() {
std::vector<RentPlace> result;
auto const rawResult = RawApi::GetRentNearby(rect, baseUrl);
diff --git a/partners_api/cian_api.hpp b/partners_api/cian_api.hpp
index 484152f1f1..f60ab3452d 100644
--- a/partners_api/cian_api.hpp
+++ b/partners_api/cian_api.hpp
@@ -57,7 +57,6 @@ public:
using ErrorCallback = std::function<void(int httpCode, uint64_t const requestId)>;
explicit Api(std::string const & baseUrl = kBaseUrl);
- virtual ~Api();
uint64_t GetRentNearby(ms::LatLon const & latlon, RentNearbyCallback const & onSuccess,
ErrorCallback const & onError);
@@ -68,6 +67,5 @@ public:
private:
uint64_t m_requestId = 0;
std::string m_baseUrl;
- base::WorkerThread m_worker;
};
} // namespace cian
diff --git a/partners_api/uber_api.cpp b/partners_api/uber_api.cpp
index 4896ed3acd..ed2cd67393 100644
--- a/partners_api/uber_api.cpp
+++ b/partners_api/uber_api.cpp
@@ -1,6 +1,8 @@
#include "partners_api/uber_api.hpp"
#include "partners_api/utils.hpp"
+#include "platform/platform.hpp"
+
#include "geometry/latlon.hpp"
#include "base/logging.hpp"
@@ -250,7 +252,7 @@ void Api::GetAvailableProducts(ms::LatLon const & from, ms::LatLon const & to,
maker->Reset(reqId);
- threads::SimpleThread([maker, from, reqId, baseUrl, successFn, errorFn]()
+ GetPlatform().RunOnNetworkThread([maker, from, reqId, baseUrl, successFn, errorFn]()
{
string result;
if (!RawApi::GetEstimatedTime(from, result, baseUrl))
@@ -258,9 +260,9 @@ void Api::GetAvailableProducts(ms::LatLon const & from, ms::LatLon const & to,
maker->SetTimes(reqId, result);
maker->MakeProducts(reqId, successFn, errorFn);
- }).detach();
+ });
- threads::SimpleThread([maker, from, to, reqId, baseUrl, successFn, errorFn]()
+ GetPlatform().RunOnNetworkThread([maker, from, to, reqId, baseUrl, successFn, errorFn]()
{
string result;
if (!RawApi::GetEstimatedPrice(from, to, result, baseUrl))
@@ -268,7 +270,7 @@ void Api::GetAvailableProducts(ms::LatLon const & from, ms::LatLon const & to,
maker->SetPrices(reqId, result);
maker->MakeProducts(reqId, successFn, errorFn);
- }).detach();
+ });
}
RideRequestLinks Api::GetRideRequestLinks(string const & productId, ms::LatLon const & from,
diff --git a/partners_api/viator_api.cpp b/partners_api/viator_api.cpp
index d6f7db1d26..3555d06236 100644
--- a/partners_api/viator_api.cpp
+++ b/partners_api/viator_api.cpp
@@ -1,6 +1,7 @@
#include "partners_api/viator_api.hpp"
#include "platform/http_client.hpp"
+#include "platform/platform.hpp"
#include "platform/preferred_languages.hpp"
#include "coding/multilang_utf8_string.hpp"
@@ -213,7 +214,7 @@ void Api::GetTop5Products(std::string const & destId, std::string const & curren
std::string curr =
kSupportedCurrencies.find(currency) == kSupportedCurrencies.cend() ? "USD" : currency;
- threads::SimpleThread([destId, curr, fn]()
+ GetPlatform().RunOnNetworkThread([destId, curr, fn]()
{
string result;
if (!RawApi::GetTopProducts(destId, curr, 5, result))
@@ -233,7 +234,7 @@ void Api::GetTop5Products(std::string const & destId, std::string const & curren
SortProducts(products);
fn(destId, products);
- }).detach();
+ });
}
bool operator<(Product const & lhs, Product const & rhs)
diff --git a/partners_api/yandex_api.cpp b/partners_api/yandex_api.cpp
index 88ab9a1bfc..5c00ba260c 100644
--- a/partners_api/yandex_api.cpp
+++ b/partners_api/yandex_api.cpp
@@ -1,6 +1,7 @@
#include "partners_api/yandex_api.hpp"
#include "platform/http_client.hpp"
+#include "platform/platform.hpp"
#include "geometry/latlon.hpp"
@@ -84,7 +85,7 @@ void Api::GetAvailableProducts(ms::LatLon const & from, ms::LatLon const & to,
auto const baseUrl = m_baseUrl;
- threads::SimpleThread([from, to, baseUrl, successFn, errorFn]()
+ GetPlatform().RunOnNetworkThread([from, to, baseUrl, successFn, errorFn]()
{
std::string result;
if (!RawApi::GetTaxiInfo(from, to, result, baseUrl))
@@ -109,7 +110,7 @@ void Api::GetAvailableProducts(ms::LatLon const & from, ms::LatLon const & to,
else
successFn(products);
- }).detach();
+ });
}
/// Returns link which allows you to launch the Yandex app.