Source code

Revision control

Other Tools

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
#ifndef __nsWifiMonitor__
6
#define __nsWifiMonitor__
7
8
#include "nsIWifiMonitor.h"
9
#include "nsCOMPtr.h"
10
#include "nsAutoPtr.h"
11
#include "nsProxyRelease.h"
12
#include "nsIThread.h"
13
#include "nsIRunnable.h"
14
#include "nsCOMArray.h"
15
#include "nsIWifiListener.h"
16
#include "mozilla/Atomics.h"
17
#include "mozilla/ReentrantMonitor.h"
18
#include "mozilla/Logging.h"
19
#include "nsIObserver.h"
20
#include "nsTArray.h"
21
#include "nsITimer.h"
22
#include "mozilla/Attributes.h"
23
#include "nsIInterfaceRequestor.h"
24
25
#ifdef XP_WIN
26
# include "win_wifiScanner.h"
27
#endif
28
29
extern mozilla::LazyLogModule gWifiMonitorLog;
30
#define LOG(args) MOZ_LOG(gWifiMonitorLog, mozilla::LogLevel::Debug, args)
31
32
class nsWifiAccessPoint;
33
34
#define kDefaultWifiScanInterval 5 /* seconds */
35
36
class nsWifiListener {
37
public:
38
explicit nsWifiListener(nsMainThreadPtrHolder<nsIWifiListener>* aListener) {
39
mListener = aListener;
40
mHasSentData = false;
41
}
42
~nsWifiListener() = default;
43
44
nsMainThreadPtrHandle<nsIWifiListener> mListener;
45
bool mHasSentData;
46
};
47
48
class nsWifiMonitor final : nsIRunnable, nsIWifiMonitor, nsIObserver {
49
public:
50
NS_DECL_THREADSAFE_ISUPPORTS
51
NS_DECL_NSIWIFIMONITOR
52
NS_DECL_NSIRUNNABLE
53
NS_DECL_NSIOBSERVER
54
55
nsWifiMonitor();
56
57
private:
58
~nsWifiMonitor() = default;
59
60
nsresult DoScan();
61
62
nsresult CallWifiListeners(const nsCOMArray<nsWifiAccessPoint>& aAccessPoints,
63
bool aAccessPointsChanged);
64
65
mozilla::Atomic<bool> mKeepGoing;
66
mozilla::Atomic<bool> mThreadComplete;
67
nsCOMPtr<nsIThread> mThread;
68
69
nsTArray<nsWifiListener> mListeners;
70
71
mozilla::ReentrantMonitor mReentrantMonitor;
72
73
#ifdef XP_WIN
74
nsAutoPtr<WinWifiScanner> mWinWifiScanner;
75
#endif
76
};
77
78
#endif