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 __nsWifiMonitor__ michael@0: #define __nsWifiMonitor__ michael@0: michael@0: #include "nsIWifiMonitor.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsProxyRelease.h" michael@0: #include "nsIThread.h" michael@0: #include "nsIRunnable.h" michael@0: #include "nsCOMArray.h" michael@0: #include "nsIWifiListener.h" michael@0: #include "mozilla/ReentrantMonitor.h" michael@0: #include "prlog.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsTArray.h" michael@0: #include "nsITimer.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsIInterfaceRequestor.h" michael@0: michael@0: #if defined(PR_LOGGING) michael@0: extern PRLogModuleInfo *gWifiMonitorLog; michael@0: #endif michael@0: #define LOG(args) PR_LOG(gWifiMonitorLog, PR_LOG_DEBUG, args) michael@0: michael@0: class nsWifiAccessPoint; michael@0: michael@0: class nsWifiListener michael@0: { michael@0: public: michael@0: michael@0: nsWifiListener(nsMainThreadPtrHolder* aListener) michael@0: { michael@0: mListener = aListener; michael@0: mHasSentData = false; michael@0: } michael@0: ~nsWifiListener() {} michael@0: michael@0: nsMainThreadPtrHandle mListener; michael@0: bool mHasSentData; michael@0: }; michael@0: michael@0: #ifndef MOZ_WIDGET_GONK michael@0: class nsWifiMonitor MOZ_FINAL : nsIRunnable, nsIWifiMonitor, nsIObserver michael@0: { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIWIFIMONITOR michael@0: NS_DECL_NSIRUNNABLE michael@0: NS_DECL_NSIOBSERVER michael@0: michael@0: nsWifiMonitor(); michael@0: michael@0: private: michael@0: ~nsWifiMonitor(); michael@0: michael@0: nsresult DoScan(); michael@0: michael@0: nsresult CallWifiListeners(const nsCOMArray &aAccessPoints, michael@0: bool aAccessPointsChanged); michael@0: michael@0: bool mKeepGoing; michael@0: nsCOMPtr mThread; michael@0: michael@0: nsTArray mListeners; michael@0: michael@0: mozilla::ReentrantMonitor mReentrantMonitor; michael@0: michael@0: }; michael@0: #else michael@0: #include "nsIWifi.h" michael@0: class nsWifiMonitor MOZ_FINAL : nsIWifiMonitor, nsIWifiScanResultsReady, nsIObserver michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIWIFIMONITOR michael@0: NS_DECL_NSIOBSERVER michael@0: NS_DECL_NSIWIFISCANRESULTSREADY michael@0: michael@0: nsWifiMonitor(); michael@0: michael@0: private: michael@0: ~nsWifiMonitor(); michael@0: michael@0: void ClearTimer() { michael@0: if (mTimer) { michael@0: mTimer->Cancel(); michael@0: mTimer = nullptr; michael@0: } michael@0: } michael@0: nsCOMArray mLastAccessPoints; michael@0: nsTArray mListeners; michael@0: nsCOMPtr mTimer; michael@0: }; michael@0: #endif michael@0: michael@0: #endif