|
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 #include "nsWifiAccessPoint.h" |
|
6 #include "nsString.h" |
|
7 #include "nsMemory.h" |
|
8 #include "prlog.h" |
|
9 |
|
10 #if defined(PR_LOGGING) |
|
11 extern PRLogModuleInfo *gWifiMonitorLog; |
|
12 #endif |
|
13 #define LOG(args) PR_LOG(gWifiMonitorLog, PR_LOG_DEBUG, args) |
|
14 |
|
15 |
|
16 NS_IMPL_ISUPPORTS(nsWifiAccessPoint, nsIWifiAccessPoint) |
|
17 |
|
18 nsWifiAccessPoint::nsWifiAccessPoint() |
|
19 { |
|
20 // make sure these are null terminated (because we are paranoid) |
|
21 mMac[0] = '\0'; |
|
22 mSsid[0] = '\0'; |
|
23 mSsidLen = 0; |
|
24 } |
|
25 |
|
26 nsWifiAccessPoint::~nsWifiAccessPoint() |
|
27 { |
|
28 } |
|
29 |
|
30 NS_IMETHODIMP nsWifiAccessPoint::GetMac(nsACString& aMac) |
|
31 { |
|
32 aMac.Assign(mMac); |
|
33 return NS_OK; |
|
34 } |
|
35 |
|
36 NS_IMETHODIMP nsWifiAccessPoint::GetSsid(nsAString& aSsid) |
|
37 { |
|
38 // just assign and embedded nulls will truncate resulting |
|
39 // in a displayable string. |
|
40 CopyASCIItoUTF16(mSsid, aSsid); |
|
41 return NS_OK; |
|
42 } |
|
43 |
|
44 |
|
45 NS_IMETHODIMP nsWifiAccessPoint::GetRawSSID(nsACString& aRawSsid) |
|
46 { |
|
47 aRawSsid.Assign(mSsid, mSsidLen); // SSIDs are 32 chars long |
|
48 return NS_OK; |
|
49 } |
|
50 |
|
51 NS_IMETHODIMP nsWifiAccessPoint::GetSignal(int32_t *aSignal) |
|
52 { |
|
53 NS_ENSURE_ARG(aSignal); |
|
54 *aSignal = mSignal; |
|
55 return NS_OK; |
|
56 } |
|
57 |
|
58 // Helper functions: |
|
59 |
|
60 bool AccessPointsEqual(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b) |
|
61 { |
|
62 if (a.Count() != b.Count()) { |
|
63 LOG(("AccessPoint lists have different lengths\n")); |
|
64 return false; |
|
65 } |
|
66 |
|
67 for (int32_t i = 0; i < a.Count(); i++) { |
|
68 LOG(("++ Looking for %s\n", a[i]->mSsid)); |
|
69 bool found = false; |
|
70 for (int32_t j = 0; j < b.Count(); j++) { |
|
71 LOG((" %s->%s | %s->%s\n", a[i]->mSsid, b[j]->mSsid, a[i]->mMac, b[j]->mMac)); |
|
72 if (!strcmp(a[i]->mSsid, b[j]->mSsid) && |
|
73 !strcmp(a[i]->mMac, b[j]->mMac)) { |
|
74 found = true; |
|
75 } |
|
76 } |
|
77 if (!found) |
|
78 return false; |
|
79 } |
|
80 LOG((" match!\n")); |
|
81 return true; |
|
82 } |
|
83 |
|
84 void ReplaceArray(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b) |
|
85 { |
|
86 a.Clear(); |
|
87 |
|
88 // better way to copy? |
|
89 for (int32_t i = 0; i < b.Count(); i++) { |
|
90 a.AppendObject(b[i]); |
|
91 } |
|
92 |
|
93 b.Clear(); |
|
94 } |
|
95 |
|
96 |