4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #ifndef __SENSOR_INTERNAL_H__
21 #define __SENSOR_INTERNAL_H__
24 #define API __attribute__((visibility("default")))
28 #include <sys/types.h>
30 /*header for common sensor type*/
31 #include <sensor_types.h>
32 #include <sensor_deprecated.h>
33 #include <sensor_internal_deprecated.h>
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);
48 * @brief Get the list of available sensors of a certain type, use ALL_SENSOR to get all the sensors.
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.
55 bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count);
58 * @brief Get the default sensor for a given type.
60 * @param[in] type the type of a sensor requested.
61 * @return the default sensor matching the asked type on success, otherwise NULL.
63 sensor_t sensord_get_sensor(sensor_type_t type);
66 * @brief Get the list of available sensors of a certain type, use ALL_SENSOR to get all the sensors.
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
77 int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *sensor_count);
80 * @brief Get the default sensor for a given type.
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
89 int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor);
92 * @brief Get the type of this sensor.
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.
98 bool sensord_get_type(sensor_t sensor, sensor_type_t *type);
101 * @brief Get the URI string of this sensor.
103 * @param[in] sensor a sensor to get uri.
104 * @return the name string of this sensor on success, otherwise NULL.
106 const char* sensord_get_uri(sensor_t sensor);
109 * @brief Get the name string of this sensor.
111 * @param[in] sensor a sensor to get name.
112 * @return the name string of this sensor on success, otherwise NULL.
114 const char* sensord_get_name(sensor_t sensor);
117 * @brief Get the vendor string of this sensor.
119 * @param[in] sensor a sensor to get vendor.
120 * @return the vendor string of this sensor on success, otherwise NULL.
122 const char* sensord_get_vendor(sensor_t sensor);
125 * @brief Get the privilege of this sensor.
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.
131 bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege);
134 * @brief Get the minimum range of this sensor in the sensor's unit.
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.
140 bool sensord_get_min_range(sensor_t sensor, float *min_range);
143 * @brief Get the maximum range of this sensor in the sensor's unit.
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.
149 bool sensord_get_max_range(sensor_t sensor, float *max_range);
152 * @brief Get the resolution of this sensor in the sensor's unit.
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.
158 bool sensord_get_resolution(sensor_t sensor, float *resolution);
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.
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.
167 bool sensord_get_min_interval(sensor_t sensor, int *min_interval);
170 * @brief Get the number of events reserved for this sensor in the batch mode FIFO.
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
176 bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count);
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.
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.
185 bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count);
188 * @brief Get the supported event types of this sensor.
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.
195 bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count);
198 * @brief Check a given event type is supporeted by this sensor.
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.
205 bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported);
208 * @brief Check a wakeup supported or not by this sensor.
210 * @param[in] sensor a sensor to check a given event type is supporeted.
211 * @return true on success, otherwise false.
213 bool sensord_is_wakeup_supported(sensor_t sensor);
216 * @brief Connect a given sensor and get a handle of a given sensor.
218 * @param[in] sensor a sensor to connect
219 * @return a handle of a given sensor on success, otherwise negative value
221 int sensord_connect(sensor_t sensor);
224 * @brief Disconnect a given sensor.
226 * @param[in] handle a handle to disconnect.
227 * @return true on success, otherwise false.
229 bool sensord_disconnect(int handle);
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.
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.
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);
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.
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.
255 bool sensord_register_events(int handle, unsigned int event_type, unsigned int max_batch_latency, sensor_events_cb_t cb, void *user_data);
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.
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.
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);
272 * @brief Unregister a event with a connected sensor. After unregistering, that event will not be sent.
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.
278 bool sensord_unregister_event(int handle, unsigned int event_type);
281 * @brief Unregister a event with a connected sensor. After unregistering, that event will not be sent.
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.
287 bool sensord_unregister_events(int handle, unsigned int event_type);
290 * @brief Register a callback with a connected sensor. This callback will be called when the accuracy of a sensor has changed.
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.
297 bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data);
300 * @brief Unregister a callback with a connected sensor. After unregistering, sensor_accuray_change_cb will not be called.
302 * @param[in] handle a handle represensting a connected sensor.
303 * @return true on success, otherwise false.
305 bool sensord_unregister_accuracy_cb(int handle);
308 * @brief Register a callback with a connected sensor. This callback will be called when attributes of a sensor has changed.
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.
315 bool sensord_register_attribute_int_changed_cb(int handle, sensor_attribute_int_changed_cb_t cb, void *user_data);
318 * @brief Unregister a callback with a connected sensor. After unregistering, sensor_attribute_int_changed_cb will not be called.
320 * @param[in] handle a handle represensting a connected sensor.
321 * @return true on success, otherwise false.
323 bool sensord_unregister_attribute_int_changed_cb(int handle);
326 * @brief Register a callback with a connected sensor. This callback will be called when attributes of a sensor has changed.
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.
333 bool sensord_register_attribute_str_changed_cb(int handle, sensor_attribute_str_changed_cb_t cb, void *user_data);
336 * @brief Unregister a callback with a connected sensor. After unregistering, sensor_attribute_str_changed_cb will not be called.
338 * @param[in] handle a handle represensting a connected sensor.
339 * @return true on success, otherwise false.
341 bool sensord_unregister_attribute_str_changed_cb(int handle);
344 * @brief Start listening events with a connected sensor.
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.
352 bool sensord_start(int handle, int option);
355 * @brief Stop listening events with a connected sensor.
357 * @param[in] handle a handle represensting a connected sensor.
358 * @return true on success, otherwise false.
360 bool sensord_stop(int handle);
363 * @brief Change the interval of a specifed event type in a connected sensor.
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.
371 bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval);
374 * @brief Change the max batch latency of a specifed event type in a connected sensor.
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.
381 bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency);
384 * @brief Change the option of a connected sensor.
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.
392 bool sensord_set_option(int handle, int option);
395 * @brief Set the attribute to a connected sensor
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
405 int sensord_set_attribute_int(int handle, int attribute, int value);
408 * @brief Get the attribute to a connected sensor
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
418 int sensord_get_attribute_int(int handle, int attribute, int* value);
421 * @brief Set the attribute to a connected sensor
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
432 int sensord_set_attribute_str(int handle, int attribute, const char *value, int len);
435 * @brief Get the attribute to a connected sensor
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
446 int sensord_get_attribute_str(int handle, int attribute, char **value, int *len);
449 * @brief Send data to sensorhub
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.
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);
460 * @brief get sensor data from a connected sensor
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.
467 bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data);
470 * @brief get sensor data from a connected sensor
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.
478 bool sensord_get_data_list(int handle, unsigned int data_id, sensor_data_t** sensor_data, int* count);
481 * @brief flush sensor data from a connected sensor
483 * @param[in] handle a handle represensting a connected context sensor.
484 * @return true on success, otherwise false.
486 bool sensord_flush(int handle);
488 bool sensord_set_passive_mode(int handle, bool passive);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);