Synchronizing sensord code with IIO driver support for accelerometer plugin
[platform/core/system/sensord.git] / src / libsensord / sensor_internal.h
1 /*
2  * libsensord
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #ifndef __SENSOR_INTERNAL_H__
21 #define __SENSOR_INTERNAL_H__
22
23 #ifndef DEPRECATED
24 #define DEPRECATED __attribute__((deprecated))
25 #endif
26
27 #include "stdbool.h"
28
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif
33
34 #include <sys/types.h>
35
36 #include <sensor_internal_deprecated.h>
37
38 /*header for common sensor type*/
39 #include <sensor_common.h>
40
41 /*header for each sensor type*/
42 #include <sensor_accel.h>
43 #include <sensor_geomag.h>
44 #include <sensor_light.h>
45 #include <sensor_proxi.h>
46 #include <sensor_motion.h>
47 #include <sensor_gyro.h>
48 #include <sensor_pressure.h>
49 #include <sensor_context.h>
50 #include <sensor_gravity.h>
51 #include <sensor_linear_accel.h>
52 #include <sensor_orientation.h>
53 #include <sensor_temperature.h>
54
55
56 typedef void (*sensor_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data);
57 typedef void (*sensorhub_cb_t)(sensor_t sensor, unsigned int event_type, sensorhub_data_t *data, void *user_data);
58 typedef void (*sensor_accuracy_changed_cb_t) (sensor_t sensor, unsigned long long timestamp, int accuracy, void *user_data);
59
60 /**
61  * @brief Get the list of available sensors of a certain type,  use ALL_SENSOR to get all the sensors.
62  *
63  * @param[in] type the type of sensors requested.
64  * @param[out] list the list of sensors matching the asked type,  the caller should explicitly free this list.
65  * @param[out] sensor count the count of sensors contained in the list.
66  * @return true on success, otherwise false.
67  */
68 bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count);
69
70 /**
71  * @brief Get the default sensor for a given type.
72  *
73  * @param[in] type the type of a sensor requested.
74  * @return the default sensor matching the asked type on success, otherwise NULL.
75  */
76 sensor_t sensord_get_sensor(sensor_type_t type);
77
78 /**
79  * @brief Get the type of this sensor.
80  *
81  * @param[in] sensor a sensor to get type.
82  * @param[out] type the type of this sensor.
83  * @return return true on success, otherwise false.
84  */
85 bool sensord_get_type(sensor_t sensor, sensor_type_t *type);
86
87 /**
88  * @brief Get the name string of this sensor.
89  *
90  * @param[in] sensor a sensor to get name.
91  * @return the name string of this sensor on success, otherwise NULL.
92  */
93 const char* sensord_get_name(sensor_t sensor);
94
95 /**
96  * @brief Get the vendor string of this sensor.
97  *
98  * @param[in] sensor a sensor to get vendor.
99  * @return the vendor string of this sensor on success, otherwise NULL.
100  */
101 const char* sensord_get_vendor(sensor_t sensor);
102
103 /**
104  * @brief Get the privilege of this sensor.
105  *
106  * @param[in] sensor a sensor to get privilege.
107  * @param[out] privilege the privilege of this sensor.
108  * @return true on success, otherwise false.
109  */
110 bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege);
111
112 /**
113  * @brief Get the minimum range of this sensor in the sensor's unit.
114  *
115  * @param[in] sensor a sensor to get minimum range.
116  * @param[out] min_range the minimum range of this sensor in the sensor's unit.
117  * @return true on success, otherwise false.
118  */
119 bool sensord_get_min_range(sensor_t sensor, float *min_range);
120
121 /**
122  * @brief Get the maximum range of this sensor in the sensor's unit.
123  *
124  * @param[in] sensor a sensor to get maximum range.
125  * @param[out] max_range the maximum range of this sensor in the sensor's unit.
126  * @return true on success, otherwise false.
127  */
128 bool sensord_get_max_range(sensor_t sensor, float *max_range);
129
130 /**
131  * @brief Get the resolution of this sensor in the sensor's unit.
132  *
133  * @param[in] sensor a sensor to get resolution.
134  * @param[out] resolution the resolution of this sensor in the sensor's unit.
135  * @return true on success, otherwise false.
136  */
137 bool sensord_get_resolution(sensor_t sensor, float *resolution);
138
139 /**
140  * @brief Get the minimum interval allowed between two events in microsecond or zero if this sensor only returns a value when the data it's measuring changes.
141  *
142  * @param[in] sensor a sensor to get minimum interval.
143  * @param[out] min_interval the minimum interval of this sensor.
144  * @return true on success, otherwise false.
145  */
146 bool sensord_get_min_interval(sensor_t sensor, int *min_interval);
147
148 /**
149  * @brief Get the number of events reserved for this sensor in the batch mode FIFO.
150  *
151  * @param[in] sensor a sensor to get the number of fifo count
152  * @param[out] fifo_count the number of events reserved for this sensor in the batch mode FIFO
153  * @return true on success, otherwise false
154  */
155 bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count);
156
157 /**
158  * @brief Get the maximum number of events of this sensor that could be batched. If this value is zero it indicates that batch mode is not supported for this sensor.
159  *
160  * @param[in] sensor a sensor to the maximum number of events that could be batched.
161  * @param[out] max_batch_count the maximum number of events of this sensor that could be batched.
162  * @return true on success, otherwise false.
163  */
164 bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count);
165
166
167 /**
168  * @brief Get the supported event types of this sensor.
169  *
170  * @param[in] sensor a sensor to get the supported event types.
171  * @param[out] event_types the array containing supported event types of this sensor, the caller should explicitly free this array.
172  * @param[out] count the count of the supported event types of this sensor.
173  * @return true on success, otherwise false.
174  */
175 bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count);
176
177
178 /**
179  * @brief Check a given event type is supporeted by this sensor.
180  *
181  * @param[in] sensor a sensor to check a given event type is supporeted.
182  * @param[out] event_type an event type to be checked whether supported or not.
183  * @param[out] supported whether a given event is supported or not in this sensor.
184  * @return true on success, otherwise false.
185  */
186 bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported);
187
188 /**
189  * @brief Connect a given sensor and get a handle of a given sensor.
190  *
191  * @param[in] sensor a sensor to connect
192  * @return a handle of a given sensor on success, otherwise negative value
193  */
194 int sensord_connect(sensor_t sensor);
195
196 /**
197  * @brief Disconnect a given sensor.
198  *
199  * @param[in] handle a handle to disconnect.
200  * @return true on success, otherwise false.
201  */
202 bool sensord_disconnect(int handle);
203
204 /**
205  * @brief Register a callback with a connected sensor for a given event_type. This callback will be called when a given event occurs in a connected sensor.
206  *
207  * @param[in] handle a handle represensting a connected sensor.
208  * @param[in] event_type an event type  to register
209  * @param[in] interval The desired interval between two consecutive events in microseconds. This is only a hint to the system so events may be received faster or slower than the specified interval.
210  *                                   It can be one of SENSOR_INTERVAL_NORMAL,  SENSOR_INTERVAL_FASTEST or the interval in microseconds.
211  * @param[in] max_batch_latency An event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled.
212  * @param[in] cb a callback which is called when a given event occurs
213  * @param[in] user_data the callback is called with user_data
214  * @return true on success, otherwise false.
215  */
216 bool sensord_register_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data);
217
218 /**
219  * @brief Register a callback with a connected context sensor for a given event_type. This callback will be called when a given event occurs in a connected context sensor.
220  *
221  * @param[in] handle a handle represensting a connected context sensor.
222  * @param[in] event_type an event type to register
223  * @param[in] interval The desired interval between two consecutive events in microseconds. This is only a hint to the system so events may be received faster or slower than the specified interval.
224  *                                    It can be one of SENSOR_INTERVAL_NORMAL,  SENSOR_INTERVAL_FASTEST or the interval in microseconds.
225  * @param[in] max_batch_latency An event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled.
226  * @param[in] cb a callback which is called when a given event occurs
227  * @param[in] user_data the callback is called with user_data
228  * @return true on success, otherwise false.
229  */
230 bool sensord_register_hub_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensorhub_cb_t cb, void *user_data);
231
232 /**
233  * @brief Unregister a event with a connected sensor.  After unregistering, that event will not be sent.
234  *
235  * @param[in] handle a handle represensting a connected sensor.
236  * @param[in] event_type an event type to unregister.
237  * @return true on success, otherwise false.
238  */
239 bool sensord_unregister_event(int handle, unsigned int event_type);
240
241 /**
242  * @brief Register a callback with a connected sensor. This callback will be called when the accuracy of a sensor has changed.
243  *
244  * @param[in] handle a handle represensting a connected sensor.
245  * @param[in] cb a callback which is called when he accuracy of a sensor has changed.
246  * @param[in] user_data the callback is called with user_data
247  * @return true on success, otherwise false.
248  */
249 bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data);
250
251 /**
252  * @brief Unregister a callback with a connected sensor.  After unregistering,  sensor_accuray_change_cb will not be called.
253  *
254  * @param[in] handle a handle represensting a connected sensor.
255  * @return true on success, otherwise false.
256  */
257 bool sensord_unregister_accuracy_cb(int handle);
258
259 /**
260  * @brief Start listening events with a connected sensor.
261  *
262  * @param[in] handle a handle represensting a connected sensor.
263  * @param[in] option either one of SENSOR_OPTION_DEFAULT and  SENSOR_OPTION_ALWAYS_ON.
264  *                                 with SENSOR_OPTION_DEFAULT, it stops to listening events when LCD is off or in power save mode.
265  *                                 with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode.
266  * @return true on success, otherwise false.
267  */
268
269 bool sensord_start(int handle, int option);
270
271 /**
272  * @brief Stop listening events with a connected sensor.
273  *
274  * @param[in] handle a handle represensting a connected sensor.
275  * @return true on success, otherwise false.
276  */
277 bool sensord_stop(int handle);
278
279 /**
280  * @brief Change the interval of a specifed event type in a connected sensor.
281  *
282  * @param[in] handle a handle represensting a connected sensor.
283  * @param[in] event_type an event type to change interval.
284  * @param[in] interval The desired interval between two consecutive events in microseconds. This is only a hint to the system so events may be received faster or slower than the specified interval.
285  *                                    It can be one of SENSOR_INTERVAL_NORMAL,  SENSOR_INTERVAL_FASTEST or the interval in microseconds.
286  * @return true on success, otherwise false.
287  */
288 bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval);
289
290 /**
291  * @brief Change the max batch latency of a specifed event type in a connected sensor.
292  *
293  * @param[in] handle a handle represensting a connected sensor.
294  * @param[in] max_batch_latency an event in the batch can be delayed by at most max_batch_latency microseconds. If this is set to zero, batch mode is disabled.
295  * @return true on success, otherwise false.
296  */
297 bool sensord_change_event_max_batch_latency(int handle, unsigned int max_batch_latency);
298
299 /**
300  * @brief Change the option of a connected sensor.
301  *
302  * @param[in] handle a handle represensting a connected sensor.
303  * @param[in] option either one of SENSOR_OPTION_DEFAULT and  SENSOR_OPTION_ALWAYS_ON.
304  *                                 with SENSOR_OPTION_DEFAULT, it stops to listening events when LCD is off or in power save mode.
305  *                                 with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode.
306  * @return true on success, otherwise false.
307  */
308 bool sensord_set_option(int handle, int option);
309
310 /**
311  * @brief Send data to sensorhub
312  *
313  * @param[in] handle a handle represensting a connected context sensor.
314  * @param[in] data it holds data to send to sensorhub
315  * @param[in] data_len the length of data
316  * @return true on success, otherwise false.
317  */
318 bool sensord_send_sensorhub_data(int handle, const char *data, int data_len);
319
320 /**
321  * @brief get sensor data from a connected sensor
322  *
323  * @param[in] handle a handle represensting a connected context sensor.
324  * @param[in] data_id it specifies data to get
325  * @param[out] sensor_data data from connected sensor
326  * @return true on success, otherwise false.
327  */
328 bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data);
329
330 /**
331   * @}
332  */
333
334 #ifdef __cplusplus
335 }
336 #endif
337
338
339 #endif