1/*
2 * Copyright (c) 2024 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 GEOLOCATIONMANAGER_UTILS_H
17#define GEOLOCATIONMANAGER_UTILS_H
18
19#include <cstdint>
20#include <functional>
21#include <string>
22#include <vector>
23#include "location.h"
24#include "location_napi_event.h"
25#include "napi_util.h"
26
27const int32_t ERRCODE_MEMORY_ERROR = -1;
28
29namespace OHOS {
30namespace GeoLocationManager {
31struct CMapStringString {
32    char** keys;
33    char** values;
34};
35
36struct CJLocation {
37    double latitude;
38    double longitude;
39    double altitude;
40    double accuracy;
41    double speed;
42    double direction;
43    int64_t timeStamp;
44    int64_t timeSinceBoot;
45    char** additions;
46    int64_t additionSize;
47    CMapStringString additionsMap;
48    double altitudeAccuracy;
49    double speedAccuracy;
50    double directionAccuracy;
51    int64_t uncertaintyOfTimeSinceBoot;
52    int32_t sourceType;
53};
54
55struct CJCurrentLocationRequest {
56    int32_t priority;
57    int32_t scenario;
58    float maxAccuracy;
59    int32_t timeoutMs;
60};
61
62struct CJSingleLocationRequest {
63    int32_t locatingPriority;
64    int32_t locatingTimeoutMs;
65};
66
67struct CJReverseGeocodeRequest {
68    char* locale;
69    char* country;
70    double latitude;
71    double longitude;
72    int32_t maxItems;
73};
74
75struct CJLocationCommand {
76    int32_t scenario;
77    char* command;
78};
79
80struct CJCountryCode {
81    char* country;
82    int32_t type;
83};
84
85struct CJReverseGeoCodeRequest {
86    char* locale;
87    char* country;
88    double latitude;
89    double longitude;
90    int32_t maxItems;
91};
92
93struct CJGeoCodeRequest {
94    char* locale;
95    char* country;
96    char* description;
97    int32_t maxItems;
98    double minLatitude;
99    double minLongitude;
100    double maxLatitude;
101    double maxLongitude;
102};
103
104
105struct CJGeoAddress {
106    double latitude;
107    double longitude;
108    char* locale;
109    char* placeName;
110    char* countryCode;
111    char* countryName;
112    char* administrativeArea;
113    char* subAdministrativeArea;
114    char* locality;
115    char* subLocality;
116    char* roadName;
117    char* subRoadName;
118    char* premises;
119    char* postalCode;
120    char* phoneNumber;
121    char* addressUrl;
122    char** descriptions;
123    int descriptionsSize;
124};
125
126struct CJGeoAddressArr {
127    CJGeoAddress* head;
128    int64_t size;
129};
130
131enum CallbackType {
132    locationChange = 0
133};
134
135struct CJLocationRequest {
136    int32_t priority;
137    int32_t scenario;
138    int32_t timeInterval;
139    double distanceInterval;
140    float maxAccuracy;
141};
142
143struct CJContinuousLocationRequest {
144    int32_t interval;
145    int32_t locationScenario;
146};
147
148struct CJCachedGnssLocationsRequest {
149    int32_t reportingPeriodSec;
150    bool wakeUpCacheQueueFull;
151};
152
153struct CJLocationArr {
154    CJLocation* head;
155    int64_t size;
156};
157
158struct CArrI32 {
159    int32_t* head;
160    int64_t size;
161};
162
163struct CArrF64 {
164    double* head;
165    int64_t size;
166};
167
168struct CJSatelliteStatusInfo {
169    int32_t satellitesNumber;
170    CArrI32 satelliteIds;
171    CArrF64 carrierToNoiseDensitys;
172    CArrF64 altitudes;
173    CArrF64 azimuths;
174    CArrF64 carrierFrequencies;
175    CArrI32 constellationTypes;
176    CArrI32 additionalInfoList;
177};
178
179char* MallocCString(const std::string& origin);
180
181char** StringVectorToCPointer(const std::vector<std::string>& arr);
182
183CMapStringString MapToCMapStringString(const std::map<std::string, std::string>& map);
184
185CJLocation NativeLocationToCJLocation(const Location::Location& loc);
186
187void CJCurrentLocationRequestToRequestConfig(const CJCurrentLocationRequest& request,
188    std::unique_ptr<Location::RequestConfig>& requestConfig);
189
190void CJSingleLocationRequestRequestToRequestConfig(const CJSingleLocationRequest& request,
191    std::unique_ptr<Location::RequestConfig>& requestConfig);
192
193bool CJReverseGeoCodeRequestToMessageParcel(CJReverseGeoCodeRequest& request, MessageParcel& dataParcel);
194
195CJGeoAddressArr ListGeoAddressToCJGeoAddressArr(std::list<std::shared_ptr<Location::GeoAddress>>& replyList);
196
197bool CJGeoCodeRequestToMessageParcel(CJGeoCodeRequest& request, MessageParcel& dataParcel);
198
199void CJLocationRequestToRequestConfig(CJLocationRequest& request,
200    std::unique_ptr<Location::RequestConfig>& requestConfig);
201
202void CJContinuousLocationRequestToRequestConfig(CJContinuousLocationRequest request,
203    std::unique_ptr<Location::RequestConfig>& requestConfig);
204
205CJLocationArr LocationVectorToCJLocationArr(const std::vector<std::unique_ptr<Location::Location>>& locations);
206
207void CJCachedGnssLocationsRequestToCachedLocationRequest(CJCachedGnssLocationsRequest& request,
208    std::unique_ptr<Location::CachedGnssLocationsRequest>& requestConfig);
209
210CArrI32 IntVectorToCArrI32(std::vector<int> arr);
211
212CArrF64 DoubleVectorToCArrF64(std::vector<double> arr);
213
214CJSatelliteStatusInfo SatelliteStatusInfoToCJSatelliteStatus(const std::unique_ptr<Location::SatelliteStatus>&
215    statusInfo);
216
217CJCountryCode CountryCodeToCJCountryCode(const std::shared_ptr<Location::CountryCode>& country);
218}
219}
220
221#endif // GEOLOCATIONMANAGER_UTILS_H