Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / netwerk / wifi / nsWifiScannerWin.cpp
blob4a0ad87cc4f11d6a8d40b10a360d06edf9c37330
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "nsWifiMonitor.h"
7 // moz headers (alphabetical)
8 #include "nsAutoPtr.h"
9 #include "nsCOMArray.h"
10 #include "nsComponentManagerUtils.h"
11 #include "nsIMutableArray.h"
12 #include "nsServiceManagerUtils.h"
13 #include "nsWifiAccessPoint.h"
14 #include "win_wifiScanner.h"
16 using namespace mozilla;
18 /**
19 * `nsWifiMonitor` is declared in the cross-platform nsWifiMonitor.h and
20 * is mostly defined in the cross-platform nsWifiMonitor.cpp. This function
21 * is implemented in various platform-specific files but the implementation
22 * is almost identical in each file. We relegate the Windows-specific
23 * work to the `WinWifiScanner` class and deal with non-Windows-specific
24 * issues like calling listeners here. Hopefully this file can be merged
25 * with the other implementations of `nsWifiMonitor::DoScan` since a lot
26 * of the code is identical
28 nsresult
29 nsWifiMonitor::DoScan()
31 if (!mWinWifiScanner) {
32 mWinWifiScanner = new WinWifiScanner();
33 if (!mWinWifiScanner) {
34 // TODO: Probably return OOM error
35 return NS_ERROR_FAILURE;
39 // Regularly get the access point data.
41 nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
42 nsCOMArray<nsWifiAccessPoint> accessPoints;
44 do {
45 accessPoints.Clear();
46 nsresult rv = mWinWifiScanner->GetAccessPointsFromWLAN(accessPoints);
47 if (NS_FAILED(rv)) {
48 return rv;
51 bool accessPointsChanged = !AccessPointsEqual(accessPoints, lastAccessPoints);
52 ReplaceArray(lastAccessPoints, accessPoints);
54 rv = CallWifiListeners(lastAccessPoints, accessPointsChanged);
55 NS_ENSURE_SUCCESS(rv, rv);
57 // wait for some reasonable amount of time. pref?
58 LOG(("waiting on monitor\n"));
60 ReentrantMonitorAutoEnter mon(mReentrantMonitor);
61 mon.Wait(PR_SecondsToInterval(kDefaultWifiScanInterval));
63 while (mKeepGoing);
65 return NS_OK;