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_H
17#define LOCATION_H
18
19#include <parcel.h>
20#include <string>
21#include <map>
22
23namespace OHOS {
24namespace Location {
25class Location : public Parcelable {
26public:
27    Location();
28    explicit Location(Location &location);
29    ~Location() override = default;
30
31    inline double GetLatitude() const
32    {
33        return latitude_;
34    }
35
36    inline void SetLatitude(double latitude)
37    {
38        latitude_ = latitude;
39    }
40
41    inline double GetLongitude() const
42    {
43        return longitude_;
44    }
45
46    inline void SetLongitude(double longitude)
47    {
48        longitude_ = longitude;
49    }
50
51    inline double GetAltitude() const
52    {
53        return altitude_;
54    }
55
56    inline void SetAltitude(double altitude)
57    {
58        altitude_ = altitude;
59    }
60
61    inline double GetAccuracy() const
62    {
63        return accuracy_;
64    }
65
66    inline void SetAccuracy(double accuracy)
67    {
68        accuracy_ = accuracy;
69    }
70
71    inline double GetSpeed() const
72    {
73        return speed_;
74    }
75
76    inline void SetSpeed(double speed)
77    {
78        speed_ = speed;
79    }
80
81    inline double GetDirection() const
82    {
83        return direction_;
84    }
85
86    inline void SetDirection(double direction)
87    {
88        direction_ = direction;
89    }
90
91    inline int64_t GetTimeStamp() const
92    {
93        return timeStamp_;
94    }
95
96    inline void SetTimeStamp(int64_t timeStamp)
97    {
98        timeStamp_ = timeStamp;
99    }
100
101    inline int64_t GetTimeSinceBoot() const
102    {
103        return timeSinceBoot_;
104    }
105
106    inline void SetTimeSinceBoot(int64_t timeStamp)
107    {
108        timeSinceBoot_ = timeStamp;
109    }
110
111    inline std::vector<std::string> GetAdditions() const
112    {
113        return additions_;
114    }
115
116    inline void SetAdditions(std::vector<std::string> additions, bool ifAppend)
117    {
118        if (!ifAppend) {
119            std::vector<std::string>().swap(additions_);
120        }
121        for (auto it = additions.begin(); it != additions.end(); ++it) {
122            additions_.push_back(*it);
123        }
124    }
125
126    inline int64_t GetAdditionSize() const
127    {
128        return additionSize_;
129    }
130
131    inline void SetAdditionSize(int64_t size)
132    {
133        additionSize_ = size;
134    }
135
136    inline int GetIsFromMock() const
137    {
138        return isFromMock_;
139    }
140
141    inline void SetIsFromMock(int fromMock)
142    {
143        isFromMock_ = fromMock;
144    }
145
146    inline int32_t GetFloorNo() const
147    {
148        return floorNo_;
149    }
150
151    inline void SetFloorNo(int32_t floorNo)
152    {
153        floorNo_ = floorNo;
154    }
155
156    inline int32_t GetIsSystemApp() const
157    {
158        return isSystemApp_;
159    }
160
161    inline void SetIsSystemApp(int32_t isSystemApp)
162    {
163        isSystemApp_ = isSystemApp;
164    }
165
166    inline int32_t GetUncertaintyOfTimeSinceBoot() const
167    {
168        return uncertaintyOfTimeSinceBoot_;
169    }
170
171    inline void SetUncertaintyOfTimeSinceBoot(int32_t uncertaintyOfTimeSinceBoot)
172    {
173        uncertaintyOfTimeSinceBoot_ = uncertaintyOfTimeSinceBoot;
174    }
175
176    inline double GetFloorAccuracy() const
177    {
178        return floorAccuracy_;
179    }
180
181    inline void SetFloorAccuracy(double floorAccuracy)
182    {
183        floorAccuracy_ = floorAccuracy;
184    }
185
186    inline double GetAltitudeAccuracy() const
187    {
188        return altitudeAccuracy_;
189    }
190
191    inline void SetAltitudeAccuracy(double altitudeAccuracy)
192    {
193        altitudeAccuracy_ = altitudeAccuracy;
194    }
195
196    inline double GetSpeedAccuracy() const
197    {
198        return speedAccuracy_;
199    }
200
201    inline void SetSpeedAccuracy(double speedAccuracy)
202    {
203        speedAccuracy_ = speedAccuracy;
204    }
205
206    inline double GetDirectionAccuracy() const
207    {
208        return directionAccuracy_;
209    }
210
211    inline void SetDirectionAccuracy(double directionAccuracy)
212    {
213        directionAccuracy_ = directionAccuracy;
214    }
215
216    inline int32_t GetLocationSourceType() const
217    {
218        return locationSourceType_;
219    }
220
221    inline void SetLocationSourceType(int32_t locationSourceType)
222    {
223        locationSourceType_ = locationSourceType;
224    }
225
226    inline std::string GetUuid() const
227    {
228        return uuid_;
229    }
230
231    inline void SetUuid(std::string uuid)
232    {
233        uuid_ = uuid;
234    }
235
236    inline std::map<std::string, std::string> GetAdditionsMap() const
237    {
238        return additionsMap_;
239    }
240
241    inline int32_t GetFieldValidity() const
242    {
243        return fieldValidity_;
244    }
245
246    inline void SetFieldValidity(int32_t fieldValidity)
247    {
248        fieldValidity_ = fieldValidity;
249    }
250
251    void ReadFromParcel(Parcel& parcel);
252    bool Marshalling(Parcel& parcel) const override;
253    std::string ToString() const;
254    static std::unique_ptr<Location> Unmarshalling(Parcel& parcel);
255    static std::shared_ptr<Location> UnmarshallingShared(Parcel& parcel);
256    bool LocationEqual(const std::unique_ptr<Location>& location);
257    bool AdditionEqual(const std::unique_ptr<Location>& location);
258    void VectorString16ToVectorString8(const std::vector<std::u16string>& additions);
259    std::vector<std::u16string> VectorString8ToVectorString16() const;
260private:
261    double latitude_;
262    double longitude_;
263    double altitude_;
264    double accuracy_;
265    double speed_;
266    double direction_;
267    int64_t timeStamp_;
268    int64_t timeSinceBoot_;
269    std::vector<std::string> additions_;
270    int64_t additionSize_;
271    bool isFromMock_;
272    int32_t isSystemApp_;
273    int32_t floorNo_;
274    double floorAccuracy_;
275    std::map<std::string, std::string> additionsMap_;
276    double altitudeAccuracy_;
277    double speedAccuracy_;
278    double directionAccuracy_;
279    int64_t uncertaintyOfTimeSinceBoot_;
280    int32_t locationSourceType_;
281    std::string uuid_;
282    int32_t fieldValidity_;
283};
284} // namespace Location
285} // namespace OHOS
286#endif // LOCATION_H