1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/wifi/nsWifiMonitor.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef __nsWifiMonitor__ 1.9 +#define __nsWifiMonitor__ 1.10 + 1.11 +#include "nsIWifiMonitor.h" 1.12 +#include "nsCOMPtr.h" 1.13 +#include "nsAutoPtr.h" 1.14 +#include "nsProxyRelease.h" 1.15 +#include "nsIThread.h" 1.16 +#include "nsIRunnable.h" 1.17 +#include "nsCOMArray.h" 1.18 +#include "nsIWifiListener.h" 1.19 +#include "mozilla/ReentrantMonitor.h" 1.20 +#include "prlog.h" 1.21 +#include "nsIObserver.h" 1.22 +#include "nsTArray.h" 1.23 +#include "nsITimer.h" 1.24 +#include "mozilla/Attributes.h" 1.25 +#include "nsIInterfaceRequestor.h" 1.26 + 1.27 +#if defined(PR_LOGGING) 1.28 +extern PRLogModuleInfo *gWifiMonitorLog; 1.29 +#endif 1.30 +#define LOG(args) PR_LOG(gWifiMonitorLog, PR_LOG_DEBUG, args) 1.31 + 1.32 +class nsWifiAccessPoint; 1.33 + 1.34 +class nsWifiListener 1.35 +{ 1.36 + public: 1.37 + 1.38 + nsWifiListener(nsMainThreadPtrHolder<nsIWifiListener>* aListener) 1.39 + { 1.40 + mListener = aListener; 1.41 + mHasSentData = false; 1.42 + } 1.43 + ~nsWifiListener() {} 1.44 + 1.45 + nsMainThreadPtrHandle<nsIWifiListener> mListener; 1.46 + bool mHasSentData; 1.47 +}; 1.48 + 1.49 +#ifndef MOZ_WIDGET_GONK 1.50 +class nsWifiMonitor MOZ_FINAL : nsIRunnable, nsIWifiMonitor, nsIObserver 1.51 +{ 1.52 + public: 1.53 + NS_DECL_THREADSAFE_ISUPPORTS 1.54 + NS_DECL_NSIWIFIMONITOR 1.55 + NS_DECL_NSIRUNNABLE 1.56 + NS_DECL_NSIOBSERVER 1.57 + 1.58 + nsWifiMonitor(); 1.59 + 1.60 + private: 1.61 + ~nsWifiMonitor(); 1.62 + 1.63 + nsresult DoScan(); 1.64 + 1.65 + nsresult CallWifiListeners(const nsCOMArray<nsWifiAccessPoint> &aAccessPoints, 1.66 + bool aAccessPointsChanged); 1.67 + 1.68 + bool mKeepGoing; 1.69 + nsCOMPtr<nsIThread> mThread; 1.70 + 1.71 + nsTArray<nsWifiListener> mListeners; 1.72 + 1.73 + mozilla::ReentrantMonitor mReentrantMonitor; 1.74 + 1.75 +}; 1.76 +#else 1.77 +#include "nsIWifi.h" 1.78 +class nsWifiMonitor MOZ_FINAL : nsIWifiMonitor, nsIWifiScanResultsReady, nsIObserver 1.79 +{ 1.80 + public: 1.81 + NS_DECL_ISUPPORTS 1.82 + NS_DECL_NSIWIFIMONITOR 1.83 + NS_DECL_NSIOBSERVER 1.84 + NS_DECL_NSIWIFISCANRESULTSREADY 1.85 + 1.86 + nsWifiMonitor(); 1.87 + 1.88 + private: 1.89 + ~nsWifiMonitor(); 1.90 + 1.91 + void ClearTimer() { 1.92 + if (mTimer) { 1.93 + mTimer->Cancel(); 1.94 + mTimer = nullptr; 1.95 + } 1.96 + } 1.97 + nsCOMArray<nsWifiAccessPoint> mLastAccessPoints; 1.98 + nsTArray<nsWifiListener> mListeners; 1.99 + nsCOMPtr<nsITimer> mTimer; 1.100 +}; 1.101 +#endif 1.102 + 1.103 +#endif