netwerk/wifi/nsWifiAccessPoint.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/wifi/nsWifiAccessPoint.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     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 +#include "nsWifiAccessPoint.h"
     1.9 +#include "nsString.h"
    1.10 +#include "nsMemory.h"
    1.11 +#include "prlog.h"
    1.12 +
    1.13 +#if defined(PR_LOGGING)
    1.14 +extern PRLogModuleInfo *gWifiMonitorLog;
    1.15 +#endif
    1.16 +#define LOG(args)     PR_LOG(gWifiMonitorLog, PR_LOG_DEBUG, args)
    1.17 +
    1.18 +
    1.19 +NS_IMPL_ISUPPORTS(nsWifiAccessPoint, nsIWifiAccessPoint)
    1.20 +
    1.21 +nsWifiAccessPoint::nsWifiAccessPoint()
    1.22 +{
    1.23 +  // make sure these are null terminated (because we are paranoid)
    1.24 +  mMac[0] = '\0';
    1.25 +  mSsid[0] = '\0';
    1.26 +  mSsidLen = 0;
    1.27 +}
    1.28 +
    1.29 +nsWifiAccessPoint::~nsWifiAccessPoint()
    1.30 +{
    1.31 +}
    1.32 +
    1.33 +NS_IMETHODIMP nsWifiAccessPoint::GetMac(nsACString& aMac)
    1.34 +{
    1.35 +  aMac.Assign(mMac);
    1.36 +  return NS_OK;
    1.37 +}
    1.38 +
    1.39 +NS_IMETHODIMP nsWifiAccessPoint::GetSsid(nsAString& aSsid)
    1.40 +{
    1.41 +  // just assign and embedded nulls will truncate resulting
    1.42 +  // in a displayable string.
    1.43 +  CopyASCIItoUTF16(mSsid, aSsid);
    1.44 +  return NS_OK;
    1.45 +}
    1.46 +
    1.47 +
    1.48 +NS_IMETHODIMP nsWifiAccessPoint::GetRawSSID(nsACString& aRawSsid)
    1.49 +{
    1.50 +  aRawSsid.Assign(mSsid, mSsidLen); // SSIDs are 32 chars long
    1.51 +  return NS_OK;
    1.52 +}
    1.53 +
    1.54 +NS_IMETHODIMP nsWifiAccessPoint::GetSignal(int32_t *aSignal)
    1.55 +{
    1.56 +  NS_ENSURE_ARG(aSignal);
    1.57 +  *aSignal = mSignal;
    1.58 +  return NS_OK;
    1.59 +}
    1.60 +
    1.61 +// Helper functions:
    1.62 +
    1.63 +bool AccessPointsEqual(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b)
    1.64 +{
    1.65 +  if (a.Count() != b.Count()) {
    1.66 +    LOG(("AccessPoint lists have different lengths\n"));
    1.67 +    return false;
    1.68 +  }
    1.69 +
    1.70 +  for (int32_t i = 0; i < a.Count(); i++) {
    1.71 +    LOG(("++ Looking for %s\n", a[i]->mSsid));
    1.72 +    bool found = false;
    1.73 +    for (int32_t j = 0; j < b.Count(); j++) {
    1.74 +      LOG(("   %s->%s | %s->%s\n", a[i]->mSsid, b[j]->mSsid, a[i]->mMac, b[j]->mMac));
    1.75 +      if (!strcmp(a[i]->mSsid, b[j]->mSsid) &&
    1.76 +          !strcmp(a[i]->mMac, b[j]->mMac)) {
    1.77 +        found = true;
    1.78 +      }
    1.79 +    }
    1.80 +    if (!found)
    1.81 +      return false;
    1.82 +  }
    1.83 +  LOG(("   match!\n"));
    1.84 +  return true;
    1.85 +}
    1.86 +
    1.87 +void ReplaceArray(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b)
    1.88 +{
    1.89 +  a.Clear();
    1.90 +
    1.91 +  // better way to copy?
    1.92 +  for (int32_t i = 0; i < b.Count(); i++) {
    1.93 +    a.AppendObject(b[i]);
    1.94 +  }
    1.95 +
    1.96 +  b.Clear();
    1.97 +}
    1.98 +
    1.99 +

mercurial