1 /* 2 * Copyright (C) 2022 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 #include "bluetooth_log.h" 16 #include "bluetooth_opp_transfer_information.h" 17 18 namespace OHOS { 19 namespace Bluetooth { BluetoothIOppTransferInformation(const bluetooth::IOppTransferInformation & other)20BluetoothIOppTransferInformation::BluetoothIOppTransferInformation(const bluetooth::IOppTransferInformation &other) 21 { 22 SetId(other.GetId()); 23 SetFileName(other.GetFileName()); 24 SetFilePath(other.GetFilePath()); 25 SetFileType(other.GetFileType()); 26 SetDeviceName(other.GetDeviceName()); 27 SetDeviceAddress(other.GetDeviceAddress()); 28 SetDirection(other.GetDirection()); 29 SetStatus(other.GetStatus()); 30 SetFailedReason(other.GetFailedReason()); 31 SetTimeStamp(other.GetTimeStamp()); 32 SetCurrentBytes(other.GetCurrentBytes()); 33 SetTotalBytes(other.GetTotalBytes()); 34 } WriteToParcel(Parcel & parcel) const35bool BluetoothIOppTransferInformation::WriteToParcel(Parcel &parcel) const 36 { 37 if (!parcel.WriteInt32(GetId())) { 38 return false; 39 } 40 if (!parcel.WriteString(GetFileName())) { 41 return false; 42 } 43 if (!parcel.WriteString(GetFilePath())) { 44 return false; 45 } 46 if (!parcel.WriteString(GetFileType())) { 47 return false; 48 } 49 if (!parcel.WriteString(GetDeviceName())) { 50 return false; 51 } 52 if (!parcel.WriteString(GetDeviceAddress())) { 53 return false; 54 } 55 if (!parcel.WriteInt32(GetDirection())) { 56 return false; 57 } 58 if (!parcel.WriteInt32(GetStatus())) { 59 return false; 60 } 61 if (!parcel.WriteInt32(GetFailedReason())) { 62 return false; 63 } 64 if (!parcel.WriteInt64(GetTimeStamp())) { 65 return false; 66 } 67 if (!parcel.WriteInt64(GetCurrentBytes())) { 68 return false; 69 } 70 if (!parcel.WriteInt64(GetTotalBytes())) { 71 return false; 72 } 73 return true; 74 } 75 ReadFromParcel(Parcel & parcel)76bool BluetoothIOppTransferInformation::ReadFromParcel(Parcel &parcel) 77 { 78 std::string str; 79 int64_t val64 = 0; 80 int val = 0; 81 if (!parcel.ReadInt32(val)) { 82 return false; 83 } 84 SetId(val); 85 if (!parcel.ReadString(str)) { 86 return false; 87 } 88 SetFileName(str); 89 if (!parcel.ReadString(str)) { 90 return false; 91 } 92 SetFilePath(str); 93 if (!parcel.ReadString(str)) { 94 return false; 95 } 96 SetFileType(str); 97 if (!parcel.ReadString(str)) { 98 return false; 99 } 100 SetDeviceName(str); 101 if (!parcel.ReadString(str)) { 102 return false; 103 } 104 SetDeviceAddress(str); 105 if (!parcel.ReadInt32(val)) { 106 return false; 107 } 108 SetDirection(val); 109 SetStatus(val); 110 if (!parcel.ReadInt32(val)) { 111 return false; 112 } 113 SetFailedReason(val); 114 if (!parcel.ReadInt64(val64)) { 115 return false; 116 } 117 SetTimeStamp(val64); 118 if (!parcel.ReadInt64(val64)) { 119 return false; 120 } 121 SetCurrentBytes(val64); 122 SetTotalBytes(val64); 123 124 return true; 125 } 126 Marshalling(Parcel & parcel) const127bool BluetoothIOppTransferInformation::Marshalling(Parcel &parcel) const 128 { 129 return WriteToParcel(parcel); 130 } 131 Unmarshalling(Parcel & parcel)132BluetoothIOppTransferInformation *BluetoothIOppTransferInformation::Unmarshalling(Parcel &parcel) 133 { 134 BluetoothIOppTransferInformation *oppTransferInformation = new BluetoothIOppTransferInformation(); 135 if (oppTransferInformation != nullptr && !oppTransferInformation->ReadFromParcel(parcel)) { 136 delete oppTransferInformation; 137 oppTransferInformation = nullptr; 138 } 139 return oppTransferInformation; 140 } 141 } // namespace Bluetooth 142 } // namespace OHOS