Source code

Revision control

Other Tools

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/. */
4
5
#include "nsWifiMonitor.h"
6
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"
15
16
using namespace mozilla;
17
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
27
*/
28
nsresult nsWifiMonitor::DoScan() {
29
if (!mWinWifiScanner) {
30
mWinWifiScanner = new WinWifiScanner();
31
if (!mWinWifiScanner) {
32
// TODO: Probably return OOM error
33
return NS_ERROR_FAILURE;
34
}
35
}
36
37
// Regularly get the access point data.
38
39
nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
40
nsCOMArray<nsWifiAccessPoint> accessPoints;
41
42
do {
43
accessPoints.Clear();
44
nsresult rv = mWinWifiScanner->GetAccessPointsFromWLAN(accessPoints);
45
if (NS_FAILED(rv)) {
46
return rv;
47
}
48
49
bool accessPointsChanged =
50
!AccessPointsEqual(accessPoints, lastAccessPoints);
51
ReplaceArray(lastAccessPoints, accessPoints);
52
53
rv = CallWifiListeners(lastAccessPoints, accessPointsChanged);
54
NS_ENSURE_SUCCESS(rv, rv);
55
56
// wait for some reasonable amount of time. pref?
57
LOG(("waiting on monitor\n"));
58
59
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
60
if (mKeepGoing) {
61
mon.Wait(PR_SecondsToInterval(kDefaultWifiScanInterval));
62
}
63
} while (mKeepGoing);
64
65
return NS_OK;
66
}