2012-05-21 15:12:37 +04: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 03:30:58 +03:00
|
|
|
|
2012-10-10 05:40:11 +04:00
|
|
|
#ifndef __nsWifiMonitor__
|
|
|
|
#define __nsWifiMonitor__
|
|
|
|
|
2009-03-17 03:30:58 +03:00
|
|
|
#include "nsIWifiMonitor.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2013-03-16 03:02:01 +04:00
|
|
|
#include "nsProxyRelease.h"
|
2009-03-17 03:30:58 +03:00
|
|
|
#include "nsIThread.h"
|
|
|
|
#include "nsIRunnable.h"
|
|
|
|
#include "nsCOMArray.h"
|
2013-09-23 07:35:05 +04:00
|
|
|
#include "nsIWifiListener.h"
|
2015-04-02 20:58:14 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
2011-04-29 23:21:57 +04:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2009-03-17 03:30:58 +03:00
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsTArray.h"
|
2012-10-10 05:40:11 +04:00
|
|
|
#include "nsITimer.h"
|
2012-06-06 07:18:25 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-10-10 05:40:11 +04:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2009-03-17 03:30:58 +03:00
|
|
|
|
2014-08-01 23:10:48 +04:00
|
|
|
#ifdef XP_WIN
|
2014-08-02 04:43:27 +04:00
|
|
|
#include "win_wifiScanner.h"
|
2014-08-01 23:10:48 +04:00
|
|
|
#endif
|
|
|
|
|
2009-03-17 03:30:58 +03:00
|
|
|
extern PRLogModuleInfo *gWifiMonitorLog;
|
2015-06-04 01:25:57 +03:00
|
|
|
#define LOG(args) MOZ_LOG(gWifiMonitorLog, mozilla::LogLevel::Debug, args)
|
2009-03-17 03:30:58 +03:00
|
|
|
|
2011-07-27 20:26:20 +04:00
|
|
|
class nsWifiAccessPoint;
|
|
|
|
|
2014-06-09 09:52:53 +04:00
|
|
|
#define kDefaultWifiScanInterval 5 /* seconds */
|
|
|
|
|
2009-03-17 03:30:58 +03:00
|
|
|
class nsWifiListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-08-05 17:20:24 +04:00
|
|
|
explicit nsWifiListener(nsMainThreadPtrHolder<nsIWifiListener>* aListener)
|
2009-03-17 03:30:58 +03:00
|
|
|
{
|
|
|
|
mListener = aListener;
|
2011-10-17 18:59:28 +04:00
|
|
|
mHasSentData = false;
|
2009-03-17 03:30:58 +03:00
|
|
|
}
|
|
|
|
~nsWifiListener() {}
|
2010-03-02 08:56:06 +03:00
|
|
|
|
2013-03-16 03:02:01 +04:00
|
|
|
nsMainThreadPtrHandle<nsIWifiListener> mListener;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mHasSentData;
|
2009-03-17 03:30:58 +03:00
|
|
|
};
|
|
|
|
|
2012-10-10 05:40:11 +04:00
|
|
|
#ifndef MOZ_WIDGET_GONK
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsWifiMonitor final : nsIRunnable, nsIWifiMonitor, nsIObserver
|
2009-03-17 03:30:58 +03:00
|
|
|
{
|
|
|
|
public:
|
2013-07-19 06:24:13 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2009-03-17 03:30:58 +03:00
|
|
|
NS_DECL_NSIWIFIMONITOR
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
nsWifiMonitor();
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsWifiMonitor();
|
|
|
|
|
|
|
|
nsresult DoScan();
|
|
|
|
|
2011-07-27 20:26:20 +04:00
|
|
|
nsresult CallWifiListeners(const nsCOMArray<nsWifiAccessPoint> &aAccessPoints,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aAccessPointsChanged);
|
2011-07-27 20:26:20 +04:00
|
|
|
|
2015-04-02 20:58:14 +03:00
|
|
|
mozilla::Atomic<bool> mKeepGoing;
|
|
|
|
mozilla::Atomic<bool> mThreadComplete;
|
2009-03-17 03:30:58 +03:00
|
|
|
nsCOMPtr<nsIThread> mThread;
|
|
|
|
|
|
|
|
nsTArray<nsWifiListener> mListeners;
|
|
|
|
|
2011-04-29 23:21:57 +04:00
|
|
|
mozilla::ReentrantMonitor mReentrantMonitor;
|
2009-03-17 03:30:58 +03:00
|
|
|
|
2014-08-01 23:10:48 +04:00
|
|
|
#ifdef XP_WIN
|
2015-06-03 15:26:47 +03:00
|
|
|
nsAutoPtr<WindowsWifiScannerInterface> mWinWifiScanner;
|
2014-08-01 23:10:48 +04:00
|
|
|
#endif
|
2009-03-17 03:30:58 +03:00
|
|
|
};
|
2012-10-10 05:40:11 +04:00
|
|
|
#else
|
|
|
|
#include "nsIWifi.h"
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsWifiMonitor final : nsIWifiMonitor, nsIWifiScanResultsReady, nsIObserver
|
2012-10-10 05:40:11 +04: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 17:31:00 +04:00
|
|
|
void StartScan();
|
2012-10-10 05:40:11 +04:00
|
|
|
nsCOMArray<nsWifiAccessPoint> mLastAccessPoints;
|
|
|
|
nsTArray<nsWifiListener> mListeners;
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
|
|
|
};
|
|
|
|
#endif
|
2009-03-17 03:30:58 +03:00
|
|
|
|
|
|
|
#endif
|