• 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 OHOS_HDI_SENSOR_V1_1_ISENSORINTERFACE_VDI_H
17 #define OHOS_HDI_SENSOR_V1_1_ISENSORINTERFACE_VDI_H
18 
19 #include "hdf_load_vdi.h"
20 #include "isensor_callback_vdi.h"
21 #include "v3_0/isensor_interface.h"
22 #include "hdf_log.h"
23 
24 struct SensorHandle : public OHOS::HDI::Sensor::V3_0::DeviceSensorInfo {
25     bool operator == (const SensorHandle& other) const
26     {
27 #ifdef TV_FLAG
28         return deviceId == other.deviceId && sensorType == other.sensorType && sensorId == other.sensorId &&
29                 location == other.location;
30 #else
31         return sensorType == other.sensorType;
32 #endif
33     }
34 
35     bool operator < (const SensorHandle& other) const
36     {
37         if (sensorType != other.sensorType) {
38             return sensorType < other.sensorType;
39         }
40         if (sensorId != other.sensorId) {
41             return sensorId < other.sensorId;
42         }
43         if (deviceId != other.deviceId) {
44             return deviceId < other.deviceId;
45         }
46         return location < other.location;
47     }
48 };
49 
50 namespace std {
51     template <>
52     struct hash<SensorHandle> {
53         std::size_t operator()(const SensorHandle& obj) const
54         {
55 #ifdef TV_FLAG
56             std::size_t h1 = std::hash<int64_t>{}(obj.deviceId);
57             std::size_t h2 = std::hash<int64_t>{}(obj.sensorType);
58             std::size_t h3 = std::hash<int64_t>{}(obj.sensorId);
59             std::size_t h4 = std::hash<int64_t>{}(obj.location);
60 
61             return h1 ^ h2 ^ h3 ^ h4;
62 #else
63             std::size_t h2 = std::hash<int64_t>{}(obj.sensorType);
64 
65             return h2;
66 #endif
67         }
68     };
69 }
70 
71 #define SENSOR_HANDLE_TO_STRING(sensorHandle) ("{" + std::to_string((sensorHandle).deviceId) + "," + \
72     std::to_string((sensorHandle).sensorType) + "," + std::to_string((sensorHandle).sensorId) + "," + \
73     std::to_string((sensorHandle).location) + "}")
74 #define SENSOR_HANDLE_TO_C_STR(sensorHandle) ("{" + std::to_string((sensorHandle).deviceId) + "," + \
75     std::to_string((sensorHandle).sensorType) + "," + std::to_string((sensorHandle).sensorId) + "," + \
76     std::to_string((sensorHandle).location) + "}").c_str()
77 
78 namespace OHOS {
79 namespace HDI {
80 namespace Sensor {
81 namespace V1_1 {
82 
83 #define HDI_SENSOR_VDI_LIBNAME "libhdi_sensor_impl.z.so"
84 
85 struct HdfSensorInformationVdi {
86     std::string sensorName;
87     std::string vendorName;
88     std::string firmwareVersion;
89     std::string hardwareVersion;
90     int32_t sensorTypeId;
91     int32_t sensorId;
92     struct SensorHandle sensorHandle;
93     float maxRange;
94     float accuracy;
95     float power;
96     int64_t minDelay;
97     int64_t maxDelay;
98     uint32_t fifoMaxEventCount;
99     uint32_t reserved;
100 };
101 
102 struct SdcSensorInfoVdi {
103     uint64_t offset;
104     int32_t sensorId;
105     struct SensorHandle sensorHandle;
106     int32_t ddrSize;
107     int32_t minRateLevel;
108     int32_t maxRateLevel;
109     uint64_t memAddr;
110     int32_t reserved;
111 };
112 
113 class ISensorInterfaceVdi {
114 public:
115 //V1_1
116     virtual ~ISensorInterfaceVdi() = default;
117     virtual int32_t Init()
118     {
119         HDF_LOGI("%{public}s: only in Hdi return", __func__);
120         return HDF_SUCCESS;
121     };
122     virtual int32_t GetAllSensorInfo(std::vector<HdfSensorInformationVdi>& info)
123     {
124         HDF_LOGI("%{public}s: only in Hdi return", __func__);
125         return HDF_SUCCESS;
126     };
127     virtual int32_t Enable(int32_t sensorId)
128     {
129         HDF_LOGI("%{public}s: only in Hdi return", __func__);
130         return HDF_SUCCESS;
131     };
132     virtual int32_t Disable(int32_t sensorId)
133     {
134         HDF_LOGI("%{public}s: only in Hdi return", __func__);
135         return HDF_SUCCESS;
136     };
137     virtual int32_t SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval)
138     {
139         HDF_LOGI("%{public}s: only in Hdi return", __func__);
140         return HDF_SUCCESS;
141     };
142     virtual int32_t SetMode(int32_t sensorId, int32_t mode)
143     {
144         HDF_LOGI("%{public}s: only in Hdi return", __func__);
145         return HDF_SUCCESS;
146     };
147     virtual int32_t SetOption(int32_t sensorId, uint32_t option)
148     {
149         HDF_LOGI("%{public}s: only in Hdi return", __func__);
150         return HDF_SUCCESS;
151     };
152     virtual int32_t Register(int32_t groupId, const sptr<ISensorCallbackVdi>& callbackObj)
153     {
154         HDF_LOGI("%{public}s: only in Hdi return", __func__);
155         return HDF_SUCCESS;
156     };
157     virtual int32_t Unregister(int32_t groupId, const sptr<ISensorCallbackVdi>& callbackObj)
158     {
159         HDF_LOGI("%{public}s: only in Hdi return", __func__);
160         return HDF_SUCCESS;
161     };
162     virtual int32_t SetSaBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval)
163     {
164         HDF_LOGI("%{public}s: only in Hdi return", __func__);
165         return HDF_SUCCESS;
166     };
167 
168 //V3_0
169     virtual int32_t GetDeviceSensorInfo(int32_t deviceId, std::vector<HdfSensorInformationVdi>& info)
170     {
171         HDF_LOGI("%{public}s: only in Hdi return", __func__);
172         return HDF_SUCCESS;
173     };
174     virtual int32_t GetSdcSensorInfo(std::vector<SdcSensorInfoVdi>& sdcSensorInfo)
175     {
176         HDF_LOGI("%{public}s: only in Hdi return", __func__);
177         return HDF_SUCCESS;
178     };
179     virtual int32_t Enable(SensorHandle sensorHandle)
180     {
181         HDF_LOGI("%{public}s: only in Hdi return", __func__);
182         return HDF_SUCCESS;
183     };
184     virtual int32_t Disable(SensorHandle sensorHandle)
185     {
186         HDF_LOGI("%{public}s: only in Hdi return", __func__);
187         return HDF_SUCCESS;
188     };
189     virtual int32_t SetBatch(SensorHandle sensorHandle, int64_t samplingInterval, int64_t reportInterval)
190     {
191         HDF_LOGI("%{public}s: only in Hdi return", __func__);
192         return HDF_SUCCESS;
193     };
194     virtual int32_t SetMode(SensorHandle sensorHandle, int32_t mode)
195     {
196         HDF_LOGI("%{public}s: only in Hdi return", __func__);
197         return HDF_SUCCESS;
198     };
199     virtual int32_t SetOption(SensorHandle sensorHandle, uint32_t option)
200     {
201         HDF_LOGI("%{public}s: only in Hdi return", __func__);
202         return HDF_SUCCESS;
203     };
204     virtual int32_t RegSensorPlugCallBack(const sptr<ISensorPlugCallback>& callbackObj)
205     {
206         HDF_LOGI("%{public}s: only in Hdi return", __func__);
207         return HDF_SUCCESS;
208     };
209     virtual int32_t UnRegSensorPlugCallBack(const sptr<ISensorPlugCallback>& callbackObj)
210     {
211         HDF_LOGI("%{public}s: only in Hdi return", __func__);
212         return HDF_SUCCESS;
213     };
214     virtual int32_t SetSaBatch(SensorHandle sensorHandle, int64_t samplingInterval, int64_t reportInterval)
215     {
216         HDF_LOGI("%{public}s: only in Hdi return", __func__);
217         return HDF_SUCCESS;
218     };
219 };
220 
221 struct WrapperSensorVdi {
222     struct HdfVdiBase base;
223     ISensorInterfaceVdi *sensorModule;
224 };
225 } // V1_1
226 } // Sensor
227 } // HDI
228 } // OHOS
229 
230 #endif // OHOS_HDI_SENSOR_V1_1_ISENSORINTERFACE_VDI_H
231