From d6b9bf5525a12ab96d16785c6c72b863f519a9ab Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Sun, 2 Oct 2011 01:40:11 +0300 Subject: [PATCH] [ios][qt] Platform refactoring --- generator/feature_sorter.cpp | 3 +- iphone/Maps/Classes/EAGLView.mm | 2 +- iphone/Maps/Maps.xcodeproj/project.pbxproj | 10 +- iphone/Maps/Platform/IPhonePlatform.hpp | 23 -- iphone/Maps/Platform/IPhonePlatform.mm | 105 ------- .../Maps/Settings/CountriesViewController.mm | 9 +- map/benchmark_framework.cpp | 2 +- map/framework.cpp | 4 +- map/framework_factory.cpp | 7 +- platform/platform.cpp | 149 --------- platform/platform.hpp | 73 ++--- platform/platform.pro | 53 ++-- platform/platform_ios.mm | 195 ++++++++++++ platform/platform_linux.cpp | 43 +++ platform/platform_mac.mm | 89 ++++++ platform/platform_qt.cpp | 184 +++++++++++ platform/platform_win.cpp | 47 +++ platform/qtplatform.cpp | 293 ------------------ yg/yg.pro | 6 +- 19 files changed, 624 insertions(+), 673 deletions(-) delete mode 100644 iphone/Maps/Platform/IPhonePlatform.hpp delete mode 100644 iphone/Maps/Platform/IPhonePlatform.mm delete mode 100644 platform/platform.cpp create mode 100644 platform/platform_ios.mm create mode 100644 platform/platform_linux.cpp create mode 100644 platform/platform_mac.mm create mode 100644 platform/platform_qt.cpp create mode 100644 platform/platform_win.cpp delete mode 100644 platform/qtplatform.cpp diff --git a/generator/feature_sorter.cpp b/generator/feature_sorter.cpp index 0e86885272..45c7fddc30 100644 --- a/generator/feature_sorter.cpp +++ b/generator/feature_sorter.cpp @@ -18,6 +18,7 @@ #include "../version/ver_serialization.hpp" +#include "../coding/internal/file_data.hpp" #include "../coding/file_container.hpp" #include "../base/string_utils.hpp" @@ -498,7 +499,7 @@ namespace feature tempDatFilePath += ".notsorted"; FileWriter::DeleteFileX(tempDatFilePath); - if (!platform.RenameFileX(datFilePath, tempDatFilePath)) + if (!my::RenameFileX(datFilePath, tempDatFilePath)) { LOG(LWARNING, ("File ", datFilePath, " doesn't exist or sharing violation!")); return false; diff --git a/iphone/Maps/Classes/EAGLView.mm b/iphone/Maps/Classes/EAGLView.mm index eb32d66709..e09b4e6c0e 100644 --- a/iphone/Maps/Classes/EAGLView.mm +++ b/iphone/Maps/Classes/EAGLView.mm @@ -9,7 +9,7 @@ #include "../../yg/resource_manager.hpp" #include "../../yg/internal/opengl.hpp" #include "../../yg/skin.hpp" -#include "IPhonePlatform.hpp" +#include "../../platform/platform.hpp" #include "RenderBuffer.hpp" #include "RenderContext.hpp" diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index 6c94233458..123306c843 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -90,9 +90,9 @@ FABF223E13FAA97A003D4D49 /* CompassView.mm in Sources */ = {isa = PBXBuildFile; fileRef = FABF223D13FAA97A003D4D49 /* CompassView.mm */; }; FAD4906C13EFF61F005E7D43 /* search.png in Resources */ = {isa = PBXBuildFile; fileRef = FAD4906A13EFF61F005E7D43 /* search.png */; }; FAD4906D13EFF61F005E7D43 /* search@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FAD4906B13EFF61F005E7D43 /* search@2x.png */; }; + FAEA8B2A1437CA80002A6737 /* libjansson.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FAEA8B291437CA80002A6737 /* libjansson.a */; }; FAF37EFF126DCE6F005EA154 /* IPhoneDownload.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAF37EFA126DCE6F005EA154 /* IPhoneDownload.mm */; }; FAF37F00126DCE6F005EA154 /* IPhoneDownloadManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAF37EFB126DCE6F005EA154 /* IPhoneDownloadManager.mm */; }; - FAF37F01126DCE6F005EA154 /* IPhonePlatform.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAF37EFD126DCE6F005EA154 /* IPhonePlatform.mm */; }; FAF8003C1417D7E50024E8C1 /* ad.png in Resources */ = {isa = PBXBuildFile; fileRef = FAF8FF3E1417D7E50024E8C1 /* ad.png */; }; FAF8003D1417D7E50024E8C1 /* ae.png in Resources */ = {isa = PBXBuildFile; fileRef = FAF8FF3F1417D7E50024E8C1 /* ae.png */; }; FAF8003E1417D7E50024E8C1 /* af.png in Resources */ = {isa = PBXBuildFile; fileRef = FAF8FF401417D7E50024E8C1 /* af.png */; }; @@ -707,10 +707,9 @@ FABF223D13FAA97A003D4D49 /* CompassView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CompassView.mm; sourceTree = ""; }; FAD4906A13EFF61F005E7D43 /* search.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = search.png; sourceTree = ""; }; FAD4906B13EFF61F005E7D43 /* search@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "search@2x.png"; sourceTree = ""; }; + FAEA8B291437CA80002A6737 /* libjansson.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libjansson.a; sourceTree = SOURCE_ROOT; }; FAF37EFA126DCE6F005EA154 /* IPhoneDownload.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; name = IPhoneDownload.mm; path = Platform/IPhoneDownload.mm; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; FAF37EFB126DCE6F005EA154 /* IPhoneDownloadManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; name = IPhoneDownloadManager.mm; path = Platform/IPhoneDownloadManager.mm; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; - FAF37EFD126DCE6F005EA154 /* IPhonePlatform.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; name = IPhonePlatform.mm; path = Platform/IPhonePlatform.mm; sourceTree = SOURCE_ROOT; }; - FAF37EFE126DCE6F005EA154 /* IPhonePlatform.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; lineEnding = 0; name = IPhonePlatform.hpp; path = Platform/IPhonePlatform.hpp; sourceTree = SOURCE_ROOT; }; FAF37F03126DCF11005EA154 /* IPhoneDownload.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = IPhoneDownload.h; path = Platform/IPhoneDownload.h; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; FAF800001417D7E50024E8C1 /* sc.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = sc.png; path = ../../data/flags/sc.png; sourceTree = SOURCE_ROOT; }; FAF800011417D7E50024E8C1 /* sd.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = sd.png; path = ../../data/flags/sd.png; sourceTree = SOURCE_ROOT; }; @@ -1253,6 +1252,7 @@ 49DE1CA513437D7A00A93417 /* libwords.a in Frameworks */, FA2EF9C713630C3B00E3E484 /* libplatform.a in Frameworks */, FAAFD699139D9C6B000AE70C /* libsearch.a in Frameworks */, + FAEA8B2A1437CA80002A6737 /* libjansson.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1407,6 +1407,7 @@ FA1DE68411E15D4E00C6D69A /* Static Libraries */ = { isa = PBXGroup; children = ( + FAEA8B291437CA80002A6737 /* libjansson.a */, FAAFD698139D9C6B000AE70C /* libsearch.a */, FA2EF9C613630C3B00E3E484 /* libplatform.a */, 49DE1CA213437D7A00A93417 /* libbzip2.a */, @@ -1459,8 +1460,6 @@ FAF37EFB126DCE6F005EA154 /* IPhoneDownloadManager.mm */, FAF37F03126DCF11005EA154 /* IPhoneDownload.h */, FAF37EFA126DCE6F005EA154 /* IPhoneDownload.mm */, - FAF37EFE126DCE6F005EA154 /* IPhonePlatform.hpp */, - FAF37EFD126DCE6F005EA154 /* IPhonePlatform.mm */, ); name = Platform; sourceTree = ""; @@ -2612,7 +2611,6 @@ EE7F29831219ECA300EB67A9 /* WindowHandle.mm in Sources */, FAF37EFF126DCE6F005EA154 /* IPhoneDownload.mm in Sources */, FAF37F00126DCE6F005EA154 /* IPhoneDownloadManager.mm in Sources */, - FAF37F01126DCE6F005EA154 /* IPhonePlatform.mm in Sources */, FAFCB63613366E78001A5C59 /* WebViewController.mm in Sources */, FA34BECA1338D72F00FFB2A7 /* CustomAlertView.mm in Sources */, FA09E01113F71F6C007E69CA /* SearchVC.mm in Sources */, diff --git a/iphone/Maps/Platform/IPhonePlatform.hpp b/iphone/Maps/Platform/IPhonePlatform.hpp deleted file mode 100644 index 5e55a27593..0000000000 --- a/iphone/Maps/Platform/IPhonePlatform.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once -#include "../../platform/platform.hpp" - - -class IPhonePlatform : public BasePlatformImpl -{ -public: - IPhonePlatform(); - virtual ~IPhonePlatform(); - - virtual int CpuCores() const; - virtual double VisualScale() const; - virtual bool IsMultiSampled() const; - virtual string SkinName() const; - virtual string DeviceID() const; - virtual int ScaleEtalonSize() const; - -private: - string m_deviceID; - string m_skinName; - double m_visualScale; - unsigned m_scaleEtalonSize; -}; diff --git a/iphone/Maps/Platform/IPhonePlatform.mm b/iphone/Maps/Platform/IPhonePlatform.mm deleted file mode 100644 index 834ca4b873..0000000000 --- a/iphone/Maps/Platform/IPhonePlatform.mm +++ /dev/null @@ -1,105 +0,0 @@ -#import -#import -#import -#import - -#import -#import -#import - -#include "IPhonePlatform.hpp" - - -IPhonePlatform::IPhonePlatform() -{ - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - - NSBundle * bundle = [NSBundle mainBundle]; - NSString * path = [bundle resourcePath]; - m_resourcesDir = [path UTF8String]; - m_resourcesDir += '/'; - - NSArray * dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - NSString * docsDir = [dirPaths objectAtIndex:0]; - m_writableDir = [docsDir UTF8String]; - m_writableDir += '/'; - - /// Hardcoding screen resolution depending on the device we are running. - m_visualScale = 1.0; - m_skinName = "basic.skn"; - - /// Calculating resolution - UIDevice * device = [UIDevice currentDevice]; - - NSRange range = [device.name rangeOfString:@"iPad"]; - if (range.location != NSNotFound) - { - m_deviceID = "iPad"; - m_visualScale = 1.3; - } - else - { - range = [device.name rangeOfString:@"iPod"]; - float ver = [device.systemVersion floatValue]; - if (ver >= 3.1999) - { - m_deviceID = "iPod"; - UIScreen * mainScr = [UIScreen mainScreen]; - if (mainScr.currentMode.size.width == 640) - { - m_deviceID = "iPod"; - m_visualScale = 2.0; - m_skinName = "basic_highres.skn"; - } - } - } - - m_scaleEtalonSize = (256 * 1.5) * m_visualScale; - - NSLog(@"Device Name : %@, SystemName : %@, SystemVersion : %@", device.name, device.systemName, device.systemVersion); - - [pool release]; -} - -IPhonePlatform::~IPhonePlatform() -{ -} - -int IPhonePlatform::CpuCores() const -{ - NSInteger numCPU = [[NSProcessInfo processInfo] activeProcessorCount]; - if (numCPU >= 1) - return numCPU; - return 1; -} - -string IPhonePlatform::SkinName() const -{ - return m_skinName; -} - -double IPhonePlatform::VisualScale() const -{ - return m_visualScale; -} - -bool IPhonePlatform::IsMultiSampled() const -{ - return false; -} - -int IPhonePlatform::ScaleEtalonSize() const -{ - return m_scaleEtalonSize; -} - -string IPhonePlatform::DeviceID() const -{ - return m_deviceID; -} - -Platform & GetPlatform() -{ - static IPhonePlatform platform; - return platform; -} diff --git a/iphone/Maps/Settings/CountriesViewController.mm b/iphone/Maps/Settings/CountriesViewController.mm index ee877ad0ca..cb5db56414 100644 --- a/iphone/Maps/Settings/CountriesViewController.mm +++ b/iphone/Maps/Settings/CountriesViewController.mm @@ -7,7 +7,8 @@ #import "DiskFreeSpace.h" #include "GetActiveConnectionType.h" -#include "IPhonePlatform.hpp" + +#include "../../platform/platform.hpp" #define MAX_3G_MEGABYTES 20 @@ -139,7 +140,7 @@ static bool IsOurIndex(TIndex const & theirs, TIndex const & ours) { case EOnDisk: { - TLocalAndRemoteSize::first_type size = m_storage->CountrySizeInBytes(countryIndex).first; + LocalAndRemoteSizeT::first_type size = m_storage->CountrySizeInBytes(countryIndex).first; // convert size to human readable values char const * kBorMB = "kB"; if (size > MB) @@ -292,8 +293,8 @@ UITableViewCell * g_clickedCell = nil; case ENotDownloaded: case EDownloadFailed: { - TLocalAndRemoteSize const sizePair = m_storage->CountrySizeInBytes(index); - TLocalAndRemoteSize::first_type size = sizePair.second - sizePair.first; + LocalAndRemoteSizeT const sizePair = m_storage->CountrySizeInBytes(index); + LocalAndRemoteSizeT::first_type size = sizePair.second - sizePair.first; // check for disk free space first if (FreeDiskSpaceInBytes() < (size + 1024*1024)) diff --git a/map/benchmark_framework.cpp b/map/benchmark_framework.cpp index 87d0171395..c655a0557c 100644 --- a/map/benchmark_framework.cpp +++ b/map/benchmark_framework.cpp @@ -195,7 +195,7 @@ void BenchmarkFramework::SaveBenchmarkResults() for (size_t i = 0; i < m_benchmarkResults.size(); ++i) { - fout << GetPlatform().DeviceID() << " " + fout << GetPlatform().DeviceName() << " " << VERSION_STRING << " " << m_startTime << " " << m_benchmarkResults[i].m_name << " " diff --git a/map/framework.cpp b/map/framework.cpp index 981aef8924..f75d826030 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -124,7 +124,9 @@ Framework::Framework(shared_ptr windowHandle, m_informationDisplay.enableDebugInfo(true); #endif - m_informationDisplay.enableLog(GetPlatform().IsVisualLog(), m_windowHandle.get()); + bool isVisualLogEnabled = false; + Settings::Get("VisualLog", isVisualLogEnabled); + m_informationDisplay.enableLog(isVisualLogEnabled, m_windowHandle.get()); m_informationDisplay.setVisualScale(visScale); // initialize gps and compass subsystem diff --git a/map/framework_factory.cpp b/map/framework_factory.cpp index 372e9cb443..6c336b519b 100644 --- a/map/framework_factory.cpp +++ b/map/framework_factory.cpp @@ -4,12 +4,15 @@ #include "benchmark_framework.hpp" #include "feature_vec_model.hpp" -#include "../platform/platform.hpp" +#include "../platform/settings.hpp" template Framework * FrameworkFactory::CreateFramework(shared_ptr const & wh, size_t bottomShift) { - if (GetPlatform().IsBenchmarking()) + bool benchmarkingEnabled = false; + (void)Settings::Get("IsBenchmarking", benchmarkingEnabled); + + if (benchmarkingEnabled) return new BenchmarkFramework(wh, bottomShift); else return new Framework(wh, bottomShift); diff --git a/platform/platform.cpp b/platform/platform.cpp deleted file mode 100644 index 465a76e554..0000000000 --- a/platform/platform.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include "platform.hpp" -#include "settings.hpp" - -#include "../coding/internal/file_data.hpp" -#include "../coding/file_reader.hpp" - -#include "../base/logging.hpp" - -#if !defined(OMIM_OS_WINDOWS_NATIVE) && !defined(OMIM_OS_BADA) -#include -#include -#include -#endif - -#include "../base/start_mem_debug.hpp" - - -string ReadPathForFile(string const & writableDir, - string const & resourcesDir, - string const & file) -{ - string fullPath = writableDir + file; - if (!GetPlatform().IsFileExists(fullPath)) - { - fullPath = resourcesDir + file; - if (!GetPlatform().IsFileExists(fullPath)) - MYTHROW(FileAbsentException, ("File doesn't exist", fullPath)); - } - return fullPath; -} - -ModelReader * BasePlatformImpl::GetReader(string const & file) const -{ - return new FileReader(ReadPathForFile(m_writableDir, m_resourcesDir, file), 10, 12); -} - -bool BasePlatformImpl::GetFileSize(string const & file, uint64_t & size) const -{ - return my::GetFileSize(file, size); -} - -void BasePlatformImpl::GetFilesInDir(string const & directory, string const & mask, FilesList & res) const -{ -#if !defined(OMIM_OS_WINDOWS_NATIVE) && !defined(OMIM_OS_BADA) - DIR * dir; - struct dirent * entry; - - if ((dir = opendir(directory.c_str())) == NULL) - return; - - // TODO: take wildcards into account... - string mask_fixed = mask; - if (mask_fixed.size() && mask_fixed[0] == '*') - mask_fixed.erase(0, 1); - - do - { - if ((entry = readdir(dir)) != NULL) - { - string fname(entry->d_name); - size_t index = fname.rfind(mask_fixed); - if (index != string::npos && index == fname.size() - mask_fixed.size()) - { - // TODO: By some strange reason under simulator stat returns -1, - // may be because of symbolic links?.. - //struct stat fileStatus; - //if (stat(string(directory + fname).c_str(), &fileStatus) == 0 && - // (fileStatus.st_mode & S_IFDIR) == 0) - //{ - res.push_back(fname); - //} - } - } - } while (entry != NULL); - - closedir(dir); -#else - MYTHROW(NotImplementedException, ("Function not implemented")); -#endif -} - -bool BasePlatformImpl::RenameFileX(string const & fOld, string const & fNew) const -{ - return my::RenameFileX(fOld, fNew); -} - -void BasePlatformImpl::GetFontNames(FilesList & res) const -{ - res.clear(); - GetFilesInDir(m_resourcesDir, "*.ttf", res); - - sort(res.begin(), res.end()); -} - -double BasePlatformImpl::VisualScale() const -{ - return 1.0; -} - -string BasePlatformImpl::SkinName() const -{ - return "basic.skn"; -} - -bool BasePlatformImpl::IsBenchmarking() const -{ - bool res = false; - (void)Settings::Get("IsBenchmarking", res); - -/*#ifndef OMIM_PRODUCTION - if (res) - { - static bool first = true; - if (first) - { - LOG(LCRITICAL, ("Benchmarking only defined in production configuration!")); - first = false; - } - res = false; - } -#endif*/ - - return res; -} - -bool BasePlatformImpl::IsVisualLog() const -{ - return false; -} - -int BasePlatformImpl::ScaleEtalonSize() const -{ - return 512 + 256; -} - -int BasePlatformImpl::MaxTilesCount() const -{ - return 120; -} - -int BasePlatformImpl::TileSize() const -{ - return 256; -} - -bool BasePlatformImpl::IsMultiThreadedRendering() const -{ - return true; -} diff --git a/platform/platform.hpp b/platform/platform.hpp index aefca3e0ff..5bed8e580e 100644 --- a/platform/platform.hpp +++ b/platform/platform.hpp @@ -8,31 +8,31 @@ #include "../std/vector.hpp" #include "../std/utility.hpp" - DECLARE_EXCEPTION(FileAbsentException, RootException); DECLARE_EXCEPTION(NotImplementedException, RootException); - class Platform { + string m_writableDir, m_resourcesDir; + class PlatformImpl; + PlatformImpl * m_impl; + public: - virtual ~Platform() {} + Platform(); + ~Platform(); /// @return always the same writable dir for current user with slash at the end - virtual string WritableDir() const = 0; + string WritableDir() const { return m_writableDir; } /// @return full path to file in user's writable directory - string WritablePathForFile(string const & file) const - { - return WritableDir() + file; - } + string WritablePathForFile(string const & file) const { return WritableDir() + file; } /// @return resource dir (on some platforms it's differ from Writable dir) - virtual string ResourcesDir() const = 0; + string ResourcesDir() const { return m_resourcesDir; } /// @return reader for file decriptor. /// @throws FileAbsentException /// @param[in] file descriptor which we want to read - virtual ModelReader * GetReader(string const & file) const = 0; + ModelReader * GetReader(string const & file) const; /// @name File operations //@{ @@ -41,11 +41,9 @@ public: /// @param directory directory path with slash at the end /// @param mask files extension to find, like ".map" etc /// @return number of files found in outFiles - virtual void GetFilesInDir(string const & directory, string const & mask, FilesList & outFiles) const = 0; + void GetFilesInDir(string const & directory, string const & mask, FilesList & outFiles) const; /// @return false if file is not exist - virtual bool GetFileSize(string const & file, uint64_t & size) const = 0; - /// Renamed to avoid conflict with Windows macroses - virtual bool RenameFileX(string const & original, string const & newName) const = 0; + bool GetFileSize(string const & file, uint64_t & size) const; /// Simple file existing check bool IsFileExists(string const & file) const { @@ -54,52 +52,25 @@ public: } //@} - virtual int CpuCores() const = 0; + int CpuCores() const; - virtual double VisualScale() const = 0; + double VisualScale() const; - virtual string SkinName() const = 0; + string SkinName() const; - virtual void GetFontNames(FilesList & res) const = 0; + void GetFontNames(FilesList & res) const; - virtual bool IsBenchmarking() const = 0; + bool IsMultiThreadedRendering() const; - virtual bool IsMultiThreadedRendering() const = 0; + int TileSize() const; - virtual int TileSize() const = 0; + int MaxTilesCount() const; - virtual int MaxTilesCount() const = 0; + string DeviceName() const; - virtual bool IsVisualLog() const = 0; + int ScaleEtalonSize() const; - virtual string DeviceID() const = 0; - - virtual int ScaleEtalonSize() const = 0; -}; - -class BasePlatformImpl : public Platform -{ -protected: - string m_writableDir, m_resourcesDir; - -public: - virtual string WritableDir() const { return m_writableDir; } - virtual string ResourcesDir() const { return m_resourcesDir; } - virtual ModelReader * GetReader(string const & file) const; - - virtual void GetFilesInDir(string const & directory, string const & mask, FilesList & res) const; - virtual bool GetFileSize(string const & file, uint64_t & size) const; - virtual bool RenameFileX(string const & fOld, string const & fNew) const; - virtual void GetFontNames(FilesList & res) const; - - virtual double VisualScale() const; - virtual string SkinName() const; - virtual bool IsBenchmarking() const; - virtual bool IsVisualLog() const; - virtual bool IsMultiThreadedRendering() const; - virtual int ScaleEtalonSize() const; - virtual int TileSize() const; - virtual int MaxTilesCount() const; + string UniqueClientId() const; }; extern "C" Platform & GetPlatform(); diff --git a/platform/platform.pro b/platform/platform.pro index 0f0d716a09..5182c6011e 100644 --- a/platform/platform.pro +++ b/platform/platform.pro @@ -11,43 +11,35 @@ include($$ROOT_DIR/common.pri) QT *= core network -!iphone*:!android* { +!iphone*:!android*:!bada { INCLUDEPATH += $$ROOT_DIR/3party/jansson/src - SOURCES += \ - qtplatform.cpp \ - wifi_location_service.cpp \ - qt_download_manager.cpp \ - qt_download.cpp \ - qt_concurrent_runner.cpp \ - - HEADERS += \ - qt_download_manager.hpp \ - qt_download.hpp \ - wifi_info.hpp + SOURCES += platform_qt.cpp \ + wifi_location_service.cpp \ + qt_download_manager.cpp \ + qt_download.cpp \ + qt_concurrent_runner.cpp + HEADERS += qt_download_manager.hpp \ + qt_download.hpp \ + wifi_info.hpp + win32* { + SOURCES += platform_win.cpp \ + wifi_info_windows.cpp + } else:macx* { + OBJECTIVE_SOURCES += platform_mac.mm \ + wifi_info_mac.mm \ + apple_video_timer.mm + } else:linux* { + SOURCES += platform_linux.cpp + } } else:iphone* { - SOURCES += ios_concurrent_runner.mm + OBJECTIVE_SOURCES += ios_video_timer.mm \ + ios_concurrent_runner.mm \ + platform_ios.mm } macx|iphone* { OBJECTIVE_SOURCES += apple_location_service.mm - LIBS += -framework CoreLocation -framework Foundation -} - -macx:!iphone* { - OBJECTIVE_SOURCES += wifi_info_mac.mm \ - apple_video_timer.mm - - LIBS += -framework CoreWLAN -framework QuartzCore -} - -iphone* { - OBJECTIVE_SOURCES += ios_video_timer.mm - LIBS += -framework QuartzCore -} - -win32 { - SOURCES += wifi_info_windows.cpp } # common sources for all platforms @@ -66,6 +58,5 @@ SOURCES += \ location_manager.cpp \ preferred_languages.cpp \ settings.cpp \ - platform.cpp \ video_timer.cpp \ languages.cpp \ diff --git a/platform/platform_ios.mm b/platform/platform_ios.mm new file mode 100644 index 0000000000..45751d8ecb --- /dev/null +++ b/platform/platform_ios.mm @@ -0,0 +1,195 @@ +#include "platform.hpp" + +#include "../coding/file_reader.hpp" + +#include +#include + +#import +#import +#import +#import + +#import +#import +#import + +class Platform::PlatformImpl +{ +public: + double m_visualScale; + int m_scaleEtalonSize; + string m_skinName; + string m_deviceName; +}; + +Platform::Platform() +{ + m_impl = new PlatformImpl; + + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + + NSBundle * bundle = [NSBundle mainBundle]; + NSString * path = [bundle resourcePath]; + m_resourcesDir = [path UTF8String]; + m_resourcesDir += '/'; + + NSArray * dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSString * docsDir = [dirPaths objectAtIndex:0]; + m_writableDir = [docsDir UTF8String]; + m_writableDir += '/'; + + // Hardcoding screen resolution depending on the device we are running. + m_impl->m_visualScale = 1.0; + m_impl->m_skinName = "basic.skn"; + + // Calculating resolution + UIDevice * device = [UIDevice currentDevice]; + + NSRange range = [device.model rangeOfString:@"iPad"]; + if (range.location != NSNotFound) + { + m_impl->m_deviceName = "iPad"; + m_impl->m_visualScale = 1.3; + } + else + { + range = [device.model rangeOfString:@"iPod"]; + if (range.location != NSNotFound) + m_impl->m_deviceName = "iPod"; + else + m_impl->m_deviceName = "iPhone"; + if ([UIScreen mainScreen].currentMode.size.width == 640) + { + m_impl->m_visualScale = 2.0; + m_impl->m_skinName = "basic_highres.skn"; + } + } + + m_impl->m_scaleEtalonSize = 256 * 1.5 * m_impl->m_visualScale; + + NSLog(@"Device: %@, SystemName: %@, SystemVersion: %@", device.model, device.systemName, device.systemVersion); + + [pool release]; +} + +Platform::~Platform() +{ + delete m_impl; +} + +void Platform::GetFilesInDir(string const & directory, string const & mask, FilesList & res) const +{ + DIR * dir; + struct dirent * entry; + + if ((dir = opendir(directory.c_str())) == NULL) + return; + + // TODO: take wildcards into account... + string mask_fixed = mask; + if (mask_fixed.size() && mask_fixed[0] == '*') + mask_fixed.erase(0, 1); + + do + { + if ((entry = readdir(dir)) != NULL) + { + string fname(entry->d_name); + size_t index = fname.rfind(mask_fixed); + if (index != string::npos && index == fname.size() - mask_fixed.size()) + { + // TODO: By some strange reason under simulator stat returns -1, + // may be because of symbolic links?.. + //struct stat fileStatus; + //if (stat(string(directory + fname).c_str(), &fileStatus) == 0 && + // (fileStatus.st_mode & S_IFDIR) == 0) + //{ + res.push_back(fname); + //} + } + } + } while (entry != NULL); + + closedir(dir); +} + +bool Platform::GetFileSize(string const & file, uint64_t & size) const +{ + struct stat s; + if (stat(file.c_str(), &s) == 0) + { + size = s.st_size; + return true; + } + return false; +} + +void Platform::GetFontNames(FilesList & res) const +{ + GetFilesInDir(ResourcesDir(), "*.ttf", res); + sort(res.begin(), res.end()); +} + +static string ReadPathForFile(string const & writableDir, + string const & resourcesDir, string const & file) +{ + string fullPath = writableDir + file; + if (!GetPlatform().IsFileExists(fullPath)) + { + fullPath = resourcesDir + file; + if (!GetPlatform().IsFileExists(fullPath)) + MYTHROW(FileAbsentException, ("File doesn't exist", fullPath)); + } + return fullPath; +} + +ModelReader * Platform::GetReader(string const & file) const +{ + return new FileReader(ReadPathForFile(m_writableDir, m_resourcesDir, file), 10, 12); +} + +int Platform::CpuCores() const +{ + NSInteger const numCPU = [[NSProcessInfo processInfo] activeProcessorCount]; + if (numCPU >= 1) + return numCPU; + return 1; +} + +string Platform::SkinName() const +{ + return m_impl->m_skinName; +} + +double Platform::VisualScale() const +{ + return m_impl->m_visualScale; +} + +int Platform::ScaleEtalonSize() const +{ + return m_impl->m_scaleEtalonSize; +} + +int Platform::MaxTilesCount() const +{ + return 120; +} + +int Platform::TileSize() const +{ + return 256; +} + +string Platform::DeviceName() const +{ + return m_impl->m_deviceName; +} + +//////////////////////////////////////////////////////////////////////// +extern "C" Platform & GetPlatform() +{ + static Platform platform; + return platform; +} diff --git a/platform/platform_linux.cpp b/platform/platform_linux.cpp new file mode 100644 index 0000000000..f3e1065b74 --- /dev/null +++ b/platform/platform_linux.cpp @@ -0,0 +1,43 @@ +#include "platform.hpp" + +#include +#include +#include + +static bool GetUserWritableDir(string & outDir) +{ + char * path = ::getenv("HOME"); + if (path) + { + outDir = path; + outDir += "." LOCALAPPDATA_DIR "/"; + ::mkdir(outDir.c_str(), 0755); + return true; + } + return false; +} + +/// @return full path including binary itself +static bool GetPathToBinary(string & outPath) +{ + char path[4096] = {0}; + if (0 < ::readlink("/proc/self/exe", path, ARRAY_SIZE(path))) + { + outPath = path; + return true; + } + return false; +} + +int Platform::CpuCores() const +{ + long numCPU = sysconf(_SC_NPROCESSORS_ONLN); + if (numCPU >= 1) + return static_cast(numCPU); + return 1; +} + +string Platform::UniqueClientId() const +{ + return "@TODO"; +} diff --git a/platform/platform_mac.mm b/platform/platform_mac.mm new file mode 100644 index 0000000000..2eed808312 --- /dev/null +++ b/platform/platform_mac.mm @@ -0,0 +1,89 @@ +#include "platform.hpp" + +#include "../std/target_os.hpp" + +#include +#include +#include +#include +#include +#include +#include + +#define LOCALAPPDATA_DIR "MapsWithMe" + +static string ExpandTildePath(char const * path) +{ + glob_t globbuf; + string result = path; + + if (::glob(path, GLOB_TILDE, NULL, &globbuf) == 0) //success + { + if (globbuf.gl_pathc > 0) + result = globbuf.gl_pathv[0]; + + globfree(&globbuf); + } + return result; +} + +bool GetUserWritableDir(string & outDir) +{ + char pathBuf[PATH_MAX]; + NSSearchPathEnumerationState state = ::NSStartSearchPathEnumeration(NSApplicationSupportDirectory, NSUserDomainMask); + while ((state = NSGetNextSearchPathEnumeration(state, pathBuf))) + { + outDir = ExpandTildePath(pathBuf); + ::mkdir(outDir.c_str(), 0755); + outDir += "/" LOCALAPPDATA_DIR "/"; + ::mkdir(outDir.c_str(), 0755); + return true; + } + return false; +} + +/// @return full path including binary itself +bool GetPathToBinary(string & outPath) +{ + char path[MAXPATHLEN] = {0}; + uint32_t pathSize = ARRAY_SIZE(path); + if (0 == ::_NSGetExecutablePath(path, &pathSize)) + { + char fixedPath[MAXPATHLEN] = {0}; + if (::realpath(path, fixedPath)) + { + outPath = fixedPath; + return true; + } + } + return false; +} + +int Platform::CpuCores() const +{ + int mib[2], numCPU = 0; + size_t len = sizeof(numCPU); + mib[0] = CTL_HW; + mib[1] = HW_AVAILCPU; + sysctl(mib, 2, &numCPU, &len, NULL, 0); + if (numCPU >= 1) + return numCPU; + // second try + mib[1] = HW_NCPU; + len = sizeof(numCPU); + sysctl(mib, 2, &numCPU, &len, NULL, 0); + if (numCPU >= 1) + return numCPU; + return 1; +} + +string Platform::UniqueClientId() const +{ + io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/"); + CFStringRef uuidCf = (CFStringRef) IORegistryEntryCreateCFProperty(ioRegistryRoot, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0); + IOObjectRelease(ioRegistryRoot); + char buf[513]; + CFStringGetCString(uuidCf, buf, 512, kCFStringEncodingMacRoman); + CFRelease(uuidCf); + return buf; +} diff --git a/platform/platform_qt.cpp b/platform/platform_qt.cpp new file mode 100644 index 0000000000..10ab490789 --- /dev/null +++ b/platform/platform_qt.cpp @@ -0,0 +1,184 @@ +#include "platform.hpp" + +#include "../coding/file_reader.hpp" + +#include "../std/target_os.hpp" + +#include +#include +#include + +// default writable directory name for dev/standalone installs +#define MAPDATA_DIR "data" +// default writable dir name in LocalAppData or ~/Library/AppData/ folders +#define LOCALAPPDATA_DIR "MapsWithMe" +// default Resources read-only dir +#define RESOURCES_DIR "Resources" + +/// @name Platform-dependent implementations in separate files +//@{ +bool GetUserWritableDir(string & outDir); +bool GetPathToBinary(string & outDir); +//@} + +static bool IsDirectoryWritable(string const & dir) +{ + if (!dir.empty()) + { + QString qDir = dir.c_str(); + if (dir[dir.size() - 1] != '/' && dir[dir.size() - 1] != '\\') + qDir.append('/'); + + QTemporaryFile file(qDir + "XXXXXX"); + if (file.open()) + return true; + } + return false; +} + +/// Scans all upper directories for the presence of given directory +/// @param[in] startPath full path to lowest file in hierarchy (usually binary) +/// @param[in] dirName directory name we want to be present +/// @return if not empty, contains full path to existing directory +static string DirFinder(string const & startPath, string dirName) +{ + char const SLASH = QDir::separator().toAscii(); + dirName = SLASH + dirName + SLASH; + + size_t slashPos = startPath.size(); + while (slashPos > 0 && (slashPos = startPath.rfind(SLASH, slashPos - 1)) != string::npos) + { + string const dir = startPath.substr(0, slashPos) + dirName; + if (QFileInfo(dir.c_str()).exists()) + return dir; + } + return string(); +} + +static bool GetOSSpecificResourcesDir(string const & exePath, string & dir) +{ + dir = DirFinder(exePath, RESOURCES_DIR); + return !dir.empty(); +} + +static void InitResourcesDir(string & dir) +{ + // Resources dir can be any "data" folder found in the nearest upper directory, + // where all necessary resources files are present and accessible + string exePath; + CHECK( GetPathToBinary(exePath), ("Can't get full path to executable") ); + dir = DirFinder(exePath, MAPDATA_DIR); + if (dir.empty()) + { + CHECK( GetOSSpecificResourcesDir(exePath, dir), ("Can't retrieve resources directory") ); + } + + /// @todo Check all necessary files +} + +static void InitWritableDir(string & dir) +{ + // Writable dir can be any "data" folder found in the nearest upper directory + // ./data - For Windows portable builds + // ../data + // ../../data - For developer builds + // etc. (for Mac in can be up to 6 levels above due to packages structure + // and if no _writable_ "data" folder was found, User/Application Data/MapsWithMe will be used + + string path; + CHECK( GetPathToBinary(path), ("Can't get full path to executable") ); + dir = DirFinder(path, MAPDATA_DIR); + if (dir.empty() || !IsDirectoryWritable(dir)) + { + CHECK( GetUserWritableDir(dir), ("Can't get User's Application Data writable directory") ); + } +} + +static string ReadPathForFile(string const & writableDir, + string const & resourcesDir, string const & file) +{ + string fullPath = writableDir + file; + if (!GetPlatform().IsFileExists(fullPath)) + { + fullPath = resourcesDir + file; + if (!GetPlatform().IsFileExists(fullPath)) + MYTHROW(FileAbsentException, ("File doesn't exist", fullPath)); + } + return fullPath; +} + +//////////////////////////////////////////////////////////////////////////////////////// +Platform::Platform() +{ + InitWritableDir(m_writableDir); + InitResourcesDir(m_resourcesDir); +} + +Platform::~Platform() +{ +} + +ModelReader * Platform::GetReader(string const & file) const +{ + return new FileReader(ReadPathForFile(m_writableDir, m_resourcesDir, file), 10, 12); +} + +bool Platform::GetFileSize(string const & file, uint64_t & size) const +{ + QFileInfo f(file.c_str()); + size = static_cast(f.size()); + return size != 0; +} + +void Platform::GetFilesInDir(string const & directory, string const & mask, FilesList & outFiles) const +{ + outFiles.clear(); + QDir dir(directory.c_str(), mask.c_str(), QDir::Unsorted, + QDir::Files | QDir::Readable | QDir::Dirs | QDir::NoDotAndDotDot); + int const count = dir.count(); + for (int i = 0; i < count; ++i) + outFiles.push_back(dir[i].toUtf8().data()); +} + +string Platform::DeviceName() const +{ + return OMIM_OS_NAME; +} + +double Platform::VisualScale() const +{ + return 1.0; +} + +string Platform::SkinName() const +{ + return "basic.skn"; +} + +void Platform::GetFontNames(FilesList & res) const +{ + GetFilesInDir(ResourcesDir(), "*.ttf", res); + sort(res.begin(), res.end()); +} + +int Platform::MaxTilesCount() const +{ + return 120; +} + +int Platform::TileSize() const +{ + return 256; +} + +int Platform::ScaleEtalonSize() const +{ + return 512 + 256; +} + +/////////////////////////////////////////////////////////////////////////////// +extern "C" Platform & GetPlatform() +{ + static Platform platform; + return platform; +} diff --git a/platform/platform_win.cpp b/platform/platform_win.cpp new file mode 100644 index 0000000000..a8c3b8d5c9 --- /dev/null +++ b/platform/platform_win.cpp @@ -0,0 +1,47 @@ +#include "platform.hpp" + +#include "../std/windows.hpp" + +#include + +static bool GetUserWritableDir(string & outDir) +{ + char pathBuf[MAX_PATH] = {0}; + if (SUCCEEDED(::SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, pathBuf))) + { + outDir = pathBuf; + ::CreateDirectoryA(outDir.c_str(), NULL); + outDir += "\\" LOCALAPPDATA_DIR "\\"; + ::CreateDirectoryA(outDir.c_str(), NULL); + return true; + } + return false; +} + +/// @return full path including binary itself +static bool GetPathToBinary(string & outPath) +{ + // get path to executable + char pathBuf[MAX_PATH] = {0}; + if (0 < ::GetModuleFileNameA(NULL, pathBuf, MAX_PATH)) + { + outPath = pathBuf; + return true; + } + return false; +} + +int Platform::CpuCores() const +{ + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + DWORD numCPU = sysinfo.dwNumberOfProcessors; + if (numCPU >= 1) + return static_cast(numCPU); + return 1; +} + +string Platform::UniqueClientId() const +{ + return "@TODO"; +} diff --git a/platform/qtplatform.cpp b/platform/qtplatform.cpp deleted file mode 100644 index c4900d2b1c..0000000000 --- a/platform/qtplatform.cpp +++ /dev/null @@ -1,293 +0,0 @@ -#include "platform.hpp" - -#include "../base/assert.hpp" -#include "../base/macros.hpp" -#include "../base/logging.hpp" - -#include "../defines.hpp" - -#include -#include -#include - -#include "../std/target_os.hpp" - -#if defined(OMIM_OS_WINDOWS) - #include "../std/windows.hpp" - #include - #define DIR_SLASH "\\" - -#elif defined(OMIM_OS_MAC) - #include - #include - #include - #include - #include - #include - #include - #include - #define DIR_SLASH "/" - -#elif defined(OMIM_OS_LINUX) - #include - #include - #include - #define DIR_SLASH "/" - -#endif - -#include "../base/start_mem_debug.hpp" - -// default writable directory name for dev/standalone installs -#define MAPDATA_DIR "data" -// default writable dir name in LocalAppData or ~/Library/AppData/ folders -#define LOCALAPPDATA_DIR "MapsWithMe" -// default Resources read-only dir -#define RESOURCES_DIR "Resources" - -#ifdef OMIM_OS_MAC -string ExpandTildePath(char const * path) -{ -// ASSERT(path, ()); - glob_t globbuf; - string result = path; - - if (::glob(path, GLOB_TILDE, NULL, &globbuf) == 0) //success - { - if (globbuf.gl_pathc > 0) - result = globbuf.gl_pathv[0]; - - globfree(&globbuf); - } - return result; -} -#endif - -static bool GetUserWritableDir(string & outDir) -{ -#if defined(OMIM_OS_WINDOWS) - char pathBuf[MAX_PATH] = {0}; - if (SUCCEEDED(::SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, pathBuf))) - { - outDir = pathBuf; - ::CreateDirectoryA(outDir.c_str(), NULL); - outDir += "\\" LOCALAPPDATA_DIR "\\"; - ::CreateDirectoryA(outDir.c_str(), NULL); - return true; - } - -#elif defined(OMIM_OS_MAC) - char pathBuf[PATH_MAX]; - NSSearchPathEnumerationState state = ::NSStartSearchPathEnumeration(NSApplicationSupportDirectory, NSUserDomainMask); - while ((state = NSGetNextSearchPathEnumeration(state, pathBuf))) - { - outDir = ExpandTildePath(pathBuf); - ::mkdir(outDir.c_str(), 0755); - outDir += "/" LOCALAPPDATA_DIR "/"; - ::mkdir(outDir.c_str(), 0755); - return true; - } - -#elif defined(OMIM_OS_LINUX) - char * path = ::getenv("HOME"); - if (path) - { - outDir = path; - outDir += "." LOCALAPPDATA_DIR "/"; - ::mkdir(outDir.c_str(), 0755); - return true; - } - -#else - #error "Implement code for your OS" - -#endif - return false; -} - -/// @return full path including binary itself -static bool GetPathToBinary(string & outPath) -{ -#if defined(OMIM_OS_WINDOWS) - // get path to executable - char pathBuf[MAX_PATH] = {0}; - if (0 < ::GetModuleFileNameA(NULL, pathBuf, MAX_PATH)) - { - outPath = pathBuf; - return true; - } - -#elif defined (OMIM_OS_MAC) - char path[MAXPATHLEN] = {0}; - uint32_t pathSize = ARRAY_SIZE(path); - if (0 == ::_NSGetExecutablePath(path, &pathSize)) - { - char fixedPath[MAXPATHLEN] = {0}; - if (::realpath(path, fixedPath)) - { - outPath = fixedPath; - return true; - } - } - -#elif defined (OMIM_OS_LINUX) - char path[4096] = {0}; - if (0 < ::readlink("/proc/self/exe", path, ARRAY_SIZE(path))) - { - outPath = path; - return true; - } - -#else - #error "Add implementation for your operating system, please" - -#endif - return false; -} - -static bool IsDirectoryWritable(string const & dir) -{ - if (!dir.empty()) - { - QString qDir = dir.c_str(); - if (dir[dir.size() - 1] != '/' && dir[dir.size() - 1] != '\\') - qDir.append('/'); - - QTemporaryFile file(qDir + "XXXXXX"); - if (file.open()) - return true; - } - return false; -} - -//////////////////////////////////////////////////////////////////////////////////////// -class QtPlatform : public BasePlatformImpl -{ - static bool IsDirExists(string const & file) - { - QFileInfo fileInfo(file.c_str()); - return fileInfo.exists(); - } - - /// Scans all upper directories for the presence of given directory - /// @param[in] startPath full path to lowest file in hierarchy (usually binary) - /// @param[in] dirName directory name we want to be present - /// @return if not empty, contains full path to existing directory - static string DirFinder(string const & startPath, string dirName) - { - dirName = DIR_SLASH + dirName + DIR_SLASH; - - size_t slashPos = startPath.size(); - while (slashPos > 0 && (slashPos = startPath.rfind(DIR_SLASH, slashPos - 1)) != string::npos) - { - string const dir = startPath.substr(0, slashPos) + dirName; - if (IsDirExists(dir)) - return dir; - } - return string(); - } - - static bool GetOSSpecificResourcesDir(string const & exePath, string & dir) - { - dir = DirFinder(exePath, RESOURCES_DIR); - return !dir.empty(); - } - - static void InitResourcesDir(string & dir) - { - // Resources dir can be any "data" folder found in the nearest upper directory, - // where all necessary resources files are present and accessible - string exePath; - CHECK( GetPathToBinary(exePath), ("Can't get full path to executable") ); - dir = DirFinder(exePath, MAPDATA_DIR); - if (dir.empty()) - { - CHECK( GetOSSpecificResourcesDir(exePath, dir), ("Can't retrieve resources directory") ); - } - - /// @todo Check all necessary files - } - - static void InitWritableDir(string & dir) - { - // Writable dir can be any "data" folder found in the nearest upper directory - // ./data - For Windows portable builds - // ../data - // ../../data - For developer builds - // etc. (for Mac in can be up to 6 levels above due to packages structure - // and if no _writable_ "data" folder was found, User/Application Data/MapsWithMe will be used - - string path; - CHECK( GetPathToBinary(path), ("Can't get full path to executable") ); - dir = DirFinder(path, MAPDATA_DIR); - if (dir.empty() || !IsDirectoryWritable(dir)) - { - CHECK( GetUserWritableDir(dir), ("Can't get User's Application Data writable directory") ); - } - } - -public: - QtPlatform() - { - InitWritableDir(m_writableDir); - InitResourcesDir(m_resourcesDir); - } - - virtual void GetFilesInDir(string const & directory, string const & mask, FilesList & outFiles) const - { - outFiles.clear(); - QDir dir(directory.c_str(), mask.c_str(), QDir::Unsorted, - QDir::Files | QDir::Readable | QDir::Dirs | QDir::NoDotAndDotDot); - int const count = dir.count(); - for (int i = 0; i < count; ++i) - outFiles.push_back(dir[i].toUtf8().data()); - } - - virtual bool RenameFileX(string const & original, string const & newName) const - { - return QFile::rename(original.c_str(), newName.c_str()); - } - - virtual int CpuCores() const - { -#if defined(OMIM_OS_WINDOWS) - SYSTEM_INFO sysinfo; - GetSystemInfo(&sysinfo); - DWORD numCPU = sysinfo.dwNumberOfProcessors; - if (numCPU >= 1) - return static_cast(numCPU); - -#elif defined(OMIM_OS_MAC) - int mib[2], numCPU = 0; - size_t len = sizeof(numCPU); - mib[0] = CTL_HW; - mib[1] = HW_AVAILCPU; - sysctl(mib, 2, &numCPU, &len, NULL, 0); - if (numCPU >= 1) - return numCPU; - // second try - mib[1] = HW_NCPU; - len = sizeof(numCPU); - sysctl(mib, 2, &numCPU, &len, NULL, 0); - if (numCPU >= 1) - return numCPU; - -#elif defined(OMIM_OS_LINUX) - long numCPU = sysconf(_SC_NPROCESSORS_ONLN); - if (numCPU >= 1) - return static_cast(numCPU); -#endif - return 1; - } - - string DeviceID() const - { - return "DesktopVersion"; - } -}; - -extern "C" Platform & GetPlatform() -{ - static QtPlatform platform; - return platform; -} diff --git a/yg/yg.pro b/yg/yg.pro index 3c6a081f00..13c2ad0ab8 100644 --- a/yg/yg.pro +++ b/yg/yg.pro @@ -6,16 +6,12 @@ CONFIG += staticlib DEFINES += YG_LIBRARY ROOT_DIR = .. -DEPENDENCIES = indexer geometry coding base freetype fribidi expat +DEPENDENCIES = indexer geometry platform coding base freetype fribidi expat INCLUDEPATH += $$ROOT_DIR/3party/freetype/include $$ROOT_DIR/3party/agg include($$ROOT_DIR/common.pri) -!iphone*:!bada* { - DEPENDENCIES += platform -} - SOURCES += \ internal/opengl.cpp \ vertex.cpp \