summaryrefslogtreecommitdiff
path: root/libandroid_net_lowpan/LowpanChannelInfo.cpp
blob: af4e7a23250c438041c415bb277f84714100ec75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "LowpanChannelInfo"

#include <android/net/lowpan/LowpanChannelInfo.h>

#include <binder/Parcel.h>
#include <log/log.h>
#include <utils/Errors.h>

using android::BAD_TYPE;
using android::BAD_VALUE;
using android::NO_ERROR;
using android::Parcel;
using android::status_t;
using android::UNEXPECTED_NULL;
using android::net::lowpan::LowpanChannelInfo;
using namespace ::android::binder;

namespace android {

namespace net {

namespace lowpan {

#define RETURN_IF_FAILED(calledOnce)                                     \
    {                                                                    \
        status_t returnStatus = calledOnce;                              \
        if (returnStatus) {                                              \
            ALOGE("Failed at %s:%d (%s)", __FILE__, __LINE__, __func__); \
            return returnStatus;                                         \
         }                                                               \
    }

status_t LowpanChannelInfo::writeToParcel(Parcel* parcel) const {
    /*
     * Keep implementation in sync with writeToParcel() in
     * frameworks/base/lowpan/java/android/net/android/net/lowpan/LowpanChannelInfo.java.
     */

    RETURN_IF_FAILED(parcel->writeInt32(mIndex));
    RETURN_IF_FAILED(parcel->writeUtf8AsUtf16(mName));
    RETURN_IF_FAILED(parcel->writeFloat(mSpectrumCenterFrequency));
    RETURN_IF_FAILED(parcel->writeFloat(mSpectrumBandwidth));
    RETURN_IF_FAILED(parcel->writeInt32(mMaxTxPower));
    RETURN_IF_FAILED(parcel->writeBool(mIsMaskedByRegulatoryDomain));

    return NO_ERROR;
}

status_t LowpanChannelInfo::readFromParcel(const Parcel* parcel) {
    /*
     * Keep implementation in sync with readFromParcel() in
     * frameworks/base/lowpan/java/android/net/android/net/lowpan/LowpanChannelInfo.java.
     */

    RETURN_IF_FAILED(parcel->readInt32(&mIndex));
    RETURN_IF_FAILED(parcel->readUtf8FromUtf16(&mName));
    RETURN_IF_FAILED(parcel->readFloat(&mSpectrumCenterFrequency));
    RETURN_IF_FAILED(parcel->readFloat(&mSpectrumBandwidth));
    RETURN_IF_FAILED(parcel->readInt32(&mMaxTxPower));
    RETURN_IF_FAILED(parcel->readBool(&mIsMaskedByRegulatoryDomain));

    return NO_ERROR;
}

bool LowpanChannelInfo::operator==(const LowpanChannelInfo& rhs)
{
    if (mIndex != rhs.mIndex) {
        return false;
    }

    if (mName != rhs.mName) {
        return false;
    }

    if (mSpectrumCenterFrequency != rhs.mSpectrumCenterFrequency) {
        return false;
    }

    if (mSpectrumBandwidth != rhs.mSpectrumBandwidth) {
        return false;
    }

    if (mMaxTxPower != rhs.mMaxTxPower) {
        return false;
    }

    if (mIsMaskedByRegulatoryDomain != rhs.mIsMaskedByRegulatoryDomain) {
        return false;
    }

    return true;
}

}  // namespace lowpan

}  // namespace net

}  // namespace android