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_ADAPTER_H
17 #define LOCATION_ADAPTER_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <sys/types.h>
22 
23 namespace OHOS::NWeb {
24 
25 class LocationRequestConfig {
26 public:
27     enum Priority {
28         PRIORITY_UNSET = 0,
29         PRIORITY_ACCURACY,
30         PRIORITY_LOW_POWER,
31         PRIORITY_FAST_FIRST_FIX,
32     };
33 
34     enum Scenario {
35         UNSET = 0,
36         NAVIGATION,
37         TRAJECTORY_TRACKING,
38         CAR_HAILING,
39         DAILY_LIFE_SERVICE,
40         NO_POWER,
41     };
42 
43     LocationRequestConfig() = default;
44 
45     virtual ~LocationRequestConfig() = default;
46 
47     virtual void SetScenario(int32_t scenario) = 0;
48 
49     virtual void SetFixNumber(int32_t number) = 0;
50 
51     virtual void SetMaxAccuracy(int32_t maxAccuary) = 0;
52 
53     virtual void SetDistanceInterval(int32_t disInterval) = 0;
54 
55     virtual void SetTimeInterval(int32_t timeInterval) = 0;
56 
57     virtual void SetPriority(int32_t priority) = 0;
58 };
59 
60 class LocationInfo {
61 public:
62     LocationInfo() = default;
63 
64     virtual ~LocationInfo() = default;
65 
66     virtual double GetLatitude() = 0;
67 
68     virtual double GetLongitude() = 0;
69 
70     virtual double GetAltitude() = 0;
71 
72     virtual float GetAccuracy() = 0;
73 
74     virtual float GetSpeed() = 0;
75 
76     virtual double GetDirection() = 0;
77 
78     virtual int64_t GetTimeStamp() = 0;
79 
80     virtual int64_t GetTimeSinceBoot() = 0;
81 
82     virtual std::vector<std::string> GetAdditions() = 0;
83 };
84 
85 class LocationCallbackAdapter {
86 public:
87     LocationCallbackAdapter() = default;
88 
89     virtual ~LocationCallbackAdapter() = default;
90 
91     virtual void OnLocationReport(const std::shared_ptr<LocationInfo> location) = 0;
92 
93     virtual void OnLocatingStatusChange(const int status) = 0;
94 
95     virtual void OnErrorReport(const int errorCode) = 0;
96 };
97 
98 class LocationProxyAdapter {
99 public:
100     LocationProxyAdapter() = default;
101 
102     virtual ~LocationProxyAdapter() = default;
103 
104     virtual int32_t StartLocating(
105         std::shared_ptr<LocationRequestConfig> requestConfig, std::shared_ptr<LocationCallbackAdapter> callback) = 0;
106 
107     virtual bool StopLocating(int32_t callbackId) = 0;
108 
109     virtual bool EnableAbility(bool isEnabled) = 0;
110 
111     virtual bool IsLocationEnabled() = 0;
112 };
113 
114 class LocationInstance {
115 public:
116     static LocationInstance& GetInstance();
117 
118     virtual ~LocationInstance() = default;
119 
120     virtual std::shared_ptr<LocationProxyAdapter> CreateLocationProxyAdapter() = 0;
121 
122     virtual std::shared_ptr<LocationRequestConfig> CreateLocationRequestConfig() = 0;
123 };
124 
125 } // namespace OHOS::NWeb
126 
127 #endif
128