2012-05-21 04:12:37 -07: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-16 17:30:58 -07:00
|
|
|
|
2012-10-09 18:40:11 -07:00
|
|
|
#ifndef __nsWifiMonitor__
|
|
|
|
#define __nsWifiMonitor__
|
|
|
|
|
2009-03-16 17:30:58 -07:00
|
|
|
#include "nsIWifiMonitor.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2013-03-15 16:02:01 -07:00
|
|
|
#include "nsProxyRelease.h"
|
2009-03-16 17:30:58 -07:00
|
|
|
#include "nsIThread.h"
|
|
|
|
#include "nsIRunnable.h"
|
|
|
|
#include "nsCOMArray.h"
|
2013-09-22 20:35:05 -07:00
|
|
|
#include "nsIWifiListener.h"
|
2011-04-29 12:21:57 -07:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
2009-03-16 17:30:58 -07:00
|
|
|
#include "prlog.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsTArray.h"
|
2012-10-09 18:40:11 -07:00
|
|
|
#include "nsITimer.h"
|
2012-06-05 20:18:25 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-10-09 18:40:11 -07:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2009-03-16 17:30:58 -07:00
|
|
|
|
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
extern PRLogModuleInfo *gWifiMonitorLog;
|
|
|
|
#endif
|
|
|
|
#define LOG(args) PR_LOG(gWifiMonitorLog, PR_LOG_DEBUG, args)
|
|
|
|
|
2011-07-27 09:26:20 -07:00
|
|
|
class nsWifiAccessPoint;
|
|
|
|
|
2014-06-08 22:52:53 -07:00
|
|
|
#define kDefaultWifiScanInterval 5 /* seconds */
|
|
|
|
|
2009-03-16 17:30:58 -07:00
|
|
|
class nsWifiListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2013-03-15 16:02:01 -07:00
|
|
|
nsWifiListener(nsMainThreadPtrHolder<nsIWifiListener>* aListener)
|
2009-03-16 17:30:58 -07:00
|
|
|
{
|
|
|
|
mListener = aListener;
|
2011-10-17 07:59:28 -07:00
|
|
|
mHasSentData = false;
|
2009-03-16 17:30:58 -07:00
|
|
|
}
|
|
|
|
~nsWifiListener() {}
|
2010-03-01 21:56:06 -08:00
|
|
|
|
2013-03-15 16:02:01 -07:00
|
|
|
nsMainThreadPtrHandle<nsIWifiListener> mListener;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHasSentData;
|
2009-03-16 17:30:58 -07:00
|
|
|
};
|
|
|
|
|
2012-10-09 18:40:11 -07:00
|
|
|
#ifndef MOZ_WIDGET_GONK
|
2012-06-05 20:18:25 -07:00
|
|
|
class nsWifiMonitor MOZ_FINAL : nsIRunnable, nsIWifiMonitor, nsIObserver
|
2009-03-16 17:30:58 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-07-18 19:24:13 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2009-03-16 17:30:58 -07:00
|
|
|
NS_DECL_NSIWIFIMONITOR
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
nsWifiMonitor();
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsWifiMonitor();
|
|
|
|
|
|
|
|
nsresult DoScan();
|
|
|
|
|
2011-07-27 09:26:20 -07:00
|
|
|
nsresult CallWifiListeners(const nsCOMArray<nsWifiAccessPoint> &aAccessPoints,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAccessPointsChanged);
|
2011-07-27 09:26:20 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mKeepGoing;
|
2009-03-16 17:30:58 -07:00
|
|
|
nsCOMPtr<nsIThread> mThread;
|
|
|
|
|
|
|
|
nsTArray<nsWifiListener> mListeners;
|
|
|
|
|
2011-04-29 12:21:57 -07:00
|
|
|
mozilla::ReentrantMonitor mReentrantMonitor;
|
2009-03-16 17:30:58 -07:00
|
|
|
|
|
|
|
};
|
2012-10-09 18:40:11 -07:00
|
|
|
#else
|
|
|
|
#include "nsIWifi.h"
|
|
|
|
class nsWifiMonitor MOZ_FINAL : nsIWifiMonitor, nsIWifiScanResultsReady, nsIObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIWIFIMONITOR
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
NS_DECL_NSIWIFISCANRESULTSREADY
|
|
|
|
|
|
|
|
nsWifiMonitor();
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsWifiMonitor();
|
|
|
|
|
|
|
|
void ClearTimer() {
|
|
|
|
if (mTimer) {
|
|
|
|
mTimer->Cancel();
|
|
|
|
mTimer = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nsCOMArray<nsWifiAccessPoint> mLastAccessPoints;
|
|
|
|
nsTArray<nsWifiListener> mListeners;
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
|
|
|
};
|
|
|
|
#endif
|
2009-03-16 17:30:58 -07:00
|
|
|
|
|
|
|
#endif
|