michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsWifiAccessPoint.h" michael@0: #include "nsString.h" michael@0: #include "nsMemory.h" michael@0: #include "prlog.h" michael@0: michael@0: #if defined(PR_LOGGING) michael@0: extern PRLogModuleInfo *gWifiMonitorLog; michael@0: #endif michael@0: #define LOG(args) PR_LOG(gWifiMonitorLog, PR_LOG_DEBUG, args) michael@0: michael@0: michael@0: NS_IMPL_ISUPPORTS(nsWifiAccessPoint, nsIWifiAccessPoint) michael@0: michael@0: nsWifiAccessPoint::nsWifiAccessPoint() michael@0: { michael@0: // make sure these are null terminated (because we are paranoid) michael@0: mMac[0] = '\0'; michael@0: mSsid[0] = '\0'; michael@0: mSsidLen = 0; michael@0: } michael@0: michael@0: nsWifiAccessPoint::~nsWifiAccessPoint() michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP nsWifiAccessPoint::GetMac(nsACString& aMac) michael@0: { michael@0: aMac.Assign(mMac); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsWifiAccessPoint::GetSsid(nsAString& aSsid) michael@0: { michael@0: // just assign and embedded nulls will truncate resulting michael@0: // in a displayable string. michael@0: CopyASCIItoUTF16(mSsid, aSsid); michael@0: return NS_OK; michael@0: } michael@0: michael@0: michael@0: NS_IMETHODIMP nsWifiAccessPoint::GetRawSSID(nsACString& aRawSsid) michael@0: { michael@0: aRawSsid.Assign(mSsid, mSsidLen); // SSIDs are 32 chars long michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsWifiAccessPoint::GetSignal(int32_t *aSignal) michael@0: { michael@0: NS_ENSURE_ARG(aSignal); michael@0: *aSignal = mSignal; michael@0: return NS_OK; michael@0: } michael@0: michael@0: // Helper functions: michael@0: michael@0: bool AccessPointsEqual(nsCOMArray& a, nsCOMArray& b) michael@0: { michael@0: if (a.Count() != b.Count()) { michael@0: LOG(("AccessPoint lists have different lengths\n")); michael@0: return false; michael@0: } michael@0: michael@0: for (int32_t i = 0; i < a.Count(); i++) { michael@0: LOG(("++ Looking for %s\n", a[i]->mSsid)); michael@0: bool found = false; michael@0: for (int32_t j = 0; j < b.Count(); j++) { michael@0: LOG((" %s->%s | %s->%s\n", a[i]->mSsid, b[j]->mSsid, a[i]->mMac, b[j]->mMac)); michael@0: if (!strcmp(a[i]->mSsid, b[j]->mSsid) && michael@0: !strcmp(a[i]->mMac, b[j]->mMac)) { michael@0: found = true; michael@0: } michael@0: } michael@0: if (!found) michael@0: return false; michael@0: } michael@0: LOG((" match!\n")); michael@0: return true; michael@0: } michael@0: michael@0: void ReplaceArray(nsCOMArray& a, nsCOMArray& b) michael@0: { michael@0: a.Clear(); michael@0: michael@0: // better way to copy? michael@0: for (int32_t i = 0; i < b.Count(); i++) { michael@0: a.AppendObject(b[i]); michael@0: } michael@0: michael@0: b.Clear(); michael@0: } michael@0: michael@0: