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 | |
| 11 | #include "critical_section_wrapper.h" |
| 12 | #include "monitor_module.h" |
| 13 | |
| 14 | namespace webrtc { |
| 15 | |
| 16 | namespace voe { |
| 17 | |
| 18 | MonitorModule::MonitorModule() : |
| 19 | _observerPtr(NULL), |
| 20 | _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()), |
| 21 | _lastProcessTime(GET_TIME_IN_MS()) |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | MonitorModule::~MonitorModule() |
| 26 | { |
| 27 | delete &_callbackCritSect; |
| 28 | } |
| 29 | |
| 30 | WebRtc_Word32 |
| 31 | MonitorModule::RegisterObserver(MonitorObserver& observer) |
| 32 | { |
| 33 | CriticalSectionScoped lock(&_callbackCritSect); |
| 34 | if (_observerPtr) |
| 35 | { |
| 36 | return -1; |
| 37 | } |
| 38 | _observerPtr = &observer; |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | WebRtc_Word32 |
| 43 | MonitorModule::DeRegisterObserver() |
| 44 | { |
| 45 | CriticalSectionScoped lock(&_callbackCritSect); |
| 46 | if (!_observerPtr) |
| 47 | { |
| 48 | return 0; |
| 49 | } |
| 50 | _observerPtr = NULL; |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | WebRtc_Word32 |
| 55 | MonitorModule::Version(char* version, |
| 56 | WebRtc_UWord32& remainingBufferInBytes, |
| 57 | WebRtc_UWord32& position) const |
| 58 | { |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | WebRtc_Word32 |
| 63 | MonitorModule::ChangeUniqueId(const WebRtc_Word32 id) |
| 64 | { |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | WebRtc_Word32 |
| 69 | MonitorModule::TimeUntilNextProcess() |
| 70 | { |
| 71 | WebRtc_UWord32 now = GET_TIME_IN_MS(); |
| 72 | WebRtc_Word32 timeToNext = |
| 73 | kAverageProcessUpdateTimeMs - (now - _lastProcessTime); |
| 74 | return (timeToNext); |
| 75 | } |
| 76 | |
| 77 | WebRtc_Word32 |
| 78 | MonitorModule::Process() |
| 79 | { |
| 80 | _lastProcessTime = GET_TIME_IN_MS(); |
| 81 | if (_observerPtr) |
| 82 | { |
| 83 | CriticalSectionScoped lock(&_callbackCritSect); |
| 84 | _observerPtr->OnPeriodicProcess(); |
| 85 | } |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | } // namespace voe |
| 90 | |
| 91 | } // namespace webrtc |