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
16#ifndef LOCATION_BLUETOOTH_SCAN_INFO_H
17#define LOCATION_BLUETOOTH_SCAN_INFO_H
18
19#include <parcel.h>
20#include <string>
21#include "string_ex.h"
22
23namespace OHOS {
24namespace Location {
25class BluetoothScanInfo : public Parcelable {
26public:
27    BluetoothScanInfo()
28    {
29        deviceName_ = "";
30        mac_ = "";
31        rssi_ = 0;
32        timestamp_ = 0;
33    }
34
35    explicit BluetoothScanInfo(BluetoothScanInfo& bluetoothScanInfo)
36    {
37        SetDeviceName(bluetoothScanInfo.GetDeviceName());
38        SetMac(bluetoothScanInfo.GetMac());
39        SetRssi(bluetoothScanInfo.GetRssi());
40        SetTimeStamp(bluetoothScanInfo.GetTimeStamp());
41    }
42
43    ~BluetoothScanInfo() override = default;
44
45    inline std::string GetMac() const
46    {
47        return mac_;
48    }
49
50    inline void SetMac(std::string mac)
51    {
52        mac_ = mac;
53    }
54
55    inline int64_t GetRssi() const
56    {
57        return rssi_;
58    }
59
60    inline void SetRssi(int64_t rssi)
61    {
62        rssi_ = rssi;
63    }
64
65    inline std::string GetDeviceName() const
66    {
67        return deviceName_;
68    }
69
70    inline void SetDeviceName(std::string deviceName)
71    {
72        deviceName_ = deviceName;
73    }
74
75    inline int64_t GetTimeStamp() const
76    {
77        return timestamp_;
78    }
79
80    inline void SetTimeStamp(int64_t timestamp)
81    {
82        timestamp_ = timestamp;
83    }
84
85    void ReadFromParcel(Parcel& parcel)
86    {
87        deviceName_ = Str16ToStr8(parcel.ReadString16());
88        mac_ = Str16ToStr8(parcel.ReadString16());
89        rssi_ = parcel.ReadInt64();
90        timestamp_ = parcel.ReadInt64();
91    }
92
93    bool Marshalling(Parcel& parcel) const override
94    {
95        return parcel.WriteString16(Str8ToStr16(deviceName_)) &&
96            parcel.WriteString16(Str8ToStr16(mac_)) &&
97            parcel.WriteInt64(rssi_) &&
98            parcel.WriteInt64(timestamp_);
99    }
100
101    static std::shared_ptr<BluetoothScanInfo> Unmarshalling(Parcel& parcel)
102    {
103        auto bluetoothScanInfo = std::make_shared<BluetoothScanInfo>();
104        bluetoothScanInfo->ReadFromParcel(parcel);
105        return bluetoothScanInfo;
106    }
107
108    std::string ToString()
109    {
110        std::string str = "deviceName_ : " + deviceName_ +
111            ", mac_ : " + mac_ +
112            ", rssi_ : " + std::to_string(rssi_) +
113            ", timestamp_ : " + std::to_string(timestamp_);
114        return str;
115    }
116
117private:
118    std::string deviceName_;
119    std::string mac_;
120    int64_t rssi_;
121    int64_t timestamp_;
122};
123} // namespace Location
124} // namespace OHOS
125#endif // LOCATION_BLUETOOTH_SCAN_INFO_H