Obj-C SDK Cleanup
This CL separates the files under sdk/objc into logical directories, replacing the previous file layout under Framework/. A long term goal is to have some system set up to generate the files under sdk/objc/api (the PeerConnection API wrappers) from the C++ code. In the shorter term the goal is to abstract out shared concepts from these classes in order to make them as uniform as possible. The separation into base/, components/, and helpers/ are to differentiate between the base layer's common protocols, various utilities and the actual platform specific components. The old directory layout that resembled a framework's internal layout is not necessary, since it is generated by the framework target when building it. Bug: webrtc:9627 Change-Id: Ib084fd83f050ae980649ca99e841f4fb0580bd8f Reviewed-on: https://webrtc-review.googlesource.com/94142 Reviewed-by: Kári Helgason <kthelgason@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> Reviewed-by: Henrik Andreassson <henrika@webrtc.org> Commit-Queue: Anders Carlsson <andersc@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24493}
This commit is contained in:
committed by
Commit Bot
parent
9ea5765f78
commit
7bca8ca4e2
@ -8,19 +8,4 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface NSString (StdString)
|
||||
|
||||
@property(nonatomic, readonly) std::string stdString;
|
||||
|
||||
+ (std::string)stdStringForString:(NSString *)nsString;
|
||||
+ (NSString *)stringForStdString:(const std::string &)stdString;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
#import "helpers/NSString+StdString.h"
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#import "NSString+StdString.h"
|
||||
|
||||
@implementation NSString (StdString)
|
||||
|
||||
- (std::string)stdString {
|
||||
return [NSString stdStringForString:self];
|
||||
}
|
||||
|
||||
+ (std::string)stdStringForString:(NSString *)nsString {
|
||||
NSData *charData = [nsString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
return std::string(reinterpret_cast<const char *>(charData.bytes),
|
||||
charData.length);
|
||||
}
|
||||
|
||||
+ (NSString *)stringForStdString:(const std::string&)stdString {
|
||||
// std::string may contain null termination character so we construct
|
||||
// using length.
|
||||
return [[NSString alloc] initWithBytes:stdString.data()
|
||||
length:stdString.length()
|
||||
encoding:NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#import "WebRTC/RTCCallbackLogger.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/logsinks.h"
|
||||
|
||||
class CallbackLogSink : public rtc::LogSink {
|
||||
public:
|
||||
CallbackLogSink(void (^callbackHandler)(NSString *message)) {
|
||||
callback_handler_ = callbackHandler;
|
||||
}
|
||||
|
||||
~CallbackLogSink() override { callback_handler_ = nil; }
|
||||
|
||||
void OnLogMessage(const std::string &message) override {
|
||||
if (callback_handler_) {
|
||||
callback_handler_([NSString stringWithUTF8String:message.c_str()]);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void (^callback_handler_)(NSString *message);
|
||||
};
|
||||
|
||||
@implementation RTCCallbackLogger {
|
||||
BOOL _hasStarted;
|
||||
std::unique_ptr<CallbackLogSink> _logSink;
|
||||
}
|
||||
|
||||
@synthesize severity = _severity;
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_severity = RTCLoggingSeverityInfo;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self stop];
|
||||
}
|
||||
|
||||
- (void)start:(nullable void (^)(NSString *))callback {
|
||||
if (_hasStarted) {
|
||||
return;
|
||||
}
|
||||
|
||||
_logSink.reset(new CallbackLogSink(callback));
|
||||
|
||||
rtc::LogMessage::AddLogToStream(_logSink.get(), [self rtcSeverity]);
|
||||
_hasStarted = YES;
|
||||
}
|
||||
|
||||
- (void)stop {
|
||||
if (!_hasStarted) {
|
||||
return;
|
||||
}
|
||||
RTC_DCHECK(_logSink);
|
||||
rtc::LogMessage::RemoveLogToStream(_logSink.get());
|
||||
_hasStarted = NO;
|
||||
_logSink.reset();
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
- (rtc::LoggingSeverity)rtcSeverity {
|
||||
switch (_severity) {
|
||||
case RTCLoggingSeverityVerbose:
|
||||
return rtc::LS_VERBOSE;
|
||||
case RTCLoggingSeverityInfo:
|
||||
return rtc::LS_INFO;
|
||||
case RTCLoggingSeverityWarning:
|
||||
return rtc::LS_WARNING;
|
||||
case RTCLoggingSeverityError:
|
||||
return rtc::LS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#import "WebRTC/RTCDispatcher.h"
|
||||
|
||||
@interface RTCDispatcher ()
|
||||
|
||||
+ (dispatch_queue_t)dispatchQueueForType:(RTCDispatcherQueueType)dispatchType;
|
||||
|
||||
@end
|
||||
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#import "RTCDispatcher+Private.h"
|
||||
|
||||
static dispatch_queue_t kAudioSessionQueue = nil;
|
||||
static dispatch_queue_t kCaptureSessionQueue = nil;
|
||||
|
||||
@implementation RTCDispatcher
|
||||
|
||||
+ (void)initialize {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
kAudioSessionQueue = dispatch_queue_create(
|
||||
"org.webrtc.RTCDispatcherAudioSession",
|
||||
DISPATCH_QUEUE_SERIAL);
|
||||
kCaptureSessionQueue = dispatch_queue_create(
|
||||
"org.webrtc.RTCDispatcherCaptureSession",
|
||||
DISPATCH_QUEUE_SERIAL);
|
||||
});
|
||||
}
|
||||
|
||||
+ (void)dispatchAsyncOnType:(RTCDispatcherQueueType)dispatchType
|
||||
block:(dispatch_block_t)block {
|
||||
dispatch_queue_t queue = [self dispatchQueueForType:dispatchType];
|
||||
dispatch_async(queue, block);
|
||||
}
|
||||
|
||||
+ (BOOL)isOnQueueForType:(RTCDispatcherQueueType)dispatchType {
|
||||
dispatch_queue_t targetQueue = [self dispatchQueueForType:dispatchType];
|
||||
const char* targetLabel = dispatch_queue_get_label(targetQueue);
|
||||
const char* currentLabel = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL);
|
||||
|
||||
NSAssert(strlen(targetLabel) > 0, @"Label is required for the target queue.");
|
||||
NSAssert(strlen(currentLabel) > 0, @"Label is required for the current queue.");
|
||||
|
||||
return strcmp(targetLabel, currentLabel) == 0;
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
+ (dispatch_queue_t)dispatchQueueForType:(RTCDispatcherQueueType)dispatchType {
|
||||
switch (dispatchType) {
|
||||
case RTCDispatcherTypeMain:
|
||||
return dispatch_get_main_queue();
|
||||
case RTCDispatcherTypeCaptureSession:
|
||||
return kCaptureSessionQueue;
|
||||
case RTCDispatcherTypeAudioSession:
|
||||
return kAudioSessionQueue;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#import "WebRTC/RTCFieldTrials.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#import "WebRTC/RTCLogging.h"
|
||||
|
||||
// Adding 'nogncheck' to disable the gn include headers check.
|
||||
// We don't want to depend on 'system_wrappers:field_trial_default' because
|
||||
// clients should be able to provide their own implementation.
|
||||
#include "system_wrappers/include/field_trial_default.h" // nogncheck
|
||||
|
||||
NSString * const kRTCFieldTrialAudioSendSideBweKey = @"WebRTC-Audio-SendSideBwe";
|
||||
NSString * const kRTCFieldTrialAudioSendSideBweForVideoKey = @"WebRTC-Audio-SendSideBwe-For-Video";
|
||||
NSString * const kRTCFieldTrialAudioForceNoTWCCKey = @"WebRTC-Audio-ForceNoTWCC";
|
||||
NSString * const kRTCFieldTrialAudioForceABWENoTWCCKey = @"WebRTC-Audio-ABWENoTWCC";
|
||||
NSString * const kRTCFieldTrialSendSideBweWithOverheadKey = @"WebRTC-SendSideBwe-WithOverhead";
|
||||
NSString * const kRTCFieldTrialFlexFec03AdvertisedKey = @"WebRTC-FlexFEC-03-Advertised";
|
||||
NSString * const kRTCFieldTrialFlexFec03Key = @"WebRTC-FlexFEC-03";
|
||||
NSString * const kRTCFieldTrialImprovedBitrateEstimateKey = @"WebRTC-ImprovedBitrateEstimate";
|
||||
NSString * const kRTCFieldTrialMedianSlopeFilterKey = @"WebRTC-BweMedianSlopeFilter";
|
||||
NSString * const kRTCFieldTrialTrendlineFilterKey = @"WebRTC-BweTrendlineFilter";
|
||||
NSString * const kRTCFieldTrialH264HighProfileKey = @"WebRTC-H264HighProfile";
|
||||
NSString * const kRTCFieldTrialMinimizeResamplingOnMobileKey =
|
||||
@"WebRTC-Audio-MinimizeResamplingOnMobile";
|
||||
NSString * const kRTCFieldTrialEnabledValue = @"Enabled";
|
||||
|
||||
static std::unique_ptr<char[]> gFieldTrialInitString;
|
||||
|
||||
NSString *RTCFieldTrialMedianSlopeFilterValue(
|
||||
size_t windowSize, double thresholdGain) {
|
||||
NSString *format = @"Enabled-%zu,%lf";
|
||||
return [NSString stringWithFormat:format, windowSize, thresholdGain];
|
||||
}
|
||||
|
||||
NSString *RTCFieldTrialTrendlineFilterValue(
|
||||
size_t windowSize, double smoothingCoeff, double thresholdGain) {
|
||||
NSString *format = @"Enabled-%zu,%lf,%lf";
|
||||
return [NSString stringWithFormat:format, windowSize, smoothingCoeff, thresholdGain];
|
||||
}
|
||||
|
||||
void RTCInitFieldTrialDictionary(NSDictionary<NSString *, NSString *> *fieldTrials) {
|
||||
if (!fieldTrials) {
|
||||
RTCLogWarning(@"No fieldTrials provided.");
|
||||
return;
|
||||
}
|
||||
// Assemble the keys and values into the field trial string.
|
||||
// We don't perform any extra format checking. That should be done by the underlying WebRTC calls.
|
||||
NSMutableString *fieldTrialInitString = [NSMutableString string];
|
||||
for (NSString *key in fieldTrials) {
|
||||
NSString *fieldTrialEntry = [NSString stringWithFormat:@"%@/%@/", key, fieldTrials[key]];
|
||||
[fieldTrialInitString appendString:fieldTrialEntry];
|
||||
}
|
||||
size_t len = fieldTrialInitString.length + 1;
|
||||
gFieldTrialInitString.reset(new char[len]);
|
||||
if (![fieldTrialInitString getCString:gFieldTrialInitString.get()
|
||||
maxLength:len
|
||||
encoding:NSUTF8StringEncoding]) {
|
||||
RTCLogError(@"Failed to convert field trial string.");
|
||||
return;
|
||||
}
|
||||
webrtc::field_trial::InitFieldTrialsFromString(gFieldTrialInitString.get());
|
||||
}
|
||||
@ -1,175 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#import "WebRTC/RTCFileLogger.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/filerotatingstream.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/logsinks.h"
|
||||
|
||||
NSString *const kDefaultLogDirName = @"webrtc_logs";
|
||||
NSUInteger const kDefaultMaxFileSize = 10 * 1024 * 1024; // 10MB.
|
||||
const char *kRTCFileLoggerRotatingLogPrefix = "rotating_log";
|
||||
|
||||
@implementation RTCFileLogger {
|
||||
BOOL _hasStarted;
|
||||
NSString *_dirPath;
|
||||
NSUInteger _maxFileSize;
|
||||
std::unique_ptr<rtc::FileRotatingLogSink> _logSink;
|
||||
}
|
||||
|
||||
@synthesize severity = _severity;
|
||||
@synthesize rotationType = _rotationType;
|
||||
@synthesize shouldDisableBuffering = _shouldDisableBuffering;
|
||||
|
||||
- (instancetype)init {
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(
|
||||
NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString *documentsDirPath = [paths firstObject];
|
||||
NSString *defaultDirPath =
|
||||
[documentsDirPath stringByAppendingPathComponent:kDefaultLogDirName];
|
||||
return [self initWithDirPath:defaultDirPath
|
||||
maxFileSize:kDefaultMaxFileSize];
|
||||
}
|
||||
|
||||
- (instancetype)initWithDirPath:(NSString *)dirPath
|
||||
maxFileSize:(NSUInteger)maxFileSize {
|
||||
return [self initWithDirPath:dirPath
|
||||
maxFileSize:maxFileSize
|
||||
rotationType:RTCFileLoggerTypeCall];
|
||||
}
|
||||
|
||||
- (instancetype)initWithDirPath:(NSString *)dirPath
|
||||
maxFileSize:(NSUInteger)maxFileSize
|
||||
rotationType:(RTCFileLoggerRotationType)rotationType {
|
||||
NSParameterAssert(dirPath.length);
|
||||
NSParameterAssert(maxFileSize);
|
||||
if (self = [super init]) {
|
||||
BOOL isDir = NO;
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
if ([fileManager fileExistsAtPath:dirPath isDirectory:&isDir]) {
|
||||
if (!isDir) {
|
||||
// Bail if something already exists there.
|
||||
return nil;
|
||||
}
|
||||
} else {
|
||||
if (![fileManager createDirectoryAtPath:dirPath
|
||||
withIntermediateDirectories:NO
|
||||
attributes:nil
|
||||
error:nil]) {
|
||||
// Bail if we failed to create a directory.
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
_dirPath = dirPath;
|
||||
_maxFileSize = maxFileSize;
|
||||
_severity = RTCFileLoggerSeverityInfo;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self stop];
|
||||
}
|
||||
|
||||
- (void)start {
|
||||
if (_hasStarted) {
|
||||
return;
|
||||
}
|
||||
switch (_rotationType) {
|
||||
case RTCFileLoggerTypeApp:
|
||||
_logSink.reset(
|
||||
new rtc::FileRotatingLogSink(_dirPath.UTF8String,
|
||||
kRTCFileLoggerRotatingLogPrefix,
|
||||
_maxFileSize,
|
||||
_maxFileSize / 10));
|
||||
break;
|
||||
case RTCFileLoggerTypeCall:
|
||||
_logSink.reset(
|
||||
new rtc::CallSessionFileRotatingLogSink(_dirPath.UTF8String,
|
||||
_maxFileSize));
|
||||
break;
|
||||
}
|
||||
if (!_logSink->Init()) {
|
||||
RTC_LOG(LS_ERROR) << "Failed to open log files at path: " << _dirPath.UTF8String;
|
||||
_logSink.reset();
|
||||
return;
|
||||
}
|
||||
if (_shouldDisableBuffering) {
|
||||
_logSink->DisableBuffering();
|
||||
}
|
||||
rtc::LogMessage::LogThreads(true);
|
||||
rtc::LogMessage::LogTimestamps(true);
|
||||
rtc::LogMessage::AddLogToStream(_logSink.get(), [self rtcSeverity]);
|
||||
_hasStarted = YES;
|
||||
}
|
||||
|
||||
- (void)stop {
|
||||
if (!_hasStarted) {
|
||||
return;
|
||||
}
|
||||
RTC_DCHECK(_logSink);
|
||||
rtc::LogMessage::RemoveLogToStream(_logSink.get());
|
||||
_hasStarted = NO;
|
||||
_logSink.reset();
|
||||
}
|
||||
|
||||
- (nullable NSData *)logData {
|
||||
if (_hasStarted) {
|
||||
return nil;
|
||||
}
|
||||
NSMutableData* logData = [NSMutableData data];
|
||||
std::unique_ptr<rtc::FileRotatingStream> stream;
|
||||
switch(_rotationType) {
|
||||
case RTCFileLoggerTypeApp:
|
||||
stream.reset(
|
||||
new rtc::FileRotatingStream(_dirPath.UTF8String,
|
||||
kRTCFileLoggerRotatingLogPrefix));
|
||||
break;
|
||||
case RTCFileLoggerTypeCall:
|
||||
stream.reset(new rtc::CallSessionFileRotatingStream(_dirPath.UTF8String));
|
||||
break;
|
||||
}
|
||||
if (!stream->Open()) {
|
||||
return logData;
|
||||
}
|
||||
size_t bufferSize = 0;
|
||||
if (!stream->GetSize(&bufferSize) || bufferSize == 0) {
|
||||
return logData;
|
||||
}
|
||||
size_t read = 0;
|
||||
// Allocate memory using malloc so we can pass it direcly to NSData without
|
||||
// copying.
|
||||
std::unique_ptr<uint8_t[]> buffer(static_cast<uint8_t*>(malloc(bufferSize)));
|
||||
stream->ReadAll(buffer.get(), bufferSize, &read, nullptr);
|
||||
logData = [[NSMutableData alloc] initWithBytesNoCopy:buffer.release()
|
||||
length:read];
|
||||
return logData;
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
- (rtc::LoggingSeverity)rtcSeverity {
|
||||
switch (_severity) {
|
||||
case RTCFileLoggerSeverityVerbose:
|
||||
return rtc::LS_VERBOSE;
|
||||
case RTCFileLoggerSeverityInfo:
|
||||
return rtc::LS_INFO;
|
||||
case RTCFileLoggerSeverityWarning:
|
||||
return rtc::LS_WARNING;
|
||||
case RTCFileLoggerSeverityError:
|
||||
return rtc::LS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#import "WebRTC/RTCLogging.h"
|
||||
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
rtc::LoggingSeverity RTCGetNativeLoggingSeverity(RTCLoggingSeverity severity) {
|
||||
switch (severity) {
|
||||
case RTCLoggingSeverityVerbose:
|
||||
return rtc::LS_VERBOSE;
|
||||
case RTCLoggingSeverityInfo:
|
||||
return rtc::LS_INFO;
|
||||
case RTCLoggingSeverityWarning:
|
||||
return rtc::LS_WARNING;
|
||||
case RTCLoggingSeverityError:
|
||||
return rtc::LS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
void RTCLogEx(RTCLoggingSeverity severity, NSString* log_string) {
|
||||
if (log_string.length) {
|
||||
const char* utf8_string = log_string.UTF8String;
|
||||
RTC_LOG_V(RTCGetNativeLoggingSeverity(severity)) << utf8_string;
|
||||
}
|
||||
}
|
||||
|
||||
void RTCSetMinDebugLogLevel(RTCLoggingSeverity severity) {
|
||||
rtc::LogMessage::LogToDebug(RTCGetNativeLoggingSeverity(severity));
|
||||
}
|
||||
|
||||
NSString* RTCFileName(const char* file_path) {
|
||||
NSString* ns_file_path =
|
||||
[[NSString alloc] initWithBytesNoCopy:const_cast<char*>(file_path)
|
||||
length:strlen(file_path)
|
||||
encoding:NSUTF8StringEncoding
|
||||
freeWhenDone:NO];
|
||||
return ns_file_path.lastPathComponent;
|
||||
}
|
||||
|
||||
@ -8,18 +8,4 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#if defined(WEBRTC_IOS)
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_EXTENSION_UNAVAILABLE_IOS("Application status not available in app extensions.")
|
||||
@interface RTCUIApplicationStatusObserver : NSObject
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
+ (void)prepareForUse;
|
||||
|
||||
- (BOOL)isApplicationActive;
|
||||
|
||||
@end
|
||||
|
||||
#endif // WEBRTC_IOS
|
||||
#import "helpers/RTCUIApplicationStatusObserver.h"
|
||||
|
||||
@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "RTCUIApplicationStatusObserver.h"
|
||||
|
||||
#if defined(WEBRTC_IOS)
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
@interface RTCUIApplicationStatusObserver ()
|
||||
|
||||
@property(nonatomic, assign) BOOL initialized;
|
||||
@property(nonatomic, assign) UIApplicationState state;
|
||||
|
||||
@end
|
||||
|
||||
@implementation RTCUIApplicationStatusObserver {
|
||||
BOOL _initialized;
|
||||
dispatch_block_t _initializeBlock;
|
||||
dispatch_semaphore_t _waitForInitializeSemaphore;
|
||||
UIApplicationState _state;
|
||||
|
||||
id<NSObject> _activeObserver;
|
||||
id<NSObject> _backgroundObserver;
|
||||
}
|
||||
|
||||
@synthesize initialized = _initialized;
|
||||
@synthesize state = _state;
|
||||
|
||||
+ (instancetype)sharedInstance {
|
||||
static id sharedInstance;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedInstance = [[self alloc] init];
|
||||
});
|
||||
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
// Method to make sure observers are added and the initialization block is
|
||||
// scheduled to run on the main queue.
|
||||
+ (void)prepareForUse {
|
||||
__unused RTCUIApplicationStatusObserver *observer = [self sharedInstance];
|
||||
}
|
||||
|
||||
- (id)init {
|
||||
if (self = [super init]) {
|
||||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||
__weak RTCUIApplicationStatusObserver *weakSelf = self;
|
||||
_activeObserver = [center addObserverForName:UIApplicationDidBecomeActiveNotification
|
||||
object:nil
|
||||
queue:[NSOperationQueue mainQueue]
|
||||
usingBlock:^(NSNotification *note) {
|
||||
weakSelf.state =
|
||||
[UIApplication sharedApplication].applicationState;
|
||||
}];
|
||||
|
||||
_backgroundObserver = [center addObserverForName:UIApplicationDidEnterBackgroundNotification
|
||||
object:nil
|
||||
queue:[NSOperationQueue mainQueue]
|
||||
usingBlock:^(NSNotification *note) {
|
||||
weakSelf.state =
|
||||
[UIApplication sharedApplication].applicationState;
|
||||
}];
|
||||
|
||||
_waitForInitializeSemaphore = dispatch_semaphore_create(1);
|
||||
_initialized = NO;
|
||||
_initializeBlock = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{
|
||||
weakSelf.state = [UIApplication sharedApplication].applicationState;
|
||||
weakSelf.initialized = YES;
|
||||
});
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), _initializeBlock);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||
[center removeObserver:_activeObserver];
|
||||
[center removeObserver:_backgroundObserver];
|
||||
}
|
||||
|
||||
- (BOOL)isApplicationActive {
|
||||
// NOTE: The function `dispatch_block_wait` can only legally be called once.
|
||||
// Because of this, if several threads call the `isApplicationActive` method before
|
||||
// the `_initializeBlock` has been executed, instead of multiple threads calling
|
||||
// `dispatch_block_wait`, the other threads need to wait for the first waiting thread
|
||||
// instead.
|
||||
if (!_initialized) {
|
||||
dispatch_semaphore_wait(_waitForInitializeSemaphore, DISPATCH_TIME_FOREVER);
|
||||
if (!_initialized) {
|
||||
long ret = dispatch_block_wait(_initializeBlock,
|
||||
dispatch_time(DISPATCH_TIME_NOW, 10.0 * NSEC_PER_SEC));
|
||||
RTC_DCHECK_EQ(ret, 0);
|
||||
}
|
||||
dispatch_semaphore_signal(_waitForInitializeSemaphore);
|
||||
}
|
||||
return _state == UIApplicationStateActive;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif // WEBRTC_IOS
|
||||
@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#import "WebRTC/UIDevice+RTCDevice.h"
|
||||
|
||||
#include <memory>
|
||||
#import <sys/utsname.h>
|
||||
|
||||
@implementation UIDevice (RTCDevice)
|
||||
|
||||
+ (RTCDeviceType)deviceType {
|
||||
NSDictionary *machineNameToType = @{
|
||||
@"iPhone1,1": @(RTCDeviceTypeIPhone1G),
|
||||
@"iPhone1,2": @(RTCDeviceTypeIPhone3G),
|
||||
@"iPhone2,1": @(RTCDeviceTypeIPhone3GS),
|
||||
@"iPhone3,1": @(RTCDeviceTypeIPhone4),
|
||||
@"iPhone3,2": @(RTCDeviceTypeIPhone4),
|
||||
@"iPhone3,3": @(RTCDeviceTypeIPhone4Verizon),
|
||||
@"iPhone4,1": @(RTCDeviceTypeIPhone4S),
|
||||
@"iPhone5,1": @(RTCDeviceTypeIPhone5GSM),
|
||||
@"iPhone5,2": @(RTCDeviceTypeIPhone5GSM_CDMA),
|
||||
@"iPhone5,3": @(RTCDeviceTypeIPhone5CGSM),
|
||||
@"iPhone5,4": @(RTCDeviceTypeIPhone5CGSM_CDMA),
|
||||
@"iPhone6,1": @(RTCDeviceTypeIPhone5SGSM),
|
||||
@"iPhone6,2": @(RTCDeviceTypeIPhone5SGSM_CDMA),
|
||||
@"iPhone7,1": @(RTCDeviceTypeIPhone6Plus),
|
||||
@"iPhone7,2": @(RTCDeviceTypeIPhone6),
|
||||
@"iPhone8,1": @(RTCDeviceTypeIPhone6S),
|
||||
@"iPhone8,2": @(RTCDeviceTypeIPhone6SPlus),
|
||||
@"iPhone8,4": @(RTCDeviceTypeIPhoneSE),
|
||||
@"iPhone9,1": @(RTCDeviceTypeIPhone7),
|
||||
@"iPhone9,2": @(RTCDeviceTypeIPhone7Plus),
|
||||
@"iPhone9,3": @(RTCDeviceTypeIPhone7),
|
||||
@"iPhone9,4": @(RTCDeviceTypeIPhone7Plus),
|
||||
@"iPhone10,1": @(RTCDeviceTypeIPhone8),
|
||||
@"iPhone10,2": @(RTCDeviceTypeIPhone8Plus),
|
||||
@"iPhone10,3": @(RTCDeviceTypeIPhoneX),
|
||||
@"iPhone10,4": @(RTCDeviceTypeIPhone8),
|
||||
@"iPhone10,5": @(RTCDeviceTypeIPhone8Plus),
|
||||
@"iPhone10,6": @(RTCDeviceTypeIPhoneX),
|
||||
@"iPod1,1": @(RTCDeviceTypeIPodTouch1G),
|
||||
@"iPod2,1": @(RTCDeviceTypeIPodTouch2G),
|
||||
@"iPod3,1": @(RTCDeviceTypeIPodTouch3G),
|
||||
@"iPod4,1": @(RTCDeviceTypeIPodTouch4G),
|
||||
@"iPod5,1": @(RTCDeviceTypeIPodTouch5G),
|
||||
@"iPod7,1": @(RTCDeviceTypeIPodTouch6G),
|
||||
@"iPad1,1": @(RTCDeviceTypeIPad),
|
||||
@"iPad2,1": @(RTCDeviceTypeIPad2Wifi),
|
||||
@"iPad2,2": @(RTCDeviceTypeIPad2GSM),
|
||||
@"iPad2,3": @(RTCDeviceTypeIPad2CDMA),
|
||||
@"iPad2,4": @(RTCDeviceTypeIPad2Wifi2),
|
||||
@"iPad2,5": @(RTCDeviceTypeIPadMiniWifi),
|
||||
@"iPad2,6": @(RTCDeviceTypeIPadMiniGSM),
|
||||
@"iPad2,7": @(RTCDeviceTypeIPadMiniGSM_CDMA),
|
||||
@"iPad3,1": @(RTCDeviceTypeIPad3Wifi),
|
||||
@"iPad3,2": @(RTCDeviceTypeIPad3GSM_CDMA),
|
||||
@"iPad3,3": @(RTCDeviceTypeIPad3GSM),
|
||||
@"iPad3,4": @(RTCDeviceTypeIPad4Wifi),
|
||||
@"iPad3,5": @(RTCDeviceTypeIPad4GSM),
|
||||
@"iPad3,6": @(RTCDeviceTypeIPad4GSM_CDMA),
|
||||
@"iPad4,1": @(RTCDeviceTypeIPadAirWifi),
|
||||
@"iPad4,2": @(RTCDeviceTypeIPadAirCellular),
|
||||
@"iPad4,3": @(RTCDeviceTypeIPadAirWifiCellular),
|
||||
@"iPad4,4": @(RTCDeviceTypeIPadMini2GWifi),
|
||||
@"iPad4,5": @(RTCDeviceTypeIPadMini2GCellular),
|
||||
@"iPad4,6": @(RTCDeviceTypeIPadMini2GWifiCellular),
|
||||
@"iPad4,7": @(RTCDeviceTypeIPadMini3),
|
||||
@"iPad4,8": @(RTCDeviceTypeIPadMini3),
|
||||
@"iPad4,9": @(RTCDeviceTypeIPadMini3),
|
||||
@"iPad5,1": @(RTCDeviceTypeIPadMini4),
|
||||
@"iPad5,2": @(RTCDeviceTypeIPadMini4),
|
||||
@"iPad5,3": @(RTCDeviceTypeIPadAir2),
|
||||
@"iPad5,4": @(RTCDeviceTypeIPadAir2),
|
||||
@"iPad6,3": @(RTCDeviceTypeIPadPro9Inch),
|
||||
@"iPad6,4": @(RTCDeviceTypeIPadPro9Inch),
|
||||
@"iPad6,7": @(RTCDeviceTypeIPadPro12Inch),
|
||||
@"iPad6,8": @(RTCDeviceTypeIPadPro12Inch),
|
||||
@"iPad6,11": @(RTCDeviceTypeIPad5),
|
||||
@"iPad6,12": @(RTCDeviceTypeIPad5),
|
||||
@"iPad7,1": @(RTCDeviceTypeIPadPro12Inch2),
|
||||
@"iPad7,2": @(RTCDeviceTypeIPadPro12Inch2),
|
||||
@"iPad7,3": @(RTCDeviceTypeIPadPro10Inch),
|
||||
@"iPad7,4": @(RTCDeviceTypeIPadPro10Inch),
|
||||
@"iPad7,5": @(RTCDeviceTypeIPad6),
|
||||
@"iPad7,6": @(RTCDeviceTypeIPad6),
|
||||
@"i386": @(RTCDeviceTypeSimulatori386),
|
||||
@"x86_64": @(RTCDeviceTypeSimulatorx86_64),
|
||||
};
|
||||
|
||||
RTCDeviceType deviceType = RTCDeviceTypeUnknown;
|
||||
NSNumber *typeNumber = machineNameToType[[self machineName]];
|
||||
if (typeNumber) {
|
||||
deviceType = static_cast<RTCDeviceType>(typeNumber.integerValue);
|
||||
}
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
+ (NSString *)machineName {
|
||||
struct utsname systemInfo;
|
||||
uname(&systemInfo);
|
||||
return [[NSString alloc] initWithCString:systemInfo.machine
|
||||
encoding:NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
+ (double)currentDeviceSystemVersion {
|
||||
return [self currentDevice].systemVersion.doubleValue;
|
||||
}
|
||||
|
||||
+ (BOOL)isIOS11OrLater {
|
||||
return [self currentDeviceSystemVersion] >= 11.0;
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef SDK_OBJC_FRAMEWORK_CLASSES_COMMON_HELPERS_H_
|
||||
#define SDK_OBJC_FRAMEWORK_CLASSES_COMMON_HELPERS_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace webrtc {
|
||||
namespace ios {
|
||||
|
||||
bool CheckAndLogError(BOOL success, NSError* error);
|
||||
|
||||
NSString* NSStringFromStdString(const std::string& stdString);
|
||||
std::string StdStringFromNSString(NSString* nsString);
|
||||
|
||||
// Return thread ID as a string.
|
||||
std::string GetThreadId();
|
||||
|
||||
// Return thread ID as string suitable for debug logging.
|
||||
std::string GetThreadInfo();
|
||||
|
||||
// Returns [NSThread currentThread] description as string.
|
||||
// Example: <NSThread: 0x170066d80>{number = 1, name = main}
|
||||
std::string GetCurrentThreadDescription();
|
||||
|
||||
#if defined(WEBRTC_IOS)
|
||||
// Returns the current name of the operating system.
|
||||
std::string GetSystemName();
|
||||
|
||||
// Returns the current version of the operating system as a string.
|
||||
std::string GetSystemVersionAsString();
|
||||
|
||||
// Returns the version of the operating system in double representation.
|
||||
// Uses a cached value of the system version.
|
||||
double GetSystemVersion();
|
||||
|
||||
// Returns the device type.
|
||||
// Examples: ”iPhone” and ”iPod touch”.
|
||||
std::string GetDeviceType();
|
||||
#endif // defined(WEBRTC_IOS)
|
||||
|
||||
// Returns a more detailed device name.
|
||||
// Examples: "iPhone 5s (GSM)" and "iPhone 6 Plus".
|
||||
std::string GetDeviceName();
|
||||
|
||||
// Returns the name of the process. Does not uniquely identify the process.
|
||||
std::string GetProcessName();
|
||||
|
||||
// Returns the identifier of the process (often called process ID).
|
||||
int GetProcessID();
|
||||
|
||||
// Returns a string containing the version of the operating system on which the
|
||||
// process is executing. The string is string is human readable, localized, and
|
||||
// is appropriate for displaying to the user.
|
||||
std::string GetOSVersionString();
|
||||
|
||||
// Returns the number of processing cores available on the device.
|
||||
int GetProcessorCount();
|
||||
|
||||
#if defined(WEBRTC_IOS)
|
||||
// Indicates whether Low Power Mode is enabled on the iOS device.
|
||||
bool GetLowPowerModeEnabled();
|
||||
#endif
|
||||
|
||||
} // namespace ios
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // SDK_OBJC_FRAMEWORK_CLASSES_COMMON_HELPERS_H_
|
||||
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <sys/sysctl.h>
|
||||
#if defined(WEBRTC_IOS)
|
||||
#import <UIKit/UIKit.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "sdk/objc/Framework/Classes/Common/helpers.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace ios {
|
||||
|
||||
NSString* NSStringFromStdString(const std::string& stdString) {
|
||||
// std::string may contain null termination character so we construct
|
||||
// using length.
|
||||
return [[NSString alloc] initWithBytes:stdString.data()
|
||||
length:stdString.length()
|
||||
encoding:NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
std::string StdStringFromNSString(NSString* nsString) {
|
||||
NSData* charData = [nsString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
return std::string(reinterpret_cast<const char*>([charData bytes]),
|
||||
[charData length]);
|
||||
}
|
||||
|
||||
bool CheckAndLogError(BOOL success, NSError* error) {
|
||||
if (!success) {
|
||||
NSString* msg =
|
||||
[NSString stringWithFormat:@"Error: %ld, %@, %@", (long)error.code,
|
||||
error.localizedDescription,
|
||||
error.localizedFailureReason];
|
||||
RTC_LOG(LS_ERROR) << StdStringFromNSString(msg);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO(henrika): see if it is possible to move to GetThreadName in
|
||||
// platform_thread.h and base it on pthread methods instead.
|
||||
std::string GetCurrentThreadDescription() {
|
||||
NSString* name = [NSString stringWithFormat:@"%@", [NSThread currentThread]];
|
||||
return StdStringFromNSString(name);
|
||||
}
|
||||
|
||||
#if defined(WEBRTC_IOS)
|
||||
std::string GetSystemName() {
|
||||
NSString* osName = [[UIDevice currentDevice] systemName];
|
||||
return StdStringFromNSString(osName);
|
||||
}
|
||||
|
||||
std::string GetSystemVersionAsString() {
|
||||
NSString* osVersion = [[UIDevice currentDevice] systemVersion];
|
||||
return StdStringFromNSString(osVersion);
|
||||
}
|
||||
|
||||
std::string GetDeviceType() {
|
||||
NSString* deviceModel = [[UIDevice currentDevice] model];
|
||||
return StdStringFromNSString(deviceModel);
|
||||
}
|
||||
|
||||
bool GetLowPowerModeEnabled() {
|
||||
return [NSProcessInfo processInfo].lowPowerModeEnabled;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string GetDeviceName() {
|
||||
size_t size;
|
||||
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
|
||||
std::unique_ptr<char[]> machine;
|
||||
machine.reset(new char[size]);
|
||||
sysctlbyname("hw.machine", machine.get(), &size, NULL, 0);
|
||||
return std::string(machine.get());
|
||||
}
|
||||
|
||||
std::string GetProcessName() {
|
||||
NSString* processName = [NSProcessInfo processInfo].processName;
|
||||
return StdStringFromNSString(processName);
|
||||
}
|
||||
|
||||
int GetProcessID() {
|
||||
return [NSProcessInfo processInfo].processIdentifier;
|
||||
}
|
||||
|
||||
std::string GetOSVersionString() {
|
||||
NSString* osVersion =
|
||||
[NSProcessInfo processInfo].operatingSystemVersionString;
|
||||
return StdStringFromNSString(osVersion);
|
||||
}
|
||||
|
||||
int GetProcessorCount() {
|
||||
return [NSProcessInfo processInfo].processorCount;
|
||||
}
|
||||
|
||||
} // namespace ios
|
||||
} // namespace webrtc
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
// This file is only needed to make ninja happy on some platforms.
|
||||
// On some platforms it is not possible to link an rtc_static_library
|
||||
// without any source file listed in the GN target.
|
||||
@ -9,108 +9,4 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_COMMON_SCOPED_CFTYPEREF_H_
|
||||
#define WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_COMMON_SCOPED_CFTYPEREF_H_
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
namespace rtc {
|
||||
|
||||
// RETAIN: ScopedTypeRef should retain the object when it takes
|
||||
// ownership.
|
||||
// ASSUME: Assume the object already has already been retained.
|
||||
// ScopedTypeRef takes over ownership.
|
||||
enum class RetainPolicy { RETAIN, ASSUME };
|
||||
|
||||
namespace internal {
|
||||
template <typename T>
|
||||
struct CFTypeRefTraits {
|
||||
static T InvalidValue() { return nullptr; }
|
||||
static void Release(T ref) { CFRelease(ref); }
|
||||
static T Retain(T ref) {
|
||||
CFRetain(ref);
|
||||
return ref;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Traits>
|
||||
class ScopedTypeRef {
|
||||
public:
|
||||
ScopedTypeRef() : ptr_(Traits::InvalidValue()) {}
|
||||
explicit ScopedTypeRef(T ptr) : ptr_(ptr) {}
|
||||
ScopedTypeRef(T ptr, RetainPolicy policy) : ScopedTypeRef(ptr) {
|
||||
if (ptr_ && policy == RetainPolicy::RETAIN)
|
||||
Traits::Retain(ptr_);
|
||||
}
|
||||
|
||||
ScopedTypeRef(const ScopedTypeRef<T, Traits>& rhs) : ptr_(rhs.ptr_) {
|
||||
if (ptr_)
|
||||
ptr_ = Traits::Retain(ptr_);
|
||||
}
|
||||
|
||||
~ScopedTypeRef() {
|
||||
if (ptr_) {
|
||||
Traits::Release(ptr_);
|
||||
}
|
||||
}
|
||||
|
||||
T get() const { return ptr_; }
|
||||
T operator->() const { return ptr_; }
|
||||
explicit operator bool() const { return ptr_; }
|
||||
|
||||
bool operator!() const { return !ptr_; }
|
||||
|
||||
ScopedTypeRef& operator=(const T& rhs) {
|
||||
if (ptr_)
|
||||
Traits::Release(ptr_);
|
||||
ptr_ = rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ScopedTypeRef& operator=(const ScopedTypeRef<T, Traits>& rhs) {
|
||||
reset(rhs.get(), RetainPolicy::RETAIN);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// This is intended to take ownership of objects that are
|
||||
// created by pass-by-pointer initializers.
|
||||
T* InitializeInto() {
|
||||
RTC_DCHECK(!ptr_);
|
||||
return &ptr_;
|
||||
}
|
||||
|
||||
void reset(T ptr, RetainPolicy policy = RetainPolicy::ASSUME) {
|
||||
if (ptr && policy == RetainPolicy::RETAIN)
|
||||
Traits::Retain(ptr);
|
||||
if (ptr_)
|
||||
Traits::Release(ptr_);
|
||||
ptr_ = ptr;
|
||||
}
|
||||
|
||||
T release() {
|
||||
T temp = ptr_;
|
||||
ptr_ = Traits::InvalidValue();
|
||||
return temp;
|
||||
}
|
||||
|
||||
private:
|
||||
T ptr_;
|
||||
};
|
||||
} // namespace internal
|
||||
|
||||
template <typename T>
|
||||
using ScopedCFTypeRef =
|
||||
internal::ScopedTypeRef<T, internal::CFTypeRefTraits<T>>;
|
||||
|
||||
template <typename T>
|
||||
static ScopedCFTypeRef<T> AdoptCF(T cftype) {
|
||||
return ScopedCFTypeRef<T>(cftype, RetainPolicy::RETAIN);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static ScopedCFTypeRef<T> ScopedCF(T cftype) {
|
||||
return ScopedCFTypeRef<T>(cftype);
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_COMMON_SCOPED_CFTYPEREF_H_
|
||||
#import "helpers/scoped_cftyperef.h"
|
||||
|
||||
Reference in New Issue
Block a user