1 /*
2 * Copyright (C) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "bluetooth_device_battery_info.h"
17 #include "bluetooth_log.h"
18
19 namespace OHOS {
20 namespace Bluetooth {
Marshalling(Parcel & parcel) const21 bool BluetoothBatteryInfo::Marshalling(Parcel &parcel) const
22 {
23 CHECK_AND_RETURN_LOG_RET(parcel.WriteInt32(batteryLevel_), false, "write batteryLevel error");
24 CHECK_AND_RETURN_LOG_RET(parcel.WriteInt32(leftEarBatteryLevel_), false, "write leftEarBatteryLevel error");
25 CHECK_AND_RETURN_LOG_RET(parcel.WriteInt32(leftEarChargeState_), false, "write leftEarChargeState error");
26 CHECK_AND_RETURN_LOG_RET(parcel.WriteInt32(rightEarBatteryLevel_), false, "write rightEarBatteryLevel error");
27 CHECK_AND_RETURN_LOG_RET(parcel.WriteInt32(rightEarChargeState_), false, "write rightEarChargeState error");
28 CHECK_AND_RETURN_LOG_RET(parcel.WriteInt32(boxBatteryLevel_), false, "write boxBatteryLevel error");
29 CHECK_AND_RETURN_LOG_RET(parcel.WriteInt32(boxChargeState_), false, "write boxChargeState error");
30 return true;
31 }
32
WriteToParcel(Parcel & parcel)33 bool BluetoothBatteryInfo::WriteToParcel(Parcel &parcel)
34 {
35 return Marshalling(parcel);
36 }
37
Unmarshalling(Parcel & parcel)38 BluetoothBatteryInfo *BluetoothBatteryInfo::Unmarshalling(Parcel &parcel)
39 {
40 BluetoothBatteryInfo *batteryInfo = new BluetoothBatteryInfo();
41 if (batteryInfo != nullptr && !batteryInfo->ReadFromParcel(parcel)) {
42 delete batteryInfo;
43 batteryInfo = nullptr;
44 }
45 return batteryInfo;
46 }
47
ReadFromParcel(Parcel & parcel)48 bool BluetoothBatteryInfo::ReadFromParcel(Parcel &parcel)
49 {
50 CHECK_AND_RETURN_LOG_RET(parcel.ReadInt32(batteryLevel_), false, "read batteryLevel error");
51 CHECK_AND_RETURN_LOG_RET(parcel.ReadInt32(leftEarBatteryLevel_), false, "read leftEarBatteryLevel error");
52 CHECK_AND_RETURN_LOG_RET(parcel.ReadInt32(leftEarChargeState_), false, "read leftEarChargeState error");
53 CHECK_AND_RETURN_LOG_RET(parcel.ReadInt32(rightEarBatteryLevel_), false, "read rightEarBatteryLevel error");
54 CHECK_AND_RETURN_LOG_RET(parcel.ReadInt32(rightEarChargeState_), false, "read rightEarChargeState error");
55 CHECK_AND_RETURN_LOG_RET(parcel.ReadInt32(boxBatteryLevel_), false, "read boxBatteryLevel error");
56 CHECK_AND_RETURN_LOG_RET(parcel.ReadInt32(boxChargeState_), false, "read boxChargeState error");
57 return true;
58 }
59
60 } // namespace Bluetooth
61 } // namespace OHOS