1 /* 2 * Copyright (C) 2025 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 "request.h" 17 #include "common_utils.h" 18 #include "constant_definition.h" 19 #include "bluetooth_scan_result.h" 20 21 namespace OHOS { 22 namespace Location { BluetoothScanResult()23BluetoothScanResult::BluetoothScanResult() 24 { 25 deviceId_ = ""; 26 deviceName_ = ""; 27 rssi_ = 0; 28 connectable_ = false; 29 } 30 BluetoothScanResult(BluetoothScanResult & bluetoothScanResult)31BluetoothScanResult::BluetoothScanResult(BluetoothScanResult& bluetoothScanResult) 32 { 33 deviceId_ = bluetoothScanResult.GetDeviceId(); 34 deviceName_ = bluetoothScanResult.GetDeviceName(); 35 rssi_ = bluetoothScanResult.GetRssi(); 36 connectable_ = bluetoothScanResult.GetConnectable(); 37 data_ = bluetoothScanResult.GetData(); 38 } 39 ~BluetoothScanResult()40BluetoothScanResult::~BluetoothScanResult() {} 41 ReadFromParcel(Parcel & parcel)42void BluetoothScanResult::ReadFromParcel(Parcel& parcel) 43 { 44 deviceId_ = Str16ToStr8(parcel.ReadString16()); 45 deviceName_ = Str16ToStr8(parcel.ReadString16()); 46 rssi_ = parcel.ReadInt64(); 47 connectable_ = parcel.ReadBool(); 48 parcel.ReadUInt8Vector(&data_); 49 } 50 UnmarshallingShared(Parcel & parcel)51std::shared_ptr<BluetoothScanResult> BluetoothScanResult::UnmarshallingShared(Parcel& parcel) 52 { 53 std::shared_ptr<BluetoothScanResult> bluetoothScanResult = std::make_shared<BluetoothScanResult>(); 54 bluetoothScanResult->ReadFromParcel(parcel); 55 return bluetoothScanResult; 56 } 57 Unmarshalling(Parcel & parcel)58std::unique_ptr<BluetoothScanResult> BluetoothScanResult::Unmarshalling(Parcel& parcel) 59 { 60 std::unique_ptr<BluetoothScanResult> bluetoothScanResult = std::make_unique<BluetoothScanResult>(); 61 bluetoothScanResult->ReadFromParcel(parcel); 62 return bluetoothScanResult; 63 } 64 Marshalling(Parcel & parcel) const65bool BluetoothScanResult::Marshalling(Parcel& parcel) const 66 { 67 return parcel.WriteString16(Str8ToStr16(deviceId_)) && 68 parcel.WriteString16(Str8ToStr16(deviceName_)) && 69 parcel.WriteInt64(rssi_) && 70 parcel.WriteBool(connectable_) && 71 parcel.WriteUInt8Vector(data_); 72 } 73 } // namespace Location 74 } // namespace OHOS