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"
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)
22 NS_IMETHODIMP
nsWifiAccessPoint::GetMac(nsACString
& aMac
) {
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
);
34 NS_IMETHODIMP
nsWifiAccessPoint::GetRawSSID(nsACString
& aRawSsid
) {
35 aRawSsid
.Assign(mSsid
, mSsidLen
); // SSIDs are 32 chars long
39 NS_IMETHODIMP
nsWifiAccessPoint::GetSignal(int32_t* aSignal
) {
40 NS_ENSURE_ARG(aSignal
);
45 int nsWifiAccessPoint::Compare(const nsWifiAccessPoint
& o
) const {
46 int ret
= strcmp(mMac
, o
.mMac
);
50 if (mSsidLen
!= o
.mSsidLen
) {
51 return (mSsidLen
< o
.mSsidLen
) ? -1 : 1;
53 ret
= strncmp(mSsid
, o
.mSsid
, mSsidLen
);
57 if (mSignal
== o
.mSignal
) {
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;