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