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 __SENSORD_INTERNAL_H__
21 #define __SENSORD_INTERNAL_H__
24 #define API __attribute__((visibility("default")))
28 #include <sys/types.h>
31 /*header for common sensor type*/
32 #include <sensor_types.h>
33 #include <sensor_deprecated.h>
34 #include <sensor_internal_deprecated.h>
36 const unsigned int SENSOR_BATCH_LATENCY_DEFAULT = UINT_MAX;
43 typedef void (*sensor_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data);
44 typedef void (*sensor_events_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t events[], int events_count, void *user_data);
45 typedef void (*sensorhub_cb_t)(sensor_t sensor, unsigned int event_type, sensorhub_data_t *data, void *user_data);
46 typedef void (*sensor_accuracy_changed_cb_t) (sensor_t sensor, unsigned long long timestamp, int accuracy, void *user_data);
47 typedef void (*sensor_attribute_int_changed_cb_t)(sensor_t sensor, int attribute, int value, void *user_data);
48 typedef void (*sensor_attribute_str_changed_cb_t)(sensor_t sensor, int attribute, const char *value, int len, void *user_data);
51 * @brief Get the list of available sensors of a certain type, use ALL_SENSOR to get all the sensors.
53 * @param[in] type the type of sensors requested.
54 * @param[out] list the list of sensors matching the asked type, the caller should explicitly free this list.
55 * @param[out] sensor count the count of sensors contained in the list.
56 * @return true on success, otherwise false.
58 bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count);
61 * @brief Get the default sensor for a given type.
63 * @param[in] type the type of a sensor requested.
64 * @return the default sensor matching the asked type on success, otherwise NULL.
66 sensor_t sensord_get_sensor(sensor_type_t type);
69 * @brief Get the list of available sensors of a certain type, use ALL_SENSOR to get all the sensors.
71 * @param[in] type the type of sensors requested.
72 * @param[out] list the list of sensors matching the asked type, the caller should explicitly free this list.
73 * @param[out] sensor count the count of sensors contained in the list.
74 * @return 0 on success, otherwise a negative error value
75 * @retval 0 Successful
76 * @retval -EPERM Operation not permitted
77 * @retval -EACCES Permission denied
78 * @retval -ENODATA NO sensor available
80 int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *sensor_count);
83 * @brief Get the default sensor for a given type.
85 * @param[in] type the type of a sensor requested.
86 * @param[out] a sensor matching the asked type.
87 * @return 0 on success, otherwise a negative error value
88 * @retval 0 Successful
89 * @retval -EPERM Operation not permitted
90 * @retval -EACCES Permission denied
92 int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor);
95 * @brief Get the type of this sensor.
97 * @param[in] sensor a sensor to get type.
98 * @param[out] type the type of this sensor.
99 * @return return true on success, otherwise false.
101 bool sensord_get_type(sensor_t sensor, sensor_type_t *type);
104 * @brief Get the URI string of this sensor.
106 * @param[in] sensor a sensor to get uri.
107 * @return the name string of this sensor on success, otherwise NULL.
109 const char* sensord_get_uri(sensor_t sensor);
112 * @brief Get the name string of this sensor.
114 * @param[in] sensor a sensor to get name.
115 * @return the name string of this sensor on success, otherwise NULL.
117 const char* sensord_get_name(sensor_t sensor);
120 * @brief Get the vendor string of this sensor.
122 * @param[in] sensor a sensor to get vendor.
123 * @return the vendor string of this sensor on success, otherwise NULL.
125 const char* sensord_get_vendor(sensor_t sensor);
128 * @brief Get the privilege of this sensor.
130 * @param[in] sensor a sensor to get privilege.
131 * @param[out] privilege the privilege of this sensor.
132 * @return true on success, otherwise false.
134 bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege);
137 * @brief Get the minimum range of this sensor in the sensor's unit.
139 * @param[in] sensor a sensor to get minimum range.
140 * @param[out] min_range the minimum range of this sensor in the sensor's unit.
141 * @return true on success, otherwise false.
143 bool sensord_get_min_range(sensor_t sensor, float *min_range);
146 * @brief Get the maximum range of this sensor in the sensor's unit.
148 * @param[in] sensor a sensor to get maximum range.
149 * @param[out] max_range the maximum range of this sensor in the sensor's unit.
150 * @return true on success, otherwise false.
152 bool sensord_get_max_range(sensor_t sensor, float *max_range);
155 * @brief Get the resolution of this sensor in the sensor's unit.
157 * @param[in] sensor a sensor to get resolution.
158 * @param[out] resolution the resolution of this sensor in the sensor's unit.
159 * @return true on success, otherwise false.
161 bool sensord_get_resolution(sensor_t sensor, float *resolution);
164 * @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.
166 * @param[in] sensor a sensor to get minimum interval.
167 * @param[out] min_interval the minimum interval of this sensor.
168 * @return true on success, otherwise false.
170 bool sensord_get_min_interval(sensor_t sensor, int *min_interval);
173 * @brief Get the number of events reserved for this sensor in the batch mode FIFO.
175 * @param[in] sensor a sensor to get the number of fifo count
176 * @param[out] fifo_count the number of events reserved for this sensor in the batch mode FIFO
177 * @return true on success, otherwise false
179 bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count);
182 * @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.
184 * @param[in] sensor a sensor to the maximum number of events that could be batched.
185 * @param[out] max_batch_count the maximum number of events of this sensor that could be batched.
186 * @return true on success, otherwise false.
188 bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count);
191 * @brief Get the supported event types of this sensor.
193 * @param[in] sensor a sensor to get the supported event types.
194 * @param[out] event_types the array containing supported event types of this sensor, the caller should explicitly free this array.
195 * @param[out] count the count of the supported event types of this sensor.
196 * @return true on success, otherwise false.
198 bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count);
201 * @brief Check a given event type is supporeted by this sensor.
203 * @param[in] sensor a sensor to check a given event type is supporeted.
204 * @param[out] event_type an event type to be checked whether supported or not.
205 * @param[out] supported whether a given event is supported or not in this sensor.
206 * @return true on success, otherwise false.
208 bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported);
211 * @brief Check a wakeup supported or not by this sensor.
213 * @param[in] sensor a sensor to check a given event type is supporeted.
214 * @return true on success, otherwise false.
216 bool sensord_is_wakeup_supported(sensor_t sensor);
219 * @brief Connect a given sensor and get a handle of a given sensor.
221 * @param[in] sensor a sensor to connect
222 * @return a handle of a given sensor on success, otherwise negative value
224 int sensord_connect(sensor_t sensor);
227 * @brief Disconnect a given sensor.
229 * @param[in] handle a handle to disconnect.
230 * @return true on success, otherwise false.
232 bool sensord_disconnect(int handle);
235 * @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.
237 * @param[in] handle a handle represensting a connected sensor.
238 * @param[in] event_type an event type to register
239 * @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.
240 * It can be one of SENSOR_INTERVAL_NORMAL, SENSOR_INTERVAL_FASTEST or the interval in microseconds.
241 * @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.
242 * @param[in] cb a callback which is called when a given event occurs
243 * @param[in] user_data the callback is called with user_data
244 * @return true on success, otherwise false.
246 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);
249 * @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.
251 * @param[in] handle a handle represensting a connected sensor.
252 * @param[in] event_type an event type to register
253 * @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.
254 * @param[in] cb a callback which is called when a given event occurs
255 * @param[in] user_data the callback is called with user_data
256 * @return true on success, otherwise false.
258 bool sensord_register_events(int handle, unsigned int event_type, unsigned int max_batch_latency, sensor_events_cb_t cb, void *user_data);
261 * @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.
263 * @param[in] handle a handle represensting a connected context sensor.
264 * @param[in] event_type an event type to register
265 * @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.
266 * It can be one of SENSOR_INTERVAL_NORMAL, SENSOR_INTERVAL_FASTEST or the interval in microseconds.
267 * @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.
268 * @param[in] cb a callback which is called when a given event occurs
269 * @param[in] user_data the callback is called with user_data
270 * @return true on success, otherwise false.
272 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);
275 * @brief Unregister a event with a connected sensor. After unregistering, that event will not be sent.
277 * @param[in] handle a handle represensting a connected sensor.
278 * @param[in] event_type an event type to unregister.
279 * @return true on success, otherwise false.
281 bool sensord_unregister_event(int handle, unsigned int event_type);
284 * @brief Unregister a event with a connected sensor. After unregistering, that event will not be sent.
286 * @param[in] handle a handle represensting a connected sensor.
287 * @param[in] event_type an event type to unregister.
288 * @return true on success, otherwise false.
290 bool sensord_unregister_events(int handle, unsigned int event_type);
293 * @brief Register a callback with a connected sensor. This callback will be called when the accuracy of a sensor has changed.
295 * @param[in] handle a handle represensting a connected sensor.
296 * @param[in] cb a callback which is called when he accuracy of a sensor has changed.
297 * @param[in] user_data the callback is called with user_data
298 * @return true on success, otherwise false.
300 bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data);
303 * @brief Unregister a callback with a connected sensor. After unregistering, sensor_accuray_change_cb will not be called.
305 * @param[in] handle a handle represensting a connected sensor.
306 * @return true on success, otherwise false.
308 bool sensord_unregister_accuracy_cb(int handle);
311 * @brief Register a callback with a connected sensor. This callback will be called when attributes of a sensor has changed.
313 * @param[in] handle a handle represensting a connected sensor.
314 * @param[in] cb a callback which is called when he attributes of a sensor has changed.
315 * @param[in] user_data the callback is called with user_data
316 * @return true on success, otherwise false.
318 bool sensord_register_attribute_int_changed_cb(int handle, sensor_attribute_int_changed_cb_t cb, void *user_data);
321 * @brief Unregister a callback with a connected sensor. After unregistering, sensor_attribute_int_changed_cb will not be called.
323 * @param[in] handle a handle represensting a connected sensor.
324 * @return true on success, otherwise false.
326 bool sensord_unregister_attribute_int_changed_cb(int handle);
329 * @brief Register a callback with a connected sensor. This callback will be called when attributes of a sensor has changed.
331 * @param[in] handle a handle represensting a connected sensor.
332 * @param[in] cb a callback which is called when he attributes of a sensor has changed.
333 * @param[in] user_data the callback is called with user_data
334 * @return true on success, otherwise false.
336 bool sensord_register_attribute_str_changed_cb(int handle, sensor_attribute_str_changed_cb_t cb, void *user_data);
339 * @brief Unregister a callback with a connected sensor. After unregistering, sensor_attribute_str_changed_cb will not be called.
341 * @param[in] handle a handle represensting a connected sensor.
342 * @return true on success, otherwise false.
344 bool sensord_unregister_attribute_str_changed_cb(int handle);
347 * @brief Start listening events with a connected sensor.
349 * @param[in] handle a handle represensting a connected sensor.
350 * @param[in] option either one of SENSOR_OPTION_DEFAULT and SENSOR_OPTION_ALWAYS_ON.
351 * with SENSOR_OPTION_DEFAULT, it stops to listening events when LCD is off or in power save mode.
352 * with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode.
353 * @return true on success, otherwise false.
355 bool sensord_start(int handle, int option);
358 * @brief Stop listening events with a connected sensor.
360 * @param[in] handle a handle represensting a connected sensor.
361 * @return true on success, otherwise false.
363 bool sensord_stop(int handle);
366 * @brief Change the interval of a specifed event type in a connected sensor.
368 * @param[in] handle a handle represensting a connected sensor.
369 * @param[in] event_type an event type to change interval.
370 * @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.
371 * It can be one of SENSOR_INTERVAL_NORMAL, SENSOR_INTERVAL_FASTEST or the interval in microseconds.
372 * @return true on success, otherwise false.
374 bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval);
377 * @brief Change the max batch latency of a specifed event type in a connected sensor.
379 * @param[in] handle a handle represensting a connected sensor.
380 * @param[in] event_type an event type to change max batch latency
381 * @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.
382 * @return true on success, otherwise false.
384 bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency);
387 * @brief Change the option of a connected sensor.
389 * @param[in] handle a handle represensting a connected sensor.
390 * @param[in] option either one of SENSOR_OPTION_DEFAULT and SENSOR_OPTION_ALWAYS_ON.
391 * with SENSOR_OPTION_DEFAULT, it stops to listening events when LCD is off or in power save mode.
392 * with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode.
393 * @return true on success, otherwise false.
395 bool sensord_set_option(int handle, int option);
398 * @brief Set the attribute to a connected sensor
400 * @param[in] handle a handle represensting a connected sensor.
401 * @param[in] attribute an attribute to change
402 * @param[in] value an attribute value
403 * @return 0 on success, otherwise a negative error value
404 * @retval 0 Successful
405 * @retval -EINVAL Invalid parameter
406 * @retval -EPERM Operation not permitted
408 int sensord_set_attribute_int(int handle, int attribute, int value);
411 * @brief Get the attribute to a connected sensor
413 * @param[in] handle a handle represensting a connected sensor.
414 * @param[in] attribute an attribute to get value
415 * @param[out] value an attribute value
416 * @return 0 on success, otherwise a negative error value
417 * @retval 0 Successful
418 * @retval -EINVAL Invalid parameter
419 * @retval -EPERM Operation not permitted
421 int sensord_get_attribute_int(int handle, int attribute, int* value);
424 * @brief Set the attribute to a connected sensor
426 * @param[in] handle a handle represensting a connected sensor.
427 * @param[in] attribute an attribute to change
428 * @param[in] value an attribute value
429 * @param[in] value_len the length of value
430 * @return 0 on success, otherwise a negative error value
431 * @retval 0 Successful
432 * @retval -EINVAL Invalid parameter
433 * @retval -EPERM Operation not permitted
435 int sensord_set_attribute_str(int handle, int attribute, const char *value, int len);
438 * @brief Get the attribute to a connected sensor
440 * @param[in] handle a handle represensting a connected sensor.
441 * @param[in] attribute an attribute to get value
442 * @param[out] value an attribute value, the caller should explicitly free this value
443 * @param[out] len the length of value
444 * @return 0 on success, otherwise a negative error value
445 * @retval 0 Successful
446 * @retval -EINVAL Invalid parameter
447 * @retval -EPERM Operation not permitted
449 int sensord_get_attribute_str(int handle, int attribute, char **value, int *len);
452 * @brief Send data to sensorhub
454 * @param[in] handle a handle represensting a connected context sensor.
455 * @param[in] data it holds data to send to sensorhub
456 * @param[in] data_len the length of data
457 * @return true on success, otherwise false.
459 bool sensord_send_sensorhub_data(int handle, const char *data, int data_len);
460 bool sensord_send_command(int handle, const char *command, int command_len);
463 * @brief get sensor data from a connected sensor
465 * @param[in] handle a handle represensting a connected context sensor.
466 * @param[in] data_id it specifies data to get
467 * @param[out] sensor_data data from connected sensor
468 * @return true on success, otherwise false.
470 bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data);
473 * @brief get sensor data from a connected sensor
475 * @param[in] handle a handle represensting a connected context sensor.
476 * @param[in] data_id it specifies data to get
477 * @param[out] sensor_data the data list from connected sensor, the caller should explicitly free this list.
478 * @param[out] count the count of data contained in the list.
479 * @return true on success, otherwise false.
481 bool sensord_get_data_list(int handle, unsigned int data_id, sensor_data_t** sensor_data, int* count);
484 * @brief flush sensor data from a connected sensor
486 * @param[in] handle a handle represensting a connected context sensor.
487 * @return true on success, otherwise false.
489 bool sensord_flush(int handle);
491 bool sensord_set_passive_mode(int handle, bool passive);
494 /* Sensor Internal API using URI */
495 int sensord_get_default_sensor_by_uri(const char *uri, sensor_t *sensor);
496 int sensord_get_sensors_by_uri(const char *uri, sensor_t **list, int *sensor_count);
498 typedef void (*sensord_added_cb)(const char *uri, void *user_data);
499 int sensord_add_sensor_added_cb(sensord_added_cb callback, void *user_data);
500 int sensord_remove_sensor_added_cb(sensord_added_cb callback);
502 typedef void (*sensord_removed_cb)(const char *uri, void *user_data);
503 int sensord_add_sensor_removed_cb(sensord_removed_cb callback, void *user_data);
504 int sensord_remove_sensor_removed_cb(sensord_removed_cb callback);
506 /* Sensor provider */
507 typedef void *sensord_provider_h;
508 int sensord_create_provider(const char *uri, sensord_provider_h *provider);
509 int sensord_destroy_provider(sensord_provider_h provider);
510 int sensord_add_provider(sensord_provider_h provider);
511 int sensord_remove_provider(sensord_provider_h provider);
513 int sensord_provider_set_name(sensord_provider_h provider, const char *name);
514 int sensord_provider_set_vendor(sensord_provider_h provider, const char *vendor);
515 int sensord_provider_set_range(sensord_provider_h provider, float min_range, float max_range);
516 int sensord_provider_set_resolution(sensord_provider_h provider, float resolution);
518 typedef void (*sensord_provider_start_cb)(sensord_provider_h provider, void *user_data);
519 int sensord_provider_set_start_cb(sensord_provider_h provider, sensord_provider_start_cb callback, void *user_data);
521 typedef void (*sensord_provider_stop_cb)(sensord_provider_h provider, void *user_data);
522 int sensord_provider_set_stop_cb(sensord_provider_h provider, sensord_provider_stop_cb callback, void *user_data);
524 typedef void (*sensord_provider_interval_changed_cb)(sensord_provider_h provider, unsigned int interval_ms, void *user_data);
525 int sensord_provider_set_interval_changed_cb(sensord_provider_h provider, sensord_provider_interval_changed_cb callback, void *user_data);
527 typedef void (*sensord_provider_attribute_str_cb)(sensord_provider_h provider, int attribute, const char *value, int count, void *user_data);
528 int sensord_provider_set_attribute_str_cb(sensord_provider_h provider, sensord_provider_attribute_str_cb callback, void *user_data);
530 int sensord_provider_publish(sensord_provider_h provider, sensor_data_t data);
531 int sensord_provider_publish_events(sensord_provider_h provider, sensor_data_t events[], int count);
534 typedef void (*sensor_external_command_cb_t)(int handle, const char* data, int data_cnt, void *user_data);
535 int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data);
536 bool sensord_external_disconnect(int handle);
537 bool sensord_external_post(int handle, unsigned long long timestamp, const float* data, int data_cnt);
547 #endif /* __SENSORD_INTERNAL_H__ */