• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_WIFI_SCAN_INFO_H
17 #define LOCATION_WIFI_SCAN_INFO_H
18 
19 #include <parcel.h>
20 #include <string>
21 
22 namespace OHOS {
23 namespace Location {
24 class WifiScanInfo : public Parcelable {
25 public:
WifiScanInfo()26     WifiScanInfo()
27     {
28         ssid_ = "";
29         bssid_ = "";
30         rssi_ = 0;
31         frequency_ = 0;
32         timestamp_ = 0;
33     }
34 
WifiScanInfo(WifiScanInfo & wifiScanInfo)35     explicit WifiScanInfo(WifiScanInfo& wifiScanInfo)
36     {
37         SetSsid(wifiScanInfo.GetSsid());
38         SetBssid(wifiScanInfo.GetBssid());
39         SetRssi(wifiScanInfo.GetRssi());
40         SetFrequency(wifiScanInfo.GetFrequency());
41         SetTimestamp(wifiScanInfo.GetTimestamp());
42     }
43 
44     ~WifiScanInfo() override = default;
45 
GetSsid()46     inline std::string GetSsid() const
47     {
48         return ssid_;
49     }
50 
SetSsid(std::string ssid)51     inline void SetSsid(std::string ssid)
52     {
53         ssid_ = ssid;
54     }
55 
GetBssid()56     inline std::string GetBssid() const
57     {
58         return bssid_;
59     }
60 
SetBssid(std::string bssid)61     inline void SetBssid(std::string bssid)
62     {
63         bssid_ = bssid;
64     }
65 
GetRssi()66     inline int GetRssi() const
67     {
68         return rssi_;
69     }
70 
SetRssi(int rssi)71     inline void SetRssi(int rssi)
72     {
73         rssi_ = rssi;
74     }
75 
GetFrequency()76     inline int GetFrequency() const
77     {
78         return frequency_;
79     }
80 
SetFrequency(int frequency)81     inline void SetFrequency(int frequency)
82     {
83         frequency_ = frequency;
84     }
85 
GetTimestamp()86     inline int64_t GetTimestamp() const
87     {
88         return timestamp_;
89     }
90 
SetTimestamp(int64_t timestamp)91     inline void SetTimestamp(int64_t timestamp)
92     {
93         timestamp_ = timestamp;
94     }
95 
ReadFromParcel(Parcel & parcel)96     void ReadFromParcel(Parcel& parcel)
97     {
98         ssid_ =  Str16ToStr8(parcel.ReadString16());
99         bssid_ =  Str16ToStr8(parcel.ReadString16());
100         rssi_ = parcel.ReadInt32();
101         frequency_ = parcel.ReadInt32();
102         timestamp_ = parcel.ReadInt64();
103     }
104 
Marshalling(Parcel & parcel)105     bool Marshalling(Parcel& parcel) const override
106     {
107         return parcel.WriteString16(Str8ToStr16(ssid_)) &&
108             parcel.WriteString16(Str8ToStr16(bssid_)) &&
109             parcel.WriteInt32(rssi_) &&
110             parcel.WriteInt32(frequency_) &&
111             parcel.WriteInt64(timestamp_);
112     }
113 
Unmarshalling(Parcel & parcel)114     static std::shared_ptr<WifiScanInfo> Unmarshalling(Parcel& parcel)
115     {
116         auto wifiScanInfo = std::make_shared<WifiScanInfo>();
117         wifiScanInfo->ReadFromParcel(parcel);
118         return wifiScanInfo;
119     }
120 
ToString()121     std::string ToString()
122     {
123         std::string str = "ssid_ : " + ssid_ +
124             ", bssid_ : " + bssid_ +
125             ", rssi_ : " + std::to_string(rssi_) +
126             ", timestamp_ : " + std::to_string(timestamp_);
127         return str;
128     }
129 
130 private:
131     std::string ssid_;
132     std::string bssid_;
133     int rssi_;
134     int frequency_;
135     int64_t timestamp_;
136 };
137 } // namespace Location
138 } // namespace OHOS
139 #endif // LOCATION_WIFI_SCAN_INFO_H