diff options
author | Ilya Grechuhin <i.grechuhin@mapswithme.com> | 2015-07-02 11:29:44 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:53:54 +0300 |
commit | c8605dad6c74f51e2daa981eb3618624ec567361 (patch) | |
tree | 629f8ded2c6260fcff6f06f50118f675741f4349 /platform | |
parent | 950162db9a7117ac18d838baeb5de5707b425572 (diff) |
[ios] Added connection info to routing.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/platform.hpp | 13 | ||||
-rw-r--r-- | platform/platform_android.cpp | 6 | ||||
-rw-r--r-- | platform/platform_ios.mm | 26 | ||||
-rw-r--r-- | platform/platform_linux.cpp | 6 | ||||
-rw-r--r-- | platform/platform_mac.mm | 22 | ||||
-rw-r--r-- | platform/platform_tizen.cpp | 6 | ||||
-rw-r--r-- | platform/platform_win.cpp | 6 |
7 files changed, 84 insertions, 1 deletions
diff --git a/platform/platform.hpp b/platform/platform.hpp index 7effb78d90..14219736f1 100644 --- a/platform/platform.hpp +++ b/platform/platform.hpp @@ -42,6 +42,13 @@ public: FILE_TYPE_DIRECTORY = 0x4 }; + enum class EConnectionType : uint8_t + { + CONNECTION_NONE, + CONNECTION_WIFI, + CONNECTION_WWAN + }; + protected: /// Usually read-only directory for application resources string m_resourcesDir; @@ -195,9 +202,13 @@ public: bool IsTablet() const { return m_isTablet; } /// @return information about kinds of memory which are relevant for a platform. - /// This methid is implemented for iOS and Android only. + /// This method is implemented for iOS and Android only. + /// @TODO Add implementation string GetMemoryInfo() const; + static EConnectionType ConnectionStatus(); + static bool IsConnected() { return ConnectionStatus() != EConnectionType::CONNECTION_NONE; }; + private: void GetSystemFontNames(FilesList & res) const; }; diff --git a/platform/platform_android.cpp b/platform/platform_android.cpp index 225547015e..95e75cd5b4 100644 --- a/platform/platform_android.cpp +++ b/platform/platform_android.cpp @@ -286,3 +286,9 @@ void Platform::RunAsync(TFunctor const & fn, Priority p) // doesn't attach to JVM threads. threads::Thread().Create(make_unique<FunctorWrapper>(fn)); } + +Platform::EConnectionType Platform::ConnectionStatus() +{ + // @TODO Add implementation + return EConnectionType::CONNECTION_NONE; +} diff --git a/platform/platform_ios.mm b/platform/platform_ios.mm index cb14de0171..2cbc073dbb 100644 --- a/platform/platform_ios.mm +++ b/platform/platform_ios.mm @@ -30,6 +30,9 @@ #import <UIKit/UIScreen.h> #import <UIKit/UIScreenMode.h> +#import <SystemConfiguration/SystemConfiguration.h> +#import <netinet/in.h> + Platform::Platform() { } @@ -169,6 +172,29 @@ void Platform::RunAsync(TFunctor const & fn, Priority p) dispatch_async_f(dispatch_get_global_queue(priority, 0), new TFunctor(fn), &PerformImpl); } +Platform::EConnectionType Platform::ConnectionStatus() +{ + struct sockaddr_in zero; + bzero(&zero, sizeof(zero)); + zero.sin_len = sizeof(zero); + zero.sin_family = AF_INET; + SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)&zero); + if (!reachability) + return EConnectionType::CONNECTION_NONE; + SCNetworkReachabilityFlags flags; + bool const gotFlags = SCNetworkReachabilityGetFlags(reachability, &flags); + CFRelease(reachability); + if (!gotFlags || ((flags & kSCNetworkReachabilityFlagsReachable) == 0)) + return EConnectionType::CONNECTION_NONE; + SCNetworkReachabilityFlags userActionRequired = kSCNetworkReachabilityFlagsConnectionRequired | kSCNetworkReachabilityFlagsInterventionRequired; + if ((flags & userActionRequired) == userActionRequired) + return EConnectionType::CONNECTION_NONE; + if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) + return EConnectionType::CONNECTION_WWAN; + else + return EConnectionType::CONNECTION_WIFI; +} + CustomIOSPlatform::CustomIOSPlatform() { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; diff --git a/platform/platform_linux.cpp b/platform/platform_linux.cpp index 52af71453b..e9b76209a5 100644 --- a/platform/platform_linux.cpp +++ b/platform/platform_linux.cpp @@ -126,3 +126,9 @@ void Platform::RunAsync(TFunctor const & fn, Priority p) /// @todo fn(); } + +Platform::EConnectionType Platform::ConnectionStatus() +{ + // @TODO Add implementation + return EConnectionType::CONNECTION_NONE; +} diff --git a/platform/platform_mac.mm b/platform/platform_mac.mm index 6c415f08d2..72de53b855 100644 --- a/platform/platform_mac.mm +++ b/platform/platform_mac.mm @@ -14,6 +14,8 @@ #include <dispatch/dispatch.h> +#import <SystemConfiguration/SystemConfiguration.h> +#import <netinet/in.h> Platform::Platform() { @@ -135,3 +137,23 @@ void Platform::RunAsync(TFunctor const & fn, Priority p) } dispatch_async_f(dispatch_get_global_queue(priority, 0), new TFunctor(fn), &PerformImpl); } + +Platform::EConnectionType Platform::ConnectionStatus() +{ + struct sockaddr_in zero; + bzero(&zero, sizeof(zero)); + zero.sin_len = sizeof(zero); + zero.sin_family = AF_INET; + SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)&zero); + if (!reachability) + return EConnectionType::CONNECTION_NONE; + SCNetworkReachabilityFlags flags; + bool const gotFlags = SCNetworkReachabilityGetFlags(reachability, &flags); + CFRelease(reachability); + if (!gotFlags || ((flags & kSCNetworkReachabilityFlagsReachable) == 0)) + return EConnectionType::CONNECTION_NONE; + SCNetworkReachabilityFlags userActionRequired = kSCNetworkReachabilityFlagsConnectionRequired | kSCNetworkReachabilityFlagsInterventionRequired; + if ((flags & userActionRequired) == userActionRequired) + return EConnectionType::CONNECTION_NONE; + return EConnectionType::CONNECTION_WIFI; +} diff --git a/platform/platform_tizen.cpp b/platform/platform_tizen.cpp index 57e18b4ef8..65112bc256 100644 --- a/platform/platform_tizen.cpp +++ b/platform/platform_tizen.cpp @@ -108,6 +108,12 @@ int Platform::PreCachingDepth() const return 3; } +Platform::EConnectionType Platform::ConnectionStatus() +{ + // @TODO Add implementation + return EConnectionType::CONNECTION_NONE; +} + extern Platform & GetPlatform() { static Platform platform; diff --git a/platform/platform_win.cpp b/platform/platform_win.cpp index 5e48ea360e..de63036a1b 100644 --- a/platform/platform_win.cpp +++ b/platform/platform_win.cpp @@ -144,6 +144,12 @@ void Platform::RunAsync(TFunctor const & fn, Priority p) fn(); } +Platform::EConnectionType Platform::ConnectionStatus() +{ + // @TODO Add implementation + return EConnectionType::CONNECTION_NONE; +} + Platform::TStorageStatus Platform::GetWritableStorageStatus(uint64_t neededSize) const { ULARGE_INTEGER freeSpace; |