OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 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 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 // foo.baz->push_back("hello world"); | 42 // foo.baz->push_back("hello world"); |
43 // uint32_t x = *foo.bar; | 43 // uint32_t x = *foo.bar; |
44 // | 44 // |
45 // Pointers to all the members are available with |Members|, allowing iteration: | 45 // Pointers to all the members are available with |Members|, allowing iteration: |
46 // | 46 // |
47 // for (const RTCStatsMemberInterface* member : foo.Members()) { | 47 // for (const RTCStatsMemberInterface* member : foo.Members()) { |
48 // printf("%s = %s\n", member->name(), member->ValueToString().c_str()); | 48 // printf("%s = %s\n", member->name(), member->ValueToString().c_str()); |
49 // } | 49 // } |
50 class RTCStats { | 50 class RTCStats { |
51 public: | 51 public: |
52 RTCStats(const std::string& id, double timestamp) | 52 RTCStats(const std::string& id, int64_t timestamp_us) |
53 : id_(id), timestamp_(timestamp) {} | 53 : id_(id), timestamp_us_(timestamp_us) {} |
54 RTCStats(std::string&& id, double timestamp) | 54 RTCStats(std::string&& id, int64_t timestamp_us) |
55 : id_(std::move(id)), timestamp_(timestamp) {} | 55 : id_(std::move(id)), timestamp_us_(timestamp_us) {} |
56 virtual ~RTCStats() {} | 56 virtual ~RTCStats() {} |
57 | 57 |
58 virtual std::unique_ptr<RTCStats> copy() const = 0; | 58 virtual std::unique_ptr<RTCStats> copy() const = 0; |
59 | 59 |
60 const std::string& id() const { return id_; } | 60 const std::string& id() const { return id_; } |
61 // Time relative to the UNIX epoch (Jan 1, 1970, UTC), in seconds. | 61 // Time relative to the UNIX epoch (Jan 1, 1970, UTC), in microseconds. |
62 double timestamp() const { return timestamp_; } | 62 int64_t timestamp_us() const { return timestamp_us_; } |
63 // Returns the static member variable |kType| of the implementing class. | 63 // Returns the static member variable |kType| of the implementing class. |
64 virtual const char* type() const = 0; | 64 virtual const char* type() const = 0; |
65 // Returns a vector of pointers to all the RTCStatsMemberInterface members of | 65 // Returns a vector of pointers to all the RTCStatsMemberInterface members of |
66 // this class. This allows for iteration of members. | 66 // this class. This allows for iteration of members. |
67 std::vector<const RTCStatsMemberInterface*> Members() const; | 67 std::vector<const RTCStatsMemberInterface*> Members() const; |
68 | 68 |
69 // Creates a human readable string representation of the report, listing all | 69 // Creates a human readable string representation of the report, listing all |
70 // of its members (names and values). | 70 // of its members (names and values). |
71 std::string ToString() const; | 71 std::string ToString() const; |
72 | 72 |
73 // Downcasts the stats object to an |RTCStats| subclass |T|. DCHECKs that the | 73 // Downcasts the stats object to an |RTCStats| subclass |T|. DCHECKs that the |
74 // object is of type |T|. | 74 // object is of type |T|. |
75 template<typename T> | 75 template<typename T> |
76 const T& cast_to() const { | 76 const T& cast_to() const { |
77 RTC_DCHECK_EQ(type(), T::kType); | 77 RTC_DCHECK_EQ(type(), T::kType); |
78 return static_cast<const T&>(*this); | 78 return static_cast<const T&>(*this); |
79 } | 79 } |
80 | 80 |
81 protected: | 81 protected: |
82 // Gets a vector of all members of this |RTCStats| object, including members | 82 // Gets a vector of all members of this |RTCStats| object, including members |
83 // derived from parent classes. |additional_capacity| is how many more members | 83 // derived from parent classes. |additional_capacity| is how many more members |
84 // shall be reserved in the vector (so that subclasses can allocate a vector | 84 // shall be reserved in the vector (so that subclasses can allocate a vector |
85 // with room for both parent and child members without it having to resize). | 85 // with room for both parent and child members without it having to resize). |
86 virtual std::vector<const RTCStatsMemberInterface*> | 86 virtual std::vector<const RTCStatsMemberInterface*> |
87 MembersOfThisObjectAndAncestors( | 87 MembersOfThisObjectAndAncestors( |
88 size_t additional_capacity) const; | 88 size_t additional_capacity) const; |
89 | 89 |
90 std::string const id_; | 90 std::string const id_; |
91 double timestamp_; | 91 int64_t timestamp_us_; |
92 }; | 92 }; |
93 | 93 |
94 // All |RTCStats| classes should use this macro in a public section of the class | 94 // All |RTCStats| classes should use this macro in a public section of the class |
95 // definition. | 95 // definition. |
96 // | 96 // |
97 // This macro declares the static |kType| and overrides methods as required by | 97 // This macro declares the static |kType| and overrides methods as required by |
98 // subclasses of |RTCStats|: |copy|, |type|, and | 98 // subclasses of |RTCStats|: |copy|, |type|, and |
99 // |MembersOfThisObjectAndAncestors|. The |...| argument is a list of addresses | 99 // |MembersOfThisObjectAndAncestors|. The |...| argument is a list of addresses |
100 // to each member defined in the implementing class (list cannot be empty, must | 100 // to each member defined in the implementing class (list cannot be empty, must |
101 // have at least one new member). | 101 // have at least one new member). |
102 // | 102 // |
103 // (Since class names need to be known to implement these methods this cannot be | 103 // (Since class names need to be known to implement these methods this cannot be |
104 // part of the base |RTCStats|. While these methods could be implemented using | 104 // part of the base |RTCStats|. While these methods could be implemented using |
105 // templates, that would only work for immediate subclasses. Subclasses of | 105 // templates, that would only work for immediate subclasses. Subclasses of |
106 // subclasses also have to override these methods, resulting in boilerplate | 106 // subclasses also have to override these methods, resulting in boilerplate |
107 // code. Using a macro avoids this and works for any |RTCStats| class, including | 107 // code. Using a macro avoids this and works for any |RTCStats| class, including |
108 // grandchildren.) | 108 // grandchildren.) |
109 // | 109 // |
110 // Sample usage: | 110 // Sample usage: |
111 // | 111 // |
112 // rtcfoostats.h: | 112 // rtcfoostats.h: |
113 // class RTCFooStats : public RTCStats { | 113 // class RTCFooStats : public RTCStats { |
114 // public: | 114 // public: |
115 // RTCFooStats(const std::string& id, double timestamp) | 115 // RTCFooStats(const std::string& id, int64_t timestamp_us) |
116 // : RTCStats(id, timestamp), | 116 // : RTCStats(id, timestamp_us), |
117 // foo("foo"), | 117 // foo("foo"), |
118 // bar("bar") { | 118 // bar("bar") { |
119 // } | 119 // } |
120 // | 120 // |
121 // WEBRTC_RTCSTATS_IMPL(RTCStats, RTCFooStats, | 121 // WEBRTC_RTCSTATS_IMPL(RTCStats, RTCFooStats, |
122 // &foo, | 122 // &foo, |
123 // &bar); | 123 // &bar); |
124 // | 124 // |
125 // RTCStatsMember<int32_t> foo; | 125 // RTCStatsMember<int32_t> foo; |
126 // RTCStatsMember<int32_t> bar; | 126 // RTCStatsMember<int32_t> bar; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 return &value_; | 274 return &value_; |
275 } | 275 } |
276 | 276 |
277 private: | 277 private: |
278 T value_; | 278 T value_; |
279 }; | 279 }; |
280 | 280 |
281 } // namespace webrtc | 281 } // namespace webrtc |
282 | 282 |
283 #endif // WEBRTC_API_RTCSTATS_H_ | 283 #endif // WEBRTC_API_RTCSTATS_H_ |
OLD | NEW |