Merge changes Ia892d299,I601ca6fb into tizen
[platform/core/system/sensord.git] / src / libsensord / sensor_internal.h
1 /*
2  * libsensord
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 DEPRECATED
24 #define DEPRECATED __attribute__((deprecated))
25 #endif
26
27 #include "stdbool.h"
28
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif
33
34 #include <sys/types.h>
35
36 #include <sensor_internal_deprecated.h>
37
38 /*header for common sensor type*/
39 #include <sensor_common.h>
40
41 /*header for each sensor type*/
42 #include <sensor_accel.h>
43 #include <sensor_geomag.h>
44 #include <sensor_light.h>
45 #include <sensor_proxi.h>
46 #include <sensor_gyro.h>
47 #include <sensor_pressure.h>
48 #include <sensor_context.h>
49 #include <sensor_gravity.h>
50 #include <sensor_linear_accel.h>
51 #include <sensor_orientation.h>
52 #include <sensor_temperature.h>
53
54
55 typedef void (*sensor_cb_t)(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data);
56 typedef void (*sensorhub_cb_t)(sensor_t sensor, unsigned int event_type, sensorhub_data_t *data, void *user_data);
57 typedef void (*sensor_accuracy_changed_cb_t) (sensor_t sensor, unsigned long long timestamp, int accuracy, void *user_data);
58
59 /**
60  * @brief Get the list of available sensors of a certain type,  use ALL_SENSOR to get all the sensors.
61  *
62  * @param[in] type the type of sensors requested.
63  * @param[out] list the list of sensors matching the asked type,  the caller should explicitly free this list.
64  * @param[out] sensor count the count of sensors contained in the list.
65  * @return true on success, otherwise false.
66  */
67 bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count);
68
69 /**
70  * @brief Get the default sensor for a given type.
71  *
72  * @param[in] type the type of a sensor requested.
73  * @return the default sensor matching the asked type on success, otherwise NULL.
74  */
75 sensor_t sensord_get_sensor(sensor_type_t type);
76
77 /**
78  * @brief Get the type of this sensor.
79  *
80  * @param[in] sensor a sensor to get type.
81  * @param[out] type the type of this sensor.
82  * @return return true on success, otherwise false.
83  */
84 bool sensord_get_type(sensor_t sensor, sensor_type_t *type);
85
86 /**
87  * @brief Get the name string of this sensor.
88  *
89  * @param[in] sensor a sensor to get name.
90  * @return the name string of this sensor on success, otherwise NULL.
91  */
92 const char* sensord_get_name(sensor_t sensor);
93
94 /**
95  * @brief Get the vendor string of this sensor.
96  *
97  * @param[in] sensor a sensor to get vendor.
98  * @return the vendor string of this sensor on success, otherwise NULL.
99  */
100 const char* sensord_get_vendor(sensor_t sensor);
101
102 /**
103  * @brief Get the privilege of this sensor.
104  *
105  * @param[in] sensor a sensor to get privilege.
106  * @param[out] privilege the privilege of this sensor.
107  * @return true on success, otherwise false.
108  */
109 bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege);
110
111 /**
112  * @brief Get the minimum range of this sensor in the sensor's unit.
113  *
114  * @param[in] sensor a sensor to get minimum range.
115  * @param[out] min_range the minimum range of this sensor in the sensor's unit.
116  * @return true on success, otherwise false.
117  */
118 bool sensord_get_min_range(sensor_t sensor, float *min_range);
119
120 /**
121  * @brief Get the maximum range of this sensor in the sensor's unit.
122  *
123  * @param[in] sensor a sensor to get maximum range.
124  * @param[out] max_range the maximum range of this sensor in the sensor's unit.
125  * @return true on success, otherwise false.
126  */
127 bool sensord_get_max_range(sensor_t sensor, float *max_range);
128
129 /**
130  * @brief Get the resolution of this sensor in the sensor's unit.
131  *
132  * @param[in] sensor a sensor to get resolution.
133  * @param[out] resolution the resolution of this sensor in the sensor's unit.
134  * @return true on success, otherwise false.
135  */
136 bool sensord_get_resolution(sensor_t sensor, float *resolution);
137
138 /**
139  * @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.
140  *
141  * @param[in] sensor a sensor to get minimum interval.
142  * @param[out] min_interval the minimum interval of this sensor.
143  * @return true on success, otherwise false.
144  */
145 bool sensord_get_min_interval(sensor_t sensor, int *min_interval);
146
147 /**
148  * @brief Get the number of events reserved for this sensor in the batch mode FIFO.
149  *
150  * @param[in] sensor a sensor to get the number of fifo count
151  * @param[out] fifo_count the number of events reserved for this sensor in the batch mode FIFO
152  * @return true on success, otherwise false
153  */
154 bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count);
155
156 /**
157  * @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.
158  *
159  * @param[in] sensor a sensor to the maximum number of events that could be batched.
160  * @param[out] max_batch_count the maximum number of events of this sensor that could be batched.
161  * @return true on success, otherwise false.
162  */
163 bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count);
164
165
166 /**
167  * @brief Get the supported event types of this sensor.
168  *
169  * @param[in] sensor a sensor to get the supported event types.
170  * @param[out] event_types the array containing supported event types of this sensor, the caller should explicitly free this array.
171  * @param[out] count the count of the supported event types of this sensor.
172  * @return true on success, otherwise false.
173  */
174 bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count);
175
176
177 /**
178  * @brief Check a given event type is supporeted by this sensor.
179  *
180  * @param[in] sensor a sensor to check a given event type is supporeted.
181  * @param[out] event_type an event type to be checked whether supported or not.
182  * @param[out] supported whether a given event is supported or not in this sensor.
183  * @return true on success, otherwise false.
184  */
185 bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported);
186
187 /**
188  * @brief Connect a given sensor and get a handle of a given sensor.
189  *
190  * @param[in] sensor a sensor to connect
191  * @return a handle of a given sensor on success, otherwise negative value
192  */
193 int sensord_connect(sensor_t sensor);
194
195 /**
196  * @brief Disconnect a given sensor.
197  *
198  * @param[in] handle a handle to disconnect.
199  * @return true on success, otherwise false.
200  */
201 bool sensord_disconnect(int handle);
202
203 /**
204  * @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.
205  *
206  * @param[in] handle a handle represensting a connected sensor.
207  * @param[in] event_type an event type  to register
208  * @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.
209  *                                   It can be one of SENSOR_INTERVAL_NORMAL,  SENSOR_INTERVAL_FASTEST or the interval in microseconds.
210  * @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.
211  * @param[in] cb a callback which is called when a given event occurs
212  * @param[in] user_data the callback is called with user_data
213  * @return true on success, otherwise false.
214  */
215 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);
216
217 /**
218  * @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.
219  *
220  * @param[in] handle a handle represensting a connected context sensor.
221  * @param[in] event_type an event type to register
222  * @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.
223  *                                    It can be one of SENSOR_INTERVAL_NORMAL,  SENSOR_INTERVAL_FASTEST or the interval in microseconds.
224  * @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.
225  * @param[in] cb a callback which is called when a given event occurs
226  * @param[in] user_data the callback is called with user_data
227  * @return true on success, otherwise false.
228  */
229 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);
230
231 /**
232  * @brief Unregister a event with a connected sensor.  After unregistering, that event will not be sent.
233  *
234  * @param[in] handle a handle represensting a connected sensor.
235  * @param[in] event_type an event type to unregister.
236  * @return true on success, otherwise false.
237  */
238 bool sensord_unregister_event(int handle, unsigned int event_type);
239
240 /**
241  * @brief Register a callback with a connected sensor. This callback will be called when the accuracy of a sensor has changed.
242  *
243  * @param[in] handle a handle represensting a connected sensor.
244  * @param[in] cb a callback which is called when he accuracy of a sensor has changed.
245  * @param[in] user_data the callback is called with user_data
246  * @return true on success, otherwise false.
247  */
248 bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data);
249
250 /**
251  * @brief Unregister a callback with a connected sensor.  After unregistering,  sensor_accuray_change_cb will not be called.
252  *
253  * @param[in] handle a handle represensting a connected sensor.
254  * @return true on success, otherwise false.
255  */
256 bool sensord_unregister_accuracy_cb(int handle);
257
258 /**
259  * @brief Start listening events with a connected sensor.
260  *
261  * @param[in] handle a handle represensting a connected sensor.
262  * @param[in] option either one of SENSOR_OPTION_DEFAULT and  SENSOR_OPTION_ALWAYS_ON.
263  *                                 with SENSOR_OPTION_DEFAULT, it stops to listening events when LCD is off or in power save mode.
264  *                                 with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode.
265  * @return true on success, otherwise false.
266  */
267
268 bool sensord_start(int handle, int option);
269
270 /**
271  * @brief Stop listening events with a connected sensor.
272  *
273  * @param[in] handle a handle represensting a connected sensor.
274  * @return true on success, otherwise false.
275  */
276 bool sensord_stop(int handle);
277
278 /**
279  * @brief Change the interval of a specifed event type in a connected sensor.
280  *
281  * @param[in] handle a handle represensting a connected sensor.
282  * @param[in] event_type an event type to change interval.
283  * @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.
284  *                                    It can be one of SENSOR_INTERVAL_NORMAL,  SENSOR_INTERVAL_FASTEST or the interval in microseconds.
285  * @return true on success, otherwise false.
286  */
287 bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval);
288
289 /**
290  * @brief Change the max batch latency of a specifed event type in a connected sensor.
291  *
292  * @param[in] handle a handle represensting a connected sensor.
293  * @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.
294  * @return true on success, otherwise false.
295  */
296 bool sensord_change_event_max_batch_latency(int handle, unsigned int max_batch_latency);
297
298 /**
299  * @brief Change the option of a connected sensor.
300  *
301  * @param[in] handle a handle represensting a connected sensor.
302  * @param[in] option either one of SENSOR_OPTION_DEFAULT and  SENSOR_OPTION_ALWAYS_ON.
303  *                                 with SENSOR_OPTION_DEFAULT, it stops to listening events when LCD is off or in power save mode.
304  *                                 with SENSOR_OPTION_ALWAYS_ON, it continues to listening events even when LCD is off or in power save mode.
305  * @return true on success, otherwise false.
306  */
307 bool sensord_set_option(int handle, int option);
308
309 /**
310  * @brief Send data to sensorhub
311  *
312  * @param[in] handle a handle represensting a connected context sensor.
313  * @param[in] data it holds data to send to sensorhub
314  * @param[in] data_len the length of data
315  * @return true on success, otherwise false.
316  */
317 bool sensord_send_sensorhub_data(int handle, const char *data, int data_len);
318
319 /**
320  * @brief get sensor data from a connected sensor
321  *
322  * @param[in] handle a handle represensting a connected context sensor.
323  * @param[in] data_id it specifies data to get
324  * @param[out] sensor_data data from connected sensor
325  * @return true on success, otherwise false.
326  */
327 bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data);
328
329 /**
330   * @}
331  */
332
333 #ifdef __cplusplus
334 }
335 #endif
336
337
338 #endif