OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 // This file contains structures used for retrieving statistics from an ongoing | 11 // This file contains structures used for retrieving statistics from an ongoing |
12 // libjingle session. | 12 // libjingle session. |
13 | 13 |
14 #ifndef WEBRTC_API_STATSTYPES_H_ | 14 #ifndef WEBRTC_API_STATSTYPES_H_ |
15 #define WEBRTC_API_STATSTYPES_H_ | 15 #define WEBRTC_API_STATSTYPES_H_ |
16 | 16 |
17 #include <algorithm> | 17 #include <algorithm> |
18 #include <list> | 18 #include <list> |
19 #include <map> | 19 #include <map> |
20 #include <string> | 20 #include <string> |
21 | 21 |
22 #include "webrtc/base/basictypes.h" | 22 #include "webrtc/base/basictypes.h" |
23 #include "webrtc/base/common.h" | 23 #include "webrtc/base/common.h" |
24 #include "webrtc/base/constructormagic.h" | 24 #include "webrtc/base/constructormagic.h" |
25 #include "webrtc/base/linked_ptr.h" | |
26 #include "webrtc/base/refcount.h" | 25 #include "webrtc/base/refcount.h" |
27 #include "webrtc/base/scoped_ref_ptr.h" | 26 #include "webrtc/base/scoped_ref_ptr.h" |
28 #include "webrtc/base/stringencode.h" | 27 #include "webrtc/base/stringencode.h" |
29 #include "webrtc/base/thread_checker.h" | 28 #include "webrtc/base/thread_checker.h" |
30 | 29 |
31 namespace webrtc { | 30 namespace webrtc { |
32 | 31 |
33 class StatsReport { | 32 class StatsReport { |
34 public: | 33 public: |
35 // Indicates whether a track is for sending or receiving. | 34 // Indicates whether a track is for sending or receiving. |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 | 256 |
258 Value(StatsValueName name, int64_t value, Type int_type); | 257 Value(StatsValueName name, int64_t value, Type int_type); |
259 Value(StatsValueName name, float f); | 258 Value(StatsValueName name, float f); |
260 Value(StatsValueName name, const std::string& value); | 259 Value(StatsValueName name, const std::string& value); |
261 Value(StatsValueName name, const char* value); | 260 Value(StatsValueName name, const char* value); |
262 Value(StatsValueName name, bool b); | 261 Value(StatsValueName name, bool b); |
263 Value(StatsValueName name, const Id& value); | 262 Value(StatsValueName name, const Id& value); |
264 | 263 |
265 ~Value(); | 264 ~Value(); |
266 | 265 |
266 // Support ref counting. Note that for performance reasons, we | |
267 // don't use thread safe operations. Therefore, all operations | |
268 // affecting the ref count (in practice, creation and copying of | |
269 // the Values mapping) must occur on webrtc's signalling thread. | |
270 int AddRef() const { | |
271 RTC_DCHECK_RUN_ON(&thread_checker_); | |
272 return ++ref_count_; | |
273 } | |
274 int Release() const { | |
275 RTC_DCHECK_RUN_ON(&thread_checker_); | |
276 int count = --ref_count_; | |
277 if (!count) | |
278 delete this; | |
279 return count; | |
280 } | |
281 | |
267 // TODO(tommi): This compares name as well as value... | 282 // TODO(tommi): This compares name as well as value... |
268 // I think we should only need to compare the value part and | 283 // I think we should only need to compare the value part and |
269 // move the name part into a hash map. | 284 // move the name part into a hash map. |
270 bool Equals(const Value& other) const; | 285 bool Equals(const Value& other) const; |
271 | 286 |
272 // Comparison operators. Return true iff the current instance is of the | 287 // Comparison operators. Return true iff the current instance is of the |
273 // correct type and holds the same value. No conversion is performed so | 288 // correct type and holds the same value. No conversion is performed so |
274 // a string value of "123" is not equal to an int value of 123 and an int | 289 // a string value of "123" is not equal to an int value of 123 and an int |
275 // value of 123 is not equal to a float value of 123.0f. | 290 // value of 123 is not equal to a float value of 123.0f. |
276 // One exception to this is that types kInt and kInt64 can be compared and | 291 // One exception to this is that types kInt and kInt64 can be compared and |
(...skipping 20 matching lines...) Expand all Loading... | |
297 | 312 |
298 // Converts the native value to a string representation of the value. | 313 // Converts the native value to a string representation of the value. |
299 std::string ToString() const; | 314 std::string ToString() const; |
300 | 315 |
301 Type type() const { return type_; } | 316 Type type() const { return type_; } |
302 | 317 |
303 // TODO(tommi): Move |name| and |display_name| out of the Value struct. | 318 // TODO(tommi): Move |name| and |display_name| out of the Value struct. |
304 const StatsValueName name; | 319 const StatsValueName name; |
305 | 320 |
306 private: | 321 private: |
322 rtc::ThreadChecker thread_checker_; | |
tommi
2017/01/18 12:48:20
just fyi, SequenceChecker is also an option and pe
nisse-webrtc
2017/01/18 12:56:21
Seems a bit tricky to convert this code to use a T
| |
323 mutable int ref_count_ ACCESS_ON(thread_checker_) = 0; | |
324 | |
307 const Type type_; | 325 const Type type_; |
308 // TODO(tommi): Use C++ 11 union and make value_ const. | 326 // TODO(tommi): Use C++ 11 union and make value_ const. |
309 union InternalType { | 327 union InternalType { |
310 int int_; | 328 int int_; |
311 int64_t int64_; | 329 int64_t int64_; |
312 float float_; | 330 float float_; |
313 bool bool_; | 331 bool bool_; |
314 std::string* string_; | 332 std::string* string_; |
315 const char* static_string_; | 333 const char* static_string_; |
316 Id* id_; | 334 Id* id_; |
317 } value_; | 335 } value_; |
318 | 336 |
319 private: | |
320 RTC_DISALLOW_COPY_AND_ASSIGN(Value); | 337 RTC_DISALLOW_COPY_AND_ASSIGN(Value); |
321 }; | 338 }; |
322 | 339 |
323 // TODO(tommi): Consider using a similar approach to how we store Ids using | 340 typedef rtc::scoped_refptr<Value> ValuePtr; |
324 // scoped_refptr for values. | |
325 typedef rtc::linked_ptr<Value> ValuePtr; | |
326 typedef std::map<StatsValueName, ValuePtr> Values; | 341 typedef std::map<StatsValueName, ValuePtr> Values; |
327 | 342 |
328 // Ownership of |id| is passed to |this|. | 343 // Ownership of |id| is passed to |this|. |
329 explicit StatsReport(const Id& id); | 344 explicit StatsReport(const Id& id); |
330 | 345 |
331 // Factory functions for various types of stats IDs. | 346 // Factory functions for various types of stats IDs. |
332 static Id NewBandwidthEstimationId(); | 347 static Id NewBandwidthEstimationId(); |
333 static Id NewTypedId(StatsType type, const std::string& id); | 348 static Id NewTypedId(StatsType type, const std::string& id); |
334 static Id NewTypedIntId(StatsType type, int id); | 349 static Id NewTypedIntId(StatsType type, int id); |
335 static Id NewIdWithDirection( | 350 static Id NewIdWithDirection( |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 StatsReport* Find(const StatsReport::Id& id); | 419 StatsReport* Find(const StatsReport::Id& id); |
405 | 420 |
406 private: | 421 private: |
407 Container list_; | 422 Container list_; |
408 rtc::ThreadChecker thread_checker_; | 423 rtc::ThreadChecker thread_checker_; |
409 }; | 424 }; |
410 | 425 |
411 } // namespace webrtc | 426 } // namespace webrtc |
412 | 427 |
413 #endif // WEBRTC_API_STATSTYPES_H_ | 428 #endif // WEBRTC_API_STATSTYPES_H_ |
OLD | NEW |