niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 11 | #include <assert.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | #include <stdio.h> |
| 13 | |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 14 | #include "webrtc/voice_engine/statistics.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 16 | #include "webrtc/system_wrappers/include/trace.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | namespace voe { |
| 21 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 22 | Statistics::Statistics(uint32_t instanceId) : |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | _instanceId(instanceId), |
xians@google.com | 22963ab | 2011-08-03 12:40:23 +0000 | [diff] [blame] | 24 | _lastError(0), |
| 25 | _isInitialized(false) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | { |
| 27 | } |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame^] | 28 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | Statistics::~Statistics() |
| 30 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | } |
| 32 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 33 | int32_t Statistics::SetInitialized() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | { |
| 35 | _isInitialized = true; |
| 36 | return 0; |
| 37 | } |
| 38 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 39 | int32_t Statistics::SetUnInitialized() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | { |
| 41 | _isInitialized = false; |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | bool Statistics::Initialized() const |
| 46 | { |
| 47 | return _isInitialized; |
| 48 | } |
| 49 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 50 | int32_t Statistics::SetLastError(int32_t error) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame^] | 52 | rtc::CritScope cs(&lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | _lastError = error; |
| 54 | return 0; |
| 55 | } |
| 56 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 57 | int32_t Statistics::SetLastError(int32_t error, |
| 58 | TraceLevel level) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | WEBRTC_TRACE(level, kTraceVoice, VoEId(_instanceId,-1), |
| 61 | "error code is set to %d", |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame^] | 62 | error); |
| 63 | rtc::CritScope cs(&lock_); |
| 64 | _lastError = error; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | return 0; |
| 66 | } |
| 67 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 68 | int32_t Statistics::SetLastError( |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 69 | int32_t error, |
| 70 | TraceLevel level, const char* msg) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 71 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | char traceMessage[KTraceMaxMessageSize]; |
| 73 | assert(strlen(msg) < KTraceMaxMessageSize); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | sprintf(traceMessage, "%s (error=%d)", msg, error); |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame^] | 75 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | WEBRTC_TRACE(level, kTraceVoice, VoEId(_instanceId,-1), "%s", |
| 77 | traceMessage); |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame^] | 78 | |
| 79 | rtc::CritScope cs(&lock_); |
| 80 | _lastError = error; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 84 | int32_t Statistics::LastError() const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame^] | 86 | int32_t ret; |
| 87 | { |
| 88 | rtc::CritScope cs(&lock_); |
| 89 | ret = _lastError; |
| 90 | } |
| 91 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId, -1), |
| 92 | "LastError() => %d", ret); |
| 93 | return ret; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | } |
| 95 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 96 | } // namespace voe |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 98 | } // namespace webrtc |