nsWifiMonitor.h 1.9 KB

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