Jon Hjelle | a2c353f | 2016-01-11 13:11:38 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
hbos | bd3dda6 | 2016-09-09 01:36:28 -0700 | [diff] [blame] | 11 | #import "RTCLegacyStatsReport+Private.h" |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 12 | |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 13 | #import "base/RTCLogging.h" |
Artem Titov | 63ee39d | 2022-05-13 14:46:42 +0000 | [diff] [blame] | 14 | #import "helpers/NSString+StdString.h" |
Jon Hjelle | a2c353f | 2016-01-11 13:11:38 -0800 | [diff] [blame] | 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "rtc_base/checks.h" |
Jon Hjelle | a2c353f | 2016-01-11 13:11:38 -0800 | [diff] [blame] | 17 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 18 | @implementation RTC_OBJC_TYPE (RTCLegacyStatsReport) |
Jon Hjelle | a2c353f | 2016-01-11 13:11:38 -0800 | [diff] [blame] | 19 | |
| 20 | @synthesize timestamp = _timestamp; |
| 21 | @synthesize type = _type; |
tkchin | aac3eb2 | 2016-03-09 21:49:40 -0800 | [diff] [blame] | 22 | @synthesize reportId = _reportId; |
Jon Hjelle | a2c353f | 2016-01-11 13:11:38 -0800 | [diff] [blame] | 23 | @synthesize values = _values; |
| 24 | |
| 25 | - (NSString *)description { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 26 | return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCLegacyStatsReport):\n%@\n%@\n%f\n%@", |
tkchin | aac3eb2 | 2016-03-09 21:49:40 -0800 | [diff] [blame] | 27 | _reportId, |
Jon Hjelle | a2c353f | 2016-01-11 13:11:38 -0800 | [diff] [blame] | 28 | _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(); |
Artem Titov | 63ee39d | 2022-05-13 14:46:42 +0000 | [diff] [blame] | 38 | _type = [NSString stringForStdString:nativeReport.TypeToString()]; |
| 39 | _reportId = [NSString stringForStdString: |
| 40 | nativeReport.id()->ToString()]; |
Jon Hjelle | a2c353f | 2016-01-11 13:11:38 -0800 | [diff] [blame] | 41 | |
| 42 | NSUInteger capacity = nativeReport.values().size(); |
| 43 | NSMutableDictionary *values = |
| 44 | [NSMutableDictionary dictionaryWithCapacity:capacity]; |
| 45 | for (auto const &valuePair : nativeReport.values()) { |
Artem Titov | 63ee39d | 2022-05-13 14:46:42 +0000 | [diff] [blame] | 46 | NSString *key = [NSString stringForStdString: |
| 47 | valuePair.second->display_name()]; |
| 48 | NSString *value = [NSString stringForStdString: |
| 49 | valuePair.second->ToString()]; |
Jon Hjelle | a2c353f | 2016-01-11 13:11:38 -0800 | [diff] [blame] | 50 | |
| 51 | // Not expecting duplicate keys. |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 52 | RTC_DCHECK(![values objectForKey:key]); |
| 53 | [values setObject:value forKey:key]; |
Jon Hjelle | a2c353f | 2016-01-11 13:11:38 -0800 | [diff] [blame] | 54 | } |
| 55 | _values = values; |
| 56 | } |
| 57 | return self; |
| 58 | } |
| 59 | |
| 60 | @end |