Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / netwerk / wifi / nsWifiAccessPoint.cpp
blob9803553994e659a7fcea6375b8c351b6c8cd756f
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/. */
5 #include "nsWifiAccessPoint.h"
6 #include "nsString.h"
7 #include "mozilla/Logging.h"
9 extern mozilla::LazyLogModule gWifiMonitorLog;
10 #define LOG(args) MOZ_LOG(gWifiMonitorLog, mozilla::LogLevel::Debug, args)
12 NS_IMPL_ISUPPORTS(nsWifiAccessPoint, nsIWifiAccessPoint)
14 nsWifiAccessPoint::nsWifiAccessPoint() {
15 // make sure these are null terminated (because we are paranoid)
16 mMac[0] = '\0';
17 mSsid[0] = '\0';
18 mSsidLen = 0;
19 mSignal = -1000;
22 NS_IMETHODIMP nsWifiAccessPoint::GetMac(nsACString& aMac) {
23 aMac.Assign(mMac);
24 return NS_OK;
27 NS_IMETHODIMP nsWifiAccessPoint::GetSsid(nsAString& aSsid) {
28 // just assign and embedded nulls will truncate resulting
29 // in a displayable string.
30 aSsid.AssignASCII(mSsid);
31 return NS_OK;
34 NS_IMETHODIMP nsWifiAccessPoint::GetRawSSID(nsACString& aRawSsid) {
35 aRawSsid.Assign(mSsid, mSsidLen); // SSIDs are 32 chars long
36 return NS_OK;
39 NS_IMETHODIMP nsWifiAccessPoint::GetSignal(int32_t* aSignal) {
40 NS_ENSURE_ARG(aSignal);
41 *aSignal = mSignal;
42 return NS_OK;
45 int nsWifiAccessPoint::Compare(const nsWifiAccessPoint& o) const {
46 int ret = strcmp(mMac, o.mMac);
47 if (ret) {
48 return ret;
50 if (mSsidLen != o.mSsidLen) {
51 return (mSsidLen < o.mSsidLen) ? -1 : 1;
53 ret = strncmp(mSsid, o.mSsid, mSsidLen);
54 if (ret) {
55 return ret;
57 if (mSignal == o.mSignal) {
58 return 0;
60 return (mSignal < o.mSignal) ? -1 : 1;
63 bool nsWifiAccessPoint::operator==(const nsWifiAccessPoint& o) const {
64 LOG(("nsWifiAccessPoint comparing %s->%s | %s->%s | %d -> %d\n", mSsid,
65 o.mSsid, mMac, o.mMac, mSignal, o.mSignal));
66 return Compare(o) == 0;