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 11 #include <assert.h> 12 #include <stdio.h> 13 14 #include "webrtc/voice_engine/statistics.h" 15 16 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" 17 #include "webrtc/system_wrappers/interface/trace.h" 18 19 namespace webrtc { 20 21 namespace voe { 22 23 Statistics::Statistics(uint32_t instanceId) : 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 40 int32_t Statistics::SetInitialized() 41 { 42 _isInitialized = true; 43 return 0; 44 } 45 46 int32_t Statistics::SetUnInitialized() 47 { 48 _isInitialized = false; 49 return 0; 50 } 51 52 bool Statistics::Initialized() const 53 { 54 return _isInitialized; 55 } 56 57 int32_t Statistics::SetLastError(int32_t error) const 58 { 59 CriticalSectionScoped cs(_critPtr); 60 _lastError = error; 61 return 0; 62 } 63 64 int32_t Statistics::SetLastError(int32_t error, 65 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 75 int32_t Statistics::SetLastError( 76 int32_t error, 77 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 89 int32_t 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 100