LowpanChannelInfo.cpp revision d38415634a6e0d2175e888618a6ebc52dfcb861e
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "LowpanChannelInfo"
18
19#include <android/net/lowpan/LowpanChannelInfo.h>
20
21#include <binder/Parcel.h>
22#include <log/log.h>
23#include <utils/Errors.h>
24
25using android::BAD_TYPE;
26using android::BAD_VALUE;
27using android::NO_ERROR;
28using android::Parcel;
29using android::status_t;
30using android::UNEXPECTED_NULL;
31using android::net::lowpan::LowpanChannelInfo;
32using namespace ::android::binder;
33
34namespace android {
35
36namespace net {
37
38namespace lowpan {
39
40#define RETURN_IF_FAILED(calledOnce)                                     \
41    {                                                                    \
42        status_t returnStatus = calledOnce;                              \
43        if (returnStatus) {                                              \
44            ALOGE("Failed at %s:%d (%s)", __FILE__, __LINE__, __func__); \
45            return returnStatus;                                         \
46         }                                                               \
47    }
48
49status_t LowpanChannelInfo::writeToParcel(Parcel* parcel) const {
50    /*
51     * Keep implementation in sync with writeToParcel() in
52     * frameworks/base/lowpan/java/android/net/android/net/lowpan/LowpanChannelInfo.java.
53     */
54
55    RETURN_IF_FAILED(parcel->writeInt32(mIndex));
56    RETURN_IF_FAILED(parcel->writeUtf8AsUtf16(mName));
57    RETURN_IF_FAILED(parcel->writeFloat(mSpectrumCenterFrequency));
58    RETURN_IF_FAILED(parcel->writeFloat(mSpectrumBandwidth));
59    RETURN_IF_FAILED(parcel->writeInt32(mMaxTxPower));
60    RETURN_IF_FAILED(parcel->writeBool(mIsMaskedByRegulatoryDomain));
61
62    return NO_ERROR;
63}
64
65status_t LowpanChannelInfo::readFromParcel(const Parcel* parcel) {
66    /*
67     * Keep implementation in sync with readFromParcel() in
68     * frameworks/base/lowpan/java/android/net/android/net/lowpan/LowpanChannelInfo.java.
69     */
70
71    RETURN_IF_FAILED(parcel->readInt32(&mIndex));
72    RETURN_IF_FAILED(parcel->readUtf8FromUtf16(&mName));
73    RETURN_IF_FAILED(parcel->readFloat(&mSpectrumCenterFrequency));
74    RETURN_IF_FAILED(parcel->readFloat(&mSpectrumBandwidth));
75    RETURN_IF_FAILED(parcel->readInt32(&mMaxTxPower));
76    RETURN_IF_FAILED(parcel->readBool(&mIsMaskedByRegulatoryDomain));
77
78    return NO_ERROR;
79}
80
81bool LowpanChannelInfo::operator==(const LowpanChannelInfo& rhs)
82{
83    if (mIndex != rhs.mIndex) {
84        return false;
85    }
86
87    if (mName != rhs.mName) {
88        return false;
89    }
90
91    if (mSpectrumCenterFrequency != rhs.mSpectrumCenterFrequency) {
92        return false;
93    }
94
95    if (mSpectrumBandwidth != rhs.mSpectrumBandwidth) {
96        return false;
97    }
98
99    if (mMaxTxPower != rhs.mMaxTxPower) {
100        return false;
101    }
102
103    if (mIsMaskedByRegulatoryDomain != rhs.mIsMaskedByRegulatoryDomain) {
104        return false;
105    }
106
107    return true;
108}
109
110}  // namespace lowpan
111
112}  // namespace net
113
114}  // namespace android
115