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