diff --git a/partners_api/partners_api_tests/uber_tests.cpp b/partners_api/partners_api_tests/uber_tests.cpp index 5da08c22f7..ab442545b8 100644 --- a/partners_api/partners_api_tests/uber_tests.cpp +++ b/partners_api/partners_api_tests/uber_tests.cpp @@ -130,7 +130,7 @@ UNIT_TEST(Uber_ProductMaker) TEST_EQUAL(returnedId, reqId, ()); for (auto const & product : returnedProducts) - TEST(IsComplete(product),()); + TEST(IsComplete(product), ()); ++reqId; @@ -181,26 +181,28 @@ UNIT_TEST(Uber_Smoke) auto const synchronousProducts = productsContainer; productsContainer.clear(); - uber::Api uberApi; + { + uber::Api uberApi; - { - lock_guard lock(resultsMutex); - reqId = uberApi.GetAvailableProducts(ms::LatLon(55.753960, 37.624513), - ms::LatLon(55.765866, 37.661270), standardCallback); - } - { - lock_guard lock(resultsMutex); - reqId = uberApi.GetAvailableProducts(ms::LatLon(59.922445, 30.367201), - ms::LatLon(59.943675, 30.361123), standardCallback); - } - { - lock_guard lock(resultsMutex); - reqId = uberApi.GetAvailableProducts(ms::LatLon(52.509621, 13.450067), - ms::LatLon(52.510811, 13.409490), standardCallback); - } - { - lock_guard lock(resultsMutex); - reqId = uberApi.GetAvailableProducts(from, to, lastCallback); + { + lock_guard lock(resultsMutex); + reqId = uberApi.GetAvailableProducts(ms::LatLon(55.753960, 37.624513), + ms::LatLon(55.765866, 37.661270), standardCallback); + } + { + lock_guard lock(resultsMutex); + reqId = uberApi.GetAvailableProducts(ms::LatLon(59.922445, 30.367201), + ms::LatLon(59.943675, 30.361123), standardCallback); + } + { + lock_guard lock(resultsMutex); + reqId = uberApi.GetAvailableProducts(ms::LatLon(52.509621, 13.450067), + ms::LatLon(52.510811, 13.409490), standardCallback); + } + { + lock_guard lock(resultsMutex); + reqId = uberApi.GetAvailableProducts(from, to, lastCallback); + } } testing::RunEventLoop(); diff --git a/partners_api/uber_api.cpp b/partners_api/uber_api.cpp index 668a910742..bd90ba3dd2 100644 --- a/partners_api/uber_api.cpp +++ b/partners_api/uber_api.cpp @@ -143,7 +143,7 @@ string RawApi::GetEstimatedPrice(ms::LatLon const & from, ms::LatLon const & to) return RunSimpleHttpRequest(url.str()); } -void ProductMaker::Reset(size_t const requestId) +void ProductMaker::Reset(uint64_t const requestId) { lock_guard lock(m_mutex); @@ -152,7 +152,7 @@ void ProductMaker::Reset(size_t const requestId) m_prices.reset(); } -void ProductMaker::SetTimes(size_t const requestId, string const & times) +void ProductMaker::SetTimes(uint64_t const requestId, string const & times) { lock_guard lock(m_mutex); @@ -162,7 +162,7 @@ void ProductMaker::SetTimes(size_t const requestId, string const & times) m_times = make_unique(times); } -void ProductMaker::SetPrices(size_t const requestId, string const & prices) +void ProductMaker::SetPrices(uint64_t const requestId, string const & prices) { lock_guard lock(m_mutex); @@ -172,7 +172,7 @@ void ProductMaker::SetPrices(size_t const requestId, string const & prices) m_prices = make_unique(prices); } -void ProductMaker::MakeProducts(size_t const requestId, ProductsCallback const & fn) +void ProductMaker::MakeProducts(uint64_t const requestId, ProductsCallback const & fn) { vector products; { @@ -189,23 +189,24 @@ void ProductMaker::MakeProducts(size_t const requestId, ProductsCallback const & fn(products, requestId); } -size_t Api::GetAvailableProducts(ms::LatLon const & from, ms::LatLon const & to, - ProductsCallback const & fn) +uint64_t Api::GetAvailableProducts(ms::LatLon const & from, ms::LatLon const & to, + ProductsCallback const & fn) { - size_t const reqId = ++m_requestId; + auto const reqId = ++m_requestId; + auto const maker = m_maker; - m_maker->Reset(reqId); + maker->Reset(reqId); - threads::SimpleThread([this, from, reqId, fn]() + threads::SimpleThread([maker, from, reqId, fn]() { - m_maker->SetTimes(reqId, uber::RawApi::GetEstimatedTime(from)); - m_maker->MakeProducts(reqId, fn); + maker->SetTimes(reqId, uber::RawApi::GetEstimatedTime(from)); + maker->MakeProducts(reqId, fn); }).detach(); - threads::SimpleThread([this, from, to, reqId, fn]() + threads::SimpleThread([maker, from, to, reqId, fn]() { - m_maker->SetPrices(reqId, uber::RawApi::GetEstimatedPrice(from, to)); - m_maker->MakeProducts(reqId, fn); + maker->SetPrices(reqId, uber::RawApi::GetEstimatedPrice(from, to)); + maker->MakeProducts(reqId, fn); }).detach(); return reqId; diff --git a/partners_api/uber_api.hpp b/partners_api/uber_api.hpp index 9aed7dacff..3fab3b6fee 100644 --- a/partners_api/uber_api.hpp +++ b/partners_api/uber_api.hpp @@ -56,13 +56,13 @@ using ProductsCallback = function const & products, size_t class ProductMaker { public: - void Reset(size_t const requestId); - void SetTimes(size_t const requestId, string const & times); - void SetPrices(size_t const requestId, string const & prices); - void MakeProducts(size_t const requestId, ProductsCallback const & fn); + void Reset(uint64_t const requestId); + void SetTimes(uint64_t const requestId, string const & times); + void SetPrices(uint64_t const requestId, string const & prices); + void MakeProducts(uint64_t const requestId, ProductsCallback const & fn); private: - size_t m_requestId = 0; + uint64_t m_requestId = 0; unique_ptr m_times; unique_ptr m_prices; mutex m_mutex; @@ -78,8 +78,8 @@ class Api { public: /// Requests list of available products from Uber. Returns request identificator immediately. - size_t GetAvailableProducts(ms::LatLon const & from, ms::LatLon const & to, - ProductsCallback const & fn); + uint64_t GetAvailableProducts(ms::LatLon const & from, ms::LatLon const & to, + ProductsCallback const & fn); /// Returns link which allows you to launch the Uber app. static RideRequestLinks GetRideRequestLinks(string const & productId, ms::LatLon const & from, @@ -87,6 +87,6 @@ public: private: shared_ptr m_maker = make_shared(); - size_t m_requestId = 0; + uint64_t m_requestId = 0; }; } // namespace uber