Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
michael@0 | 1 | /* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef _LOADMANAGER_H_ |
michael@0 | 7 | #define _LOADMANAGER_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include "LoadMonitor.h" |
michael@0 | 10 | #include "webrtc/common_types.h" |
michael@0 | 11 | #include "webrtc/video_engine/include/vie_base.h" |
michael@0 | 12 | #include "mozilla/TimeStamp.h" |
michael@0 | 13 | #include "nsTArray.h" |
michael@0 | 14 | |
michael@0 | 15 | extern PRLogModuleInfo *gLoadManagerLog; |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | |
michael@0 | 19 | class LoadManager : public LoadNotificationCallback, |
michael@0 | 20 | public webrtc::CPULoadStateCallbackInvoker, |
michael@0 | 21 | public webrtc::CpuOveruseObserver |
michael@0 | 22 | { |
michael@0 | 23 | public: |
michael@0 | 24 | LoadManager(int aLoadMeasurementInterval, |
michael@0 | 25 | int aAveragingMeasurements, |
michael@0 | 26 | float aHighLoadThreshold, |
michael@0 | 27 | float aLowLoadThreshold); |
michael@0 | 28 | ~LoadManager(); |
michael@0 | 29 | |
michael@0 | 30 | // LoadNotificationCallback interface |
michael@0 | 31 | virtual void LoadChanged(float aSystemLoad, float aProcessLoad) MOZ_OVERRIDE; |
michael@0 | 32 | // CpuOveruseObserver interface |
michael@0 | 33 | // Called as soon as an overuse is detected. |
michael@0 | 34 | virtual void OveruseDetected() MOZ_OVERRIDE; |
michael@0 | 35 | // Called periodically when the system is not overused any longer. |
michael@0 | 36 | virtual void NormalUsage() MOZ_OVERRIDE; |
michael@0 | 37 | // CPULoadStateCallbackInvoker interface |
michael@0 | 38 | virtual void AddObserver(webrtc::CPULoadStateObserver * aObserver) MOZ_OVERRIDE; |
michael@0 | 39 | virtual void RemoveObserver(webrtc::CPULoadStateObserver * aObserver) MOZ_OVERRIDE; |
michael@0 | 40 | |
michael@0 | 41 | private: |
michael@0 | 42 | void LoadHasChanged(); |
michael@0 | 43 | |
michael@0 | 44 | nsRefPtr<LoadMonitor> mLoadMonitor; |
michael@0 | 45 | float mLoadSum; |
michael@0 | 46 | int mLoadSumMeasurements; |
michael@0 | 47 | // Set when overuse was signaled to us, and hasn't been un-signaled yet. |
michael@0 | 48 | bool mOveruseActive; |
michael@0 | 49 | // Load measurement settings |
michael@0 | 50 | int mLoadMeasurementInterval; |
michael@0 | 51 | int mAveragingMeasurements; |
michael@0 | 52 | float mHighLoadThreshold; |
michael@0 | 53 | float mLowLoadThreshold; |
michael@0 | 54 | |
michael@0 | 55 | webrtc::CPULoadState mCurrentState; |
michael@0 | 56 | |
michael@0 | 57 | nsTArray<webrtc::CPULoadStateObserver*> mObservers; |
michael@0 | 58 | }; |
michael@0 | 59 | |
michael@0 | 60 | } //namespace |
michael@0 | 61 | |
michael@0 | 62 | #endif /* _LOADMANAGER_H_ */ |