blob: 89e1b85a6912a74af736ec8723b3885a05500bba [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
hbosbd3dda62016-09-09 01:36:28 -070011#import "RTCLegacyStatsReport+Private.h"
tkchin9eeb6242016-04-27 01:54:20 -070012
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020013#import "base/RTCLogging.h"
14#import "helpers/NSString+StdString.h"
Jon Hjellea2c353f2016-01-11 13:11:38 -080015
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "rtc_base/checks.h"
Jon Hjellea2c353f2016-01-11 13:11:38 -080017
hbosbd3dda62016-09-09 01:36:28 -070018@implementation RTCLegacyStatsReport
Jon Hjellea2c353f2016-01-11 13:11:38 -080019
20@synthesize timestamp = _timestamp;
21@synthesize type = _type;
tkchinaac3eb22016-03-09 21:49:40 -080022@synthesize reportId = _reportId;
Jon Hjellea2c353f2016-01-11 13:11:38 -080023@synthesize values = _values;
24
25- (NSString *)description {
hbosbd3dda62016-09-09 01:36:28 -070026 return [NSString stringWithFormat:@"RTCLegacyStatsReport:\n%@\n%@\n%f\n%@",
tkchinaac3eb22016-03-09 21:49:40 -080027 _reportId,
Jon Hjellea2c353f2016-01-11 13:11:38 -080028 _type,
29 _timestamp,
30 _values];
31}
32
33#pragma mark - Private
34
35- (instancetype)initWithNativeReport:(const webrtc::StatsReport &)nativeReport {
36 if (self = [super init]) {
37 _timestamp = nativeReport.timestamp();
38 _type = [NSString stringForStdString:nativeReport.TypeToString()];
tkchinaac3eb22016-03-09 21:49:40 -080039 _reportId = [NSString stringForStdString:
Jon Hjellea2c353f2016-01-11 13:11:38 -080040 nativeReport.id()->ToString()];
41
42 NSUInteger capacity = nativeReport.values().size();
43 NSMutableDictionary *values =
44 [NSMutableDictionary dictionaryWithCapacity:capacity];
45 for (auto const &valuePair : nativeReport.values()) {
46 NSString *key = [NSString stringForStdString:
47 valuePair.second->display_name()];
48 NSString *value = [NSString stringForStdString:
49 valuePair.second->ToString()];
50
51 // Not expecting duplicate keys.
hjon6b039952016-02-25 12:32:58 -080052 RTC_DCHECK(![values objectForKey:key]);
53 [values setObject:value forKey:key];
Jon Hjellea2c353f2016-01-11 13:11:38 -080054 }
55 _values = values;
56 }
57 return self;
58}
59
60@end