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