Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/Common/helpers.mm

Issue 2890513002: Revert of Split iOS sdk in to separate targets (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11
12 #import <Foundation/Foundation.h>
13 #import <sys/sysctl.h>
14 #if defined(WEBRTC_IOS)
15 #import <UIKit/UIKit.h>
16 #endif
17
18 #include <memory>
19
20 #include "webrtc/base/checks.h"
21 #include "webrtc/base/logging.h"
22 #include "webrtc/sdk/objc/Framework/Classes/Common/helpers.h"
23
24 namespace webrtc {
25 namespace ios {
26
27 #if defined(WEBRTC_IOS)
28 bool isOperatingSystemAtLeastVersion(double version) {
29 return GetSystemVersion() >= version;
30 }
31 #endif
32
33 NSString* NSStringFromStdString(const std::string& stdString) {
34 // std::string may contain null termination character so we construct
35 // using length.
36 return [[NSString alloc] initWithBytes:stdString.data()
37 length:stdString.length()
38 encoding:NSUTF8StringEncoding];
39 }
40
41 std::string StdStringFromNSString(NSString* nsString) {
42 NSData* charData = [nsString dataUsingEncoding:NSUTF8StringEncoding];
43 return std::string(reinterpret_cast<const char*>([charData bytes]),
44 [charData length]);
45 }
46
47 bool CheckAndLogError(BOOL success, NSError* error) {
48 if (!success) {
49 NSString* msg =
50 [NSString stringWithFormat:@"Error: %ld, %@, %@", (long)error.code,
51 error.localizedDescription,
52 error.localizedFailureReason];
53 LOG(LS_ERROR) << StdStringFromNSString(msg);
54 return false;
55 }
56 return true;
57 }
58
59 // TODO(henrika): see if it is possible to move to GetThreadName in
60 // platform_thread.h and base it on pthread methods instead.
61 std::string GetCurrentThreadDescription() {
62 NSString* name = [NSString stringWithFormat:@"%@", [NSThread currentThread]];
63 return StdStringFromNSString(name);
64 }
65
66 #if defined(WEBRTC_IOS)
67 std::string GetSystemName() {
68 NSString* osName = [[UIDevice currentDevice] systemName];
69 return StdStringFromNSString(osName);
70 }
71
72 std::string GetSystemVersionAsString() {
73 NSString* osVersion = [[UIDevice currentDevice] systemVersion];
74 return StdStringFromNSString(osVersion);
75 }
76
77 double GetSystemVersion() {
78 static dispatch_once_t once_token;
79 static double system_version;
80 dispatch_once(&once_token, ^{
81 system_version = [UIDevice currentDevice].systemVersion.doubleValue;
82 });
83 return system_version;
84 }
85
86 std::string GetDeviceType() {
87 NSString* deviceModel = [[UIDevice currentDevice] model];
88 return StdStringFromNSString(deviceModel);
89 }
90 #endif
91
92 std::string GetDeviceName() {
93 size_t size;
94 sysctlbyname("hw.machine", NULL, &size, NULL, 0);
95 std::unique_ptr<char[]> machine;
96 machine.reset(new char[size]);
97 sysctlbyname("hw.machine", machine.get(), &size, NULL, 0);
98 return std::string(machine.get());
99 }
100
101 std::string GetProcessName() {
102 NSString* processName = [NSProcessInfo processInfo].processName;
103 return StdStringFromNSString(processName);
104 }
105
106 int GetProcessID() {
107 return [NSProcessInfo processInfo].processIdentifier;
108 }
109
110 std::string GetOSVersionString() {
111 NSString* osVersion =
112 [NSProcessInfo processInfo].operatingSystemVersionString;
113 return StdStringFromNSString(osVersion);
114 }
115
116 int GetProcessorCount() {
117 return [NSProcessInfo processInfo].processorCount;
118 }
119
120 #if defined(__IPHONE_9_0) && defined(__IPHONE_OS_VERSION_MAX_ALLOWED) \
121 && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0
122 bool GetLowPowerModeEnabled() {
123 if (isOperatingSystemAtLeastVersion(9.0)) {
124 // lowPoweredModeEnabled is only available on iOS9+.
125 return [NSProcessInfo processInfo].lowPowerModeEnabled;
126 }
127 LOG(LS_WARNING) << "webrtc::ios::GetLowPowerModeEnabled() is not "
128 "supported. Requires at least iOS 9.0";
129 return false;
130 }
131 #endif
132
133 } // namespace ios
134 } // namespace webrtc
135
OLDNEW
« no previous file with comments | « webrtc/sdk/objc/Framework/Classes/Common/helpers.h ('k') | webrtc/sdk/objc/Framework/Classes/NSString+StdString.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698