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