blob: 76de95078c1d6b43b16312402f95be5d9988f105 [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
hjon6b039952016-02-25 12:32:58 -080019// TODO(hjon): Update nullability types. See http://crbug/webrtc/5592
20
Jon Hjellea2c353f2016-01-11 13:11:38 -080021@implementation RTCStatsReport
22
23@synthesize timestamp = _timestamp;
24@synthesize type = _type;
25@synthesize statsId = _statsId;
26@synthesize values = _values;
27
28- (NSString *)description {
29 return [NSString stringWithFormat:@"RTCStatsReport:\n%@\n%@\n%f\n%@",
30 _statsId,
31 _type,
32 _timestamp,
33 _values];
34}
35
36#pragma mark - Private
37
38- (instancetype)initWithNativeReport:(const webrtc::StatsReport &)nativeReport {
39 if (self = [super init]) {
40 _timestamp = nativeReport.timestamp();
41 _type = [NSString stringForStdString:nativeReport.TypeToString()];
42 _statsId = [NSString stringForStdString:
43 nativeReport.id()->ToString()];
44
45 NSUInteger capacity = nativeReport.values().size();
46 NSMutableDictionary *values =
47 [NSMutableDictionary dictionaryWithCapacity:capacity];
48 for (auto const &valuePair : nativeReport.values()) {
49 NSString *key = [NSString stringForStdString:
50 valuePair.second->display_name()];
51 NSString *value = [NSString stringForStdString:
52 valuePair.second->ToString()];
53
54 // Not expecting duplicate keys.
hjon6b039952016-02-25 12:32:58 -080055 RTC_DCHECK(![values objectForKey:key]);
56 [values setObject:value forKey:key];
Jon Hjellea2c353f2016-01-11 13:11:38 -080057 }
58 _values = values;
59 }
60 return self;
61}
62
63@end