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