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