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