andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 1 | /* |
| 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.org | 50ff6a5 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 11 | #include <assert.h> |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 12 | #include <stdio.h> |
| 13 | |
pbos@webrtc.org | be72fe4 | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 14 | #include "webrtc/voice_engine/statistics.h" |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 15 | |
pbos@webrtc.org | be72fe4 | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 16 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 17 | #include "webrtc/system_wrappers/interface/trace.h" |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | namespace voe { |
| 22 | |
pbos@webrtc.org | 07a1c11 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 23 | Statistics::Statistics(uint32_t instanceId) : |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 24 | _critPtr(CriticalSectionWrapper::CreateCriticalSection()), |
| 25 | _instanceId(instanceId), |
| 26 | _lastError(0), |
| 27 | _isInitialized(false) |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | Statistics::~Statistics() |
| 32 | { |
| 33 | if (_critPtr) |
| 34 | { |
| 35 | delete _critPtr; |
| 36 | _critPtr = NULL; |
| 37 | } |
| 38 | } |
| 39 | |
pbos@webrtc.org | 1d46b92 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 40 | int32_t Statistics::SetInitialized() |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 41 | { |
| 42 | _isInitialized = true; |
| 43 | return 0; |
| 44 | } |
| 45 | |
pbos@webrtc.org | 1d46b92 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 46 | int32_t Statistics::SetUnInitialized() |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 47 | { |
| 48 | _isInitialized = false; |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | bool Statistics::Initialized() const |
| 53 | { |
| 54 | return _isInitialized; |
| 55 | } |
| 56 | |
pbos@webrtc.org | 07a1c11 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 57 | int32_t Statistics::SetLastError(int32_t error) const |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 58 | { |
| 59 | CriticalSectionScoped cs(_critPtr); |
| 60 | _lastError = error; |
| 61 | return 0; |
| 62 | } |
| 63 | |
pbos@webrtc.org | 07a1c11 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 64 | int32_t Statistics::SetLastError(int32_t error, |
| 65 | TraceLevel level) const |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 1d46b92 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 75 | int32_t Statistics::SetLastError( |
pbos@webrtc.org | 07a1c11 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 76 | int32_t error, |
| 77 | TraceLevel level, const char* msg) const |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 1d46b92 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 89 | int32_t Statistics::LastError() const |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 90 | { |
| 91 | CriticalSectionScoped cs(_critPtr); |
| 92 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId,-1), |
| 93 | "LastError() => %d", _lastError); |
| 94 | return _lastError; |
| 95 | } |
| 96 | |
pbos@webrtc.org | 5ab7b93 | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 97 | } // namespace voe |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 98 | |
pbos@webrtc.org | 5ab7b93 | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 99 | } // namespace webrtc |