blob: 99cdd287b8a66a738b9ff36892ae54bbe2ae8675 [file] [log] [blame]
Jon Hjellea2c353f2016-01-11 13:11:38 -08001/*
2 * Copyright 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#import "RTCStatsReport.h"
12
13#include "webrtc/base/checks.h"
14
15#import "webrtc/api/objc/RTCStatsReport+Private.h"
16#import "webrtc/base/objc/NSString+StdString.h"
17#import "webrtc/base/objc/RTCLogging.h"
18
19@implementation RTCStatsReport
20
21@synthesize timestamp = _timestamp;
22@synthesize type = _type;
tkchinaac3eb22016-03-09 21:49:40 -080023@synthesize reportId = _reportId;
Jon Hjellea2c353f2016-01-11 13:11:38 -080024@synthesize values = _values;
25
26- (NSString *)description {
27 return [NSString stringWithFormat:@"RTCStatsReport:\n%@\n%@\n%f\n%@",
tkchinaac3eb22016-03-09 21:49:40 -080028 _reportId,
Jon Hjellea2c353f2016-01-11 13:11:38 -080029 _type,
30 _timestamp,
31 _values];
32}
33
34#pragma mark - Private
35
36- (instancetype)initWithNativeReport:(const webrtc::StatsReport &)nativeReport {
37 if (self = [super init]) {
38 _timestamp = nativeReport.timestamp();
39 _type = [NSString stringForStdString:nativeReport.TypeToString()];
tkchinaac3eb22016-03-09 21:49:40 -080040 _reportId = [NSString stringForStdString:
Jon Hjellea2c353f2016-01-11 13:11:38 -080041 nativeReport.id()->ToString()];
42
43 NSUInteger capacity = nativeReport.values().size();
44 NSMutableDictionary *values =
45 [NSMutableDictionary dictionaryWithCapacity:capacity];
46 for (auto const &valuePair : nativeReport.values()) {
47 NSString *key = [NSString stringForStdString:
48 valuePair.second->display_name()];
49 NSString *value = [NSString stringForStdString:
50 valuePair.second->ToString()];
51
52 // Not expecting duplicate keys.
hjon6b039952016-02-25 12:32:58 -080053 RTC_DCHECK(![values objectForKey:key]);
54 [values setObject:value forKey:key];
Jon Hjellea2c353f2016-01-11 13:11:38 -080055 }
56 _values = values;
57 }
58 return self;
59}
60
61@end