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