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_ASYNC_CONTEXT_H 17 #define LOCATION_ASYNC_CONTEXT_H 18 19 #include <list> 20 #include <string> 21 22 #include "message_parcel.h" 23 #include "napi/native_api.h" 24 25 #include "async_context.h" 26 #include "constant_definition.h" 27 #include "country_code.h" 28 #include "geo_address.h" 29 #include "geo_coding_mock_info.h" 30 #include "locating_required_data.h" 31 #include "locating_required_data_callback_napi.h" 32 #include "locating_required_data_config.h" 33 #include "location.h" 34 #include "location_log.h" 35 #include "locator_callback_napi.h" 36 #include "request_config.h" 37 #include "satellite_status.h" 38 #include "location_gnss_geofence_callback_napi.h" 39 40 namespace OHOS { 41 namespace Location { 42 class LocationAsyncContext : public AsyncContext { 43 public: 44 std::unique_ptr<Location> loc; 45 46 explicit LocationAsyncContext(napi_env env, napi_async_work work = nullptr, 47 napi_deferred deferred = nullptr) : AsyncContext(env, work, deferred), loc(nullptr) {} 48 49 LocationAsyncContext() = delete; 50 ~LocationAsyncContext()51 ~LocationAsyncContext() override {} 52 }; 53 54 class ReverseGeocodeMockAsyncContext : public AsyncContext { 55 public: 56 std::vector<std::shared_ptr<GeocodingMockInfo>> mockInfo; 57 bool enable; 58 59 explicit ReverseGeocodeMockAsyncContext(napi_env env, napi_async_work work = nullptr, 60 napi_deferred deferred = nullptr) : AsyncContext(env, work, deferred), enable(false) {} 61 62 ReverseGeocodeMockAsyncContext() = delete; 63 ~ReverseGeocodeMockAsyncContext()64 ~ReverseGeocodeMockAsyncContext() override {} 65 }; 66 67 class LocationMockAsyncContext : public AsyncContext { 68 public: 69 int32_t timeInterval; 70 bool enable; 71 72 std::vector<std::shared_ptr<Location>> LocationNapi; 73 LocationMockAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) 74 : AsyncContext(env, work, deferred), timeInterval(0), enable(false) {} 75 76 LocationMockAsyncContext() = delete; 77 ~LocationMockAsyncContext()78 ~LocationMockAsyncContext() override {} 79 }; 80 81 class CountryCodeContext : public AsyncContext { 82 public: 83 std::shared_ptr<CountryCode> country; 84 85 explicit CountryCodeContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) 86 : AsyncContext(env, work, deferred), country(nullptr) {} 87 88 CountryCodeContext() = delete; 89 ~CountryCodeContext()90 ~CountryCodeContext() override {} 91 }; 92 93 class LocationRequestAsyncContext : public AsyncContext { 94 public: 95 std::unique_ptr<Location> loc; 96 std::unique_ptr<RequestConfig> request; 97 98 explicit LocationRequestAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) 99 : AsyncContext(env, work, deferred), loc(nullptr), request(nullptr) {} 100 101 LocationRequestAsyncContext() = delete; 102 ~LocationRequestAsyncContext()103 ~LocationRequestAsyncContext() override {} 104 }; 105 106 class SwitchAsyncContext : public AsyncContext { 107 public: 108 bool enable; 109 110 explicit SwitchAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) 111 : AsyncContext(env, work, deferred), enable(false) {} 112 113 SwitchAsyncContext() = delete; 114 ~SwitchAsyncContext()115 ~SwitchAsyncContext() override {} 116 }; 117 118 class NmeaAsyncContext : public AsyncContext { 119 public: 120 std::string msg; 121 122 explicit NmeaAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) 123 : AsyncContext(env, work, deferred), msg("") {} 124 125 NmeaAsyncContext() = delete; 126 ~NmeaAsyncContext()127 ~NmeaAsyncContext() override {} 128 }; 129 130 class GnssStatusAsyncContext : public AsyncContext { 131 public: 132 std::shared_ptr<SatelliteStatus> statusInfo; 133 134 explicit GnssStatusAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) 135 : AsyncContext(env, work, deferred), statusInfo(nullptr) {} 136 137 GnssStatusAsyncContext() = delete; 138 ~GnssStatusAsyncContext()139 ~GnssStatusAsyncContext() override {} 140 }; 141 142 class CachedLocationAsyncContext : public AsyncContext { 143 public: 144 std::vector<std::unique_ptr<Location>> locationList; 145 146 explicit CachedLocationAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) 147 : AsyncContext(env, work, deferred) {} 148 149 CachedLocationAsyncContext() = delete; 150 ~CachedLocationAsyncContext()151 ~CachedLocationAsyncContext() override {} 152 }; 153 154 class PrivacyAsyncContext : public AsyncContext { 155 public: 156 int type; 157 bool isConfirmed; 158 159 explicit PrivacyAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) 160 : AsyncContext(env, work, deferred), type(PRIVACY_TYPE_OTHERS), isConfirmed(false) {} 161 162 PrivacyAsyncContext() = delete; 163 ~PrivacyAsyncContext()164 ~PrivacyAsyncContext() override {} 165 }; 166 167 class CachedAsyncContext : public AsyncContext { 168 public: 169 bool enable; 170 int locationSize; 171 172 explicit CachedAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) 173 : AsyncContext(env, work, deferred), enable(false), locationSize(0) {} 174 175 CachedAsyncContext() = delete; 176 ~CachedAsyncContext()177 ~CachedAsyncContext() override {} 178 }; 179 180 class CommandAsyncContext : public AsyncContext { 181 public: 182 bool enable; 183 std::unique_ptr<LocationCommand> command; 184 185 explicit CommandAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) 186 : AsyncContext(env, work, deferred), enable(false), command(nullptr) {} 187 188 CommandAsyncContext() = delete; 189 ~CommandAsyncContext()190 ~CommandAsyncContext() override {} 191 }; 192 193 class ReverseGeoCodeAsyncContext : public AsyncContext { 194 public: 195 MessageParcel reverseGeoCodeRequest; 196 std::list<std::shared_ptr<GeoAddress>> replyList; 197 198 explicit ReverseGeoCodeAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) 199 : AsyncContext(env, work, deferred) {} 200 201 ReverseGeoCodeAsyncContext() = delete; 202 ~ReverseGeoCodeAsyncContext()203 ~ReverseGeoCodeAsyncContext() override {} 204 }; 205 206 class GeoCodeAsyncContext : public AsyncContext { 207 public: 208 MessageParcel geoCodeRequest; 209 std::list<std::shared_ptr<GeoAddress>> replyList; 210 211 explicit GeoCodeAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) 212 : AsyncContext(env, work, deferred) {} 213 214 GeoCodeAsyncContext() = delete; 215 ~GeoCodeAsyncContext()216 ~GeoCodeAsyncContext() override {} 217 }; 218 219 class SingleLocationAsyncContext : public AsyncContext { 220 public: 221 int timeout_; 222 sptr<LocatorCallbackNapi> callbackHost_; 223 std::unique_ptr<RequestConfig> request_; 224 225 explicit SingleLocationAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) 226 : AsyncContext(env, work, deferred), timeout_(0), callbackHost_(nullptr), request_(nullptr) {} 227 228 SingleLocationAsyncContext() = delete; 229 ~SingleLocationAsyncContext()230 ~SingleLocationAsyncContext() override {} 231 }; 232 233 class LocatingRequiredDataAsyncContext : public AsyncContext { 234 public: 235 std::vector<std::shared_ptr<LocatingRequiredData>> locatingRequiredDataList_; 236 237 explicit LocatingRequiredDataAsyncContext(napi_env env, 238 napi_async_work work = nullptr, napi_deferred deferred = nullptr) 239 : AsyncContext(env, work, deferred) {} 240 241 LocatingRequiredDataAsyncContext() = delete; 242 ~LocatingRequiredDataAsyncContext()243 ~LocatingRequiredDataAsyncContext() override {} 244 }; 245 246 class LocatingRequiredDataConfigAsyncContext : public AsyncContext { 247 public: 248 std::unique_ptr<LocatingRequiredDataConfig> requestConfig_; 249 std::vector<std::shared_ptr<LocatingRequiredData>> locatingRequiredDataList_; 250 251 explicit LocatingRequiredDataConfigAsyncContext(napi_env env, 252 napi_async_work work = nullptr, napi_deferred deferred = nullptr) 253 : AsyncContext(env, work, deferred) {} 254 255 LocatingRequiredDataConfigAsyncContext() = delete; 256 ~LocatingRequiredDataConfigAsyncContext()257 ~LocatingRequiredDataConfigAsyncContext() override {} 258 }; 259 260 class SingleScanAsyncContext : public AsyncContext { 261 public: 262 int timeout_; 263 sptr<LocatingRequiredDataCallbackNapi> callbackHost_; 264 265 explicit SingleScanAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) 266 : AsyncContext(env, work, deferred), timeout_(0), callbackHost_(nullptr) {} 267 268 SingleScanAsyncContext() = delete; 269 ~SingleScanAsyncContext()270 ~SingleScanAsyncContext() override {} 271 }; 272 273 class LocationErrorAsyncContext : public AsyncContext { 274 public: 275 int32_t errCode; 276 277 explicit LocationErrorAsyncContext(napi_env env, napi_async_work work = nullptr, napi_deferred deferred = nullptr) 278 : AsyncContext(env, work, deferred), errCode(-1) {} 279 280 LocationErrorAsyncContext() = delete; 281 ~LocationErrorAsyncContext()282 ~LocationErrorAsyncContext() override {} 283 }; 284 } // namespace Location 285 } // namespace OHOS 286 #endif // LOCATION_ASYNC_CONTEXT_H