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 "locating_required_data_callback_host.h" 23 #include "location_switch_callback_host.h" 24 #include "locator.h" 25 #include "locator_callback_host.h" 26 #include "nmea_message_callback_host.h" 27 #include "request_config.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 #endif 42 43 void InitOffFuncMap(); 44 bool OffAllLocationServiceStateCallback(const napi_env& env); 45 bool OffAllLocationChangeCallback(const napi_env& env); 46 bool OffAllGnssStatusChangeCallback(const napi_env& env); 47 bool OffAllNmeaMessageChangeCallback(const napi_env& env); 48 bool OffAllCachedGnssLocationsReportingCallback(const napi_env& env); 49 bool OffAllCountryCodeChangeCallback(const napi_env& env); 50 bool OffLocationServiceStateCallback(const napi_env& env, const napi_value& handler); 51 bool OffLocationChangeCallback(const napi_env& env, const napi_value& handler); 52 bool OffGnssStatusChangeCallback(const napi_env& env, const napi_value& handler); 53 bool OffNmeaMessageChangeCallback(const napi_env& env, const napi_value& handler); 54 bool OffCachedGnssLocationsReportingCallback(const napi_env& env, const napi_value& handler); 55 bool OffCountryCodeChangeCallback(const napi_env& env, const napi_value& handler); 56 #ifdef ENABLE_NAPI_MANAGER 57 bool OffAllLocatingRequiredDataChangeCallback(const napi_env& env); 58 bool OffLocatingRequiredDataChangeCallback(const napi_env& env, const napi_value& handler); 59 60 #endif 61 62 void SubscribeLocationServiceState(const napi_env& env, 63 const napi_ref& handlerRef, sptr<LocationSwitchCallbackHost>& switchCallbackHost); 64 void SubscribeGnssStatus(const napi_env& env, const napi_ref& handlerRef, 65 sptr<GnssStatusCallbackHost>& gnssStatusCallbackHost); 66 void SubscribeNmeaMessage(const napi_env& env, const napi_ref& handlerRef, 67 sptr<NmeaMessageCallbackHost>& nmeaMessageCallbackHost); 68 void SubscribeLocationChange(const napi_env& env, const napi_value& object, 69 const napi_ref& handlerRef, sptr<LocatorCallbackHost>& locatorCallbackHost); 70 void SubscribeCacheLocationChange(const napi_env& env, const napi_value& object, 71 const napi_ref& handlerRef, sptr<CachedLocationsCallbackHost>& cachedCallbackHost); 72 void SubscribeFenceStatusChange(const napi_env& env, const napi_value& object, const napi_value& handler); 73 void UnSubscribeLocationChange(sptr<ILocatorCallback>& callback); 74 void UnSubscribeFenceStatusChange(const napi_env& env, const napi_value& object, const napi_value& handler); 75 void UnSubscribeCacheLocationChange(sptr<ICachedLocationsCallback>& callback); 76 void UnSubscribeLocationServiceState(sptr<LocationSwitchCallbackHost>& switchCallbackHost); 77 void UnSubscribeGnssStatus(sptr<GnssStatusCallbackHost>& gnssStatusCallbackHost); 78 void UnSubscribeNmeaMessage(sptr<NmeaMessageCallbackHost>& nmeaMessageCallbackHost); 79 bool IsCallbackEquals(const napi_env& env, const napi_value& handler, const napi_ref& savedCallback); 80 void GenRequestConfig(const napi_env& env, const napi_value* argv, 81 const size_t& objectArgsNum, std::unique_ptr<RequestConfig>& requestConfig); 82 bool IsRequestConfigValid(std::unique_ptr<RequestConfig>& config); 83 napi_value RequestLocationOnce(const napi_env& env, const size_t argc, const napi_value* argv); 84 napi_value On(napi_env env, napi_callback_info cbinfo); 85 napi_value Off(napi_env env, napi_callback_info cbinfo); 86 napi_value GetCurrentLocation(napi_env env, napi_callback_info cbinfo); 87 88 #ifdef ENABLE_NAPI_MANAGER 89 LocationErrCode SubscribeLocationServiceStateV9(const napi_env& env, 90 const napi_ref& handlerRef, sptr<LocationSwitchCallbackHost>& switchCallbackHost); 91 LocationErrCode SubscribeGnssStatusV9(const napi_env& env, const napi_ref& handlerRef, 92 sptr<GnssStatusCallbackHost>& gnssStatusCallbackHost); 93 LocationErrCode SubscribeNmeaMessageV9(const napi_env& env, const napi_ref& handlerRef, 94 sptr<NmeaMessageCallbackHost>& nmeaMessageCallbackHost); 95 LocationErrCode SubscribeLocationChangeV9(const napi_env& env, const napi_value& object, 96 const napi_ref& handlerRef, sptr<LocatorCallbackHost>& locatorCallbackHost); 97 LocationErrCode SubscribeCacheLocationChangeV9(const napi_env& env, const napi_value& object, 98 const napi_ref& handlerRef, sptr<CachedLocationsCallbackHost>& cachedCallbackHost); 99 LocationErrCode SubscribeFenceStatusChangeV9(const napi_env& env, const napi_value& object, const napi_value& handler); 100 LocationErrCode SubscribeLocatingRequiredDataChange(const napi_env& env, const napi_value& object, 101 const napi_ref& handlerRef, sptr<LocatingRequiredDataCallbackHost>& locatingCallbackHost); 102 LocationErrCode UnSubscribeLocationChangeV9(sptr<ILocatorCallback>& callback); 103 LocationErrCode UnSubscribeFenceStatusChangeV9(const napi_env& env, 104 const napi_value& object, const napi_value& handler); 105 LocationErrCode UnSubscribeCacheLocationChangeV9(sptr<ICachedLocationsCallback>& callback); 106 LocationErrCode UnSubscribeLocationServiceStateV9(sptr<LocationSwitchCallbackHost>& switchCallbackHost); 107 LocationErrCode UnSubscribeGnssStatusV9(sptr<GnssStatusCallbackHost>& gnssStatusCallbackHost); 108 LocationErrCode UnSubscribeNmeaMessageV9(sptr<NmeaMessageCallbackHost>& nmeaMessageCallbackHost); 109 LocationErrCode UnSubscribeLocatingRequiredDataChange(sptr<LocatingRequiredDataCallbackHost>& callbackHost); 110 napi_value RequestLocationOnceV9(const napi_env& env, const size_t argc, const napi_value* argv); 111 LocationErrCode CheckLocationSwitchEnable(); 112 #endif 113 114 class CallbackResumeManager : public ICallbackResumeManager { 115 public: 116 CallbackResumeManager() = default; 117 ~CallbackResumeManager() = default; 118 void ResumeCallback() override; 119 private: 120 void InitResumeCallbackFuncMap(); 121 void ResumeSwitchCallback(); 122 void ResumeGnssStatusCallback(); 123 void ResumeNmeaMessageCallback(); 124 void ResumeCountryCodeCallback(); 125 void ResumeCachedLocationCallback(); 126 void ResumeLocating(); 127 }; 128 } // namespace Location 129 } // namespace OHOS 130 #endif // LOCATION_NAPI_EVENT_H 131