Add sensor APIs related to batch event
[platform/core/system/sensord.git] / include / sensor_internal.h
1 /*
2  * sensord
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 API
24 #define API __attribute__((visibility("default")))
25 #endif
26
27 #include <stdbool.h>
28 #include <sys/types.h>
29
30 /*header for common sensor type*/
31 #include <sensor_types.h>
32 #include <sensor_deprecated.h>
33 #include <sensor_internal_deprecated.h>
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39
40 typedef void (*sensor_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data);
41 typedef void (*sensor_events_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t* events[], int events_count, void *user_data);
42 typedef void (*sensorhub_cb_t)(sensor_t sensor, unsigned int event_type, sensorhub_data_t *data, void *user_data);
43 typedef void (*sensor_accuracy_changed_cb_t) (sensor_t sensor, unsigned long long timestamp, int accuracy, void *user_data);
44
45 /**
46  * @brief Get the list of available sensors of a certain type,  use ALL_SENSOR to get all the sensors.
47  *
48  * @param[in] type the type of sensors requested.
49  * @param[out] list the list of sensors matching the asked type,  the caller should explicitly free this list.
50  * @param[out] sensor count the count of sensors contained in the list.
51  * @return true on success, otherwise false.
52  */
53 bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count);
54
55 /**
56  * @brief Get the default sensor for a given type.
57  *
58  * @param[in] type the type of a sensor requested.
59  * @return the default sensor matching the asked type on success, otherwise NULL.
60  */
61 sensor_t sensord_get_sensor(sensor_type_t type);
62
63 /**
64  * @brief Get the list of available sensors of a certain type,  use ALL_SENSOR to get all the sensors.
65  *
66  * @param[in] type the type of sensors requested.
67  * @param[out] list the list of sensors matching the asked type,  the caller should explicitly free this list.
68  * @param[out] sensor count the count of sensors contained in the list.
69  * @return 0 on success, otherwise a negative error value
70  * @retval 0 Successful
71  * @retval -EPERM Operation not permitted
72  * @retval -EACCES Permission denied
73  * @retval -ENODATA NO sensor available
74  */
75 int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *sensor_count);
76
77 /**
78  * @brief Get the default sensor for a given type.
79  *
80  * @param[in] type the type of a sensor requested.
81  * @param[out] a sensor matching the asked type.
82  * @return 0 on success, otherwise a negative error value
83  * @retval 0 Successful
84  * @retval -EPERM Operation not permitted
85  * @retval -EACCES Permission denied
86  */
87 int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor);
88
89 /**
90  * @brief Get the type of this sensor.
91  *
92  * @param[in] sensor a sensor to get type.
93  * @param[out] type the type of this sensor.
94  * @return return true on success, otherwise false.
95  */
96 bool sensord_get_type(sensor_t sensor, sensor_type_t *type);
97
98 /**
99  * @brief Get the URI string of this sensor.
100  *
101  * @param[in] sensor a sensor to get uri.
102  * @return the name string of this sensor on success, otherwise NULL.
103  */
104 const char* sensord_get_uri(sensor_t sensor);
105
106 /**
107  * @brief Get the name string of this sensor.
108  *
109  * @param[in] sensor a sensor to get name.
110  * @return the name string of this sensor on success, otherwise NULL.
111  */
112 const char* sensord_get_name(sensor_t sensor);
113
114 /**
115  * @brief Get the vendor string of this sensor.
116  *
117  * @param[in] sensor a sensor to get vendor.
118  * @return the vendor string of this sensor on success, otherwise NULL.
119  */
120 const char* sensord_get_vendor(sensor_t sensor);
121
122 /**
123  * @brief Get the privilege of this sensor.
124  *
125  * @param[in] sensor a sensor to get privilege.
126  * @param[out] privilege the privilege of this sensor.
127  * @return true on success, otherwise false.
128  */
129 bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege);
130
131 /**
132  * @brief Get the minimum range of this sensor in the sensor's unit.
133  *
134  * @param[in] sensor a sensor to get minimum range.
135  * @param[out] min_range the minimum range of this sensor in the sensor's unit.
136  * @return true on success, otherwise false.
137  */
138 bool sensord_get_min_range(sensor_t sensor, float *min_range);
139
140 /**
141  * @brief Get the maximum range of this sensor in the sensor's unit.
142  *
143  * @param[in] sensor a sensor to get maximum range.
144  * @param[out] max_range the maximum range of this sensor in the sensor's unit.
145  * @return true on success, otherwise false.
146  */
147 bool sensord_get_max_range(sensor_t sensor, float *max_range);
148
149 /**
150  * @brief Get the resolution of this sensor in the sensor's unit.
151  *
152  * @param[in] sensor a sensor to get resolution.
153  * @param[out] resolution the resolution of this sensor in the sensor's unit.
154  * @return true on success, otherwise false.
155  */
156 bool sensord_get_resolution(sensor_t sensor, float *resolution);
157
158 /**
159  * @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.
160  *
161  * @param[in] sensor a sensor to get minimum interval.
162  * @param[out] min_interval the minimum interval of this sensor.
163  * @return true on success, otherwise false.
164  */
165 bool sensord_get_min_interval(sensor_t sensor, int *min_interval);
166
167 /**
168  * @brief Get the number of events reserved for this sensor in the batch mode FIFO.
169  *
170  * @param[in] sensor a sensor to get the number of fifo count
171  * @param[out] fifo_count the number of events reserved for this sensor in the batch mode FIFO
172  * @return true on success, otherwise false
173  */
174 bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count);
175
176 /**
177  * @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.
178  *
179  * @param[in] sensor a sensor to the maximum number of events that could be batched.
180  * @param[out] max_batch_count the maximum number of events of this sensor that could be batched.
181  * @return true on success, otherwise false.
182  */
183 bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count);
184
185 /**
186  * @brief Get the supported event types of this sensor.
187  *
188  * @param[in] sensor a sensor to get the supported event types.
189  * @param[out] event_types the array containing supported event types of this sensor, the caller should explicitly free this array.
190  * @param[out] count the count of the supported event types of this sensor.
191  * @return true on success, otherwise false.
192  */
193 bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count);
194
195 /**
196  * @brief Check a given event type is supporeted by this sensor.
197  *
198  * @param[in] sensor a sensor to check a given event type is supporeted.
199  * @param[out] event_type an event type to be checked whether supported or not.
200  * @param[out] supported whether a given event is supported or not in this sensor.
201  * @return true on success, otherwise false.
202  */
203 bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported);
204
205 /**
206  * @brief Check a wakeup supported or not by this sensor.
207  *
208  * @param[in] sensor a sensor to check a given event type is supporeted.
209  * @return true on success, otherwise false.
210  */
211 bool sensord_is_wakeup_supported(sensor_t sensor);
212
213 /**
214  * @brief Connect a given sensor and get a handle of a given sensor.
215  *
216  * @param[in] sensor a sensor to connect
217  * @return a handle of a given sensor on success, otherwise negative value
218  */
219 int sensord_connect(sensor_t sensor);
220
221 /**
222  * @brief Disconnect a given sensor.
223  *
224  * @param[in] handle a handle to disconnect.
225  * @return true on success, otherwise false.
226  */
227 bool sensord_disconnect(int handle);
228
229 /**
230  * @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.
231  *
232  * @param[in] handle a handle represensting a connected sensor.
233  * @param[in] event_type an event type  to register
234  * @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.
235  *                                   It can be one of SENSOR_INTERVAL_NORMAL,  SENSOR_INTERVAL_FASTEST or the interval in microseconds.
236  * @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.
237  * @param[in] cb a callback which is called when a given event occurs
238  * @param[in] user_data the callback is called with user_data
239  * @return true on success, otherwise false.
240  */
241 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);
242
243 /**
244  * @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.
245  *
246  * @param[in] handle a handle represensting a connected sensor.
247  * @param[in] event_type an event type  to register
248  * @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.
249  * @param[in] cb a callback which is called when a given event occurs
250  * @param[in] user_data the callback is called with user_data
251  * @return true on success, otherwise false.
252  */
253 bool sensord_register_events(int handle, unsigned int event_type, unsigned int max_batch_latency, sensor_events_cb_t cb, void *user_data);
254
255 /**
256  * @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.
257  *
258  * @param[in] handle a handle represensting a connected context sensor.
259  * @param[in] event_type an event type to register
260  * @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.
261  *                                    It can be one of SENSOR_INTERVAL_NORMAL,  SENSOR_INTERVAL_FASTEST or the interval in microseconds.
262  * @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.
263  * @param[in] cb a callback which is called when a given event occurs
264  * @param[in] user_data the callback is called with user_data
265  * @return true on success, otherwise false.
266  */
267 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);
268
269 /**
270  * @brief Unregister a event with a connected sensor.  After unregistering, that event will not be sent.
271  *
272  * @param[in] handle a handle represensting a connected sensor.
273  * @param[in] event_type an event type to unregister.
274  * @return true on success, otherwise false.
275  */
276 bool sensord_unregister_event(int handle, unsigned int event_type);
277
278 /**
279  * @brief Unregister a event with a connected sensor.  After unregistering, that event will not be sent.
280  *
281  * @param[in] handle a handle represensting a connected sensor.
282  * @param[in] event_type an event type to unregister.
283  * @return true on success, otherwise false.
284  */
285 bool sensord_unregister_events(int handle, unsigned int event_type);
286
287 /**
288  * @brief Register a callback with a connected sensor. This callback will be called when the accuracy of a sensor has changed.
289  *
290  * @param[in] handle a handle represensting a connected sensor.
291  * @param[in] cb a callback which is called when he accuracy of a sensor has changed.
292  * @param[in] user_data the callback is called with user_data
293  * @return true on success, otherwise false.
294  */
295 bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data);
296
297 /**
298  * @brief Unregister a callback with a connected sensor.  After unregistering,  sensor_accuray_change_cb will not be called.
299  *
300  * @param[in] handle a handle represensting a connected sensor.
301  * @return true on success, otherwise false.
302  */
303 bool sensord_unregister_accuracy_cb(int handle);
304
305 /**
306  * @brief Start listening events with a connected sensor.
307  *
308  * @param[in] handle a handle represensting a connected sensor.
309  * @param[in] option either one of SENSOR_OPTION_DEFAULT and  SENSOR_OPTION_ALWAYS_ON.
310  *                                 with SENSOR_OPTION_DEFAULT, it stops to listening events when LCD is off or in power save mode.
311  *                                 with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode.
312  * @return true on success, otherwise false.
313  */
314 bool sensord_start(int handle, int option);
315
316 /**
317  * @brief Stop listening events with a connected sensor.
318  *
319  * @param[in] handle a handle represensting a connected sensor.
320  * @return true on success, otherwise false.
321  */
322 bool sensord_stop(int handle);
323
324 /**
325  * @brief Change the interval of a specifed event type in a connected sensor.
326  *
327  * @param[in] handle a handle represensting a connected sensor.
328  * @param[in] event_type an event type to change interval.
329  * @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.
330  *                                    It can be one of SENSOR_INTERVAL_NORMAL,  SENSOR_INTERVAL_FASTEST or the interval in microseconds.
331  * @return true on success, otherwise false.
332  */
333 bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval);
334
335 /**
336  * @brief Change the max batch latency of a specifed event type in a connected sensor.
337  *
338  * @param[in] handle a handle represensting a connected sensor.
339  * @param[in] event_type an event type to change max batch latency
340  * @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.
341  * @return true on success, otherwise false.
342  */
343 bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency);
344
345 /**
346  * @brief Change the option of a connected sensor.
347  *
348  * @param[in] handle a handle represensting a connected sensor.
349  * @param[in] option either one of SENSOR_OPTION_DEFAULT and  SENSOR_OPTION_ALWAYS_ON.
350  *                                 with SENSOR_OPTION_DEFAULT, it stops to listening events when LCD is off or in power save mode.
351  *                                 with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode.
352  * @return true on success, otherwise false.
353  */
354 bool sensord_set_option(int handle, int option);
355
356 /*
357  * @brief Set the attribute to a connected sensor
358  *
359  * @param[in] handle a handle represensting a connected sensor.
360  * @param[in] attribute an attribute to change
361  * @param[in] value an attribute value
362  * @return 0 on success, otherwise a negative error value
363  * @retval 0 Successful
364  * @retval -EINVAL Invalid parameter
365  * @retval -EPERM Operation not permitted
366  */
367 int sensord_set_attribute_int(int handle, int attribute, int value);
368
369 /**
370  * @brief Set the attribute to a connected sensor
371  *
372  * @param[in] handle a handle represensting a connected sensor.
373  * @param[in] attribute an attribute to change
374  * @param[in] value an attribute value
375  * @param[in] value_len the length of value
376  * @return 0 on success, otherwise a negative error value
377  * @retval 0 Successful
378  * @retval -EINVAL Invalid parameter
379  * @retval -EPERM Operation not permitted
380  */
381 int sensord_set_attribute_str(int handle, int attribute, const char *value, int len);
382
383 /**
384  * @brief Send data to sensorhub
385  *
386  * @param[in] handle a handle represensting a connected context sensor.
387  * @param[in] data it holds data to send to sensorhub
388  * @param[in] data_len the length of data
389  * @return true on success, otherwise false.
390  */
391 bool sensord_send_sensorhub_data(int handle, const char *data, int data_len);
392 bool sensord_send_command(int handle, const char *command, int command_len);
393
394 /**
395  * @brief get sensor data from a connected sensor
396  *
397  * @param[in] handle a handle represensting a connected context sensor.
398  * @param[in] data_id it specifies data to get
399  * @param[out] sensor_data data from connected sensor
400  * @return true on success, otherwise false.
401  */
402 bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data);
403
404 /**
405  * @brief flush sensor data from a connected sensor
406  *
407  * @param[in] handle a handle represensting a connected context sensor.
408  * @return true on success, otherwise false.
409  */
410 bool sensord_flush(int handle);
411
412 bool sensord_set_passive_mode(int handle, bool passive);
413
414
415 /* Sensor Internal API using URI */
416 int sensord_get_default_sensor_by_uri(const char *uri, sensor_t *sensor);
417 int sensord_get_sensors_by_uri(const char *uri, sensor_t **list, int *sensor_count);
418
419 typedef void (*sensord_added_cb)(const char *uri, void *user_data);
420 int sensord_add_sensor_added_cb(sensord_added_cb callback, void *user_data);
421 int sensord_remove_sensor_added_cb(sensord_added_cb callback);
422
423 typedef void (*sensord_removed_cb)(const char *uri, void *user_data);
424 int sensord_add_sensor_removed_cb(sensord_removed_cb callback, void *user_data);
425 int sensord_remove_sensor_removed_cb(sensord_removed_cb callback);
426
427 /* Sensor provider */
428 typedef void *sensord_provider_h;
429 int sensord_create_provider(const char *uri, sensord_provider_h *provider);
430 int sensord_destroy_provider(sensord_provider_h provider);
431 int sensord_add_provider(sensord_provider_h provider);
432 int sensord_remove_provider(sensord_provider_h provider);
433
434 int sensord_provider_set_name(sensord_provider_h provider, const char *name);
435 int sensord_provider_set_vendor(sensord_provider_h provider, const char *vendor);
436 int sensord_provider_set_range(sensord_provider_h provider, float min_range, float max_range);
437 int sensord_provider_set_resolution(sensord_provider_h provider, float resolution);
438
439 typedef void (*sensord_provider_start_cb)(sensord_provider_h provider, void *user_data);
440 int sensord_provider_set_start_cb(sensord_provider_h provider, sensord_provider_start_cb callback, void *user_data);
441
442 typedef void (*sensord_provider_stop_cb)(sensord_provider_h provider, void *user_data);
443 int sensord_provider_set_stop_cb(sensord_provider_h provider, sensord_provider_stop_cb callback, void *user_data);
444
445 typedef void (*sensord_provider_interval_changed_cb)(sensord_provider_h provider, unsigned int interval_ms, void *user_data);
446 int sensord_provider_set_interval_changed_cb(sensord_provider_h provider, sensord_provider_interval_changed_cb callback, void *user_data);
447
448 typedef void (*sensord_provider_attribute_str_cb)(sensord_provider_h provider, int attribute, const char *value, int count, void *user_data);
449 int sensord_provider_set_attribute_str_cb(sensord_provider_h provider, sensord_provider_attribute_str_cb callback, void *user_data);
450
451 int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data);
452 int sensord_provider_publish_events(sensord_provider_h provider, sensor_data_t events[], int count);
453
454 /* Deprecated */
455 typedef void (*sensor_external_command_cb_t)(int handle, const char* data, int data_cnt, void *user_data);
456 int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data);
457 bool sensord_external_disconnect(int handle);
458 bool sensord_external_post(int handle, unsigned long long timestamp, const float* data, int data_cnt);
459
460 /**
461   * @}
462  */
463
464 #ifdef __cplusplus
465 }
466 #endif
467
468 #endif