michael@0: /* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _LOADMONITOR_H_ michael@0: #define _LOADMONITOR_H_ michael@0: michael@0: #include "mozilla/Mutex.h" michael@0: #include "mozilla/CondVar.h" michael@0: #include "mozilla/RefPtr.h" michael@0: #include "mozilla/Atomics.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIThread.h" michael@0: #include "nsIObserver.h" michael@0: michael@0: namespace mozilla { michael@0: class LoadInfoUpdateRunner; michael@0: class LoadInfoCollectRunner; michael@0: michael@0: class LoadNotificationCallback michael@0: { michael@0: public: michael@0: virtual void LoadChanged(float aSystemLoad, float aProcessLoad) = 0; michael@0: }; michael@0: michael@0: class LoadMonitor MOZ_FINAL : public nsIObserver michael@0: { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIOBSERVER michael@0: michael@0: LoadMonitor(int aLoadUpdateInterval); michael@0: ~LoadMonitor(); michael@0: michael@0: nsresult Init(nsRefPtr &self); michael@0: void SetLoadChangeCallback(LoadNotificationCallback* aCallback); michael@0: void Shutdown(); michael@0: float GetSystemLoad(); michael@0: float GetProcessLoad(); michael@0: michael@0: friend class LoadInfoCollectRunner; michael@0: michael@0: private: michael@0: michael@0: void SetProcessLoad(float load); michael@0: void SetSystemLoad(float load); michael@0: void FireCallbacks(); michael@0: michael@0: int mLoadUpdateInterval; michael@0: mozilla::Mutex mLock; michael@0: mozilla::CondVar mCondVar; michael@0: bool mShutdownPending; michael@0: nsCOMPtr mLoadInfoThread; michael@0: float mSystemLoad; michael@0: float mProcessLoad; michael@0: LoadNotificationCallback* mLoadNotificationCallback; michael@0: }; michael@0: michael@0: } //namespace michael@0: michael@0: #endif /* _LOADMONITOR_H_ */