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 <mach-o/dyld.h>
6
#include <dlfcn.h>
7
#include <unistd.h>
8
9
#include "osx_wifi.h"
10
11
#include "nsAutoPtr.h"
12
#include "nsCOMArray.h"
13
#include "nsWifiMonitor.h"
14
#include "nsWifiAccessPoint.h"
15
16
#include "nsServiceManagerUtils.h"
17
#include "nsComponentManagerUtils.h"
18
#include "nsIMutableArray.h"
19
20
using namespace mozilla;
21
22
// defined in osx_corewlan.mm
23
// basically replaces accesspoints in the passed reference
24
// it lives in a separate file so that we can use objective c.
25
extern nsresult GetAccessPointsFromWLAN(
26
nsCOMArray<nsWifiAccessPoint>& accessPoints);
27
28
nsresult nsWifiMonitor::DoScan() {
29
// Regularly get the access point data.
30
31
nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
32
nsCOMArray<nsWifiAccessPoint> accessPoints;
33
34
do {
35
nsresult rv = GetAccessPointsFromWLAN(accessPoints);
36
if (NS_FAILED(rv)) return rv;
37
38
bool accessPointsChanged =
39
!AccessPointsEqual(accessPoints, lastAccessPoints);
40
ReplaceArray(lastAccessPoints, accessPoints);
41
42
rv = CallWifiListeners(lastAccessPoints, accessPointsChanged);
43
NS_ENSURE_SUCCESS(rv, rv);
44
45
// wait for some reasonable amount of time. pref?
46
LOG(("waiting on monitor\n"));
47
48
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
49
mon.Wait(PR_SecondsToInterval(kDefaultWifiScanInterval));
50
} while (mKeepGoing);
51
52
return NS_OK;
53
}