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-21 14:49:51 +03:00
|
|
|
|
|
|
|
#include "nsWifiMonitor.h"
|
|
|
|
|
2014-08-01 23:10:48 +04:00
|
|
|
// moz headers (alphabetical)
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMArray.h"
|
2009-03-21 14:49:51 +03:00
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsIMutableArray.h"
|
2014-08-01 23:10:48 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsWifiAccessPoint.h"
|
|
|
|
#include "win_wifiScanner.h"
|
2014-02-18 02:32:52 +04:00
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2014-08-01 23:10:48 +04:00
|
|
|
/**
|
|
|
|
* `nsWifiMonitor` is declared in the cross-platform nsWifiMonitor.h and
|
|
|
|
* is mostly defined in the cross-platform nsWifiMonitor.cpp. This function
|
|
|
|
* is implemented in various platform-specific files but the implementation
|
|
|
|
* is almost identical in each file. We relegate the Windows-specific
|
|
|
|
* work to the `WinWifiScanner` class and deal with non-Windows-specific
|
|
|
|
* issues like calling listeners here. Hopefully this file can be merged
|
|
|
|
* with the other implementations of `nsWifiMonitor::DoScan` since a lot
|
|
|
|
* of the code is identical
|
|
|
|
*/
|
2009-03-21 14:49:51 +03:00
|
|
|
nsresult
|
|
|
|
nsWifiMonitor::DoScan()
|
|
|
|
{
|
2014-08-01 23:10:48 +04:00
|
|
|
if (!mWinWifiScanner) {
|
|
|
|
mWinWifiScanner = new WinWifiScanner();
|
|
|
|
if (!mWinWifiScanner) {
|
|
|
|
// TODO: Probably return OOM error
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
2010-03-02 08:56:06 +03:00
|
|
|
|
2009-03-21 14:49:51 +03:00
|
|
|
// Regularly get the access point data.
|
2010-03-02 08:56:06 +03:00
|
|
|
|
2009-03-21 14:49:51 +03:00
|
|
|
nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
|
|
|
|
nsCOMArray<nsWifiAccessPoint> accessPoints;
|
2010-03-02 08:56:06 +03:00
|
|
|
|
2009-03-21 14:49:51 +03:00
|
|
|
do {
|
|
|
|
accessPoints.Clear();
|
2014-08-01 23:10:48 +04:00
|
|
|
nsresult rv = mWinWifiScanner->GetAccessPointsFromWLAN(accessPoints);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2009-03-21 14:49:51 +03:00
|
|
|
}
|
2010-03-02 08:56:06 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool accessPointsChanged = !AccessPointsEqual(accessPoints, lastAccessPoints);
|
2009-03-21 14:49:51 +03:00
|
|
|
ReplaceArray(lastAccessPoints, accessPoints);
|
2010-03-02 08:56:06 +03:00
|
|
|
|
2014-08-01 23:10:48 +04:00
|
|
|
rv = CallWifiListeners(lastAccessPoints, accessPointsChanged);
|
2011-07-27 20:26:20 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-03-02 08:56:06 +03:00
|
|
|
|
2009-03-21 14:49:51 +03:00
|
|
|
// wait for some reasonable amount of time. pref?
|
|
|
|
LOG(("waiting on monitor\n"));
|
2010-03-02 08:56:06 +03:00
|
|
|
|
2011-04-29 23:21:57 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2014-06-09 09:52:53 +04:00
|
|
|
mon.Wait(PR_SecondsToInterval(kDefaultWifiScanInterval));
|
2009-03-21 14:49:51 +03:00
|
|
|
}
|
2010-02-07 18:52:43 +03:00
|
|
|
while (mKeepGoing);
|
2010-09-29 02:07:15 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2009-03-21 14:49:51 +03:00
|
|
|
}
|