Bug 1760181 [wpt PR 33182] - Update wpt metadata, a=testonly
[gecko.git] / netwerk / wifi / nsWifiMonitor.h
blob5a2943f1280eea46943fac304a7ce1bbbf3830f0
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"
9 #include "nsCOMPtr.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"
19 #include "nsTArray.h"
20 #include "mozilla/Attributes.h"
22 #ifdef XP_WIN
23 # include "win_wifiScanner.h"
24 #endif
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 {
34 public:
35 explicit nsWifiListener(nsMainThreadPtrHolder<nsIWifiListener>* aListener) {
36 mListener = aListener;
37 mHasSentData = false;
39 ~nsWifiListener() = default;
41 nsMainThreadPtrHandle<nsIWifiListener> mListener;
42 bool mHasSentData;
45 class nsWifiMonitor final : nsIRunnable, nsIWifiMonitor, nsIObserver {
46 public:
47 NS_DECL_THREADSAFE_ISUPPORTS
48 NS_DECL_NSIWIFIMONITOR
49 NS_DECL_NSIRUNNABLE
50 NS_DECL_NSIOBSERVER
52 nsWifiMonitor();
54 private:
55 ~nsWifiMonitor() = default;
57 nsresult DoScan();
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;
70 #ifdef XP_WIN
71 mozilla::UniquePtr<WinWifiScanner> mWinWifiScanner;
72 #endif
75 #endif