blob: 0d8250fa98a10f66f2fbcc63b218d8c1f234c27c [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
mflodman@webrtc.org9a065d12012-03-07 08:12:21 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.org12dc1a32013-08-05 16:22:53 +000011#include <assert.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000012#include <stdio.h>
13
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000014#include "webrtc/voice_engine/statistics.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000015
Henrik Kjellander98f53512015-10-28 18:17:40 +010016#include "webrtc/system_wrappers/include/trace.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
18namespace webrtc {
19
20namespace voe {
21
pbos@webrtc.org92135212013-05-14 08:31:39 +000022Statistics::Statistics(uint32_t instanceId) :
niklase@google.com470e71d2011-07-07 08:21:25 +000023 _instanceId(instanceId),
xians@google.com22963ab2011-08-03 12:40:23 +000024 _lastError(0),
25 _isInitialized(false)
niklase@google.com470e71d2011-07-07 08:21:25 +000026{
27}
tommi31fc21f2016-01-21 10:37:37 -080028
niklase@google.com470e71d2011-07-07 08:21:25 +000029Statistics::~Statistics()
30{
niklase@google.com470e71d2011-07-07 08:21:25 +000031}
32
pbos@webrtc.org6141e132013-04-09 10:09:10 +000033int32_t Statistics::SetInitialized()
niklase@google.com470e71d2011-07-07 08:21:25 +000034{
35 _isInitialized = true;
36 return 0;
37}
38
pbos@webrtc.org6141e132013-04-09 10:09:10 +000039int32_t Statistics::SetUnInitialized()
niklase@google.com470e71d2011-07-07 08:21:25 +000040{
41 _isInitialized = false;
42 return 0;
43}
44
45bool Statistics::Initialized() const
46{
47 return _isInitialized;
48}
49
pbos@webrtc.org92135212013-05-14 08:31:39 +000050int32_t Statistics::SetLastError(int32_t error) const
niklase@google.com470e71d2011-07-07 08:21:25 +000051{
tommi31fc21f2016-01-21 10:37:37 -080052 rtc::CritScope cs(&lock_);
niklase@google.com470e71d2011-07-07 08:21:25 +000053 _lastError = error;
54 return 0;
55}
56
pbos@webrtc.org92135212013-05-14 08:31:39 +000057int32_t Statistics::SetLastError(int32_t error,
58 TraceLevel level) const
niklase@google.com470e71d2011-07-07 08:21:25 +000059{
niklase@google.com470e71d2011-07-07 08:21:25 +000060 WEBRTC_TRACE(level, kTraceVoice, VoEId(_instanceId,-1),
61 "error code is set to %d",
tommi31fc21f2016-01-21 10:37:37 -080062 error);
63 rtc::CritScope cs(&lock_);
64 _lastError = error;
niklase@google.com470e71d2011-07-07 08:21:25 +000065 return 0;
66}
67
pbos@webrtc.org6141e132013-04-09 10:09:10 +000068int32_t Statistics::SetLastError(
pbos@webrtc.org92135212013-05-14 08:31:39 +000069 int32_t error,
70 TraceLevel level, const char* msg) const
niklase@google.com470e71d2011-07-07 08:21:25 +000071{
niklase@google.com470e71d2011-07-07 08:21:25 +000072 char traceMessage[KTraceMaxMessageSize];
73 assert(strlen(msg) < KTraceMaxMessageSize);
niklase@google.com470e71d2011-07-07 08:21:25 +000074 sprintf(traceMessage, "%s (error=%d)", msg, error);
tommi31fc21f2016-01-21 10:37:37 -080075
niklase@google.com470e71d2011-07-07 08:21:25 +000076 WEBRTC_TRACE(level, kTraceVoice, VoEId(_instanceId,-1), "%s",
77 traceMessage);
tommi31fc21f2016-01-21 10:37:37 -080078
79 rtc::CritScope cs(&lock_);
80 _lastError = error;
niklase@google.com470e71d2011-07-07 08:21:25 +000081 return 0;
82}
83
pbos@webrtc.org6141e132013-04-09 10:09:10 +000084int32_t Statistics::LastError() const
niklase@google.com470e71d2011-07-07 08:21:25 +000085{
tommi31fc21f2016-01-21 10:37:37 -080086 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.com470e71d2011-07-07 08:21:25 +000094}
95
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000096} // namespace voe
niklase@google.com470e71d2011-07-07 08:21:25 +000097
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000098} // namespace webrtc