1 /* 2 * Copyright (c) 2023 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_PROXY_ADAPTER_IMPL_H 17 #define LOCATION_PROXY_ADAPTER_IMPL_H 18 19 #include <map> 20 #include <vector> 21 22 #if defined(NWEB_LOCATION_ENABLE) 23 #include "i_locator_callback.h" 24 #include "location.h" 25 #include "request_config.h" 26 #endif 27 28 #include "location_adapter.h" 29 30 namespace OHOS::NWeb { 31 class LocationRequestConfigImpl : public LocationRequestConfig { 32 public: 33 LocationRequestConfigImpl(); 34 virtual ~LocationRequestConfigImpl() = default; 35 36 void SetScenario(int32_t scenario) override; 37 void SetFixNumber(int32_t number) override; 38 void SetMaxAccuracy(int32_t maxAccuary) override; 39 void SetDistanceInterval(int32_t disInterval) override; 40 void SetTimeInterval(int32_t timeInterval) override; 41 void SetPriority(int32_t priority) override; 42 #if defined(NWEB_LOCATION_ENABLE) 43 std::unique_ptr<OHOS::Location::RequestConfig>& GetConfig(); 44 private: 45 std::unique_ptr<OHOS::Location::RequestConfig> config_; 46 #endif 47 }; 48 49 class LocationInfoImpl : public LocationInfo { 50 public: 51 #if defined(NWEB_LOCATION_ENABLE) 52 LocationInfoImpl() = delete; 53 explicit LocationInfoImpl(std::unique_ptr<OHOS::Location::Location>& location); 54 #endif 55 virtual ~LocationInfoImpl() = default; 56 57 double GetLatitude() override; 58 double GetLongitude() override; 59 double GetAltitude() override; 60 float GetAccuracy() override; 61 float GetSpeed() override; 62 double GetDirection() override; 63 int64_t GetTimeStamp() override; 64 int64_t GetTimeSinceBoot() override; 65 std::vector<std::string> GetAdditions() override; 66 #if defined(NWEB_LOCATION_ENABLE) 67 std::unique_ptr<OHOS::Location::Location>& GetLocation(); 68 private: 69 std::unique_ptr<OHOS::Location::Location> location_; 70 #endif 71 }; 72 73 #if defined(NWEB_LOCATION_ENABLE) 74 using LocatorCallbackMap = 75 std::map<int32_t, sptr<OHOS::Location::ILocatorCallback>>; 76 using IsEnableLocationFuncType = bool(*)(bool& isEnabled); 77 using EnableAbilityFuncType = bool(*)(bool enable); 78 using StartLocatingFuncType = bool(*)( 79 std::unique_ptr<OHOS::Location::RequestConfig>& requestConfig, 80 OHOS::sptr<OHOS::Location::ILocatorCallback>& callback); 81 using StopLocatingFuncType = bool(*)( 82 OHOS::sptr<OHOS::Location::ILocatorCallback>& callback); 83 #endif 84 85 class LocationProxyAdapterImpl : public LocationProxyAdapter { 86 public: 87 LocationProxyAdapterImpl(); 88 virtual ~LocationProxyAdapterImpl() = default; 89 90 int32_t StartLocating( 91 std::shared_ptr<LocationRequestConfig> requestConfig, 92 std::shared_ptr<LocationCallbackAdapter> callback) override; 93 bool StopLocating(int32_t callbackId) override; 94 bool EnableAbility(bool isEnabled) override; 95 bool IsLocationEnabled() override; 96 #if defined(NWEB_LOCATION_ENABLE) 97 private: 98 static void* wrapperHandle_; 99 static IsEnableLocationFuncType isEnableLocationFunc_; 100 static EnableAbilityFuncType enableAbilityFunc_; 101 static StartLocatingFuncType startLocatingFunc_; 102 static StopLocatingFuncType stopLocatingFunc_; 103 LocatorCallbackMap reg_; 104 #endif 105 }; 106 } 107 108 #endif 109