summaryrefslogtreecommitdiff
path: root/include/device.h
blob: f53c08770f55fe3666fe42ea474666e524923467 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
/*
 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. 
 */




#ifndef __TIZEN_SYSTEM_DEVICE_H__
#define __TIZEN_SYSTEM_DEVICE_H__

#include <stdbool.h>
#include <tizen_error.h>

#ifdef __cplusplus
extern "C" {
#endif


/**
 * @addtogroup CAPI_SYSTEM_DEVICE_MODULE
 * @{
 */

/**
 * @brief Enumerations of error code for Device.
 */
typedef enum
{
    DEVICE_ERROR_NONE              = TIZEN_ERROR_NONE,                  /**< Successful */
    DEVICE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,   /**< Invalid parameter */
    DEVICE_ERROR_OPERATION_FAILED  = TIZEN_ERROR_SYSTEM_CLASS | 0x12, /**< Operation failed */
    DEVICE_ERROR_NOT_SUPPORTED     = TIZEN_ERROR_SYSTEM_CLASS | 0x13, /**< Not supported in this device */
} device_error_e;

/**
 * @brief Enumerations of the battery warning status
 */
typedef enum
{
    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. */
    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. */
    DEVICE_BATTERY_WARN_LOW,       /**< The battery has little charge left. */
    DEVICE_BATTERY_WARN_NORMAL,    /**< The battery status is not to be careful. */
    DEVICE_BATTERY_WARN_FULL,      /**< The battery status is full. */
} device_battery_warn_e;

/**
 * @brief Enumerations of the battery remaining time type
 */
typedef enum
{
    DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED,
    DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED
} device_battery_remaining_time_type_e;

/**
 * @brief Structure of the time information system spent, measured in units of USER_HZ
 */
typedef struct {
	unsigned long long total;
	unsigned long long user;
	unsigned long long nice;
	unsigned long long system;
	unsigned long long idle;
	unsigned long long iowait;
	unsigned long long irq;
	unsigned long long softirq;
} device_system_time_s;

/**
 * @}
*/

 /**
 * @addtogroup CAPI_SYSTEM_DEVICE_MODULE
 * @{
 */

/**
 * @brief Called when an battery charge percentage changed
 *
 * @param[in] percent       The remaining battery charge percentage (0 ~ 100)
 * @param[in] user_data     The user data passed from the callback registration function
 *
 */
typedef void (*device_battery_cb)(int percent, void *user_data); 

/**
 * @brief Called when the device warn about the battery status.
 *
 * @param[in] status       The battery warning status
 * @param[in] user_data    The user data passed from the callback registration function
 *
 */
typedef void (*device_battery_warn_cb)(device_battery_warn_e status, void *user_data);

/**
 * @brief This callback take remained time for fully charged or discharged.
 *
 * @param[in] time         The battery remainig seconds to fully chagred or discharged
 * @param[in] user_data    The user data passed from the callback registration function
 *
 */
typedef void (*device_battery_remaining_time_changed_cb)(int time, void* user_data);

/**
 * @brief Gets the battery warning status.
 *
 * @param[out] status The battery warning status.
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 *
 * @see device_battery_status_e
 * @see device_battery_status_set_cb()
 */
int device_battery_get_warning_status(device_battery_warn_e *status);

/**
 * @brief Set callback to be observing battery warning.
 *
 * @param[in] callback      The callback function to set
 * @param[in] user_data     The user data to be passed to the callback function
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 *
 * @see device_battery_status_e
 * @see device_battery_get_status()
 */
int device_battery_warning_set_cb(device_battery_warn_cb callback, void* user_data);

/**
 * @brief Unset battery warning callback function.
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE               Successful
 * @retval #DEVICE_ERROR_OPERATION_FAILED   Operation failed
 */
int device_battery_warning_unset_cb(void);

/**
 * @brief Gets the battery charge percentage.
 * @details It returns integer value from 0 to 100 that indicates remaining battery charge
 * as a percentage of the maximum level.
 * @remarks In order to be notified when the battery state changes, use system_info_set_changed_cb().
 *
 * @param[out] percent The remaining battery charge percentage (0 ~ 100) 
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 *
 * @see device_battery_is_full()
 * @see device_battery_get_detail()
 * @see device_battery_set_cb()
 */
int device_battery_get_percent(int *percent);

/**
 * @brief Gets the battery detail charge as a per ten thousand.
 * @details It return integer value from 0 to 10000 that indicates remaining battery charge as a per ten thousand of the maximum level.
 * @remarks this function return #DEVICE_ERROR_NOT_SUPPORTED when device can not be supported detail battery information.
 *
 * @param[out] detail   The remaining battery charge as a per ten thousand. (0 ~ 10000)
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 * @retval #DEVICE_ERROR_NOT_SUPPORTED      Not supported device
 *
 * @see device_battery_is_full()
 * @see device_battery_get_percent()
 * @see device_battery_set_cb()
 */
int device_battery_get_detail(int *detail);

/**
 * @brief Get charging state
 *
 * @param[out] charging The battery charging state.
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 *
 */
int device_battery_is_charging(bool *charging);

/**
 * @brief Set callback to be observing battery charge percentage.
 *
 * @param[in] callback      The callback function to set
 * @param[in] user_data     The user data to be passed to the callback function
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 */
int device_battery_set_cb(device_battery_cb callback, void* user_data);

/**
 * @brief Unset battery charge percentage callback function.
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 */
int device_battery_unset_cb(void);

/**
 * @brief Checks whether the battery is fully charged.
 * @remarks In order to be notified when the battery state changes, use system_info_set_changed_cb().
 *
 * @param[out] full @c true when the battery is fully charged, otherwise @c false.
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 *
 * @see device_battery_get_percent()
 * @see	system_info_set_changed_cb()
 * @see system_info_get_value_int(SYSTEM_INFO_KEY_BATTERY_PERCENTAGE, ...)
 * @see system_info_get_value_int(SYSTEM_INFO_KEY_BATTERY_CHARGE, ...)
 */
int device_battery_is_full(bool *full);

/**
 * @brief Retrive the remaining time for fully charged or discharged.
 *
 * @remark @a time will be retrieved the time to fully charged or discharged depending on @a type
 *
 * @param[in]  type   The type of battery remaining time
 * @param[out] time   battery remainig seconds to fully chagred or discharged

 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 *
 * @see device_battery_set_remaining_time_changed_cb()
 * @see device_battery_unset_remaining_time_changed_cb()
 */
int device_battery_get_remaining_time(device_battery_remaining_time_type_e type, int* time);

/**
 * @brief Set callback to be return battery remaining time to fully charged or discharged.
 *
 * @remark @a callback will be retrieved the time to fully charged or discharged depending on @a type
 *
 * @param[in] callback      The callback function to set
 * @param[in] user_data     The user data to be passed to the callback function
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 *
 */
int device_battery_set_remaining_time_changed_cb(
        device_battery_remaining_time_type_e type,
        device_battery_remaining_time_changed_cb callback, void* user_data);

/**
 * @brief Unset battery remaining time callback function.
 *
 * @param[in] type The type of battery remainig time
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 */
int device_battery_unset_remaining_time_changed_cb(device_battery_remaining_time_type_e type);

/**
 * @brief Gets the number of display devices.
 *
 * @return The number of display devices that the device provides.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 *
 * @see	device_get_brightness()
 * @see device_set_brightness()
 * @see device_get_max_brightness()
 * @see device_set_brightness_from_settings()
 * @see device_set_brightness_to_settings()
 */
int device_get_display_numbers(int* device_number);

/**
 * @brief Gets the display brightness value.
 *
 * @param[in] display_index	The index of the display, it be greater than or equal to 0 and less than \n
 *                          the number of displays returned by device_get_display_numbers().\n
 *                          The index zero is always assigned to the main display.
 * @param[out] brightness	The current brightness value of the display
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 *
 * @see device_get_display_numbers()
 * @see device_set_brightness()
 * @see device_get_max_brightness()
 * @see device_set_brightness_from_settings()
 * @see device_set_brightness_to_settings()
 */
int device_get_brightness(int display_index, int *brightness);

/**
 * @brief Sets the display brightness value. 
 *
 * @param[in] display_index	The index of the display, it be greater than or equal to 0 and less than \n
 *                          the number of displays returned by device_get_display_numbers().\n
 *                          The index zero is always assigned to the main display.
 * @param[in] brightness	The new brightness value to set \n
 *							The maximum value can be represented by device_get_max_brightness()
 * 
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER  Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED   Operation failed
 *
 * @see device_get_display_numbers()
 * @see device_get_max_brightness()
 * @see device_get_brightness()
 * @see device_set_brightness_from_settings()
 * @see device_set_brightness_to_settings()
 */
int device_set_brightness(int display_index, int brightness);

/**
 * @brief Gets the maximum brightness value that can be set. 
 *
 * @param[in] display_index	The index of the display, it be greater than or equal to 0 and less than \n
 *                          the number of displays returned by device_get_display_numbers().\n
 *                          The index zero is always assigned to the main display.
 * @param[out] max_brightness	The maximum brightness value of the display
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 *
 * @see device_get_display_numbers()
 * @see device_set_brightness()
 * @see device_get_brightness()
 * @see device_set_brightness_from_settings()
 * @see device_set_brightness_to_settings()
 */
int device_get_max_brightness(int display_index, int *max_brightness);

/**
 * @brief Sets the display brightness value from registed in settings.
 *
 * @details
 * This function set display brightness to condition in the settings.
 * if auto brightness option is enabled in setting, display's brightness will be changed automatically.
 *
 * @param[in] display_index	The index of the display, it be greater than or equal to 0 and less than \n
 *                          the number of displays returned by device_get_display_numbers().\n
 *                          The index zero is always assigned to the main display.
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 *
 * @see device_get_display_numbers()
 * @see device_get_max_brightness()
 * @see device_set_brightness()
 * @see device_get_brightness()
 * @see device_set_brightness_to_settings()
 */
int device_set_brightness_from_settings(int display_index);

/**
 * @brief Sets the display brightness value to specific display and set to variable in settings.
 *
 * @details
 * This function set given brightness value to given index of display.
 * And also brightness variable in settings will be changed to given brightness value too.
 *
 * @param[in] display_index	The index of the display, it be greater than or equal to 0 and less than \n
 *                          the number of displays returned by device_get_display_numbers().\n
 *                          The index zero is always assigned to the main display.
 * @param[in] brightness	The new brightness value to set \n
 *							The maximum value can be represented by device_get_max_brightness()
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 *
 * @see device_get_display_numbers()
 * @see device_get_max_brightness()
 * @see device_set_brightness()
 * @see device_get_brightness()
 * @see device_set_brightness_from_settings()
 */
int device_set_brightness_to_settings(int display_index, int brightness);

/**
 * @brief Get brightness value of LED that placed to camera flash.
 *
 * @param[out] brightness brightness value of LED (0 ~ MAX)
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 */
int device_flash_get_brightness(int *brightness);

/**
 * @brief Set brightness value of LED that placed to camera flash.
 *
 * @param[in] brightness brightness value of LED (0 ~ MAX)
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 */
int device_flash_set_brightness(int brightness);

/**
 * @brief Get max brightness value of LED that placed to camera flash.
 *
 * @remark
 * Brightness control does not support yet. so this functioon always return 1. \n
 * Set function can only use to switch on/off the flash. \n
 * Get function can only use to retrive on/off state of flash.
 *
 * @param[out] max_brightness max brightness value of LED
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 */
int device_flash_get_max_brightness(int *max_brightness);

/**
 * @brief Get total amount of physical RAM, in kilobytes
 *
 * @remark
 *
 * @param[out] total_mem total amount of physical RAM
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 */
int device_memory_get_total(unsigned int *total_mem);

/**
 * @brief Get available amount of physical RAM, in kilobytes
 *
 * @remark
 * Available amount is defined by following formula currently.
 * available mem = MemFree+Buffers+Cached+SwapCached-Shmem
 *
 * @param[out] avail_mem available amount of physical RAM
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 */
int device_memory_get_available(unsigned int *avail_mem);

/**
 * @brief Get time information the CPU has spent performing work.
 *
 * @remark
 * Time units are in USER_HZ (typically hundredths of a second).
 *
 * @param[out] time structure of time information the CPU has spent
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 */
int device_cpu_get_system_time(device_system_time_s *time);

/**
 * @brief Get all of CPU count
 *
 * @remark
 *
 * @param[out] cpu_cnt total count of CPU
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 */
int device_cpu_get_count(int *cpu_cnt);

/**
 * @brief Get currently frequency of CPU
 *
 * @remark
 *
 * @param[in]  cpu the index of CPU which want to know
 * @param[out] cur_freq currently frequency value of CPU
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 */
int device_cpu_get_current_freq(int cpu, unsigned int *cur_freq);

/**
 * @brief Get max frequency of CPU
 *
 * @remark
 *
 * @param[in]  cpu the index of CPU which want to know
 * @param[out] max_freq max frequency value of CPU
 *
 * @return 0 on success, otherwise a negative error value.
 * @retval #DEVICE_ERROR_NONE				Successful
 * @retval #DEVICE_ERROR_INVALID_PARAMETER	Invalid parameter
 * @retval #DEVICE_ERROR_OPERATION_FAILED	Operation failed
 */
int device_cpu_get_max_freq(int cpu, unsigned int *max_freq);

/**
 * @}
 */

#ifdef __cplusplus
}
#endif

#endif  // __TIZEN_SYSTEM_DEVICE_H__