michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "osx_wifi.h" michael@0: michael@0: #include "nsAutoPtr.h" michael@0: #include "nsCOMArray.h" michael@0: #include "nsWifiMonitor.h" michael@0: #include "nsWifiAccessPoint.h" michael@0: michael@0: #include "nsServiceManagerUtils.h" michael@0: #include "nsComponentManagerUtils.h" michael@0: #include "nsIMutableArray.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: // defined in osx_corewlan.mm michael@0: // basically replaces accesspoints in the passed reference michael@0: // it lives in a separate file so that we can use objective c. michael@0: extern nsresult GetAccessPointsFromWLAN(nsCOMArray &accessPoints); michael@0: michael@0: nsresult michael@0: nsWifiMonitor::DoScan() michael@0: { michael@0: // Regularly get the access point data. michael@0: michael@0: nsCOMArray lastAccessPoints; michael@0: nsCOMArray accessPoints; michael@0: michael@0: do { michael@0: nsresult rv = GetAccessPointsFromWLAN(accessPoints); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: bool accessPointsChanged = !AccessPointsEqual(accessPoints, lastAccessPoints); michael@0: ReplaceArray(lastAccessPoints, accessPoints); michael@0: michael@0: rv = CallWifiListeners(lastAccessPoints, accessPointsChanged); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: // wait for some reasonable amount of time. pref? michael@0: LOG(("waiting on monitor\n")); michael@0: michael@0: ReentrantMonitorAutoEnter mon(mReentrantMonitor); michael@0: mon.Wait(PR_SecondsToInterval(60)); michael@0: } michael@0: while (mKeepGoing); michael@0: michael@0: return NS_OK; michael@0: }