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