device: Merge public api on Tizen 2.3 into tizen branch
[platform/core/api/device.git] / include / device.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License. 
15  */
16
17
18
19
20 #ifndef __TIZEN_SYSTEM_DEVICE_H__
21 #define __TIZEN_SYSTEM_DEVICE_H__
22
23 #include <stdbool.h>
24 #include "device-error.h"
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30
31 /**
32  * @addtogroup CAPI_SYSTEM_DEVICE_MODULE
33  * @{
34  */
35
36 /**
37  * @brief Enumerations of the battery warning status
38  */
39 typedef enum
40 {
41     DEVICE_BATTERY_WARN_EMPTY,      /**< The battery goes empty. Prepare for the safe termination of the application, because the device starts a shutdown process soon after entering this level. */
42     DEVICE_BATTERY_WARN_CRITICAL,  /**< The battery charge is at a critical state. You may have to stop using multimedia features, because they are not guaranteed to work correctly at this battery status. */
43     DEVICE_BATTERY_WARN_LOW,       /**< The battery has little charge left. */
44     DEVICE_BATTERY_WARN_NORMAL,    /**< The battery status is not to be careful. */
45     DEVICE_BATTERY_WARN_FULL,      /**< The battery status is full. */
46 } device_battery_warn_e;
47
48 /**
49  * @brief Enumerations of the battery remaining time type
50  */
51 typedef enum
52 {
53     DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED,
54     DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED
55 } device_battery_remaining_time_type_e;
56
57 /**
58  * @brief Enumerations of the battery level status
59  */
60 typedef enum
61 {
62     DEVICE_BATTERY_LEVEL_EMPTY = 0,      /**< The battery goes empty. Prepare for the safe termination of the application, because the device starts a shutdown process soon after entering this level. */
63     DEVICE_BATTERY_LEVEL_CRITICAL,  /**< The battery charge is at a critical state. You may have to stop using multimedia features, because they are not guaranteed to work correctly at this battery status. */
64     DEVICE_BATTERY_LEVEL_LOW,       /**< The battery has little charge left. */
65     DEVICE_BATTERY_LEVEL_HIGH,    /**< The battery status is not to be careful. */
66     DEVICE_BATTERY_LEVEL_FULL,      /**< The battery status is full. */
67 } device_battery_level_e;
68
69
70 /**
71  * @brief Structure of the time information system spent, measured in units of USER_HZ
72  */
73 typedef struct {
74         unsigned long long total;
75         unsigned long long user;
76         unsigned long long nice;
77         unsigned long long system;
78         unsigned long long idle;
79         unsigned long long iowait;
80         unsigned long long irq;
81         unsigned long long softirq;
82 } device_system_time_s;
83
84 /**
85  * @}
86 */
87
88  /**
89  * @addtogroup CAPI_SYSTEM_DEVICE_MODULE
90  * @{
91  */
92
93 /**
94  * @brief Called when an battery charge percentage changed
95  *
96  * @param[in] percent       The remaining battery charge percentage (0 ~ 100)
97  * @param[in] user_data     The user data passed from the callback registration function
98  *
99  */
100 typedef void (*device_battery_cb)(int percent, void *user_data); 
101
102 /**
103  * @brief Called when the device warn about the battery status.
104  *
105  * @param[in] status       The battery warning status
106  * @param[in] user_data    The user data passed from the callback registration function
107  *
108  */
109 typedef void (*device_battery_warn_cb)(device_battery_warn_e status, void *user_data);
110
111 /**
112  * @brief This callback take remained time for fully charged or discharged.
113  *
114  * @param[in] time         The battery remainig seconds to fully chagred or discharged
115  * @param[in] user_data    The user data passed from the callback registration function
116  *
117  */
118 typedef void (*device_battery_remaining_time_changed_cb)(int time, void* user_data);
119
120 /**
121  * @brief Called when an battery level changed
122  *
123  * @param[in] status       The remaining battery level (empty[0~1] critical[2~5] low[6~15] high[16~94] full[95~100])
124  * @param[in] user_data     The user data passed from the callback registration function
125  *
126  */
127 typedef void (*device_battery_level_cb)(device_battery_level_e status, void *user_data);
128
129 /**
130  * @brief Gets the battery warning status.
131  *
132  * @param[out] status The battery warning status.
133  * @return 0 on success, otherwise a negative error value.
134  * @retval #DEVICE_ERROR_NONE                           Successful
135  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
136  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
137  *
138  * @see device_battery_status_e
139  * @see device_battery_status_set_cb()
140  */
141 int device_battery_get_warning_status(device_battery_warn_e *status);
142
143 /**
144  * @brief Set callback to be observing battery warning.
145  *
146  * @param[in] callback      The callback function to set
147  * @param[in] user_data     The user data to be passed to the callback function
148  *
149  * @return 0 on success, otherwise a negative error value.
150  * @retval #DEVICE_ERROR_NONE                           Successful
151  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
152  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
153  *
154  * @see device_battery_status_e
155  * @see device_battery_get_status()
156  */
157 int device_battery_warning_set_cb(device_battery_warn_cb callback, void* user_data);
158
159 /**
160  * @brief Unset battery warning callback function.
161  *
162  * @return 0 on success, otherwise a negative error value.
163  * @retval #DEVICE_ERROR_NONE               Successful
164  * @retval #DEVICE_ERROR_OPERATION_FAILED   Operation failed
165  */
166 int device_battery_warning_unset_cb(void);
167
168 /**
169  * @brief Gets the battery charge percentage.
170  * @details It returns integer value from 0 to 100 that indicates remaining battery charge
171  * as a percentage of the maximum level.
172  * @remarks In order to be notified when the battery state changes, use system_info_set_changed_cb().
173  *
174  * @param[out] percent The remaining battery charge percentage (0 ~ 100) 
175  *
176  * @return 0 on success, otherwise a negative error value.
177  * @retval #DEVICE_ERROR_NONE                           Successful
178  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
179  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
180  *
181  * @see device_battery_is_full()
182  * @see device_battery_get_detail()
183  * @see device_battery_set_cb()
184  */
185 int device_battery_get_percent(int *percent);
186
187 /**
188  * @brief Gets the battery detail charge as a per ten thousand.
189  * @details It return integer value from 0 to 10000 that indicates remaining battery charge as a per ten thousand of the maximum level.
190  * @remarks this function return #DEVICE_ERROR_NOT_SUPPORTED when device can not be supported detail battery information.
191  *
192  * @param[out] detail   The remaining battery charge as a per ten thousand. (0 ~ 10000)
193  *
194  * @return 0 on success, otherwise a negative error value.
195  * @retval #DEVICE_ERROR_NONE                           Successful
196  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
197  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
198  * @retval #DEVICE_ERROR_NOT_SUPPORTED      Not supported device
199  *
200  * @see device_battery_is_full()
201  * @see device_battery_get_percent()
202  * @see device_battery_set_cb()
203  */
204 int device_battery_get_detail(int *detail);
205
206 /**
207  * @brief Get charging state
208  *
209  * @param[out] charging The battery charging state.
210  *
211  * @return 0 on success, otherwise a negative error value.
212  * @retval #DEVICE_ERROR_NONE                           Successful
213  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
214  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
215  *
216  */
217 int device_battery_is_charging(bool *charging);
218
219 /**
220  * @brief Set callback to be observing battery charge percentage.
221  *
222  * @param[in] callback      The callback function to set
223  * @param[in] user_data     The user data to be passed to the callback function
224  *
225  * @return 0 on success, otherwise a negative error value.
226  * @retval #DEVICE_ERROR_NONE                           Successful
227  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
228  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
229  */
230 int device_battery_set_cb(device_battery_cb callback, void* user_data);
231
232 /**
233  * @brief Unset battery charge percentage callback function.
234  *
235  * @return 0 on success, otherwise a negative error value.
236  * @retval #DEVICE_ERROR_NONE                           Successful
237  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
238  */
239 int device_battery_unset_cb(void);
240
241 /**
242  * @brief Checks whether the battery is fully charged.
243  * @remarks In order to be notified when the battery state changes, use system_info_set_changed_cb().
244  *
245  * @param[out] full @c true when the battery is fully charged, otherwise @c false.
246  *
247  * @return 0 on success, otherwise a negative error value.
248  * @retval #DEVICE_ERROR_NONE                           Successful
249  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
250  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
251  *
252  * @see device_battery_get_percent()
253  * @see system_info_set_changed_cb()
254  * @see system_info_get_value_int(SYSTEM_INFO_KEY_BATTERY_PERCENTAGE, ...)
255  * @see system_info_get_value_int(SYSTEM_INFO_KEY_BATTERY_CHARGE, ...)
256  */
257 int device_battery_is_full(bool *full);
258
259 /**
260  * @brief Retrive the remaining time for fully charged or discharged.
261  *
262  * @remark @a time will be retrieved the time to fully charged or discharged depending on @a type
263  *
264  * @param[in]  type   The type of battery remaining time
265  * @param[out] time   battery remainig seconds to fully chagred or discharged
266
267  * @return 0 on success, otherwise a negative error value.
268  * @retval #DEVICE_ERROR_NONE                           Successful
269  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
270  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
271  *
272  * @see device_battery_set_remaining_time_changed_cb()
273  * @see device_battery_unset_remaining_time_changed_cb()
274  */
275 int device_battery_get_remaining_time(device_battery_remaining_time_type_e type, int* time);
276
277 /**
278  * @brief Set callback to be return battery remaining time to fully charged or discharged.
279  *
280  * @remark @a callback will be retrieved the time to fully charged or discharged depending on @a type
281  *
282  * @param[in] callback      The callback function to set
283  * @param[in] user_data     The user data to be passed to the callback function
284  *
285  * @return 0 on success, otherwise a negative error value.
286  * @retval #DEVICE_ERROR_NONE                           Successful
287  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
288  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
289  *
290  */
291 int device_battery_set_remaining_time_changed_cb(
292         device_battery_remaining_time_type_e type,
293         device_battery_remaining_time_changed_cb callback, void* user_data);
294
295 /**
296  * @brief Unset battery remaining time callback function.
297  *
298  * @param[in] type The type of battery remainig time
299  *
300  * @return 0 on success, otherwise a negative error value.
301  * @retval #DEVICE_ERROR_NONE                           Successful
302  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
303  */
304 int device_battery_unset_remaining_time_changed_cb(device_battery_remaining_time_type_e type);
305
306 /**
307  * @brief Gets the battery level status.
308  *
309  * @param[out] status The battery level status.
310  * @return 0 on success, otherwise a negative error value.
311  * @retval #DEVICE_ERROR_NONE                           Successful
312  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
313  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
314  *
315  * @see device_battery_level_e
316  * @see device_battery_level_set_cb()
317  */
318 int device_battery_get_level_status(device_battery_level_e *status);
319
320 /**
321  * @brief Set/Unset callback to be observing battery level.
322  *
323  * @param[in] callback      The callback function to set, if you input NULL, observing is disabled
324  * @param[in] user_data     The user data to be passed to the callback function
325  *
326  * @return 0 on success, otherwise a negative error value.
327  * @retval #DEVICE_ERROR_NONE                   Successful
328  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
329  *
330  * @see device_battery_level_e
331  * @see device_battery_get_level_status()
332  */
333 int device_battery_level_set_cb(device_battery_level_cb callback, void* user_data);
334
335 /**
336  * @brief Gets the number of display devices.
337  *
338  * @return The number of display devices that the device provides.
339  * @retval #DEVICE_ERROR_NONE                           Successful
340  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
341  *
342  * @see device_get_brightness()
343  * @see device_set_brightness()
344  * @see device_get_max_brightness()
345  * @see device_set_brightness_from_settings()
346  * @see device_set_brightness_to_settings()
347  */
348 int device_get_display_numbers(int* device_number);
349
350 /**
351  * @brief Gets the display brightness value.
352  *
353  * @param[in] display_index     The index of the display, it be greater than or equal to 0 and less than \n
354  *                          the number of displays returned by device_get_display_numbers().\n
355  *                          The index zero is always assigned to the main display.
356  * @param[out] brightness       The current brightness value of the display
357  *
358  * @return 0 on success, otherwise a negative error value.
359  * @retval #DEVICE_ERROR_NONE                           Successful
360  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
361  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
362  *
363  * @see device_get_display_numbers()
364  * @see device_set_brightness()
365  * @see device_get_max_brightness()
366  * @see device_set_brightness_from_settings()
367  * @see device_set_brightness_to_settings()
368  */
369 int device_get_brightness(int display_index, int *brightness);
370
371 /**
372  * @brief Sets the display brightness value. 
373  *
374  * @param[in] display_index     The index of the display, it be greater than or equal to 0 and less than \n
375  *                          the number of displays returned by device_get_display_numbers().\n
376  *                          The index zero is always assigned to the main display.
377  * @param[in] brightness        The new brightness value to set \n
378  *                                                      The maximum value can be represented by device_get_max_brightness()
379  * 
380  * @return 0 on success, otherwise a negative error value.
381  * @retval #DEVICE_ERROR_NONE                           Successful
382  * @retval #DEVICE_ERROR_INVALID_PARAMETER  Invalid parameter
383  * @retval #DEVICE_ERROR_OPERATION_FAILED   Operation failed
384  *
385  * @see device_get_display_numbers()
386  * @see device_get_max_brightness()
387  * @see device_get_brightness()
388  * @see device_set_brightness_from_settings()
389  * @see device_set_brightness_to_settings()
390  */
391 int device_set_brightness(int display_index, int brightness);
392
393 /**
394  * @brief Gets the maximum brightness value that can be set. 
395  *
396  * @param[in] display_index     The index of the display, it be greater than or equal to 0 and less than \n
397  *                          the number of displays returned by device_get_display_numbers().\n
398  *                          The index zero is always assigned to the main display.
399  * @param[out] max_brightness   The maximum brightness value of the display
400  *
401  * @return 0 on success, otherwise a negative error value.
402  * @retval #DEVICE_ERROR_NONE                           Successful
403  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
404  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
405  *
406  * @see device_get_display_numbers()
407  * @see device_set_brightness()
408  * @see device_get_brightness()
409  * @see device_set_brightness_from_settings()
410  * @see device_set_brightness_to_settings()
411  */
412 int device_get_max_brightness(int display_index, int *max_brightness);
413
414 /**
415  * @brief Sets the display brightness value from registed in settings.
416  *
417  * @details
418  * This function set display brightness to condition in the settings.
419  * if auto brightness option is enabled in setting, display's brightness will be changed automatically.
420  *
421  * @param[in] display_index     The index of the display, it be greater than or equal to 0 and less than \n
422  *                          the number of displays returned by device_get_display_numbers().\n
423  *                          The index zero is always assigned to the main display.
424  *
425  * @return 0 on success, otherwise a negative error value.
426  * @retval #DEVICE_ERROR_NONE                           Successful
427  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
428  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
429  *
430  * @see device_get_display_numbers()
431  * @see device_get_max_brightness()
432  * @see device_set_brightness()
433  * @see device_get_brightness()
434  * @see device_set_brightness_to_settings()
435  */
436 int device_set_brightness_from_settings(int display_index);
437
438 /**
439  * @brief Sets the display brightness value to specific display and set to variable in settings.
440  *
441  * @details
442  * This function set given brightness value to given index of display.
443  * And also brightness variable in settings will be changed to given brightness value too.
444  *
445  * @param[in] display_index     The index of the display, it be greater than or equal to 0 and less than \n
446  *                          the number of displays returned by device_get_display_numbers().\n
447  *                          The index zero is always assigned to the main display.
448  * @param[in] brightness        The new brightness value to set \n
449  *                                                      The maximum value can be represented by device_get_max_brightness()
450  *
451  * @return 0 on success, otherwise a negative error value.
452  * @retval #DEVICE_ERROR_NONE                           Successful
453  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
454  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
455  *
456  * @see device_get_display_numbers()
457  * @see device_get_max_brightness()
458  * @see device_set_brightness()
459  * @see device_get_brightness()
460  * @see device_set_brightness_from_settings()
461  */
462 int device_set_brightness_to_settings(int display_index, int brightness);
463
464 /**
465  * @brief Get brightness value of LED that placed to camera flash.
466  *
467  * @param[out] brightness brightness value of LED (0 ~ MAX)
468  *
469  * @return 0 on success, otherwise a negative error value.
470  * @retval #DEVICE_ERROR_NONE                           Successful
471  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
472  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
473  */
474 int device_flash_get_brightness(int *brightness);
475
476 /**
477  * @brief Set brightness value of LED that placed to camera flash.
478  *
479  * @param[in] brightness brightness value of LED (0 ~ MAX)
480  *
481  * @return 0 on success, otherwise a negative error value.
482  * @retval #DEVICE_ERROR_NONE                           Successful
483  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
484  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
485  */
486 int device_flash_set_brightness(int brightness);
487
488 /**
489  * @brief Get max brightness value of LED that placed to camera flash.
490  *
491  * @remark
492  * Brightness control does not support yet. so this functioon always return 1. \n
493  * Set function can only use to switch on/off the flash. \n
494  * Get function can only use to retrive on/off state of flash.
495  *
496  * @param[out] max_brightness max brightness value of LED
497  *
498  * @return 0 on success, otherwise a negative error value.
499  * @retval #DEVICE_ERROR_NONE                           Successful
500  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
501  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
502  */
503 int device_flash_get_max_brightness(int *max_brightness);
504
505 /**
506  * @brief Get total amount of physical RAM, in kilobytes
507  *
508  * @remark
509  *
510  * @param[out] total_mem total amount of physical RAM
511  *
512  * @return 0 on success, otherwise a negative error value.
513  * @retval #DEVICE_ERROR_NONE                           Successful
514  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
515  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
516  */
517 int device_memory_get_total(unsigned int *total_mem);
518
519 /**
520  * @brief Get available amount of physical RAM, in kilobytes
521  *
522  * @remark
523  * Available amount is defined by following formula currently.
524  * available mem = MemFree+Buffers+Cached+SwapCached-Shmem
525  *
526  * @param[out] avail_mem available amount of physical RAM
527  *
528  * @return 0 on success, otherwise a negative error value.
529  * @retval #DEVICE_ERROR_NONE                           Successful
530  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
531  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
532  */
533 int device_memory_get_available(unsigned int *avail_mem);
534
535 /**
536  * @brief Get time information the CPU has spent performing work.
537  *
538  * @remark
539  * Time units are in USER_HZ (typically hundredths of a second).
540  *
541  * @param[out] time structure of time information the CPU has spent
542  *
543  * @return 0 on success, otherwise a negative error value.
544  * @retval #DEVICE_ERROR_NONE                           Successful
545  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
546  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
547  */
548 int device_cpu_get_system_time(device_system_time_s *time);
549
550 /**
551  * @brief Get all of CPU count
552  *
553  * @remark
554  *
555  * @param[out] cpu_cnt total count of CPU
556  *
557  * @return 0 on success, otherwise a negative error value.
558  * @retval #DEVICE_ERROR_NONE                           Successful
559  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
560  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
561  */
562 int device_cpu_get_count(int *cpu_cnt);
563
564 /**
565  * @brief Get currently frequency of CPU
566  *
567  * @remark
568  *
569  * @param[in]  cpu the index of CPU which want to know
570  * @param[out] cur_freq currently frequency value of CPU
571  *
572  * @return 0 on success, otherwise a negative error value.
573  * @retval #DEVICE_ERROR_NONE                           Successful
574  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
575  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
576  */
577 int device_cpu_get_current_freq(int cpu, unsigned int *cur_freq);
578
579 /**
580  * @brief Get max frequency of CPU
581  *
582  * @remark
583  *
584  * @param[in]  cpu the index of CPU which want to know
585  * @param[out] max_freq max frequency value of CPU
586  *
587  * @return 0 on success, otherwise a negative error value.
588  * @retval #DEVICE_ERROR_NONE                           Successful
589  * @retval #DEVICE_ERROR_INVALID_PARAMETER      Invalid parameter
590  * @retval #DEVICE_ERROR_OPERATION_FAILED       Operation failed
591  */
592 int device_cpu_get_max_freq(int cpu, unsigned int *max_freq);
593
594 /**
595  * @}
596  */
597
598 #ifdef __cplusplus
599 }
600 #endif
601
602 #endif  // __TIZEN_SYSTEM_DEVICE_H__