diff --git a/map/routing_manager.cpp b/map/routing_manager.cpp index 870800afa3..803e7bf0eb 100644 --- a/map/routing_manager.cpp +++ b/map/routing_manager.cpp @@ -314,8 +314,8 @@ RoutingManager::RoutingManager(Callbacks && callbacks, Delegate & delegate) , m_delegate(delegate) , m_trackingReporter(platform::CreateSocket(), TRACKING_REALTIME_HOST, TRACKING_REALTIME_PORT, tracking::Reporter::kPushDelayMs) - //TODO (o.khlopkova) remove ifdef when all platforms are ready. -#if defined(OMIM_OS_ANDROID) +// TODO (o.khlopkova) remove ifdef when all platforms are ready. +#if !defined(OMIM_OS_IPHONE) , m_trackingReporterArchive(TRACKING_HISTORICAL_HOST) #endif , m_extrapolator( @@ -487,7 +487,7 @@ void RoutingManager::OnLocationUpdate(location::GpsInfo const & info) m_extrapolator.OnLocationUpdate(info); //TODO (o.khlopkova) remove ifdef when all platforms are ready. -#if defined(OMIM_OS_ANDROID) +#if !defined(OMIM_OS_IPHONE) if (IsTrackingReporterArchiveEnabled()) { location::GpsInfo gpsInfo(info); @@ -1144,6 +1144,14 @@ void RoutingManager::CallRouteBuilded(RouterResultCode code, m_routingBuildingCallback(code, absentCountries); } +void RoutingManager::ConfigureArchivalReporter(tracking::ArchivingSettings const & settings) +{ + // TODO (o.khlopkova) remove ifdef when all platforms are ready. +#if !defined(OMIM_OS_IPHONE) + m_trackingReporterArchive.SetArchivalManagerSettings(settings); +#endif +} + void RoutingManager::CallRouteBuildStart(std::vector const & points) { m_routingStartBuildCallback(points); diff --git a/map/routing_manager.hpp b/map/routing_manager.hpp index 25bdd86cc0..7e8af2f1ee 100644 --- a/map/routing_manager.hpp +++ b/map/routing_manager.hpp @@ -251,6 +251,7 @@ public: { m_trackingReporter.SetAllowSendingPoints(isAllowed); } + void ConfigureArchivalReporter(tracking::ArchivingSettings const & settings); routing::SpeedCameraManager & GetSpeedCamManager() { return m_routingSession.GetSpeedCamManager(); } bool IsSpeedLimitExceeded() const; @@ -370,7 +371,7 @@ private: Delegate & m_delegate; tracking::Reporter m_trackingReporter; // TODO(o.khlopkova) remove ifdef when all platforms are ready. -#if defined(OMIM_OS_ANDROID) +#if !defined(OMIM_OS_IPHONE) tracking::ArchivalReporter m_trackingReporterArchive; #endif BookmarkManager * m_bmManager = nullptr; diff --git a/platform/CMakeLists.txt b/platform/CMakeLists.txt index b52d792195..460b7a38ed 100644 --- a/platform/CMakeLists.txt +++ b/platform/CMakeLists.txt @@ -109,6 +109,7 @@ else() # neither iPhone nor Android http_user_agent_dummy.cpp http_thread_qt.cpp http_thread_qt.hpp + http_uploader_background_dummy.cpp http_uploader_dummy.cpp marketing_service_dummy.cpp platform_win.cpp @@ -124,6 +125,7 @@ else() # neither iPhone nor Android http_thread_apple.h http_thread_apple.mm http_uploader_apple.mm + http_uploader_background_dummy.cpp http_user_agent_dummy.cpp marketing_service_dummy.cpp platform_mac.mm @@ -141,6 +143,7 @@ else() # neither iPhone nor Android http_thread_qt.cpp http_thread_qt.hpp http_uploader_dummy.cpp + http_uploader_background_dummy.cpp http_user_agent_dummy.cpp marketing_service_dummy.cpp platform_linux.cpp diff --git a/platform/http_uploader_background_dummy.cpp b/platform/http_uploader_background_dummy.cpp new file mode 100644 index 0000000000..76e80607e6 --- /dev/null +++ b/platform/http_uploader_background_dummy.cpp @@ -0,0 +1,6 @@ +#include "platform/http_uploader_background.hpp" + +namespace platform +{ +void HttpUploaderBackground::Upload() const {} +} // namespace platform diff --git a/tracking/archival_manager.cpp b/tracking/archival_manager.cpp index e466b010f0..0d62ffa1cd 100644 --- a/tracking/archival_manager.cpp +++ b/tracking/archival_manager.cpp @@ -15,20 +15,6 @@ namespace { -size_t constexpr KMinFreeSpaceOnDiskBytes = 30 * 1024 * 1024; // 30 Mb - -#ifdef DEBUG -size_t constexpr kDumpIntervalSeconds = 60; -size_t constexpr kMaxFilesToSave = 100; -size_t constexpr kMaxArchivesToSave = 10; -size_t constexpr kUploadIntervalSeconds = 15 * 60; -#else -size_t constexpr kDumpIntervalSeconds = 10 * 60; // One time per 10 minutes -size_t constexpr kMaxFilesToSave = 1000; -size_t constexpr kMaxArchivesToSave = 10; -size_t constexpr kUploadIntervalSeconds = 12 * 60 * 60; // One time per 12 hours -#endif - std::string const kTracksArchive = "tracks_archive"; std::string const kFileTimestampName = "latest_upload"; @@ -51,19 +37,20 @@ std::string GetTimestampFile(std::string const & tracksDir) namespace tracking { -ArchivalManager::ArchivalManager(uint32_t version, std::string const & url) +ArchivalManager::ArchivalManager(std::string const & url) : m_url(url) - , m_version(version) , m_tracksDir(GetTracksDirectory()) , m_timestampFile(GetTimestampFile(m_tracksDir)) { } +void ArchivalManager::SetSettings(ArchivingSettings const & settings) { m_settings = settings; } + std::optional ArchivalManager::GetFileWriter( routing::RouterType const & trackType) const { std::string const fileName = - archival_file::GetArchiveFilename(m_version, GetTimestamp(), trackType); + archival_file::GetArchiveFilename(m_settings.m_version, GetTimestamp(), trackType); try { return std::optional(base::JoinPath(m_tracksDir, fileName)); @@ -84,8 +71,7 @@ bool ArchivalManager::CreateTracksDir() const return true; } -// static -size_t ArchivalManager::IntervalBetweenDumpsSeconds() { return kDumpIntervalSeconds; } +size_t ArchivalManager::IntervalBetweenDumpsSeconds() { return m_settings.m_dumpIntervalSeconds; } std::vector ArchivalManager::GetFilesOrderedByCreation( std::string const & extension) const @@ -111,7 +97,7 @@ size_t ArchivalManager::GetTimeFromLastUploadSeconds() bool ArchivalManager::ReadyToUpload() { - return GetTimeFromLastUploadSeconds() > kUploadIntervalSeconds; + return GetTimeFromLastUploadSeconds() > m_settings.m_uploadIntervalSeconds; } void ArchivalManager::PrepareUpload(std::vector const & files) @@ -147,7 +133,7 @@ void ArchivalManager::CreateUploadTask(std::string const & filePath) bool ArchivalManager::CanDumpToDisk(size_t neededFreeSpace) const { - size_t const neededSize = std::max(KMinFreeSpaceOnDiskBytes, neededFreeSpace); + size_t const neededSize = std::max(m_settings.m_minFreeSpaceOnDiskBytes, neededFreeSpace); auto const storageStatus = GetPlatform().GetWritableStorageStatus(neededSize); if (storageStatus != Platform::TStorageStatus::STORAGE_OK) { @@ -177,13 +163,12 @@ std::chrono::seconds ArchivalManager::ReadTimestamp(std::string const & filePath return std::chrono::seconds(0); } -// static -size_t ArchivalManager::GetMaxSavedFilesCount(std::string const & extension) +size_t ArchivalManager::GetMaxSavedFilesCount(std::string const & extension) const { if (extension == ARCHIVE_TRACKS_FILE_EXTENSION) - return kMaxFilesToSave; + return m_settings.m_maxFilesToSave; if (extension == ARCHIVE_TRACKS_ZIPPED_FILE_EXTENSION) - return kMaxArchivesToSave; + return m_settings.m_maxArchivesToSave; UNREACHABLE(); } diff --git a/tracking/archival_manager.hpp b/tracking/archival_manager.hpp index 9b238a2162..cd69e3fa1b 100644 --- a/tracking/archival_manager.hpp +++ b/tracking/archival_manager.hpp @@ -16,21 +16,33 @@ namespace tracking { +struct ArchivingSettings +{ + size_t m_minFreeSpaceOnDiskBytes = 30 * 1024 * 1024; // 30 Mb + size_t m_dumpIntervalSeconds = 60; + size_t m_maxFilesToSave = 100; + size_t m_maxArchivesToSave = 10; + size_t m_uploadIntervalSeconds = 15 * 60; + uint32_t m_version = 1; +}; + class ArchivalManager { public: - ArchivalManager(uint32_t version, std::string const & url); + ArchivalManager(std::string const & url); ArchivalManager(ArchivalManager const &) = delete; ArchivalManager & operator=(ArchivalManager const &) = delete; + void SetSettings(ArchivingSettings const & settings); + /// \brief Saves to file contents of the |archive| if it is necessary to |dumpAnyway| /// or the |archive| is ready to be dumped. template void Dump(T & archive, routing::RouterType const & trackType, bool dumpAnyway); /// \returns time span between Archive dumps. - static size_t IntervalBetweenDumpsSeconds(); + size_t IntervalBetweenDumpsSeconds(); /// \brief Prepares zipped files and creates task for uploading them. void PrepareUpload(); @@ -42,7 +54,7 @@ private: bool ReadyToUpload(); size_t GetTimeFromLastUploadSeconds(); - static size_t GetMaxSavedFilesCount(std::string const & extension); + size_t GetMaxSavedFilesCount(std::string const & extension) const; std::chrono::seconds ReadTimestamp(std::string const & filePath); void WriteTimestamp(std::string const & filePath); @@ -56,8 +68,7 @@ private: void CreateUploadTask(std::string const & filePath); std::string const m_url; - uint32_t const m_version; - + ArchivingSettings m_settings; std::string m_tracksDir; std::string m_timestampFile; }; diff --git a/tracking/archival_reporter.cpp b/tracking/archival_reporter.cpp index 6079957f1d..1f1080bc5c 100644 --- a/tracking/archival_reporter.cpp +++ b/tracking/archival_reporter.cpp @@ -9,7 +9,6 @@ namespace { -uint32_t constexpr kLatestVersion = 1; double constexpr kRequiredHorizontalAccuracyM = 15.0; double constexpr kMinDelaySecondsCar = 1.0; @@ -29,7 +28,7 @@ ArchivalReporter::ArchivalReporter(std::string const & host) : m_archiveBicycle(kItemsForDump, kMinDelaySecondsBicycle) , m_archivePedestrian(kItemsForDump, kMinDelaySecondsPedestrian) , m_archiveCar(kItemsForDump, kMinDelaySecondsCar) - , m_manager(kLatestVersion, host) + , m_manager(host) , m_isAlive(true) , m_threadDump([this] { Run(); }) { @@ -46,6 +45,11 @@ ArchivalReporter::~ArchivalReporter() m_threadDump.join(); } +void ArchivalReporter::SetArchivalManagerSettings(ArchivingSettings const & settings) +{ + m_manager.SetSettings(settings); +} + void ArchivalReporter::Run() { { diff --git a/tracking/archival_reporter.hpp b/tracking/archival_reporter.hpp index b4cc41f7af..5e4eff6a1f 100644 --- a/tracking/archival_reporter.hpp +++ b/tracking/archival_reporter.hpp @@ -32,6 +32,8 @@ public: ArchivalReporter(ArchivalReporter const &) = delete; ArchivalReporter & operator=(ArchivalReporter const &) = delete; + void SetArchivalManagerSettings(ArchivingSettings const & settings); + void Insert(routing::RouterType const & trackType, location::GpsInfo const & info, traffic::SpeedGroup const & speedGroup); void DumpToDisk(bool dumpAnyway = false); diff --git a/xcode/platform/platform.xcodeproj/project.pbxproj b/xcode/platform/platform.xcodeproj/project.pbxproj index f60f4975ec..54b56a5020 100644 --- a/xcode/platform/platform.xcodeproj/project.pbxproj +++ b/xcode/platform/platform.xcodeproj/project.pbxproj @@ -123,6 +123,7 @@ 67B30B2A2084B7D8008AEBFD /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67B30B292084B7D7008AEBFD /* CoreLocation.framework */; }; D50B2296238591570056820A /* http_payload.hpp in Headers */ = {isa = PBXBuildFile; fileRef = D50B2293238591570056820A /* http_payload.hpp */; }; D50B2297238591570056820A /* http_payload.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D50B2294238591570056820A /* http_payload.cpp */; }; + D593E50423CDBC5F004D6B89 /* http_uploader_background_dummy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D593E50323CDBC5F004D6B89 /* http_uploader_background_dummy.cpp */; }; D5B191CF2386C7E4009CD0D6 /* http_uploader_background.hpp in Headers */ = {isa = PBXBuildFile; fileRef = D5B191CE2386C7E4009CD0D6 /* http_uploader_background.hpp */; }; EB60B4DC204C130300E4953B /* network_policy_ios.mm in Sources */ = {isa = PBXBuildFile; fileRef = EB60B4DB204C130300E4953B /* network_policy_ios.mm */; }; EB60B4DE204C175700E4953B /* network_policy_ios.h in Headers */ = {isa = PBXBuildFile; fileRef = EB60B4DD204C175700E4953B /* network_policy_ios.h */; }; @@ -256,6 +257,7 @@ 67B30B292084B7D7008AEBFD /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; }; D50B2293238591570056820A /* http_payload.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = http_payload.hpp; sourceTree = ""; }; D50B2294238591570056820A /* http_payload.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = http_payload.cpp; sourceTree = ""; }; + D593E50323CDBC5F004D6B89 /* http_uploader_background_dummy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = http_uploader_background_dummy.cpp; sourceTree = ""; }; D5B191CE2386C7E4009CD0D6 /* http_uploader_background.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = http_uploader_background.hpp; sourceTree = ""; }; EB60B4DB204C130300E4953B /* network_policy_ios.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = network_policy_ios.mm; sourceTree = ""; }; EB60B4DD204C175700E4953B /* network_policy_ios.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = network_policy_ios.h; sourceTree = ""; }; @@ -390,6 +392,7 @@ 6753437A1A3F5CF500A0A8C3 /* platform */ = { isa = PBXGroup; children = ( + D593E50323CDBC5F004D6B89 /* http_uploader_background_dummy.cpp */, 3DF528EA238BFFC1000ED0D5 /* downloader_defines.hpp */, D5B191CE2386C7E4009CD0D6 /* http_uploader_background.hpp */, 470C77C923CCB04C006F6385 /* http_uploader_background.mm */, @@ -718,6 +721,7 @@ 34513AFB1DCB37C100471BDA /* marketing_service.cpp in Sources */, 6741250C1B4C00CC00A3E828 /* local_country_file_utils.cpp in Sources */, 3D97F64B1D9C05E800380945 /* http_client.cpp in Sources */, + D593E50423CDBC5F004D6B89 /* http_uploader_background_dummy.cpp in Sources */, 67AB92EA1B7B3E9100AB5194 /* get_text_by_id.cpp in Sources */, 34C624BD1DABCCD100510300 /* socket_apple.mm in Sources */, 470C77CA23CCB04C006F6385 /* http_uploader_background.mm in Sources */,