• 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_NAPI_EVENT_H
17 #define LOCATION_NAPI_EVENT_H
18 
19 #include "cached_locations_callback_napi.h"
20 #include "gnss_status_callback_napi.h"
21 #include "locating_required_data_callback_napi.h"
22 #include "location_switch_callback_napi.h"
23 #include "locator.h"
24 #include "locator_callback_napi.h"
25 #include "nmea_message_callback_napi.h"
26 #include "request_config.h"
27 #include "location_error_callback_napi.h"
28 #include "bluetooth_scan_result_callback_napi.h"
29 
30 namespace OHOS {
31 namespace Location {
32 void InitOnFuncMap();
33 bool OnLocationServiceStateCallback(const napi_env& env, const size_t argc, const napi_value* argv);
34 bool OnCachedGnssLocationsReportingCallback(const napi_env& env, const size_t argc, const napi_value* argv);
35 bool OnGnssStatusChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv);
36 bool OnLocationChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv);
37 bool OnNmeaMessageChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv);
38 bool OnCountryCodeChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv);
39 bool OnFenceStatusChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv);
40 #ifdef ENABLE_NAPI_MANAGER
41 bool OnLocatingRequiredDataChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv);
42 bool OnLocationErrorCallback(const napi_env& env, const size_t argc, const napi_value* argv);
43 bool OnBluetoothScanResultChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv);
44 #endif
45 
46 void InitOffFuncMap();
47 bool OffAllLocationServiceStateCallback(const napi_env& env);
48 bool OffAllLocationChangeCallback(const napi_env& env);
49 bool OffAllGnssStatusChangeCallback(const napi_env& env);
50 bool OffAllNmeaMessageChangeCallback(const napi_env& env);
51 bool OffAllCachedGnssLocationsReportingCallback(const napi_env& env);
52 bool OffAllCountryCodeChangeCallback(const napi_env& env);
53 bool OffLocationServiceStateCallback(const napi_env& env, const napi_value& handler);
54 bool OffLocationChangeCallback(const napi_env& env, const napi_value& handler);
55 bool OffGnssStatusChangeCallback(const napi_env& env, const napi_value& handler);
56 bool OffNmeaMessageChangeCallback(const napi_env& env, const napi_value& handler);
57 bool OffCachedGnssLocationsReportingCallback(const napi_env& env, const napi_value& handler);
58 bool OffCountryCodeChangeCallback(const napi_env& env, const napi_value& handler);
59 #ifdef ENABLE_NAPI_MANAGER
60 bool OffAllLocatingRequiredDataChangeCallback(const napi_env& env);
61 bool OffLocatingRequiredDataChangeCallback(const napi_env& env, const napi_value& handler);
62 bool OffLocationErrorCallback(const napi_env& env, const napi_value& handler);
63 bool OffBluetoothScanResultChangeCallback(const napi_env& env, const napi_value& handler);
64 bool OffAllBluetoothScanResultChangeCallback(const napi_env& env);
65 #endif
66 
67 void SubscribeLocationServiceState(const napi_env& env,
68     const napi_ref& handlerRef, sptr<LocationSwitchCallbackNapi>& switchCallbackHost);
69 void SubscribeGnssStatus(const napi_env& env, const napi_ref& handlerRef,
70     sptr<GnssStatusCallbackNapi>& gnssStatusCallbackHost);
71 void SubscribeNmeaMessage(const napi_env& env, const napi_ref& handlerRef,
72     sptr<NmeaMessageCallbackNapi>& nmeaMessageCallbackHost);
73 void SubscribeLocationChange(const napi_env& env, const napi_value& object,
74     const napi_ref& handlerRef, sptr<LocatorCallbackNapi>& locatorCallbackHost);
75 void SubscribeCacheLocationChange(const napi_env& env, const napi_value& object,
76     const napi_ref& handlerRef, sptr<CachedLocationsCallbackNapi>& cachedCallbackHost);
77 void SubscribeFenceStatusChange(const napi_env& env, const napi_value& object, const napi_value& handler);
78 void UnSubscribeLocationChange(sptr<ILocatorCallback>& callback);
79 void UnSubscribeFenceStatusChange(const napi_env& env, const napi_value& object, const napi_value& handler);
80 void UnSubscribeCacheLocationChange(sptr<ICachedLocationsCallback>& callback);
81 void UnSubscribeLocationServiceState(sptr<LocationSwitchCallbackNapi>& switchCallbackHost);
82 void UnSubscribeGnssStatus(sptr<GnssStatusCallbackNapi>& gnssStatusCallbackHost);
83 void UnSubscribeNmeaMessage(sptr<NmeaMessageCallbackNapi>& nmeaMessageCallbackHost);
84 bool IsCallbackEquals(const napi_env& env, const napi_value& handler, const napi_ref& savedCallback);
85 void GenRequestConfig(const napi_env& env, const napi_value* argv,
86     const size_t& objectArgsNum, std::unique_ptr<RequestConfig>& requestConfig);
87 bool IsRequestConfigValid(std::unique_ptr<RequestConfig>& config);
88 napi_value RequestLocationOnce(const napi_env& env, const size_t argc, const napi_value* argv);
89 napi_value On(napi_env env, napi_callback_info cbinfo);
90 napi_value Off(napi_env env, napi_callback_info cbinfo);
91 napi_value GetCurrentLocation(napi_env env, napi_callback_info cbinfo);
92 void UpdateErrorCodeOfContext(SingleLocationAsyncContext* context);
93 void UpdatePoiErrorCode(bool isNeedLocation, SingleLocationAsyncContext* context);
94 bool GetIsNeedLocation(SingleLocationAsyncContext* context);
95 bool NeedReportLastLocation(const std::unique_ptr<RequestConfig>& config, const std::unique_ptr<Location>& location);
96 
97 #ifdef ENABLE_NAPI_MANAGER
98 LocationErrCode SubscribeLocationServiceStateV9(const napi_env& env,
99     const napi_ref& handlerRef, sptr<LocationSwitchCallbackNapi>& switchCallbackHost);
100 LocationErrCode SubscribeGnssStatusV9(const napi_env& env, const napi_ref& handlerRef,
101     sptr<GnssStatusCallbackNapi>& gnssStatusCallbackHost);
102 LocationErrCode SubscribeNmeaMessageV9(const napi_env& env, const napi_ref& handlerRef,
103     sptr<NmeaMessageCallbackNapi>& nmeaMessageCallbackHost);
104 LocationErrCode SubscribeLocationChangeV9(const napi_env& env, const napi_value& object,
105     const napi_ref& handlerRef, sptr<LocatorCallbackNapi>& locatorCallbackHost);
106 LocationErrCode SubscribeCacheLocationChangeV9(const napi_env& env, const napi_value& object,
107     const napi_ref& handlerRef, sptr<CachedLocationsCallbackNapi>& cachedCallbackHost);
108 LocationErrCode SubscribeFenceStatusChangeV9(const napi_env& env, const napi_value& object, const napi_value& handler);
109 LocationErrCode SubscribeLocatingRequiredDataChange(const napi_env& env, const napi_value& object,
110     const napi_ref& handlerRef, sptr<LocatingRequiredDataCallbackNapi>& locatingCallbackHost);
111 LocationErrCode SubscribeLocationError(const napi_env& env,
112     const napi_ref& handlerRef, sptr<LocationErrorCallbackNapi>& locationErrorCallbackHost);
113 LocationErrCode SubscribeBluetoothScanResultChange(const napi_env& env,
114     const napi_ref& handlerRef, sptr<BluetoothScanResultCallbackNapi>& bluetoothScanResultCallbackHost);
115 LocationErrCode UnSubscribeBluetoothScanResultChange(sptr<BluetoothScanResultCallbackNapi>& callback);
116 LocationErrCode UnSubscribeLocationChangeV9(sptr<ILocatorCallback>& callback);
117 LocationErrCode UnSubscribeFenceStatusChangeV9(const napi_env& env,
118     const napi_value& object, const napi_value& handler);
119 LocationErrCode UnSubscribeCacheLocationChangeV9(sptr<ICachedLocationsCallback>& callback);
120 LocationErrCode UnSubscribeLocationServiceStateV9(sptr<LocationSwitchCallbackNapi>& switchCallbackHost);
121 LocationErrCode UnSubscribeGnssStatusV9(sptr<GnssStatusCallbackNapi>& gnssStatusCallbackHost);
122 LocationErrCode UnSubscribeNmeaMessageV9(sptr<NmeaMessageCallbackNapi>& nmeaMessageCallbackHost);
123 LocationErrCode UnSubscribeLocatingRequiredDataChange(sptr<LocatingRequiredDataCallbackNapi>& callbackHost);
124 LocationErrCode UnSubscribeLocationError(sptr<ILocatorCallback>& callback);
125 napi_value RequestLocationOnceV9(const napi_env& env, const size_t argc, const napi_value* argv);
126 LocationErrCode CheckLocationSwitchEnable();
127 napi_value RequestPoiInfoOnce(const napi_env& env, const size_t argc, const napi_value* argv);
128 #endif
129 }  // namespace Location
130 }  // namespace OHOS
131 #endif // LOCATION_NAPI_EVENT_H
132