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