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_host.h" 20 #include "geofence_state.h" 21 #include "gnss_status_callback_host.h" 22 #include "location_switch_callback_host.h" 23 #include "locator_callback_host.h" 24 #include "nmea_message_callback_host.h" 25 #include "request_config.h" 26 27 namespace OHOS { 28 namespace Location { 29 void InitOnFuncMap(); 30 bool OnLocationServiceStateCallback(const napi_env& env, const size_t argc, const napi_value* argv); 31 bool OnCachedGnssLocationsReportingCallback(const napi_env& env, const size_t argc, const napi_value* argv); 32 bool OnGnssStatusChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv); 33 bool OnLocationChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv); 34 bool OnNmeaMessageChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv); 35 bool OnCountryCodeChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv); 36 bool OnFenceStatusChangeCallback(const napi_env& env, const size_t argc, const napi_value* argv); 37 38 void InitOffFuncMap(); 39 bool OffAllLocationServiceStateCallback(const napi_env& env); 40 bool OffAllLocationChangeCallback(const napi_env& env); 41 bool OffAllGnssStatusChangeCallback(const napi_env& env); 42 bool OffAllNmeaMessageChangeCallback(const napi_env& env); 43 bool OffAllCachedGnssLocationsReportingCallback(const napi_env& env); 44 bool OffAllCountryCodeChangeCallback(const napi_env& env); 45 bool OffLocationServiceStateCallback(const napi_env& env, const napi_value& handler); 46 bool OffLocationChangeCallback(const napi_env& env, const napi_value& handler); 47 bool OffGnssStatusChangeCallback(const napi_env& env, const napi_value& handler); 48 bool OffNmeaMessageChangeCallback(const napi_env& env, const napi_value& handler); 49 bool OffCachedGnssLocationsReportingCallback(const napi_env& env, const napi_value& handler); 50 bool OffCountryCodeChangeCallback(const napi_env& env, const napi_value& handler); 51 52 void SubscribeLocationServiceState(const napi_env& env, 53 const napi_ref& handlerRef, sptr<LocationSwitchCallbackHost>& switchCallbackHost); 54 void SubscribeGnssStatus(const napi_env& env, const napi_ref& handlerRef, 55 sptr<GnssStatusCallbackHost>& gnssStatusCallbackHost); 56 void SubscribeNmeaMessage(const napi_env& env, const napi_ref& handlerRef, 57 sptr<NmeaMessageCallbackHost>& nmeaMessageCallbackHost); 58 void SubscribeLocationChange(const napi_env& env, const napi_value& object, 59 const napi_ref& handlerRef, sptr<LocatorCallbackHost>& locatorCallbackHost); 60 void SubscribeCacheLocationChange(const napi_env& env, const napi_value& object, 61 const napi_ref& handlerRef, sptr<CachedLocationsCallbackHost>& cachedCallbackHost); 62 void SubscribeFenceStatusChange(const napi_env& env, const napi_value& object, const napi_value& handler); 63 void UnSubscribeLocationChange(sptr<ILocatorCallback>& callback); 64 void UnSubscribeFenceStatusChange(const napi_env& env, const napi_value& object, const napi_value& handler); 65 void UnSubscribeCacheLocationChange(sptr<ICachedLocationsCallback>& callback); 66 void UnSubscribeLocationServiceState(sptr<LocationSwitchCallbackHost>& switchCallbackHost); 67 void UnSubscribeGnssStatus(sptr<GnssStatusCallbackHost>& gnssStatusCallbackHost); 68 void UnSubscribeNmeaMessage(sptr<NmeaMessageCallbackHost>& nmeaMessageCallbackHost); 69 bool IsCallbackEquals(const napi_env& env, const napi_value& handler, const napi_ref& savedCallback); 70 void GenRequestConfig(const napi_env& env, const napi_value* argv, 71 const size_t& objectArgsNum, std::unique_ptr<RequestConfig>& requestConfig); 72 napi_value RequestLocationOnce(const napi_env& env, const size_t argc, const napi_value* argv); 73 napi_value On(napi_env env, napi_callback_info cbinfo); 74 napi_value Off(napi_env env, napi_callback_info cbinfo); 75 napi_value GetCurrentLocation(napi_env env, napi_callback_info cbinfo); 76 77 #ifdef ENABLE_NAPI_MANAGER 78 LocationErrCode SubscribeLocationServiceStateV9(const napi_env& env, 79 const napi_ref& handlerRef, sptr<LocationSwitchCallbackHost>& switchCallbackHost); 80 LocationErrCode SubscribeGnssStatusV9(const napi_env& env, const napi_ref& handlerRef, 81 sptr<GnssStatusCallbackHost>& gnssStatusCallbackHost); 82 LocationErrCode SubscribeNmeaMessageV9(const napi_env& env, const napi_ref& handlerRef, 83 sptr<NmeaMessageCallbackHost>& nmeaMessageCallbackHost); 84 LocationErrCode SubscribeLocationChangeV9(const napi_env& env, const napi_value& object, 85 const napi_ref& handlerRef, sptr<LocatorCallbackHost>& locatorCallbackHost); 86 LocationErrCode SubscribeCacheLocationChangeV9(const napi_env& env, const napi_value& object, 87 const napi_ref& handlerRef, sptr<CachedLocationsCallbackHost>& cachedCallbackHost); 88 LocationErrCode SubscribeFenceStatusChangeV9(const napi_env& env, const napi_value& object, const napi_value& handler); 89 LocationErrCode UnSubscribeLocationChangeV9(sptr<ILocatorCallback>& callback); 90 LocationErrCode UnSubscribeFenceStatusChangeV9(const napi_env& env, 91 const napi_value& object, const napi_value& handler); 92 LocationErrCode UnSubscribeCacheLocationChangeV9(sptr<ICachedLocationsCallback>& callback); 93 LocationErrCode UnSubscribeLocationServiceStateV9(sptr<LocationSwitchCallbackHost>& switchCallbackHost); 94 LocationErrCode UnSubscribeGnssStatusV9(sptr<GnssStatusCallbackHost>& gnssStatusCallbackHost); 95 LocationErrCode UnSubscribeNmeaMessageV9(sptr<NmeaMessageCallbackHost>& nmeaMessageCallbackHost); 96 napi_value RequestLocationOnceV9(const napi_env& env, const size_t argc, const napi_value* argv); 97 LocationErrCode CheckLocationSwitchEnable(); 98 #endif 99 } // namespace Location 100 } // namespace OHOS 101 #endif // LOCATION_NAPI_EVENT_H 102