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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 int64_t timestamp_us_; | 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 these macros. |
95 // definition. | 95 // |WEBRTC_RTCSTATS_DECL| is placed in a public section of the class definition. |
96 // |WEBRTC_RTCSTATS_IMPL| is placed outside the class definition (in a .cc). | |
96 // | 97 // |
97 // This macro declares the static |kType| and overrides methods as required by | 98 // The macro declares and defines the static |kType| and overrides methods as |
hta-webrtc
2016/10/04 13:51:04
More precise:
These macros declare (in _DECL) and
hbos
2016/10/06 08:38:57
Done.
| |
98 // subclasses of |RTCStats|: |copy|, |type|, and | 99 // required by subclasses of |RTCStats|: |copy|, |type|, and |
99 // |MembersOfThisObjectAndAncestors|. The |...| argument is a list of addresses | 100 // |MembersOfThisObjectAndAncestors|. The |...| argument is a list of addresses |
100 // to each member defined in the implementing class (list cannot be empty, must | 101 // to each member defined in the implementing class (list cannot be empty, must |
101 // have at least one new member). | 102 // have at least one new member). |
hta-webrtc
2016/10/04 13:51:04
Suggest replacing parenthesis with "The list must
hbos
2016/10/06 08:38:57
Done.
| |
102 // | 103 // |
103 // (Since class names need to be known to implement these methods this cannot be | 104 // (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 | 105 // part of the base |RTCStats|. While these methods could be implemented using |
105 // templates, that would only work for immediate subclasses. Subclasses of | 106 // templates, that would only work for immediate subclasses. Subclasses of |
106 // subclasses also have to override these methods, resulting in boilerplate | 107 // subclasses also have to override these methods, resulting in boilerplate |
107 // code. Using a macro avoids this and works for any |RTCStats| class, including | 108 // code. Using a macro avoids this and works for any |RTCStats| class, including |
108 // grandchildren.) | 109 // grandchildren.) |
109 // | 110 // |
110 // Sample usage: | 111 // Sample usage: |
111 // | 112 // |
112 // rtcfoostats.h: | 113 // rtcfoostats.h: |
113 // class RTCFooStats : public RTCStats { | 114 // class RTCFooStats : public RTCStats { |
114 // public: | 115 // public: |
115 // RTCFooStats(const std::string& id, int64_t timestamp_us) | 116 // WEBRTC_RTCSTATS_DECL(); |
116 // : RTCStats(id, timestamp_us), | |
117 // foo("foo"), | |
118 // bar("bar") { | |
119 // } | |
120 // | 117 // |
121 // WEBRTC_RTCSTATS_IMPL(RTCStats, RTCFooStats, | 118 // RTCFooStats(const std::string& id, int64_t timestamp_us); |
122 // &foo, | |
123 // &bar); | |
124 // | 119 // |
125 // RTCStatsMember<int32_t> foo; | 120 // RTCStatsMember<int32_t> foo; |
126 // RTCStatsMember<int32_t> bar; | 121 // RTCStatsMember<int32_t> bar; |
127 // }; | 122 // }; |
128 // | 123 // |
129 // rtcfoostats.cc: | 124 // rtcfoostats.cc: |
130 // const char RTCFooStats::kType[] = "foo-stats"; | 125 // WEBRTC_RTCSTATS_IMPL(RTCFooStats, RTCStats, "foo-stats" |
126 // &foo, | |
127 // &bar); | |
131 // | 128 // |
132 #define WEBRTC_RTCSTATS_IMPL(parent_class, this_class, ...) \ | 129 // RTCFooStats::RTCFooStats(const std::string& id, int64_t timestamp_us) |
130 // : RTCStats(id, timestamp_us), | |
131 // foo("foo"), | |
132 // bar("bar") { | |
133 // } | |
134 // | |
135 #define WEBRTC_RTCSTATS_DECL() \ | |
133 public: \ | 136 public: \ |
134 static const char kType[]; \ | 137 static const char kType[]; \ |
135 std::unique_ptr<webrtc::RTCStats> copy() const override { \ | 138 \ |
136 return std::unique_ptr<webrtc::RTCStats>(new this_class(*this)); \ | 139 std::unique_ptr<webrtc::RTCStats> copy() const override; \ |
137 } \ | 140 const char* type() const override; \ |
138 const char* type() const override { return this_class::kType; } \ | 141 \ |
139 protected: \ | 142 protected: \ |
140 std::vector<const webrtc::RTCStatsMemberInterface*> \ | 143 std::vector<const webrtc::RTCStatsMemberInterface*> \ |
141 MembersOfThisObjectAndAncestors( \ | 144 MembersOfThisObjectAndAncestors( \ |
142 size_t local_var_additional_capacity) const override { \ | 145 size_t local_var_additional_capacity) const override; \ |
146 \ | |
147 public: | |
148 | |
149 #define WEBRTC_RTCSTATS_IMPL(this_class, parent_class, type_str, ...) \ | |
150 const char this_class::kType[] = type_str; \ | |
151 \ | |
152 std::unique_ptr<webrtc::RTCStats> this_class::copy() const { \ | |
153 return std::unique_ptr<webrtc::RTCStats>(new this_class(*this)); \ | |
154 } \ | |
155 \ | |
156 const char* this_class::type() const { \ | |
157 return this_class::kType; \ | |
158 } \ | |
159 \ | |
160 std::vector<const webrtc::RTCStatsMemberInterface*> \ | |
161 this_class::MembersOfThisObjectAndAncestors( \ | |
162 size_t local_var_additional_capacity) const { \ | |
143 const webrtc::RTCStatsMemberInterface* local_var_members[] = { \ | 163 const webrtc::RTCStatsMemberInterface* local_var_members[] = { \ |
144 __VA_ARGS__ \ | 164 __VA_ARGS__ \ |
145 }; \ | 165 }; \ |
146 size_t local_var_members_count = \ | 166 size_t local_var_members_count = \ |
147 sizeof(local_var_members) / sizeof(local_var_members[0]); \ | 167 sizeof(local_var_members) / sizeof(local_var_members[0]); \ |
148 std::vector<const webrtc::RTCStatsMemberInterface*> local_var_members_vec =\ | 168 std::vector<const webrtc::RTCStatsMemberInterface*> local_var_members_vec =\ |
149 parent_class::MembersOfThisObjectAndAncestors( \ | 169 parent_class::MembersOfThisObjectAndAncestors( \ |
150 local_var_members_count + local_var_additional_capacity); \ | 170 local_var_members_count + local_var_additional_capacity); \ |
151 RTC_DCHECK_GE( \ | 171 RTC_DCHECK_GE( \ |
152 local_var_members_vec.capacity() - local_var_members_vec.size(), \ | 172 local_var_members_vec.capacity() - local_var_members_vec.size(), \ |
153 local_var_members_count + local_var_additional_capacity); \ | 173 local_var_members_count + local_var_additional_capacity); \ |
154 local_var_members_vec.insert(local_var_members_vec.end(), \ | 174 local_var_members_vec.insert(local_var_members_vec.end(), \ |
155 &local_var_members[0], \ | 175 &local_var_members[0], \ |
156 &local_var_members[local_var_members_count]); \ | 176 &local_var_members[local_var_members_count]); \ |
157 return local_var_members_vec; \ | 177 return local_var_members_vec; \ |
158 } \ | 178 } |
159 public: | |
160 | 179 |
161 // Interface for |RTCStats| members, which have a name and a value of a type | 180 // Interface for |RTCStats| members, which have a name and a value of a type |
162 // defined in a subclass. Only the types listed in |Type| are supported, these | 181 // defined in a subclass. Only the types listed in |Type| are supported, these |
163 // are implemented by |RTCStatsMember<T>|. The value of a member may be | 182 // are implemented by |RTCStatsMember<T>|. The value of a member may be |
164 // undefined, the value can only be read if |is_defined|. | 183 // undefined, the value can only be read if |is_defined|. |
165 class RTCStatsMemberInterface { | 184 class RTCStatsMemberInterface { |
166 public: | 185 public: |
167 // Member value types. | 186 // Member value types. |
168 enum Type { | 187 enum Type { |
169 kInt32, // int32_t | 188 kInt32, // int32_t |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 return &value_; | 291 return &value_; |
273 } | 292 } |
274 | 293 |
275 private: | 294 private: |
276 T value_; | 295 T value_; |
277 }; | 296 }; |
278 | 297 |
279 } // namespace webrtc | 298 } // namespace webrtc |
280 | 299 |
281 #endif // WEBRTC_API_STATS_RTCSTATS_H_ | 300 #endif // WEBRTC_API_STATS_RTCSTATS_H_ |
OLD | NEW |