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 
29 namespace OHOS {
30 namespace Location {
31 void InitOnFuncMap();
32 bool OnLocationServiceStateCallback(const napi_env& env, const size_t argc, const napi_value* argv);
33 bool OnCachedGnssLocationsReportingCallback(const napi_env& env, const size_t argc, const napi_value* argv);
34 bool OnGnssStatusChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv);
35 bool OnLocationChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv);
36 bool OnNmeaMessageChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv);
37 bool OnCountryCodeChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv);
38 bool OnFenceStatusChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv);
39 #ifdef ENABLE_NAPI_MANAGER
40 bool OnLocatingRequiredDataChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv);
41 bool OnLocationErrorCallback(const napi_env& env, const size_t argc, const napi_value* argv);
42 #endif
43 
44 void InitOffFuncMap();
45 bool OffAllLocationServiceStateCallback(const napi_env& env);
46 bool OffAllLocationChangeCallback(const napi_env& env);
47 bool OffAllGnssStatusChangeCallback(const napi_env& env);
48 bool OffAllNmeaMessageChangeCallback(const napi_env& env);
49 bool OffAllCachedGnssLocationsReportingCallback(const napi_env& env);
50 bool OffAllCountryCodeChangeCallback(const napi_env& env);
51 bool OffLocationServiceStateCallback(const napi_env& env, const napi_value& handler);
52 bool OffLocationChangeCallback(const napi_env& env, const napi_value& handler);
53 bool OffGnssStatusChangeCallback(const napi_env& env, const napi_value& handler);
54 bool OffNmeaMessageChangeCallback(const napi_env& env, const napi_value& handler);
55 bool OffCachedGnssLocationsReportingCallback(const napi_env& env, const napi_value& handler);
56 bool OffCountryCodeChangeCallback(const napi_env& env, const napi_value& handler);
57 #ifdef ENABLE_NAPI_MANAGER
58 bool OffAllLocatingRequiredDataChangeCallback(const napi_env& env);
59 bool OffLocatingRequiredDataChangeCallback(const napi_env& env, const napi_value& handler);
60 bool OffLocationErrorCallback(const napi_env& env, const napi_value& handler);
61 #endif
62 
63 void SubscribeLocationServiceState(const napi_env& env,
64     const napi_ref& handlerRef, sptr<LocationSwitchCallbackNapi>& switchCallbackHost);
65 void SubscribeGnssStatus(const napi_env& env, const napi_ref& handlerRef,
66     sptr<GnssStatusCallbackNapi>& gnssStatusCallbackHost);
67 void SubscribeNmeaMessage(const napi_env& env, const napi_ref& handlerRef,
68     sptr<NmeaMessageCallbackNapi>& nmeaMessageCallbackHost);
69 void SubscribeLocationChange(const napi_env& env, const napi_value& object,
70     const napi_ref& handlerRef, sptr<LocatorCallbackNapi>& locatorCallbackHost);
71 void SubscribeCacheLocationChange(const napi_env& env, const napi_value& object,
72     const napi_ref& handlerRef, sptr<CachedLocationsCallbackNapi>& cachedCallbackHost);
73 void SubscribeFenceStatusChange(const napi_env& env, const napi_value& object, const napi_value& handler);
74 void UnSubscribeLocationChange(sptr<ILocatorCallback>& callback);
75 void UnSubscribeFenceStatusChange(const napi_env& env, const napi_value& object, const napi_value& handler);
76 void UnSubscribeCacheLocationChange(sptr<ICachedLocationsCallback>& callback);
77 void UnSubscribeLocationServiceState(sptr<LocationSwitchCallbackNapi>& switchCallbackHost);
78 void UnSubscribeGnssStatus(sptr<GnssStatusCallbackNapi>& gnssStatusCallbackHost);
79 void UnSubscribeNmeaMessage(sptr<NmeaMessageCallbackNapi>& nmeaMessageCallbackHost);
80 bool IsCallbackEquals(const napi_env& env, const napi_value& handler, const napi_ref& savedCallback);
81 void GenRequestConfig(const napi_env& env, const napi_value* argv,
82     const size_t& objectArgsNum, std::unique_ptr<RequestConfig>& requestConfig);
83 bool IsRequestConfigValid(std::unique_ptr<RequestConfig>& config);
84 napi_value RequestLocationOnce(const napi_env& env, const size_t argc, const napi_value* argv);
85 napi_value On(napi_env env, napi_callback_info cbinfo);
86 napi_value Off(napi_env env, napi_callback_info cbinfo);
87 napi_value GetCurrentLocation(napi_env env, napi_callback_info cbinfo);
88 int GetCurrentLocationType(std::unique_ptr<RequestConfig>& config);
89 
90 #ifdef ENABLE_NAPI_MANAGER
91 LocationErrCode SubscribeLocationServiceStateV9(const napi_env& env,
92     const napi_ref& handlerRef, sptr<LocationSwitchCallbackNapi>& switchCallbackHost);
93 LocationErrCode SubscribeGnssStatusV9(const napi_env& env, const napi_ref& handlerRef,
94     sptr<GnssStatusCallbackNapi>& gnssStatusCallbackHost);
95 LocationErrCode SubscribeNmeaMessageV9(const napi_env& env, const napi_ref& handlerRef,
96     sptr<NmeaMessageCallbackNapi>& nmeaMessageCallbackHost);
97 LocationErrCode SubscribeLocationChangeV9(const napi_env& env, const napi_value& object,
98     const napi_ref& handlerRef, sptr<LocatorCallbackNapi>& locatorCallbackHost);
99 LocationErrCode SubscribeCacheLocationChangeV9(const napi_env& env, const napi_value& object,
100     const napi_ref& handlerRef, sptr<CachedLocationsCallbackNapi>& cachedCallbackHost);
101 LocationErrCode SubscribeFenceStatusChangeV9(const napi_env& env, const napi_value& object, const napi_value& handler);
102 LocationErrCode SubscribeLocatingRequiredDataChange(const napi_env& env, const napi_value& object,
103     const napi_ref& handlerRef, sptr<LocatingRequiredDataCallbackNapi>& locatingCallbackHost);
104 LocationErrCode SubscribeLocationError(const napi_env& env,
105     const napi_ref& handlerRef, sptr<LocationErrorCallbackNapi>& locationErrorCallbackHost);
106 LocationErrCode UnSubscribeLocationChangeV9(sptr<ILocatorCallback>& callback);
107 LocationErrCode UnSubscribeFenceStatusChangeV9(const napi_env& env,
108     const napi_value& object, const napi_value& handler);
109 LocationErrCode UnSubscribeCacheLocationChangeV9(sptr<ICachedLocationsCallback>& callback);
110 LocationErrCode UnSubscribeLocationServiceStateV9(sptr<LocationSwitchCallbackNapi>& switchCallbackHost);
111 LocationErrCode UnSubscribeGnssStatusV9(sptr<GnssStatusCallbackNapi>& gnssStatusCallbackHost);
112 LocationErrCode UnSubscribeNmeaMessageV9(sptr<NmeaMessageCallbackNapi>& nmeaMessageCallbackHost);
113 LocationErrCode UnSubscribeLocatingRequiredDataChange(sptr<LocatingRequiredDataCallbackNapi>& callbackHost);
114 LocationErrCode UnSubscribeLocationError(sptr<ILocatorCallback>& callback);
115 napi_value RequestLocationOnceV9(const napi_env& env, const size_t argc, const napi_value* argv);
116 LocationErrCode CheckLocationSwitchEnable();
117 #endif
118 }  // namespace Location
119 }  // namespace OHOS
120 #endif // LOCATION_NAPI_EVENT_H
121