15c735df2Sopenharmony_ci/* 25c735df2Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 35c735df2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 45c735df2Sopenharmony_ci * you may not use this file except in compliance with the License. 55c735df2Sopenharmony_ci * You may obtain a copy of the License at 65c735df2Sopenharmony_ci * 75c735df2Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 85c735df2Sopenharmony_ci * 95c735df2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 105c735df2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 115c735df2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125c735df2Sopenharmony_ci * See the License for the specific language governing permissions and 135c735df2Sopenharmony_ci * limitations under the License. 145c735df2Sopenharmony_ci */ 155c735df2Sopenharmony_ci 165c735df2Sopenharmony_ci#ifndef LOCATION_BLUETOOTH_SCAN_INFO_H 175c735df2Sopenharmony_ci#define LOCATION_BLUETOOTH_SCAN_INFO_H 185c735df2Sopenharmony_ci 195c735df2Sopenharmony_ci#include <parcel.h> 205c735df2Sopenharmony_ci#include <string> 215c735df2Sopenharmony_ci#include "string_ex.h" 225c735df2Sopenharmony_ci 235c735df2Sopenharmony_cinamespace OHOS { 245c735df2Sopenharmony_cinamespace Location { 255c735df2Sopenharmony_ciclass BluetoothScanInfo : public Parcelable { 265c735df2Sopenharmony_cipublic: 275c735df2Sopenharmony_ci BluetoothScanInfo() 285c735df2Sopenharmony_ci { 295c735df2Sopenharmony_ci deviceName_ = ""; 305c735df2Sopenharmony_ci mac_ = ""; 315c735df2Sopenharmony_ci rssi_ = 0; 325c735df2Sopenharmony_ci timestamp_ = 0; 335c735df2Sopenharmony_ci } 345c735df2Sopenharmony_ci 355c735df2Sopenharmony_ci explicit BluetoothScanInfo(BluetoothScanInfo& bluetoothScanInfo) 365c735df2Sopenharmony_ci { 375c735df2Sopenharmony_ci SetDeviceName(bluetoothScanInfo.GetDeviceName()); 385c735df2Sopenharmony_ci SetMac(bluetoothScanInfo.GetMac()); 395c735df2Sopenharmony_ci SetRssi(bluetoothScanInfo.GetRssi()); 405c735df2Sopenharmony_ci SetTimeStamp(bluetoothScanInfo.GetTimeStamp()); 415c735df2Sopenharmony_ci } 425c735df2Sopenharmony_ci 435c735df2Sopenharmony_ci ~BluetoothScanInfo() override = default; 445c735df2Sopenharmony_ci 455c735df2Sopenharmony_ci inline std::string GetMac() const 465c735df2Sopenharmony_ci { 475c735df2Sopenharmony_ci return mac_; 485c735df2Sopenharmony_ci } 495c735df2Sopenharmony_ci 505c735df2Sopenharmony_ci inline void SetMac(std::string mac) 515c735df2Sopenharmony_ci { 525c735df2Sopenharmony_ci mac_ = mac; 535c735df2Sopenharmony_ci } 545c735df2Sopenharmony_ci 555c735df2Sopenharmony_ci inline int64_t GetRssi() const 565c735df2Sopenharmony_ci { 575c735df2Sopenharmony_ci return rssi_; 585c735df2Sopenharmony_ci } 595c735df2Sopenharmony_ci 605c735df2Sopenharmony_ci inline void SetRssi(int64_t rssi) 615c735df2Sopenharmony_ci { 625c735df2Sopenharmony_ci rssi_ = rssi; 635c735df2Sopenharmony_ci } 645c735df2Sopenharmony_ci 655c735df2Sopenharmony_ci inline std::string GetDeviceName() const 665c735df2Sopenharmony_ci { 675c735df2Sopenharmony_ci return deviceName_; 685c735df2Sopenharmony_ci } 695c735df2Sopenharmony_ci 705c735df2Sopenharmony_ci inline void SetDeviceName(std::string deviceName) 715c735df2Sopenharmony_ci { 725c735df2Sopenharmony_ci deviceName_ = deviceName; 735c735df2Sopenharmony_ci } 745c735df2Sopenharmony_ci 755c735df2Sopenharmony_ci inline int64_t GetTimeStamp() const 765c735df2Sopenharmony_ci { 775c735df2Sopenharmony_ci return timestamp_; 785c735df2Sopenharmony_ci } 795c735df2Sopenharmony_ci 805c735df2Sopenharmony_ci inline void SetTimeStamp(int64_t timestamp) 815c735df2Sopenharmony_ci { 825c735df2Sopenharmony_ci timestamp_ = timestamp; 835c735df2Sopenharmony_ci } 845c735df2Sopenharmony_ci 855c735df2Sopenharmony_ci void ReadFromParcel(Parcel& parcel) 865c735df2Sopenharmony_ci { 875c735df2Sopenharmony_ci deviceName_ = Str16ToStr8(parcel.ReadString16()); 885c735df2Sopenharmony_ci mac_ = Str16ToStr8(parcel.ReadString16()); 895c735df2Sopenharmony_ci rssi_ = parcel.ReadInt64(); 905c735df2Sopenharmony_ci timestamp_ = parcel.ReadInt64(); 915c735df2Sopenharmony_ci } 925c735df2Sopenharmony_ci 935c735df2Sopenharmony_ci bool Marshalling(Parcel& parcel) const override 945c735df2Sopenharmony_ci { 955c735df2Sopenharmony_ci return parcel.WriteString16(Str8ToStr16(deviceName_)) && 965c735df2Sopenharmony_ci parcel.WriteString16(Str8ToStr16(mac_)) && 975c735df2Sopenharmony_ci parcel.WriteInt64(rssi_) && 985c735df2Sopenharmony_ci parcel.WriteInt64(timestamp_); 995c735df2Sopenharmony_ci } 1005c735df2Sopenharmony_ci 1015c735df2Sopenharmony_ci static std::shared_ptr<BluetoothScanInfo> Unmarshalling(Parcel& parcel) 1025c735df2Sopenharmony_ci { 1035c735df2Sopenharmony_ci auto bluetoothScanInfo = std::make_shared<BluetoothScanInfo>(); 1045c735df2Sopenharmony_ci bluetoothScanInfo->ReadFromParcel(parcel); 1055c735df2Sopenharmony_ci return bluetoothScanInfo; 1065c735df2Sopenharmony_ci } 1075c735df2Sopenharmony_ci 1085c735df2Sopenharmony_ci std::string ToString() 1095c735df2Sopenharmony_ci { 1105c735df2Sopenharmony_ci std::string str = "deviceName_ : " + deviceName_ + 1115c735df2Sopenharmony_ci ", mac_ : " + mac_ + 1125c735df2Sopenharmony_ci ", rssi_ : " + std::to_string(rssi_) + 1135c735df2Sopenharmony_ci ", timestamp_ : " + std::to_string(timestamp_); 1145c735df2Sopenharmony_ci return str; 1155c735df2Sopenharmony_ci } 1165c735df2Sopenharmony_ci 1175c735df2Sopenharmony_ciprivate: 1185c735df2Sopenharmony_ci std::string deviceName_; 1195c735df2Sopenharmony_ci std::string mac_; 1205c735df2Sopenharmony_ci int64_t rssi_; 1215c735df2Sopenharmony_ci int64_t timestamp_; 1225c735df2Sopenharmony_ci}; 1235c735df2Sopenharmony_ci} // namespace Location 1245c735df2Sopenharmony_ci} // namespace OHOS 1255c735df2Sopenharmony_ci#endif // LOCATION_BLUETOOTH_SCAN_INFO_H