2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-03-17 00:30:58 +00:00
|
|
|
|
2012-10-10 01:40:11 +00:00
|
|
|
#ifndef __nsWifiMonitor__
|
|
|
|
#define __nsWifiMonitor__
|
|
|
|
|
2009-03-17 00:30:58 +00:00
|
|
|
#include "nsIWifiMonitor.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2013-03-15 23:02:01 +00:00
|
|
|
#include "nsProxyRelease.h"
|
2009-03-17 00:30:58 +00:00
|
|
|
#include "nsIThread.h"
|
|
|
|
#include "nsIRunnable.h"
|
|
|
|
#include "nsCOMArray.h"
|
2013-09-23 03:35:05 +00:00
|
|
|
#include "nsIWifiListener.h"
|
2011-04-29 19:21:57 +00:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
2009-03-17 00:30:58 +00:00
|
|
|
#include "prlog.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsTArray.h"
|
2012-10-10 01:40:11 +00:00
|
|
|
#include "nsITimer.h"
|
2012-06-06 03:18:25 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-10-10 01:40:11 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2009-03-17 00:30:58 +00:00
|
|
|
|
2014-08-01 19:10:48 +00:00
|
|
|
#ifdef XP_WIN
|
2014-08-02 00:43:27 +00:00
|
|
|
#include "win_wifiScanner.h"
|
2014-08-01 19:10:48 +00:00
|
|
|
#endif
|
|
|
|
|
2009-03-17 00:30:58 +00:00
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
extern PRLogModuleInfo *gWifiMonitorLog;
|
|
|
|
#endif
|
|
|
|
#define LOG(args) PR_LOG(gWifiMonitorLog, PR_LOG_DEBUG, args)
|
|
|
|
|
2011-07-27 16:26:20 +00:00
|
|
|
class nsWifiAccessPoint;
|
|
|
|
|
2014-06-09 05:52:53 +00:00
|
|
|
#define kDefaultWifiScanInterval 5 /* seconds */
|
|
|
|
|
2009-03-17 00:30:58 +00:00
|
|
|
class nsWifiListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-08-05 13:20:24 +00:00
|
|
|
explicit nsWifiListener(nsMainThreadPtrHolder<nsIWifiListener>* aListener)
|
2009-03-17 00:30:58 +00:00
|
|
|
{
|
|
|
|
mListener = aListener;
|
2011-10-17 14:59:28 +00:00
|
|
|
mHasSentData = false;
|
2009-03-17 00:30:58 +00:00
|
|
|
}
|
|
|
|
~nsWifiListener() {}
|
2010-03-02 05:56:06 +00:00
|
|
|
|
2013-03-15 23:02:01 +00:00
|
|
|
nsMainThreadPtrHandle<nsIWifiListener> mListener;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mHasSentData;
|
2009-03-17 00:30:58 +00:00
|
|
|
};
|
|
|
|
|
2012-10-10 01:40:11 +00:00
|
|
|
#ifndef MOZ_WIDGET_GONK
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsWifiMonitor final : nsIRunnable, nsIWifiMonitor, nsIObserver
|
2009-03-17 00:30:58 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-07-19 02:24:13 +00:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2009-03-17 00:30:58 +00:00
|
|
|
NS_DECL_NSIWIFIMONITOR
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
nsWifiMonitor();
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsWifiMonitor();
|
|
|
|
|
|
|
|
nsresult DoScan();
|
|
|
|
|
2011-07-27 16:26:20 +00:00
|
|
|
nsresult CallWifiListeners(const nsCOMArray<nsWifiAccessPoint> &aAccessPoints,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aAccessPointsChanged);
|
2011-07-27 16:26:20 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mKeepGoing;
|
2009-03-17 00:30:58 +00:00
|
|
|
nsCOMPtr<nsIThread> mThread;
|
|
|
|
|
|
|
|
nsTArray<nsWifiListener> mListeners;
|
|
|
|
|
2011-04-29 19:21:57 +00:00
|
|
|
mozilla::ReentrantMonitor mReentrantMonitor;
|
2009-03-17 00:30:58 +00:00
|
|
|
|
2014-08-01 19:10:48 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
nsAutoPtr<WinWifiScanner> mWinWifiScanner;
|
|
|
|
#endif
|
2009-03-17 00:30:58 +00:00
|
|
|
};
|
2012-10-10 01:40:11 +00:00
|
|
|
#else
|
|
|
|
#include "nsIWifi.h"
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsWifiMonitor final : nsIWifiMonitor, nsIWifiScanResultsReady, nsIObserver
|
2012-10-10 01:40:11 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIWIFIMONITOR
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
NS_DECL_NSIWIFISCANRESULTSREADY
|
|
|
|
|
|
|
|
nsWifiMonitor();
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsWifiMonitor();
|
|
|
|
|
|
|
|
void ClearTimer() {
|
|
|
|
if (mTimer) {
|
|
|
|
mTimer->Cancel();
|
|
|
|
mTimer = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2014-06-30 13:31:00 +00:00
|
|
|
void StartScan();
|
2012-10-10 01:40:11 +00:00
|
|
|
nsCOMArray<nsWifiAccessPoint> mLastAccessPoints;
|
|
|
|
nsTArray<nsWifiListener> mListeners;
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
|
|
|
};
|
|
|
|
#endif
|
2009-03-17 00:30:58 +00:00
|
|
|
|
|
|
|
#endif
|