|
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(nsCOMArray<nsWifiAccessPoint> &accessPoints); |
|
26 |
|
27 nsresult |
|
28 nsWifiMonitor::DoScan() |
|
29 { |
|
30 // Regularly get the access point data. |
|
31 |
|
32 nsCOMArray<nsWifiAccessPoint> lastAccessPoints; |
|
33 nsCOMArray<nsWifiAccessPoint> accessPoints; |
|
34 |
|
35 do { |
|
36 nsresult rv = GetAccessPointsFromWLAN(accessPoints); |
|
37 if (NS_FAILED(rv)) |
|
38 return rv; |
|
39 |
|
40 bool accessPointsChanged = !AccessPointsEqual(accessPoints, lastAccessPoints); |
|
41 ReplaceArray(lastAccessPoints, accessPoints); |
|
42 |
|
43 rv = CallWifiListeners(lastAccessPoints, accessPointsChanged); |
|
44 NS_ENSURE_SUCCESS(rv, rv); |
|
45 |
|
46 // wait for some reasonable amount of time. pref? |
|
47 LOG(("waiting on monitor\n")); |
|
48 |
|
49 ReentrantMonitorAutoEnter mon(mReentrantMonitor); |
|
50 mon.Wait(PR_SecondsToInterval(60)); |
|
51 } |
|
52 while (mKeepGoing); |
|
53 |
|
54 return NS_OK; |
|
55 } |