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