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/. */
5 #ifndef __nsWifiMonitor__
6 #define __nsWifiMonitor__
8 #include "nsIWifiMonitor.h"
10 #include "nsProxyRelease.h"
11 #include "nsIThread.h"
12 #include "nsIRunnable.h"
13 #include "nsCOMArray.h"
14 #include "nsIWifiListener.h"
15 #include "mozilla/Atomics.h"
16 #include "mozilla/ReentrantMonitor.h"
17 #include "mozilla/Logging.h"
18 #include "nsIObserver.h"
20 #include "mozilla/Attributes.h"
23 # include "win_wifiScanner.h"
26 extern mozilla::LazyLogModule gWifiMonitorLog
;
27 #define LOG(args) MOZ_LOG(gWifiMonitorLog, mozilla::LogLevel::Debug, args)
29 class nsWifiAccessPoint
;
31 #define kDefaultWifiScanInterval 5 /* seconds */
33 class nsWifiListener
{
35 explicit nsWifiListener(nsMainThreadPtrHolder
<nsIWifiListener
>* aListener
) {
36 mListener
= aListener
;
39 ~nsWifiListener() = default;
41 nsMainThreadPtrHandle
<nsIWifiListener
> mListener
;
45 class nsWifiMonitor final
: nsIRunnable
, nsIWifiMonitor
, nsIObserver
{
47 NS_DECL_THREADSAFE_ISUPPORTS
48 NS_DECL_NSIWIFIMONITOR
55 ~nsWifiMonitor() = default;
59 nsresult
CallWifiListeners(const nsCOMArray
<nsWifiAccessPoint
>& aAccessPoints
,
60 bool aAccessPointsChanged
);
62 mozilla::Atomic
<bool> mKeepGoing
;
63 mozilla::Atomic
<bool> mThreadComplete
;
64 nsCOMPtr
<nsIThread
> mThread
; // only accessed on MainThread
66 nsTArray
<nsWifiListener
> mListeners
GUARDED_BY(mReentrantMonitor
);
68 mozilla::ReentrantMonitor mReentrantMonitor
;
71 mozilla::UniquePtr
<WinWifiScanner
> mWinWifiScanner
;