blob: 4717fd139198f6116e0576a022ba7e25b2e37d7c [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
2 * Copyright (c) 2012 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
pbos@webrtc.org3f45c2e2013-08-05 16:22:53 +000011#include <assert.h>
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000012#include <stdio.h>
13
pbos@webrtc.org471ae722013-05-21 13:52:32 +000014#include "webrtc/voice_engine/statistics.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000015
pbos@webrtc.org471ae722013-05-21 13:52:32 +000016#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
17#include "webrtc/system_wrappers/interface/trace.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000018
19namespace webrtc {
20
21namespace voe {
22
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000023Statistics::Statistics(uint32_t instanceId) :
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000024 _critPtr(CriticalSectionWrapper::CreateCriticalSection()),
25 _instanceId(instanceId),
26 _lastError(0),
27 _isInitialized(false)
28{
29}
30
31Statistics::~Statistics()
32{
33 if (_critPtr)
34 {
35 delete _critPtr;
36 _critPtr = NULL;
37 }
38}
39
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000040int32_t Statistics::SetInitialized()
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000041{
42 _isInitialized = true;
43 return 0;
44}
45
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000046int32_t Statistics::SetUnInitialized()
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000047{
48 _isInitialized = false;
49 return 0;
50}
51
52bool Statistics::Initialized() const
53{
54 return _isInitialized;
55}
56
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000057int32_t Statistics::SetLastError(int32_t error) const
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000058{
59 CriticalSectionScoped cs(_critPtr);
60 _lastError = error;
61 return 0;
62}
63
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000064int32_t Statistics::SetLastError(int32_t error,
65 TraceLevel level) const
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000066{
67 CriticalSectionScoped cs(_critPtr);
68 _lastError = error;
69 WEBRTC_TRACE(level, kTraceVoice, VoEId(_instanceId,-1),
70 "error code is set to %d",
71 _lastError);
72 return 0;
73}
74
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000075int32_t Statistics::SetLastError(
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000076 int32_t error,
77 TraceLevel level, const char* msg) const
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000078{
79 CriticalSectionScoped cs(_critPtr);
80 char traceMessage[KTraceMaxMessageSize];
81 assert(strlen(msg) < KTraceMaxMessageSize);
82 _lastError = error;
83 sprintf(traceMessage, "%s (error=%d)", msg, error);
84 WEBRTC_TRACE(level, kTraceVoice, VoEId(_instanceId,-1), "%s",
85 traceMessage);
86 return 0;
87}
88
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000089int32_t Statistics::LastError() const
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000090{
91 CriticalSectionScoped cs(_critPtr);
92 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId,-1),
93 "LastError() => %d", _lastError);
94 return _lastError;
95}
96
pbos@webrtc.org3b89e102013-07-03 15:12:26 +000097} // namespace voe
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000098
pbos@webrtc.org3b89e102013-07-03 15:12:26 +000099} // namespace webrtc