|
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/ReentrantMonitor.h" |
|
17 #include "prlog.h" |
|
18 #include "nsIObserver.h" |
|
19 #include "nsTArray.h" |
|
20 #include "nsITimer.h" |
|
21 #include "mozilla/Attributes.h" |
|
22 #include "nsIInterfaceRequestor.h" |
|
23 |
|
24 #if defined(PR_LOGGING) |
|
25 extern PRLogModuleInfo *gWifiMonitorLog; |
|
26 #endif |
|
27 #define LOG(args) PR_LOG(gWifiMonitorLog, PR_LOG_DEBUG, args) |
|
28 |
|
29 class nsWifiAccessPoint; |
|
30 |
|
31 class nsWifiListener |
|
32 { |
|
33 public: |
|
34 |
|
35 nsWifiListener(nsMainThreadPtrHolder<nsIWifiListener>* aListener) |
|
36 { |
|
37 mListener = aListener; |
|
38 mHasSentData = false; |
|
39 } |
|
40 ~nsWifiListener() {} |
|
41 |
|
42 nsMainThreadPtrHandle<nsIWifiListener> mListener; |
|
43 bool mHasSentData; |
|
44 }; |
|
45 |
|
46 #ifndef MOZ_WIDGET_GONK |
|
47 class nsWifiMonitor MOZ_FINAL : nsIRunnable, nsIWifiMonitor, nsIObserver |
|
48 { |
|
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(); |
|
59 |
|
60 nsresult DoScan(); |
|
61 |
|
62 nsresult CallWifiListeners(const nsCOMArray<nsWifiAccessPoint> &aAccessPoints, |
|
63 bool aAccessPointsChanged); |
|
64 |
|
65 bool mKeepGoing; |
|
66 nsCOMPtr<nsIThread> mThread; |
|
67 |
|
68 nsTArray<nsWifiListener> mListeners; |
|
69 |
|
70 mozilla::ReentrantMonitor mReentrantMonitor; |
|
71 |
|
72 }; |
|
73 #else |
|
74 #include "nsIWifi.h" |
|
75 class nsWifiMonitor MOZ_FINAL : nsIWifiMonitor, nsIWifiScanResultsReady, nsIObserver |
|
76 { |
|
77 public: |
|
78 NS_DECL_ISUPPORTS |
|
79 NS_DECL_NSIWIFIMONITOR |
|
80 NS_DECL_NSIOBSERVER |
|
81 NS_DECL_NSIWIFISCANRESULTSREADY |
|
82 |
|
83 nsWifiMonitor(); |
|
84 |
|
85 private: |
|
86 ~nsWifiMonitor(); |
|
87 |
|
88 void ClearTimer() { |
|
89 if (mTimer) { |
|
90 mTimer->Cancel(); |
|
91 mTimer = nullptr; |
|
92 } |
|
93 } |
|
94 nsCOMArray<nsWifiAccessPoint> mLastAccessPoints; |
|
95 nsTArray<nsWifiListener> mListeners; |
|
96 nsCOMPtr<nsITimer> mTimer; |
|
97 }; |
|
98 #endif |
|
99 |
|
100 #endif |