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