1 : /* ***** BEGIN LICENSE BLOCK *****
2 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 : *
4 : * The contents of this file are subject to the Mozilla Public License Version
5 : * 1.1 (the "License"); you may not use this file except in compliance with
6 : * the License. You may obtain a copy of the License at
7 : * http://www.mozilla.org/MPL/
8 : *
9 : * Software distributed under the License is distributed on an "AS IS" basis,
10 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 : * for the specific language governing rights and limitations under the
12 : * License.
13 : *
14 : * The Original Code is Geolocation.
15 : *
16 : * The Initial Developer of the Original Code is Mozilla Foundation
17 : * Portions created by the Initial Developer are Copyright (C) 2009
18 : * the Initial Developer. All Rights Reserved.
19 : *
20 : * This is a derivative of work done by Google under a BSD style License.
21 : * See: http://gears.googlecode.com/svn/trunk/gears/geolocation/
22 : *
23 : * Contributor(s):
24 : * Doug Turner <dougt@meer.net> (Original Author)
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #include "nsWifiAccessPoint.h"
41 : #include "nsString.h"
42 : #include "nsMemory.h"
43 : #include "prlog.h"
44 :
45 : #if defined(PR_LOGGING)
46 : extern PRLogModuleInfo *gWifiMonitorLog;
47 : #endif
48 : #define LOG(args) PR_LOG(gWifiMonitorLog, PR_LOG_DEBUG, args)
49 :
50 :
51 0 : NS_IMPL_THREADSAFE_ISUPPORTS1(nsWifiAccessPoint, nsIWifiAccessPoint)
52 :
53 0 : nsWifiAccessPoint::nsWifiAccessPoint()
54 : {
55 : // make sure these are null terminated (because we are paranoid)
56 0 : mMac[0] = nsnull;
57 0 : mSsid[0] = nsnull;
58 0 : mSsidLen = 0;
59 0 : }
60 :
61 0 : nsWifiAccessPoint::~nsWifiAccessPoint()
62 : {
63 0 : }
64 :
65 0 : NS_IMETHODIMP nsWifiAccessPoint::GetMac(nsACString& aMac)
66 : {
67 0 : aMac.Assign(mMac);
68 0 : return NS_OK;
69 : }
70 :
71 0 : NS_IMETHODIMP nsWifiAccessPoint::GetSsid(nsAString& aSsid)
72 : {
73 : // just assign and embedded nulls will truncate resulting
74 : // in a displayable string.
75 0 : CopyASCIItoUTF16(mSsid, aSsid);
76 0 : return NS_OK;
77 : }
78 :
79 :
80 0 : NS_IMETHODIMP nsWifiAccessPoint::GetRawSSID(nsACString& aRawSsid)
81 : {
82 0 : aRawSsid.Assign(mSsid, mSsidLen); // SSIDs are 32 chars long
83 0 : return NS_OK;
84 : }
85 :
86 0 : NS_IMETHODIMP nsWifiAccessPoint::GetSignal(PRInt32 *aSignal)
87 : {
88 0 : NS_ENSURE_ARG(aSignal);
89 0 : *aSignal = mSignal;
90 0 : return NS_OK;
91 : }
92 :
93 : // Helper functions:
94 :
95 1 : bool AccessPointsEqual(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b)
96 : {
97 1 : if (a.Count() != b.Count()) {
98 0 : LOG(("AccessPoint lists have different lengths\n"));
99 0 : return false;
100 : }
101 :
102 1 : for (PRInt32 i = 0; i < a.Count(); i++) {
103 0 : LOG(("++ Looking for %s\n", a[i]->mSsid));
104 0 : bool found = false;
105 0 : for (PRInt32 j = 0; j < b.Count(); j++) {
106 0 : LOG((" %s->%s | %s->%s\n", a[i]->mSsid, b[j]->mSsid, a[i]->mMac, b[j]->mMac));
107 0 : if (!strcmp(a[i]->mSsid, b[j]->mSsid) &&
108 0 : !strcmp(a[i]->mMac, b[j]->mMac)) {
109 0 : found = true;
110 : }
111 : }
112 0 : if (!found)
113 0 : return false;
114 : }
115 1 : LOG((" match!\n"));
116 1 : return true;
117 : }
118 :
119 1 : void ReplaceArray(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b)
120 : {
121 1 : a.Clear();
122 :
123 : // better way to copy?
124 1 : for (PRInt32 i = 0; i < b.Count(); i++) {
125 0 : a.AppendObject(b[i]);
126 : }
127 :
128 1 : b.Clear();
129 1 : }
130 :
131 :
|