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