blob: a5340300c4c202e1e58f6843b568559774b4a2b9 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
2 * Copyright (c) 2011 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
11#include <cassert>
12#include <stdio.h>
13
14#include "statistics.h"
15
16#include "trace.h"
17#include "critical_section_wrapper.h"
18
19namespace webrtc {
20
21namespace voe {
22
23Statistics::Statistics(const WebRtc_UWord32 instanceId) :
24 _critPtr(CriticalSectionWrapper::CreateCriticalSection()),
25 _instanceId(instanceId),
xians@google.com22963ab2011-08-03 12:40:23 +000026 _lastError(0),
27 _isInitialized(false)
niklase@google.com470e71d2011-07-07 08:21:25 +000028{
29}
30
31Statistics::~Statistics()
32{
33 if (_critPtr)
34 {
35 delete _critPtr;
36 _critPtr = NULL;
37 }
38}
39
40WebRtc_Word32 Statistics::SetInitialized()
41{
42 _isInitialized = true;
43 return 0;
44}
45
46WebRtc_Word32 Statistics::SetUnInitialized()
47{
48 _isInitialized = false;
49 return 0;
50}
51
52bool Statistics::Initialized() const
53{
54 return _isInitialized;
55}
56
57WebRtc_Word32 Statistics::SetLastError(const WebRtc_Word32 error) const
58{
59 CriticalSectionScoped cs(*_critPtr);
60 _lastError = error;
61 return 0;
62}
63
64WebRtc_Word32 Statistics::SetLastError(const WebRtc_Word32 error,
65 const TraceLevel level) const
66{
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
75WebRtc_Word32 Statistics::SetLastError(
76 const WebRtc_Word32 error,
77 const TraceLevel level, const char* msg) const
78{
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
89WebRtc_Word32 Statistics::LastError() const
90{
91 CriticalSectionScoped cs(*_critPtr);
92 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId,-1),
93 "LastError() => %d", _lastError);
94 return _lastError;
95}
96
97} // namespace voe
98
99} // namespace webrtc