Move implementation of types in statstypes. to its cc file.

R=perkj@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/34439004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7850 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
tommi@webrtc.org 2014-12-09 18:18:06 +00:00
parent a954c07ee1
commit c9d155faeb
3 changed files with 333 additions and 259 deletions

View File

@ -36,203 +36,6 @@
#include "webrtc/base/timing.h" #include "webrtc/base/timing.h"
namespace webrtc { namespace webrtc {
// The items below are in alphabetical order.
const char StatsReport::kStatsValueNameActiveConnection[] =
"googActiveConnection";
const char StatsReport::kStatsValueNameActualEncBitrate[] =
"googActualEncBitrate";
const char StatsReport::kStatsValueNameAudioOutputLevel[] = "audioOutputLevel";
const char StatsReport::kStatsValueNameAudioInputLevel[] = "audioInputLevel";
const char StatsReport::kStatsValueNameAvailableReceiveBandwidth[] =
"googAvailableReceiveBandwidth";
const char StatsReport::kStatsValueNameAvailableSendBandwidth[] =
"googAvailableSendBandwidth";
const char StatsReport::kStatsValueNameAvgEncodeMs[] = "googAvgEncodeMs";
const char StatsReport::kStatsValueNameBucketDelay[] = "googBucketDelay";
const char StatsReport::kStatsValueNameBytesReceived[] = "bytesReceived";
const char StatsReport::kStatsValueNameBytesSent[] = "bytesSent";
const char StatsReport::kStatsValueNameBandwidthLimitedResolution[] =
"googBandwidthLimitedResolution";
const char StatsReport::kStatsValueNameCaptureJitterMs[] =
"googCaptureJitterMs";
const char StatsReport::kStatsValueNameCaptureQueueDelayMsPerS[] =
"googCaptureQueueDelayMsPerS";
const char StatsReport::kStatsValueNameChannelId[] = "googChannelId";
const char StatsReport::kStatsValueNameCodecName[] = "googCodecName";
const char StatsReport::kStatsValueNameComponent[] = "googComponent";
const char StatsReport::kStatsValueNameContentName[] = "googContentName";
const char StatsReport::kStatsValueNameCpuLimitedResolution[] =
"googCpuLimitedResolution";
const char StatsReport::kStatsValueNameDecodingCTSG[] =
"googDecodingCTSG";
const char StatsReport::kStatsValueNameDecodingCTN[] =
"googDecodingCTN";
const char StatsReport::kStatsValueNameDecodingNormal[] =
"googDecodingNormal";
const char StatsReport::kStatsValueNameDecodingPLC[] =
"googDecodingPLC";
const char StatsReport::kStatsValueNameDecodingCNG[] =
"googDecodingCNG";
const char StatsReport::kStatsValueNameDecodingPLCCNG[] =
"googDecodingPLCCNG";
const char StatsReport::kStatsValueNameDer[] = "googDerBase64";
// Echo metrics from the audio processing module.
const char StatsReport::kStatsValueNameEchoCancellationQualityMin[] =
"googEchoCancellationQualityMin";
const char StatsReport::kStatsValueNameEchoDelayMedian[] =
"googEchoCancellationEchoDelayMedian";
const char StatsReport::kStatsValueNameEchoDelayStdDev[] =
"googEchoCancellationEchoDelayStdDev";
const char StatsReport::kStatsValueNameEchoReturnLoss[] =
"googEchoCancellationReturnLoss";
const char StatsReport::kStatsValueNameEchoReturnLossEnhancement[] =
"googEchoCancellationReturnLossEnhancement";
const char StatsReport::kStatsValueNameEncodeUsagePercent[] =
"googEncodeUsagePercent";
const char StatsReport::kStatsValueNameExpandRate[] = "googExpandRate";
const char StatsReport::kStatsValueNameFingerprint[] = "googFingerprint";
const char StatsReport::kStatsValueNameFingerprintAlgorithm[] =
"googFingerprintAlgorithm";
const char StatsReport::kStatsValueNameFirsReceived[] = "googFirsReceived";
const char StatsReport::kStatsValueNameFirsSent[] = "googFirsSent";
const char StatsReport::kStatsValueNameFrameHeightInput[] =
"googFrameHeightInput";
const char StatsReport::kStatsValueNameFrameHeightReceived[] =
"googFrameHeightReceived";
const char StatsReport::kStatsValueNameFrameHeightSent[] =
"googFrameHeightSent";
const char StatsReport::kStatsValueNameFrameRateReceived[] =
"googFrameRateReceived";
const char StatsReport::kStatsValueNameFrameRateDecoded[] =
"googFrameRateDecoded";
const char StatsReport::kStatsValueNameFrameRateOutput[] =
"googFrameRateOutput";
const char StatsReport::kStatsValueNameDecodeMs[] = "googDecodeMs";
const char StatsReport::kStatsValueNameMaxDecodeMs[] = "googMaxDecodeMs";
const char StatsReport::kStatsValueNameCurrentDelayMs[] = "googCurrentDelayMs";
const char StatsReport::kStatsValueNameTargetDelayMs[] = "googTargetDelayMs";
const char StatsReport::kStatsValueNameJitterBufferMs[] = "googJitterBufferMs";
const char StatsReport::kStatsValueNameMinPlayoutDelayMs[] =
"googMinPlayoutDelayMs";
const char StatsReport::kStatsValueNameRenderDelayMs[] = "googRenderDelayMs";
const char StatsReport::kStatsValueNameCaptureStartNtpTimeMs[] =
"googCaptureStartNtpTimeMs";
const char StatsReport::kStatsValueNameFrameRateInput[] = "googFrameRateInput";
const char StatsReport::kStatsValueNameFrameRateSent[] = "googFrameRateSent";
const char StatsReport::kStatsValueNameFrameWidthInput[] =
"googFrameWidthInput";
const char StatsReport::kStatsValueNameFrameWidthReceived[] =
"googFrameWidthReceived";
const char StatsReport::kStatsValueNameFrameWidthSent[] = "googFrameWidthSent";
const char StatsReport::kStatsValueNameInitiator[] = "googInitiator";
const char StatsReport::kStatsValueNameIssuerId[] = "googIssuerId";
const char StatsReport::kStatsValueNameJitterReceived[] = "googJitterReceived";
const char StatsReport::kStatsValueNameLocalAddress[] = "googLocalAddress";
const char StatsReport::kStatsValueNameLocalCandidateType[] =
"googLocalCandidateType";
const char StatsReport::kStatsValueNameLocalCertificateId[] =
"googLocalCertificateId";
const char StatsReport::kStatsValueNameAdaptationChanges[] =
"googAdaptationChanges";
const char StatsReport::kStatsValueNameNacksReceived[] = "googNacksReceived";
const char StatsReport::kStatsValueNameNacksSent[] = "googNacksSent";
const char StatsReport::kStatsValueNamePlisReceived[] = "googPlisReceived";
const char StatsReport::kStatsValueNamePlisSent[] = "googPlisSent";
const char StatsReport::kStatsValueNamePacketsReceived[] = "packetsReceived";
const char StatsReport::kStatsValueNamePacketsSent[] = "packetsSent";
const char StatsReport::kStatsValueNamePacketsLost[] = "packetsLost";
const char StatsReport::kStatsValueNamePreferredJitterBufferMs[] =
"googPreferredJitterBufferMs";
const char StatsReport::kStatsValueNameReadable[] = "googReadable";
const char StatsReport::kStatsValueNameRecvPacketGroupArrivalTimeDebug[] =
"googReceivedPacketGroupArrivalTimeDebug";
const char StatsReport::kStatsValueNameRecvPacketGroupPropagationDeltaDebug[] =
"googReceivedPacketGroupPropagationDeltaDebug";
const char
StatsReport::kStatsValueNameRecvPacketGroupPropagationDeltaSumDebug[] =
"googReceivedPacketGroupPropagationDeltaSumDebug";
const char StatsReport::kStatsValueNameRemoteAddress[] = "googRemoteAddress";
const char StatsReport::kStatsValueNameRemoteCandidateType[] =
"googRemoteCandidateType";
const char StatsReport::kStatsValueNameRemoteCertificateId[] =
"googRemoteCertificateId";
const char StatsReport::kStatsValueNameRetransmitBitrate[] =
"googRetransmitBitrate";
const char StatsReport::kStatsValueNameRtt[] = "googRtt";
const char StatsReport::kStatsValueNameSsrc[] = "ssrc";
const char StatsReport::kStatsValueNameSendPacketsDiscarded[] =
"packetsDiscardedOnSend";
const char StatsReport::kStatsValueNameTargetEncBitrate[] =
"googTargetEncBitrate";
const char StatsReport::kStatsValueNameTransmitBitrate[] =
"googTransmitBitrate";
const char StatsReport::kStatsValueNameTransportId[] = "transportId";
const char StatsReport::kStatsValueNameTransportType[] = "googTransportType";
const char StatsReport::kStatsValueNameTrackId[] = "googTrackId";
const char StatsReport::kStatsValueNameTypingNoiseState[] =
"googTypingNoiseState";
const char StatsReport::kStatsValueNameViewLimitedResolution[] =
"googViewLimitedResolution";
const char StatsReport::kStatsValueNameWritable[] = "googWritable";
const char StatsReport::kStatsReportTypeSession[] = "googLibjingleSession";
const char StatsReport::kStatsReportTypeBwe[] = "VideoBwe";
const char StatsReport::kStatsReportTypeRemoteSsrc[] = "remoteSsrc";
const char StatsReport::kStatsReportTypeSsrc[] = "ssrc";
const char StatsReport::kStatsReportTypeTrack[] = "googTrack";
const char StatsReport::kStatsReportTypeIceCandidate[] = "iceCandidate";
const char StatsReport::kStatsReportTypeTransport[] = "googTransport";
const char StatsReport::kStatsReportTypeComponent[] = "googComponent";
const char StatsReport::kStatsReportTypeCandidatePair[] = "googCandidatePair";
const char StatsReport::kStatsReportTypeCertificate[] = "googCertificate";
const char StatsReport::kStatsReportVideoBweId[] = "bweforvideo";
// Implementations of functions in statstypes.h
void StatsReport::AddValue(StatsReport::StatsValueName name,
const std::string& value) {
values.push_back(Value(name, value));
}
void StatsReport::AddValue(StatsReport::StatsValueName name, int64 value) {
AddValue(name, rtc::ToString<int64>(value));
}
template <typename T>
void StatsReport::AddValue(StatsReport::StatsValueName name,
const std::vector<T>& value) {
std::ostringstream oss;
oss << "[";
for (size_t i = 0; i < value.size(); ++i) {
oss << rtc::ToString<T>(value[i]);
if (i != value.size() - 1)
oss << ", ";
}
oss << "]";
AddValue(name, oss.str());
}
void StatsReport::AddBoolean(StatsReport::StatsValueName name, bool value) {
AddValue(name, value ? "true" : "false");
}
void StatsReport::ReplaceValue(StatsReport::StatsValueName name,
const std::string& value) {
for (Values::iterator it = values.begin(); it != values.end(); ++it) {
if ((*it).name == name) {
it->value = value;
return;
}
}
// It is not reachable here, add an ASSERT to make sure the overwriting is
// always a success.
ASSERT(false);
}
namespace { namespace {
double GetTimeNow() { double GetTimeNow() {

View File

@ -29,7 +29,316 @@
namespace webrtc { namespace webrtc {
// TODO(tommi): Move implementation to here from statstypes.h and // The items below are in alphabetical order.
// statscollector.cc. const char StatsReport::kStatsValueNameActiveConnection[] =
"googActiveConnection";
const char StatsReport::kStatsValueNameActualEncBitrate[] =
"googActualEncBitrate";
const char StatsReport::kStatsValueNameAudioOutputLevel[] = "audioOutputLevel";
const char StatsReport::kStatsValueNameAudioInputLevel[] = "audioInputLevel";
const char StatsReport::kStatsValueNameAvailableReceiveBandwidth[] =
"googAvailableReceiveBandwidth";
const char StatsReport::kStatsValueNameAvailableSendBandwidth[] =
"googAvailableSendBandwidth";
const char StatsReport::kStatsValueNameAvgEncodeMs[] = "googAvgEncodeMs";
const char StatsReport::kStatsValueNameBucketDelay[] = "googBucketDelay";
const char StatsReport::kStatsValueNameBytesReceived[] = "bytesReceived";
const char StatsReport::kStatsValueNameBytesSent[] = "bytesSent";
const char StatsReport::kStatsValueNameBandwidthLimitedResolution[] =
"googBandwidthLimitedResolution";
const char StatsReport::kStatsValueNameCaptureJitterMs[] =
"googCaptureJitterMs";
const char StatsReport::kStatsValueNameCaptureQueueDelayMsPerS[] =
"googCaptureQueueDelayMsPerS";
const char StatsReport::kStatsValueNameChannelId[] = "googChannelId";
const char StatsReport::kStatsValueNameCodecName[] = "googCodecName";
const char StatsReport::kStatsValueNameComponent[] = "googComponent";
const char StatsReport::kStatsValueNameContentName[] = "googContentName";
const char StatsReport::kStatsValueNameCpuLimitedResolution[] =
"googCpuLimitedResolution";
const char StatsReport::kStatsValueNameDecodingCTSG[] =
"googDecodingCTSG";
const char StatsReport::kStatsValueNameDecodingCTN[] =
"googDecodingCTN";
const char StatsReport::kStatsValueNameDecodingNormal[] =
"googDecodingNormal";
const char StatsReport::kStatsValueNameDecodingPLC[] =
"googDecodingPLC";
const char StatsReport::kStatsValueNameDecodingCNG[] =
"googDecodingCNG";
const char StatsReport::kStatsValueNameDecodingPLCCNG[] =
"googDecodingPLCCNG";
const char StatsReport::kStatsValueNameDer[] = "googDerBase64";
// Echo metrics from the audio processing module.
const char StatsReport::kStatsValueNameEchoCancellationQualityMin[] =
"googEchoCancellationQualityMin";
const char StatsReport::kStatsValueNameEchoDelayMedian[] =
"googEchoCancellationEchoDelayMedian";
const char StatsReport::kStatsValueNameEchoDelayStdDev[] =
"googEchoCancellationEchoDelayStdDev";
const char StatsReport::kStatsValueNameEchoReturnLoss[] =
"googEchoCancellationReturnLoss";
const char StatsReport::kStatsValueNameEchoReturnLossEnhancement[] =
"googEchoCancellationReturnLossEnhancement";
const char StatsReport::kStatsValueNameEncodeUsagePercent[] =
"googEncodeUsagePercent";
const char StatsReport::kStatsValueNameExpandRate[] = "googExpandRate";
const char StatsReport::kStatsValueNameFingerprint[] = "googFingerprint";
const char StatsReport::kStatsValueNameFingerprintAlgorithm[] =
"googFingerprintAlgorithm";
const char StatsReport::kStatsValueNameFirsReceived[] = "googFirsReceived";
const char StatsReport::kStatsValueNameFirsSent[] = "googFirsSent";
const char StatsReport::kStatsValueNameFrameHeightInput[] =
"googFrameHeightInput";
const char StatsReport::kStatsValueNameFrameHeightReceived[] =
"googFrameHeightReceived";
const char StatsReport::kStatsValueNameFrameHeightSent[] =
"googFrameHeightSent";
const char StatsReport::kStatsValueNameFrameRateReceived[] =
"googFrameRateReceived";
const char StatsReport::kStatsValueNameFrameRateDecoded[] =
"googFrameRateDecoded";
const char StatsReport::kStatsValueNameFrameRateOutput[] =
"googFrameRateOutput";
const char StatsReport::kStatsValueNameDecodeMs[] = "googDecodeMs";
const char StatsReport::kStatsValueNameMaxDecodeMs[] = "googMaxDecodeMs";
const char StatsReport::kStatsValueNameCurrentDelayMs[] = "googCurrentDelayMs";
const char StatsReport::kStatsValueNameTargetDelayMs[] = "googTargetDelayMs";
const char StatsReport::kStatsValueNameJitterBufferMs[] = "googJitterBufferMs";
const char StatsReport::kStatsValueNameMinPlayoutDelayMs[] =
"googMinPlayoutDelayMs";
const char StatsReport::kStatsValueNameRenderDelayMs[] = "googRenderDelayMs";
const char StatsReport::kStatsValueNameCaptureStartNtpTimeMs[] =
"googCaptureStartNtpTimeMs";
const char StatsReport::kStatsValueNameFrameRateInput[] = "googFrameRateInput";
const char StatsReport::kStatsValueNameFrameRateSent[] = "googFrameRateSent";
const char StatsReport::kStatsValueNameFrameWidthInput[] =
"googFrameWidthInput";
const char StatsReport::kStatsValueNameFrameWidthReceived[] =
"googFrameWidthReceived";
const char StatsReport::kStatsValueNameFrameWidthSent[] = "googFrameWidthSent";
const char StatsReport::kStatsValueNameInitiator[] = "googInitiator";
const char StatsReport::kStatsValueNameIssuerId[] = "googIssuerId";
const char StatsReport::kStatsValueNameJitterReceived[] = "googJitterReceived";
const char StatsReport::kStatsValueNameLocalAddress[] = "googLocalAddress";
const char StatsReport::kStatsValueNameLocalCandidateType[] =
"googLocalCandidateType";
const char StatsReport::kStatsValueNameLocalCertificateId[] =
"googLocalCertificateId";
const char StatsReport::kStatsValueNameAdaptationChanges[] =
"googAdaptationChanges";
const char StatsReport::kStatsValueNameNacksReceived[] = "googNacksReceived";
const char StatsReport::kStatsValueNameNacksSent[] = "googNacksSent";
const char StatsReport::kStatsValueNamePlisReceived[] = "googPlisReceived";
const char StatsReport::kStatsValueNamePlisSent[] = "googPlisSent";
const char StatsReport::kStatsValueNamePacketsReceived[] = "packetsReceived";
const char StatsReport::kStatsValueNamePacketsSent[] = "packetsSent";
const char StatsReport::kStatsValueNamePacketsLost[] = "packetsLost";
const char StatsReport::kStatsValueNamePreferredJitterBufferMs[] =
"googPreferredJitterBufferMs";
const char StatsReport::kStatsValueNameReadable[] = "googReadable";
const char StatsReport::kStatsValueNameRecvPacketGroupArrivalTimeDebug[] =
"googReceivedPacketGroupArrivalTimeDebug";
const char StatsReport::kStatsValueNameRecvPacketGroupPropagationDeltaDebug[] =
"googReceivedPacketGroupPropagationDeltaDebug";
const char
StatsReport::kStatsValueNameRecvPacketGroupPropagationDeltaSumDebug[] =
"googReceivedPacketGroupPropagationDeltaSumDebug";
const char StatsReport::kStatsValueNameRemoteAddress[] = "googRemoteAddress";
const char StatsReport::kStatsValueNameRemoteCandidateType[] =
"googRemoteCandidateType";
const char StatsReport::kStatsValueNameRemoteCertificateId[] =
"googRemoteCertificateId";
const char StatsReport::kStatsValueNameRetransmitBitrate[] =
"googRetransmitBitrate";
const char StatsReport::kStatsValueNameRtt[] = "googRtt";
const char StatsReport::kStatsValueNameSsrc[] = "ssrc";
const char StatsReport::kStatsValueNameSendPacketsDiscarded[] =
"packetsDiscardedOnSend";
const char StatsReport::kStatsValueNameTargetEncBitrate[] =
"googTargetEncBitrate";
const char StatsReport::kStatsValueNameTransmitBitrate[] =
"googTransmitBitrate";
const char StatsReport::kStatsValueNameTransportId[] = "transportId";
const char StatsReport::kStatsValueNameTransportType[] = "googTransportType";
const char StatsReport::kStatsValueNameTrackId[] = "googTrackId";
const char StatsReport::kStatsValueNameTypingNoiseState[] =
"googTypingNoiseState";
const char StatsReport::kStatsValueNameViewLimitedResolution[] =
"googViewLimitedResolution";
const char StatsReport::kStatsValueNameWritable[] = "googWritable";
const char StatsReport::kStatsReportTypeSession[] = "googLibjingleSession";
const char StatsReport::kStatsReportTypeBwe[] = "VideoBwe";
const char StatsReport::kStatsReportTypeRemoteSsrc[] = "remoteSsrc";
const char StatsReport::kStatsReportTypeSsrc[] = "ssrc";
const char StatsReport::kStatsReportTypeTrack[] = "googTrack";
const char StatsReport::kStatsReportTypeIceCandidate[] = "iceCandidate";
const char StatsReport::kStatsReportTypeTransport[] = "googTransport";
const char StatsReport::kStatsReportTypeComponent[] = "googComponent";
const char StatsReport::kStatsReportTypeCandidatePair[] = "googCandidatePair";
const char StatsReport::kStatsReportTypeCertificate[] = "googCertificate";
const char StatsReport::kStatsReportVideoBweId[] = "bweforvideo";
StatsReport::StatsReport(const StatsReport& src)
: id(src.id),
type(src.type),
timestamp(src.timestamp),
values(src.values) {
}
StatsReport::StatsReport(const std::string& id)
: id(id), timestamp(0) {
}
StatsReport& StatsReport::operator=(const StatsReport& src) {
ASSERT(id == src.id);
type = src.type;
timestamp = src.timestamp;
values = src.values;
return *this;
}
// Operators provided for STL container/algorithm support.
bool StatsReport::operator<(const StatsReport& other) const {
return id < other.id;
}
bool StatsReport::operator==(const StatsReport& other) const {
return id == other.id;
}
// Special support for being able to use std::find on a container
// without requiring a new StatsReport instance.
bool StatsReport::operator==(const std::string& other_id) const {
return id == other_id;
}
StatsReport::Value::Value()
: name(NULL) {
}
// The copy ctor can't be declared as explicit due to problems with STL.
StatsReport::Value::Value(const Value& other)
: name(other.name), value(other.value) {
}
StatsReport::Value::Value(StatsValueName name)
: name(name) {
}
StatsReport::Value::Value(StatsValueName name, const std::string& value)
: name(name), value(value) {
}
StatsReport::Value& StatsReport::Value::operator=(const Value& other) {
const_cast<StatsValueName&>(name) = other.name;
value = other.value;
return *this;
}
// TODO(tommi): Change implementation to do a simple enum value-to-static-
// string conversion when client code has been updated to use this method
// instead of the |name| member variable.
const char* StatsReport::Value::display_name() const {
return name;
}
void StatsReport::AddValue(StatsReport::StatsValueName name,
const std::string& value) {
values.push_back(Value(name, value));
}
void StatsReport::AddValue(StatsReport::StatsValueName name, int64 value) {
AddValue(name, rtc::ToString<int64>(value));
}
template <typename T>
void StatsReport::AddValue(StatsReport::StatsValueName name,
const std::vector<T>& value) {
std::ostringstream oss;
oss << "[";
for (size_t i = 0; i < value.size(); ++i) {
oss << rtc::ToString<T>(value[i]);
if (i != value.size() - 1)
oss << ", ";
}
oss << "]";
AddValue(name, oss.str());
}
// Implementation specializations for the variants of AddValue that we use.
// TODO(tommi): Converting these ints to strings and copying strings, is not
// very efficient. Figure out a way to reduce the string churn.
template
void StatsReport::AddValue<std::string>(
StatsReport::StatsValueName, const std::vector<std::string>&);
template
void StatsReport::AddValue<int>(
StatsReport::StatsValueName, const std::vector<int>&);
template
void StatsReport::AddValue<int64_t>(
StatsReport::StatsValueName, const std::vector<int64_t>&);
void StatsReport::AddBoolean(StatsReport::StatsValueName name, bool value) {
AddValue(name, value ? "true" : "false");
}
void StatsReport::ReplaceValue(StatsReport::StatsValueName name,
const std::string& value) {
for (Values::iterator it = values.begin(); it != values.end(); ++it) {
if ((*it).name == name) {
it->value = value;
return;
}
}
// It is not reachable here, add an ASSERT to make sure the overwriting is
// always a success.
ASSERT(false);
}
StatsSet::StatsSet() {
}
StatsSet::~StatsSet() {
}
StatsSet::const_iterator StatsSet::begin() const {
return list_.begin();
}
StatsSet::const_iterator StatsSet::end() const {
return list_.end();
}
StatsReport* StatsSet::InsertNew(const std::string& id) {
ASSERT(Find(id) == NULL);
const StatsReport* ret = &(*list_.insert(StatsReportCopyable(id)).first);
return const_cast<StatsReport*>(ret);
}
StatsReport* StatsSet::FindOrAddNew(const std::string& id) {
StatsReport* ret = Find(id);
return ret ? ret : InsertNew(id);
}
StatsReport* StatsSet::ReplaceOrAddNew(const std::string& id) {
list_.erase(id);
return InsertNew(id);
}
// Looks for a report with the given |id|. If one is not found, NULL
// will be returned.
StatsReport* StatsSet::Find(const std::string& id) {
const_iterator it = std::find(begin(), end(), id);
return it == end() ? NULL :
const_cast<StatsReport*>(static_cast<const StatsReport*>(&(*it)));
}
} // namespace webrtc } // namespace webrtc

View File

@ -42,40 +42,24 @@
namespace webrtc { namespace webrtc {
// TODO(tommi): Move all the implementation that's in this file and
// statscollector.cc related to these types, into a new, statstypes.cc file.
class StatsReport { class StatsReport {
public: public:
// TODO(tommi): Remove this ctor.
StatsReport() : timestamp(0) {}
// TODO(tommi): Make protected and disallow copy completely once not needed. // TODO(tommi): Make protected and disallow copy completely once not needed.
StatsReport(const StatsReport& src) StatsReport(const StatsReport& src);
: id(src.id),
type(src.type),
timestamp(src.timestamp),
values(src.values) {}
// TODO(tommi): Make this copy constructor protected.
StatsReport& operator=(const StatsReport& src) {
ASSERT(id == src.id);
type = src.type;
timestamp = src.timestamp;
values = src.values;
return *this;
}
// Constructor is protected to force use of StatsSet. // Constructor is protected to force use of StatsSet.
// TODO(tommi): Make this ctor protected. // TODO(tommi): Make this ctor protected.
explicit StatsReport(const std::string& id) : id(id), timestamp(0) {} explicit StatsReport(const std::string& id);
// TODO(tommi): Make this protected.
StatsReport& operator=(const StatsReport& src);
// Operators provided for STL container/algorithm support. // Operators provided for STL container/algorithm support.
bool operator<(const StatsReport& other) const { return id < other.id; } bool operator<(const StatsReport& other) const;
bool operator==(const StatsReport& other) const { return id == other.id; } bool operator==(const StatsReport& other) const;
// Special support for being able to use std::find on a container // Special support for being able to use std::find on a container
// without requiring a new StatsReport instance. // without requiring a new StatsReport instance.
bool operator==(const std::string& other_id) const { return id == other_id; } bool operator==(const std::string& other_id) const;
// TODO(tommi): Change this to be an enum type that holds all the // TODO(tommi): Change this to be an enum type that holds all the
// kStatsValueName constants. // kStatsValueName constants.
@ -89,27 +73,21 @@ class StatsReport {
std::string type; // See below for contents. std::string type; // See below for contents.
struct Value { struct Value {
Value() : name(NULL) {} Value();
// The copy ctor can't be declared as explicit due to problems with STL. // The copy ctor can't be declared as explicit due to problems with STL.
Value(const Value& other) : name(other.name), value(other.value) {} Value(const Value& other);
explicit Value(StatsValueName name) : name(name) {} explicit Value(StatsValueName name);
Value(StatsValueName name, const std::string& value) Value(StatsValueName name, const std::string& value);
: name(name), value(value) {
}
// TODO(tommi): Remove this operator once we don't need it. // TODO(tommi): Remove this operator once we don't need it.
// The operator is provided for compatibility with STL containers. // The operator is provided for compatibility with STL containers.
// The public |name| member variable is otherwise meant to be read-only. // The public |name| member variable is otherwise meant to be read-only.
Value& operator=(const Value& other) { Value& operator=(const Value& other);
const_cast<StatsValueName&>(name) = other.name;
value = other.value;
return *this;
}
// TODO(tommi): Change implementation to do a simple enum value-to-static- // TODO(tommi): Change implementation to do a simple enum value-to-static-
// string conversion when client code has been updated to use this method // string conversion when client code has been updated to use this method
// instead of the |name| member variable. // instead of the |name| member variable.
const char* display_name() const { return name; } const char* display_name() const;
const StatsValueName name; const StatsValueName name;
@ -302,41 +280,25 @@ typedef std::vector<const StatsReport*> StatsReports;
// TODO(tommi): Use a thread checker here (currently not in libjingle). // TODO(tommi): Use a thread checker here (currently not in libjingle).
class StatsSet { class StatsSet {
public: public:
StatsSet() {} StatsSet();
~StatsSet() {} ~StatsSet();
typedef std::set<StatsReportCopyable> Container; typedef std::set<StatsReportCopyable> Container;
typedef Container::iterator iterator; typedef Container::iterator iterator;
typedef Container::const_iterator const_iterator; typedef Container::const_iterator const_iterator;
const_iterator begin() const { return list_.begin(); } const_iterator begin() const;
const_iterator end() const { return list_.end(); } const_iterator end() const;
// Creates a new report object with |id| that does not already // Creates a new report object with |id| that does not already
// exist in the list of reports. // exist in the list of reports.
StatsReport* InsertNew(const std::string& id) { StatsReport* InsertNew(const std::string& id);
ASSERT(Find(id) == NULL); StatsReport* FindOrAddNew(const std::string& id);
const StatsReport* ret = &(*list_.insert(StatsReportCopyable(id)).first); StatsReport* ReplaceOrAddNew(const std::string& id);
return const_cast<StatsReport*>(ret);
}
StatsReport* FindOrAddNew(const std::string& id) {
StatsReport* ret = Find(id);
return ret ? ret : InsertNew(id);
}
StatsReport* ReplaceOrAddNew(const std::string& id) {
list_.erase(id);
return InsertNew(id);
}
// Looks for a report with the given |id|. If one is not found, NULL // Looks for a report with the given |id|. If one is not found, NULL
// will be returned. // will be returned.
StatsReport* Find(const std::string& id) { StatsReport* Find(const std::string& id);
const_iterator it = std::find(begin(), end(), id);
return it == end() ? NULL :
const_cast<StatsReport*>(static_cast<const StatsReport*>(&(*it)));
}
private: private:
Container list_; Container list_;