| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <assert.h> | 11 #include <assert.h> |
| 12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 | 13 |
| 14 #include "webrtc/voice_engine/statistics.h" | 14 #include "webrtc/voice_engine/statistics.h" |
| 15 | 15 |
| 16 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | |
| 17 #include "webrtc/system_wrappers/include/trace.h" | 16 #include "webrtc/system_wrappers/include/trace.h" |
| 18 | 17 |
| 19 namespace webrtc { | 18 namespace webrtc { |
| 20 | 19 |
| 21 namespace voe { | 20 namespace voe { |
| 22 | 21 |
| 23 Statistics::Statistics(uint32_t instanceId) : | 22 Statistics::Statistics(uint32_t instanceId) : |
| 24 _critPtr(CriticalSectionWrapper::CreateCriticalSection()), | |
| 25 _instanceId(instanceId), | 23 _instanceId(instanceId), |
| 26 _lastError(0), | 24 _lastError(0), |
| 27 _isInitialized(false) | 25 _isInitialized(false) |
| 28 { | 26 { |
| 29 } | 27 } |
| 30 » | 28 |
| 31 Statistics::~Statistics() | 29 Statistics::~Statistics() |
| 32 { | 30 { |
| 33 if (_critPtr) | |
| 34 { | |
| 35 delete _critPtr; | |
| 36 _critPtr = NULL; | |
| 37 } | |
| 38 } | 31 } |
| 39 | 32 |
| 40 int32_t Statistics::SetInitialized() | 33 int32_t Statistics::SetInitialized() |
| 41 { | 34 { |
| 42 _isInitialized = true; | 35 _isInitialized = true; |
| 43 return 0; | 36 return 0; |
| 44 } | 37 } |
| 45 | 38 |
| 46 int32_t Statistics::SetUnInitialized() | 39 int32_t Statistics::SetUnInitialized() |
| 47 { | 40 { |
| 48 _isInitialized = false; | 41 _isInitialized = false; |
| 49 return 0; | 42 return 0; |
| 50 } | 43 } |
| 51 | 44 |
| 52 bool Statistics::Initialized() const | 45 bool Statistics::Initialized() const |
| 53 { | 46 { |
| 54 return _isInitialized; | 47 return _isInitialized; |
| 55 } | 48 } |
| 56 | 49 |
| 57 int32_t Statistics::SetLastError(int32_t error) const | 50 int32_t Statistics::SetLastError(int32_t error) const |
| 58 { | 51 { |
| 59 CriticalSectionScoped cs(_critPtr); | 52 rtc::CritScope cs(&lock_); |
| 60 _lastError = error; | 53 _lastError = error; |
| 61 return 0; | 54 return 0; |
| 62 } | 55 } |
| 63 | 56 |
| 64 int32_t Statistics::SetLastError(int32_t error, | 57 int32_t Statistics::SetLastError(int32_t error, |
| 65 TraceLevel level) const | 58 TraceLevel level) const |
| 66 { | 59 { |
| 67 CriticalSectionScoped cs(_critPtr); | |
| 68 _lastError = error; | |
| 69 WEBRTC_TRACE(level, kTraceVoice, VoEId(_instanceId,-1), | 60 WEBRTC_TRACE(level, kTraceVoice, VoEId(_instanceId,-1), |
| 70 "error code is set to %d", | 61 "error code is set to %d", |
| 71 _lastError); | 62 error); |
| 63 rtc::CritScope cs(&lock_); |
| 64 _lastError = error; |
| 72 return 0; | 65 return 0; |
| 73 } | 66 } |
| 74 | 67 |
| 75 int32_t Statistics::SetLastError( | 68 int32_t Statistics::SetLastError( |
| 76 int32_t error, | 69 int32_t error, |
| 77 TraceLevel level, const char* msg) const | 70 TraceLevel level, const char* msg) const |
| 78 { | 71 { |
| 79 CriticalSectionScoped cs(_critPtr); | |
| 80 char traceMessage[KTraceMaxMessageSize]; | 72 char traceMessage[KTraceMaxMessageSize]; |
| 81 assert(strlen(msg) < KTraceMaxMessageSize); | 73 assert(strlen(msg) < KTraceMaxMessageSize); |
| 82 _lastError = error; | |
| 83 sprintf(traceMessage, "%s (error=%d)", msg, error); | 74 sprintf(traceMessage, "%s (error=%d)", msg, error); |
| 75 |
| 84 WEBRTC_TRACE(level, kTraceVoice, VoEId(_instanceId,-1), "%s", | 76 WEBRTC_TRACE(level, kTraceVoice, VoEId(_instanceId,-1), "%s", |
| 85 traceMessage); | 77 traceMessage); |
| 78 |
| 79 rtc::CritScope cs(&lock_); |
| 80 _lastError = error; |
| 86 return 0; | 81 return 0; |
| 87 } | 82 } |
| 88 | 83 |
| 89 int32_t Statistics::LastError() const | 84 int32_t Statistics::LastError() const |
| 90 { | 85 { |
| 91 CriticalSectionScoped cs(_critPtr); | 86 int32_t ret; |
| 92 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId,-1), | 87 { |
| 93 "LastError() => %d", _lastError); | 88 rtc::CritScope cs(&lock_); |
| 94 return _lastError; | 89 ret = _lastError; |
| 90 } |
| 91 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId, -1), |
| 92 "LastError() => %d", ret); |
| 93 return ret; |
| 95 } | 94 } |
| 96 | 95 |
| 97 } // namespace voe | 96 } // namespace voe |
| 98 | 97 |
| 99 } // namespace webrtc | 98 } // namespace webrtc |
| OLD | NEW |