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