From 94efdf305286f312e6e685967a7a949040c06d15 Mon Sep 17 00:00:00 2001 From: "jk7744.park" Date: Sun, 1 Feb 2015 13:29:56 +0900 Subject: tizen 2.3 release --- CMakeLists.txt | 31 +-- TC/testcase/tslist | 3 + TC/testcase/utc_system_device_battery.c | 366 ++++++++++++++++++++++--- TC/testcase/utc_system_device_brightness.c | 315 ++++++++++------------ TC/testcase/utc_system_device_cpu.c | 212 +++++++++++++++ TC/testcase/utc_system_device_flash.c | 136 ++++++++++ TC/testcase/utc_system_device_memory.c | 104 ++++++++ capi-system-device.pc.in | 7 +- doc/device_doc.h | 149 +++++++++++ include/battery.h | 117 ++++++++ include/callback.h | 109 ++++++++ include/device-error.h | 55 ++++ include/device.h | 88 +----- include/device_doc.h | 41 --- include/device_log.h | 30 --- include/display.h | 216 +++++++++++++++ include/haptic.h | 175 ++++++++++++ include/led.h | 152 +++++++++++ include/power.h | 134 ++++++++++ packaging/capi-system-device.spec | 17 +- src/battery.c | 87 ++++++ src/callback.c | 236 +++++++++++++++++ src/common.h | 50 ++++ src/cpu.c | 171 ++++++++++++ src/dbus.c | 235 +++++++++++++++++ src/dbus.h | 55 ++++ src/device.c | 289 ++++++++++++++++++++ src/display.c | 214 +++++++++++++++ src/haptic.c | 179 +++++++++++++ src/led.c | 169 ++++++++++++ src/list.h | 83 ++++++ src/memory.c | 136 ++++++++++ src/mobile/battery.c | 410 ---------------------------- src/mobile/cpu.c | 171 ------------ src/mobile/device.c | 211 --------------- src/mobile/memory.c | 136 ---------- src/power.c | 217 +++++++++++++++ src/wearable/battery.c | 411 ----------------------------- src/wearable/cpu.c | 171 ------------ src/wearable/device.c | 201 -------------- src/wearable/memory.c | 136 ---------- 41 files changed, 4173 insertions(+), 2252 deletions(-) create mode 100644 TC/testcase/utc_system_device_cpu.c create mode 100644 TC/testcase/utc_system_device_flash.c create mode 100644 TC/testcase/utc_system_device_memory.c create mode 100755 doc/device_doc.h create mode 100755 include/battery.h create mode 100755 include/callback.h create mode 100755 include/device-error.h delete mode 100755 include/device_doc.h delete mode 100644 include/device_log.h create mode 100755 include/display.h create mode 100755 include/haptic.h create mode 100755 include/led.h create mode 100755 include/power.h create mode 100644 src/battery.c create mode 100644 src/callback.c create mode 100644 src/common.h create mode 100644 src/cpu.c create mode 100644 src/dbus.c create mode 100644 src/dbus.h create mode 100644 src/device.c create mode 100644 src/display.c create mode 100644 src/haptic.c create mode 100644 src/led.c create mode 100644 src/list.h create mode 100644 src/memory.c delete mode 100644 src/mobile/battery.c delete mode 100644 src/mobile/cpu.c delete mode 100644 src/mobile/device.c delete mode 100644 src/mobile/memory.c create mode 100644 src/power.c delete mode 100644 src/wearable/battery.c delete mode 100644 src/wearable/cpu.c delete mode 100644 src/wearable/device.c delete mode 100644 src/wearable/memory.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a54217..c222b82 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,21 +10,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) -IF("${ARCH}" STREQUAL "mobile") - OPTION(USE_MOBILE "Use Mobile" ON) -ELSEIF("${ARCH}" STREQUAL "wearable") - OPTION(USE_WEARABLE "Use Wearable" ON) -ENDIF() - -IF(USE_MOBILE) - SET(SRCS src/mobile) - SET(dependents devman) -ELSEIF(USE_WEARABLE) - SET(SRCS src/wearable) - SET(dependents deviced) -ENDIF() - -SET(dependents ${dependents} "dlog vconf capi-base-common") +SET(dependents "deviced dlog vconf dbus-1 dbus-glib-1 capi-base-common capi-system-info") SET(pc_dependents "capi-base-common") INCLUDE(FindPkgConfig) @@ -36,12 +22,16 @@ ENDFOREACH(flag) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") -ADD_DEFINITIONS("-DTIZEN_DEBUG") +ADD_DEFINITIONS("-DFEATURE_DEVICE_DLOG") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") -aux_source_directory(${SRCS} SOURCES) +aux_source_directory(src SOURCES) ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS}) @@ -54,12 +44,13 @@ SET_TARGET_PROPERTIES(${fw_name} ) INSTALL(TARGETS ${fw_name} DESTINATION lib) +INSTALL(FILES ${INC_DIR}/device.h ${INC_DIR}/device-error.h + DESTINATION include/system) INSTALL( - DIRECTORY ${INC_DIR}/ DESTINATION include/system + DIRECTORY ${INC_DIR}/ DESTINATION include/device FILES_MATCHING - PATTERN "*_private.h" EXCLUDE - PATTERN "*_log.h" EXCLUDE PATTERN "*_doc.h" EXCLUDE + PATTERN "device.h" EXCLUDE PATTERN "${INC_DIR}/*.h" ) diff --git a/TC/testcase/tslist b/TC/testcase/tslist index 9517124..c919e23 100644 --- a/TC/testcase/tslist +++ b/TC/testcase/tslist @@ -1,3 +1,6 @@ /testcase/utc_system_device_battery /testcase/utc_system_device_brightness +/testcase/utc_system_device_flash +/testcase/utc_system_device_memory +/testcase/utc_system_device_cpu diff --git a/TC/testcase/utc_system_device_battery.c b/TC/testcase/utc_system_device_battery.c index a93ba00..0ab951c 100644 --- a/TC/testcase/utc_system_device_battery.c +++ b/TC/testcase/utc_system_device_battery.c @@ -18,11 +18,20 @@ #include #include +#define API_NAME_DEVICE_BATTERY_GET_WARNING_STATUS "device_battery_get_warning_status" +#define API_NAME_DEVICE_BATTERY_WARNING_SET_CB "device_battery_warning_set_cb" +#define API_NAME_DEVICE_BATTERY_WARNING_UNSET_CB "device_battery_warning_unset_cb" #define API_NAME_DEVICE_BATTERY_GET_PERCENT "device_battery_get_percent" -#define API_NAME_DEVICE_BATTERY_IS_FULL "device_battery_is_full" +#define API_NAME_DEVICE_BATTERY_GET_DETAIL "device_battery_get_detail" #define API_NAME_DEVICE_BATTERY_IS_CHARGING "device_battery_is_charging" #define API_NAME_DEVICE_BATTERY_SET_CB "device_battery_set_cb" #define API_NAME_DEVICE_BATTERY_UNSET_CB "device_battery_unset_cb" +#define API_NAME_DEVICE_BATTERY_IS_FULL "device_battery_is_full" +#define API_NAME_DEVICE_BATTERY_GET_REMAINING_TIME "device_battery_get_remaining_time" +#define API_NAME_DEVICE_BATTERY_SET_REMAINING_TIME_CHANGED_CB "device_battery_set_remaining_time_changed_cb" +#define API_NAME_DEVICE_BATTERY_UNSET_REMAINING_TIME_CHANGED_CB "device_battery_unset_remaining_time_changed_cb" +#define API_NAME_DEVICE_BATTERY_GET_LEVEL_STATUS "device_battery_get_level_status" +#define API_NAME_DEVICE_BATTERY_LEVEL_SET_CB "device_battery_level_set_cb" static void startup(void); static void cleanup(void); @@ -30,16 +39,35 @@ static void cleanup(void); void (*tet_startup)(void) = startup; void (*tet_cleanup)(void) = cleanup; + +static void utc_system_device_battery_get_warning_status_p(void); +static void utc_system_device_battery_get_warning_status_n(void); +static void utc_system_device_battery_warning_set_cb_p(void); +static void utc_system_device_battery_warning_set_cb_n(void); +static void utc_system_device_battery_warning_unset_cb_p(void); static void utc_system_device_battery_get_percent_p(void); static void utc_system_device_battery_get_percent_n(void); -static void utc_system_device_battery_is_full_p(void); -static void utc_system_device_battery_is_full_n(void); +static void utc_system_device_battery_get_detail_p(void); +static void utc_system_device_battery_get_detail_n(void); static void utc_system_device_battery_is_charging_p(void); static void utc_system_device_battery_is_charging_n(void); static void utc_system_device_battery_set_cb_p(void); static void utc_system_device_battery_set_cb_n(void); static void utc_system_device_battery_unset_cb_p(void); - +static void utc_system_device_battery_is_full_p(void); +static void utc_system_device_battery_is_full_n(void); +static void utc_system_device_battery_get_remaining_time_p(void); +static void utc_system_device_battery_get_remaining_time_n_1(void); +static void utc_system_device_battery_get_remaining_time_n_2(void); +static void utc_system_device_battery_set_remaining_time_changed_cb_p(void); +static void utc_system_device_battery_set_remaining_time_changed_cb_n_1(void); +static void utc_system_device_battery_set_remaining_time_changed_cb_n_2(void); +static void utc_system_device_battery_unset_remaining_time_changed_cb_p(void); +static void utc_system_device_battery_unset_remaining_time_changed_cb_n(void); +static void utc_system_device_battery_get_level_status_p(void); +static void utc_system_device_battery_get_level_status_n(void); +static void utc_system_device_battery_level_set_cb_p(void); +static void utc_system_device_battery_level_set_cb_n(void); enum { POSITIVE_TC_IDX = 0x01, @@ -47,15 +75,34 @@ enum { }; struct tet_testlist tet_testlist[] = { + { utc_system_device_battery_get_warning_status_p, POSITIVE_TC_IDX }, + { utc_system_device_battery_get_warning_status_n, NEGATIVE_TC_IDX }, + { utc_system_device_battery_warning_set_cb_p, POSITIVE_TC_IDX }, + { utc_system_device_battery_warning_set_cb_n, NEGATIVE_TC_IDX }, + { utc_system_device_battery_warning_unset_cb_p, POSITIVE_TC_IDX }, { utc_system_device_battery_get_percent_p, POSITIVE_TC_IDX }, { utc_system_device_battery_get_percent_n, NEGATIVE_TC_IDX }, - { utc_system_device_battery_is_full_p, POSITIVE_TC_IDX }, - { utc_system_device_battery_is_full_n, NEGATIVE_TC_IDX }, + { utc_system_device_battery_get_detail_p, POSITIVE_TC_IDX }, + { utc_system_device_battery_get_detail_n, NEGATIVE_TC_IDX }, { utc_system_device_battery_is_charging_p, POSITIVE_TC_IDX }, { utc_system_device_battery_is_charging_n, NEGATIVE_TC_IDX }, { utc_system_device_battery_set_cb_p, POSITIVE_TC_IDX }, { utc_system_device_battery_set_cb_n, NEGATIVE_TC_IDX }, { utc_system_device_battery_unset_cb_p, POSITIVE_TC_IDX }, + { utc_system_device_battery_is_full_p, POSITIVE_TC_IDX }, + { utc_system_device_battery_is_full_n, NEGATIVE_TC_IDX }, + { utc_system_device_battery_get_remaining_time_p, POSITIVE_TC_IDX }, + { utc_system_device_battery_get_remaining_time_n_1, NEGATIVE_TC_IDX }, + { utc_system_device_battery_get_remaining_time_n_2, NEGATIVE_TC_IDX }, + { utc_system_device_battery_set_remaining_time_changed_cb_p, POSITIVE_TC_IDX }, + { utc_system_device_battery_set_remaining_time_changed_cb_n_1, NEGATIVE_TC_IDX }, + { utc_system_device_battery_set_remaining_time_changed_cb_n_2, NEGATIVE_TC_IDX }, + { utc_system_device_battery_unset_remaining_time_changed_cb_p, POSITIVE_TC_IDX }, + { utc_system_device_battery_unset_remaining_time_changed_cb_n, NEGATIVE_TC_IDX }, + { utc_system_device_battery_get_level_status_p, POSITIVE_TC_IDX }, + { utc_system_device_battery_get_level_status_n, NEGATIVE_TC_IDX }, + { utc_system_device_battery_level_set_cb_p, POSITIVE_TC_IDX }, + { utc_system_device_battery_level_set_cb_n, NEGATIVE_TC_IDX }, { NULL, 0}, }; @@ -69,16 +116,77 @@ static void cleanup(void) /* end of TC */ } +/** + * @brief Positive test case of device_battery_get_warning_status() + */ +static void utc_system_device_battery_get_warning_status_p(void) +{ + device_battery_warn_e status = 0; + int error = DEVICE_ERROR_NONE; + error = device_battery_get_warning_status(&status); + + dts_check_eq(API_NAME_DEVICE_BATTERY_GET_WARNING_STATUS, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_battery_get_warning_status() + */ +static void utc_system_device_battery_get_warning_status_n(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_battery_get_warning_status(NULL); + + dts_check_ne(API_NAME_DEVICE_BATTERY_GET_PERCENT, error, DEVICE_ERROR_NONE); +} + +static void warning_set_cb(device_battery_warn_e status, void *user_data) +{ + +} + +/** + * @brief Positive test case of device_battery_warning_set_cb() + */ +static void utc_system_device_battery_warning_set_cb_p(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_battery_warning_set_cb(warning_set_cb, NULL); + + dts_check_eq(API_NAME_DEVICE_BATTERY_WARNING_SET_CB, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_battery_warning_set_cb() + */ +static void utc_system_device_battery_warning_set_cb_n(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_battery_warning_set_cb(NULL, NULL); + + dts_check_ne(API_NAME_DEVICE_BATTERY_WARNING_SET_CB, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Positive test case of device_battery_warning_unset_cb() + */ +static void utc_system_device_battery_warning_unset_cb_p(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_battery_warning_unset_cb(); + + dts_check_eq(API_NAME_DEVICE_BATTERY_WARNING_SET_CB, error, DEVICE_ERROR_NONE); +} + /** * @brief Positive test case of device_battery_get_percent() */ static void utc_system_device_battery_get_percent_p(void) { - int percent = 0; - int error = DEVICE_ERROR_NONE; - error = device_battery_get_percent(&percent); + int percent = 0; + int error = DEVICE_ERROR_NONE; + error = device_battery_get_percent(&percent); - dts_check_eq(API_NAME_DEVICE_BATTERY_GET_PERCENT, error, DEVICE_ERROR_NONE); + dts_check_eq(API_NAME_DEVICE_BATTERY_GET_PERCENT, error, DEVICE_ERROR_NONE); } /** @@ -86,71 +194,245 @@ static void utc_system_device_battery_get_percent_p(void) */ static void utc_system_device_battery_get_percent_n(void) { - int error = DEVICE_ERROR_NONE; - error = device_battery_get_percent(NULL); + int error = DEVICE_ERROR_NONE; + error = device_battery_get_percent(NULL); - dts_check_ne(API_NAME_DEVICE_BATTERY_GET_PERCENT, error, DEVICE_ERROR_NONE); + dts_check_ne(API_NAME_DEVICE_BATTERY_GET_PERCENT, error, DEVICE_ERROR_NONE); } /** - * @brief Positive test case of device_battery_is_full() + * @brief Positive test case of device_battery_get_detail() */ -static void utc_system_device_battery_is_full_p(void) +static void utc_system_device_battery_get_detail_p(void) { - bool full; - int error = DEVICE_ERROR_NONE; - error = device_battery_is_full(&full); - dts_check_eq(API_NAME_DEVICE_BATTERY_IS_FULL, error, DEVICE_ERROR_NONE); + int detail = 0; + int error = DEVICE_ERROR_NONE; + error = device_battery_get_detail(&detail); + + dts_check_eq(API_NAME_DEVICE_BATTERY_GET_DETAIL, error, DEVICE_ERROR_NONE); } /** - * @brief Negative test case of device_battery_is_full() + * @brief Negative test case of device_battery_get_detail() */ -static void utc_system_device_battery_is_full_n(void) +static void utc_system_device_battery_get_detail_n(void) { - int error = DEVICE_ERROR_NONE; - error = device_battery_is_full(NULL); - dts_check_ne(API_NAME_DEVICE_BATTERY_IS_FULL, error, DEVICE_ERROR_NONE); -} + int error = DEVICE_ERROR_NONE; + error = device_battery_get_detail(NULL); + dts_check_ne(API_NAME_DEVICE_BATTERY_GET_DETAIL, error, DEVICE_ERROR_NONE); +} +/** + * @brief Positive test case of device_battery_is_charging() + */ static void utc_system_device_battery_is_charging_p(void) { - bool charging; - int error = DEVICE_ERROR_NONE; - error = device_battery_is_charging(&charging); - dts_check_eq(API_NAME_DEVICE_BATTERY_IS_CHARGING, error, DEVICE_ERROR_NONE); + bool charging; + int error = DEVICE_ERROR_NONE; + error = device_battery_is_charging(&charging); + dts_check_eq(API_NAME_DEVICE_BATTERY_IS_CHARGING, error, DEVICE_ERROR_NONE); } +/** + * @brief Negative test case of device_battery_is_charging() + */ static void utc_system_device_battery_is_charging_n(void) { - bool charging; - int error = DEVICE_ERROR_NONE; - error = device_battery_is_charging(NULL); - dts_check_ne(API_NAME_DEVICE_BATTERY_IS_CHARGING, error, DEVICE_ERROR_NONE); + int error = DEVICE_ERROR_NONE; + error = device_battery_is_charging(NULL); + dts_check_ne(API_NAME_DEVICE_BATTERY_IS_CHARGING, error, DEVICE_ERROR_NONE); } static void battery_cb(int percent, void *user_data) { } +/** + * @brief Positive test case of device_battery_set_cb() + */ static void utc_system_device_battery_set_cb_p(void) { - int error = device_battery_set_cb(battery_cb, NULL); - device_battery_unset_cb(); - dts_check_eq(API_NAME_DEVICE_BATTERY_SET_CB, error, DEVICE_ERROR_NONE); + int error = device_battery_set_cb(battery_cb, NULL); + device_battery_unset_cb(); + dts_check_eq(API_NAME_DEVICE_BATTERY_SET_CB, error, DEVICE_ERROR_NONE); } +/** + * @brief Negative test case of device_battery_set_cb() + */ static void utc_system_device_battery_set_cb_n(void) { - int error = device_battery_set_cb(NULL, NULL); - device_battery_unset_cb(); - dts_check_ne(API_NAME_DEVICE_BATTERY_SET_CB, error, DEVICE_ERROR_NONE); + int error = device_battery_set_cb(NULL, NULL); + device_battery_unset_cb(); + dts_check_ne(API_NAME_DEVICE_BATTERY_SET_CB, error, DEVICE_ERROR_NONE); } +/** + * @brief Positive test case of device_battery_unset_cb() + */ static void utc_system_device_battery_unset_cb_p(void) { - device_battery_set_cb(battery_cb, NULL); - int error = device_battery_unset_cb(); - dts_check_eq(API_NAME_DEVICE_BATTERY_SET_CB, error, DEVICE_ERROR_NONE); + device_battery_set_cb(battery_cb, NULL); + int error = device_battery_unset_cb(); + dts_check_eq(API_NAME_DEVICE_BATTERY_SET_CB, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Positive test case of device_battery_is_full() + */ +static void utc_system_device_battery_is_full_p(void) +{ + bool full; + int error = DEVICE_ERROR_NONE; + error = device_battery_is_full(&full); + dts_check_eq(API_NAME_DEVICE_BATTERY_IS_FULL, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_battery_is_full() + */ +static void utc_system_device_battery_is_full_n(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_battery_is_full(NULL); + dts_check_ne(API_NAME_DEVICE_BATTERY_IS_FULL, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Positive test case of device_battery_get_remaining_time() + */ +static void utc_system_device_battery_get_remaining_time_p(void) +{ + int stime = 0; + int error = DEVICE_ERROR_NONE; + error = device_battery_get_remaining_time(DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED, &stime); + dts_check_eq(API_NAME_DEVICE_BATTERY_GET_REMAINING_TIME, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_battery_get_remaing_time() + */ +static void utc_system_device_battery_get_remaining_time_n_1(void) +{ + int stime = 0; + int error = DEVICE_ERROR_NONE; + error = device_battery_get_remaining_time(-1, &stime); + dts_check_ne(API_NAME_DEVICE_BATTERY_IS_FULL, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_battery_get_remaing_time() + */ +static void utc_system_device_battery_get_remaining_time_n_2(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_battery_get_remaining_time(DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED, NULL); + dts_check_ne(API_NAME_DEVICE_BATTERY_IS_FULL, error, DEVICE_ERROR_NONE); +} + +static void remaining_time_changed_cb(int time, void *user_data) +{ + +} + +/** + * @brief Positive test case of device_battery_set_remaining_time_changed_cb() + */ +static void utc_system_device_battery_set_remaining_time_changed_cb_p(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_battery_set_remaining_time_changed_cb( + DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED, + remaining_time_changed_cb, NULL); + dts_check_eq(API_NAME_DEVICE_BATTERY_SET_REMAINING_TIME_CHANGED_CB, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_battery_set_remaing_time_changed_cb() + */ +static void utc_system_device_battery_set_remaining_time_changed_cb_n_1(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_battery_set_remaining_time_changed_cb( + -1, remaining_time_changed_cb, NULL); + dts_check_ne(API_NAME_DEVICE_BATTERY_SET_REMAINING_TIME_CHANGED_CB, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_battery_set_remaing_time_changed_cb() + */ +static void utc_system_device_battery_set_remaining_time_changed_cb_n_2(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_battery_set_remaining_time_changed_cb( + DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED, NULL, NULL); + dts_check_ne(API_NAME_DEVICE_BATTERY_SET_REMAINING_TIME_CHANGED_CB, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Positive test case of device_battery_unset_remaining_time_changed_cb() + */ +static void utc_system_device_battery_unset_remaining_time_changed_cb_p(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_battery_unset_remaining_time_changed_cb( + DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED); + dts_check_eq(API_NAME_DEVICE_BATTERY_UNSET_REMAINING_TIME_CHANGED_CB, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_battery_unset_remaing_time_changed_cb() + */ +static void utc_system_device_battery_unset_remaining_time_changed_cb_n(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_battery_unset_remaining_time_changed_cb(-1); + dts_check_ne(API_NAME_DEVICE_BATTERY_UNSET_REMAINING_TIME_CHANGED_CB, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Positive test case of device_battery_get_level_status() + */ +static void utc_system_device_battery_get_level_status_p(void) +{ + device_battery_level_e status; + int error = DEVICE_ERROR_NONE; + error = device_battery_get_level_status(&status); + dts_check_eq(API_NAME_DEVICE_BATTERY_GET_LEVEL_STATUS, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_battery_get_level_status() + */ +static void utc_system_device_battery_get_level_status_n(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_battery_get_level_status(NULL); + dts_check_ne(API_NAME_DEVICE_BATTERY_GET_LEVEL_STATUS, error, DEVICE_ERROR_NONE); +} + +static void level_set_cb(device_battery_level_e status, void *user_data) +{ + +} + +/** + * @brief Positive test case of device_battery_level_set_cb() + */ +static void utc_system_device_battery_level_set_cb_p(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_battery_level_set_cb(level_set_cb, NULL); + dts_check_eq(API_NAME_DEVICE_BATTERY_LEVEL_SET_CB, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_battery_level_set_cb() + */ +static void utc_system_device_battery_level_set_cb_n(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_battery_level_set_cb(NULL, NULL); + dts_check_ne(API_NAME_DEVICE_BATTERY_LEVEL_SET_CB, error, DEVICE_ERROR_NONE); } diff --git a/TC/testcase/utc_system_device_brightness.c b/TC/testcase/utc_system_device_brightness.c index 3914e9f..4f418a9 100644 --- a/TC/testcase/utc_system_device_brightness.c +++ b/TC/testcase/utc_system_device_brightness.c @@ -21,9 +21,10 @@ #define API_NAME_DEVICE_GET_DISPLAY_COUNT "device_get_display_numbers" #define API_NAME_DEVICE_GET_BRIGHTNESS "device_get_brightness" -#define API_NAME_DEVICE_GET_MAX_BRIGHTNESS "device_get_max_brightness" #define API_NAME_DEVICE_SET_BRIGHTNESS "device_set_brightness" +#define API_NAME_DEVICE_GET_MAX_BRIGHTNESS "device_get_max_brightness" #define API_NAME_DEVICE_SET_BRIGHTNESS_FROM_SETTINGS "device_set_brightness_from_settings" +#define API_NAME_DEVICE_SET_BRIGHTNESS_TO_SETTINGS "device_set_brightness_to_settings" static void startup(void); static void cleanup(void); @@ -33,19 +34,20 @@ void (*tet_cleanup)(void) = cleanup; static void utc_system_device_get_display_numbers_p(void); +static void utc_system_device_get_display_numbers_n(void); static void utc_system_device_get_brightness_p(void); static void utc_system_device_get_brightness_n_1(void); static void utc_system_device_get_brightness_n_2(void); +static void utc_system_device_set_brightness_p(void); +static void utc_system_device_set_brightness_n_1(void); +static void utc_system_device_set_brightness_n_2(void); static void utc_system_device_get_max_brightness_p(void); static void utc_system_device_get_max_brightness_n_1(void); static void utc_system_device_get_max_brightness_n_2(void); -static void utc_system_device_set_brightness_p_1(void); -static void utc_system_device_set_brightness_p_2(void); -static void utc_system_device_set_brightness_n_1(void); -static void utc_system_device_set_brightness_n_2(void); static void utc_system_device_set_brightness_from_settings_p(void); static void utc_system_device_set_brightness_from_settings_n(void); - +static void utc_system_device_set_brightness_to_settings_p(void); +static void utc_system_device_set_brightness_to_settings_n(void); enum { POSITIVE_TC_IDX = 0x01, @@ -53,19 +55,21 @@ enum { }; struct tet_testlist tet_testlist[] = { - { utc_system_device_get_display_numbers_p, POSITIVE_TC_IDX}, + { utc_system_device_get_display_numbers_p, POSITIVE_TC_IDX}, + { utc_system_device_get_display_numbers_n, NEGATIVE_TC_IDX }, { utc_system_device_get_brightness_p, POSITIVE_TC_IDX }, { utc_system_device_get_brightness_n_1, NEGATIVE_TC_IDX }, { utc_system_device_get_brightness_n_2, NEGATIVE_TC_IDX }, + { utc_system_device_set_brightness_p, POSITIVE_TC_IDX }, + { utc_system_device_set_brightness_n_1, NEGATIVE_TC_IDX }, + { utc_system_device_set_brightness_n_2, NEGATIVE_TC_IDX }, { utc_system_device_get_max_brightness_p, POSITIVE_TC_IDX }, { utc_system_device_get_max_brightness_n_1, NEGATIVE_TC_IDX }, { utc_system_device_get_max_brightness_n_2, NEGATIVE_TC_IDX }, - { utc_system_device_set_brightness_p_1, POSITIVE_TC_IDX }, - { utc_system_device_set_brightness_p_2, POSITIVE_TC_IDX }, - { utc_system_device_set_brightness_n_1, NEGATIVE_TC_IDX }, - { utc_system_device_set_brightness_n_2, NEGATIVE_TC_IDX }, { utc_system_device_set_brightness_from_settings_p, POSITIVE_TC_IDX }, { utc_system_device_set_brightness_from_settings_n, NEGATIVE_TC_IDX }, + { utc_system_device_set_brightness_to_settings_p, POSITIVE_TC_IDX }, + { utc_system_device_set_brightness_to_settings_n, NEGATIVE_TC_IDX }, { NULL, 0}, }; @@ -74,53 +78,53 @@ static int cnt; static void startup(void) { /* start of TC */ - power_wakeup(false); - power_lock_state(POWER_STATE_NORMAL, 0); + power_wakeup(false); + power_lock_state(POWER_STATE_NORMAL, 0); - device_get_display_numbers(&cnt); + device_get_display_numbers(&cnt); } static void cleanup(void) { /* end of TC */ - power_unlock_state(POWER_STATE_NORMAL); + power_unlock_state(POWER_STATE_NORMAL); } +/** + * @brief Positive test case of device_get_display_numbers() + */ static void utc_system_device_get_display_numbers_p(void) { - int _cnt, err; - err = device_get_display_numbers(&_cnt); - - if(err < 0){ - dts_fail(API_NAME_DEVICE_GET_DISPLAY_COUNT); - } - else{ - dts_pass(API_NAME_DEVICE_GET_DISPLAY_COUNT); - } + int _cnt, error = DEVICE_ERROR_NONE; + error = device_get_display_numbers(&_cnt); + + dts_check_eq(API_NAME_DEVICE_GET_DISPLAY_COUNT, error, DEVICE_ERROR_NONE); } /** - * @brief Positive test case of device_get_brightness() + * @brief Negative test case of device_get_display_numbers() */ -static void utc_system_device_get_brightness_p(void) +static void utc_system_device_get_display_numbers_n(void) { - int i; - int value = 0; - int error = DEVICE_ERROR_NONE; - - for(i=0; i 1 ? max_value / 2 : 1; - - if( device_set_brightness(i, setting) != DEVICE_ERROR_NONE ) { - dts_fail(API_NAME_DEVICE_SET_BRIGHTNESS); - } - dts_message(API_NAME_DEVICE_SET_BRIGHTNESS, "brightness=%d", setting); + int value = 0; + int error = DEVICE_ERROR_NONE; + error = device_get_max_brightness(cnt+1, &value); + dts_check_ne(API_NAME_DEVICE_GET_MAX_BRIGHTNESS, error, DEVICE_ERROR_NONE); +} - if ( device_get_brightness(i, &value) != DEVICE_ERROR_NONE ) { - dts_fail(API_NAME_DEVICE_SET_BRIGHTNESS); - } - dts_message(API_NAME_DEVICE_SET_BRIGHTNESS, "brightness=%d", value); +/** + * @brief Negative test case of device_get_max_brightness() with null pointer + */ +static void utc_system_device_get_max_brightness_n_2(void) +{ + int i; + int error = DEVICE_ERROR_NONE; - if ( value != setting ){ - dts_fail(API_NAME_DEVICE_SET_BRIGHTNESS); - } - } + for (i = 0; i < cnt; i++) { + dts_message(API_NAME_DEVICE_GET_MAX_BRIGHTNESS, "index=%d", i); - dts_pass(API_NAME_DEVICE_SET_BRIGHTNESS); + error = device_get_max_brightness(i, NULL); + dts_check_ne(API_NAME_DEVICE_GET_MAX_BRIGHTNESS, error, DEVICE_ERROR_NONE); + } } /** - * @brief Negative test case of device_set_brightness() + * @brief Positive test case of device_set_brightness_from_settings() */ -static void utc_system_device_set_brightness_n_1(void) +static void utc_system_device_set_brightness_from_settings_p(void) { - int i=0; - int max_value = 0; - - for(i=0; i +#include + +#define API_NAME_DEVICE_CPU_GET_SYSTEM_TIME "device_cpu_get_system_time" +#define API_NAME_DEVICE_CPU_GET_COUNT "device_cpu_get_count" +#define API_NAME_DEVICE_CPU_GET_CURRENT_FREQ "device_cpu_get_current_freq" +#define API_NAME_DEVICE_CPU_GET_MAX_FREQ "device_cpu_get_max_freq" + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + + +static void utc_system_device_cpu_get_system_time_p(void); +static void utc_system_device_cpu_get_system_time_n(void); +static void utc_system_device_cpu_get_count_p(void); +static void utc_system_device_cpu_get_count_n(void); +static void utc_system_device_cpu_get_current_freq_p(void); +static void utc_system_device_cpu_get_current_freq_n_1(void); +static void utc_system_device_cpu_get_current_freq_n_2(void); +static void utc_system_device_cpu_get_max_freq_p(void); +static void utc_system_device_cpu_get_max_freq_n_1(void); +static void utc_system_device_cpu_get_max_freq_n_2(void); + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_system_device_cpu_get_system_time_p, POSITIVE_TC_IDX }, + { utc_system_device_cpu_get_system_time_n, NEGATIVE_TC_IDX }, + { utc_system_device_cpu_get_count_p, POSITIVE_TC_IDX }, + { utc_system_device_cpu_get_count_n, NEGATIVE_TC_IDX }, + { utc_system_device_cpu_get_current_freq_p, POSITIVE_TC_IDX }, + { utc_system_device_cpu_get_current_freq_n_1, NEGATIVE_TC_IDX }, + { utc_system_device_cpu_get_current_freq_n_2, NEGATIVE_TC_IDX }, + { utc_system_device_cpu_get_max_freq_p, POSITIVE_TC_IDX }, + { utc_system_device_cpu_get_max_freq_n_1, NEGATIVE_TC_IDX }, + { utc_system_device_cpu_get_max_freq_n_2, NEGATIVE_TC_IDX }, + { NULL, 0}, +}; + +static int cnt; + +static void startup(void) +{ + /* start of TC */ + + device_cpu_get_count(&cnt); +} + +static void cleanup(void) +{ + /* end of TC */ +} + +/** + * @brief Positive test case of device_cpu_get_system_time() + */ +static void utc_system_device_cpu_get_system_time_p(void) +{ + device_system_time_s stime; + int error = DEVICE_ERROR_NONE; + error = device_cpu_get_system_time(&stime); + + dts_check_eq(API_NAME_DEVICE_CPU_GET_SYSTEM_TIME, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_cpu_get_system_time() + */ +static void utc_system_device_cpu_get_system_time_n(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_cpu_get_system_time(NULL); + + dts_check_ne(API_NAME_DEVICE_CPU_GET_SYSTEM_TIME, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Positive test case of device_cpu_get_count() + */ +static void utc_system_device_cpu_get_count_p(void) +{ + int _cnt; + int error = DEVICE_ERROR_NONE; + error = device_cpu_get_count(&_cnt); + + dts_check_eq(API_NAME_DEVICE_CPU_GET_COUNT, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_cpu_get_count() + */ +static void utc_system_device_cpu_get_count_n(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_cpu_get_count(NULL); + + dts_check_ne(API_NAME_DEVICE_CPU_GET_COUNT, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Positive test case of device_cpu_get_current_freq() + */ +static void utc_system_device_cpu_get_current_freq_p(void) +{ + unsigned int freq; + int i; + int error = DEVICE_ERROR_NONE; + + for (i = 0; i < cnt; ++i) { + dts_message(API_NAME_DEVICE_CPU_GET_CURRENT_FREQ, "index=%d", i); + + error = device_cpu_get_current_freq(i, &freq); + dts_check_eq(API_NAME_DEVICE_CPU_GET_CURRENT_FREQ, error, DEVICE_ERROR_NONE); + } +} + +/** + * @brief Negative test case of device_cpu_get_current_freq() + */ +static void utc_system_device_cpu_get_current_freq_n_1(void) +{ + unsigned int freq; + int error = DEVICE_ERROR_NONE; + error = device_cpu_get_current_freq(-1, &freq); + + dts_check_ne(API_NAME_DEVICE_CPU_GET_CURRENT_FREQ, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_cpu_get_current_freq() + */ +static void utc_system_device_cpu_get_current_freq_n_2(void) +{ + int i; + int error = DEVICE_ERROR_NONE; + + for (i = 0; i < cnt; ++i) { + dts_message(API_NAME_DEVICE_CPU_GET_CURRENT_FREQ, "index=%d", i); + + error = device_cpu_get_current_freq(i, NULL); + dts_check_ne(API_NAME_DEVICE_CPU_GET_CURRENT_FREQ, error, DEVICE_ERROR_NONE); + } +} + +/** + * @brief Positive test case of device_cpu_get_max_freq() + */ +static void utc_system_device_cpu_get_max_freq_p(void) +{ + unsigned int freq; + int i; + int error = DEVICE_ERROR_NONE; + + for (i = 0; i < cnt; ++i) { + dts_message(API_NAME_DEVICE_CPU_GET_MAX_FREQ, "index=%d", i); + + error = device_cpu_get_max_freq(i, &freq); + dts_check_eq(API_NAME_DEVICE_CPU_GET_MAX_FREQ, error, DEVICE_ERROR_NONE); + } +} + +/** + * @brief Negative test case of device_cpu_get_max_freq() + */ +static void utc_system_device_cpu_get_max_freq_n_1(void) +{ + unsigned int freq; + int error = DEVICE_ERROR_NONE; + error = device_cpu_get_max_freq(-1, &freq); + + dts_check_ne(API_NAME_DEVICE_CPU_GET_MAX_FREQ, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_cpu_get_max_freq() + */ +static void utc_system_device_cpu_get_max_freq_n_2(void) +{ + int i; + int error = DEVICE_ERROR_NONE; + + for (i = 0; i < cnt; ++i) { + dts_message(API_NAME_DEVICE_CPU_GET_MAX_FREQ, "index=%d", i); + + error = device_cpu_get_max_freq(i, NULL); + dts_check_ne(API_NAME_DEVICE_CPU_GET_MAX_FREQ, error, DEVICE_ERROR_NONE); + } +} diff --git a/TC/testcase/utc_system_device_flash.c b/TC/testcase/utc_system_device_flash.c new file mode 100644 index 0000000..725272c --- /dev/null +++ b/TC/testcase/utc_system_device_flash.c @@ -0,0 +1,136 @@ +/* + * + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * PROPRIETARY/CONFIDENTIAL + * + * This software is the confidential and proprietary information of SAMSUNG + * ELECTRONICS ("Confidential Information"). You agree and acknowledge that + * this software is owned by Samsung and you shall not disclose such + * Confidential Information and shall use it only in accordance with the terms + * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG + * make no representations or warranties about the suitability of the software, + * either express or implied, including but not limited to the implied + * warranties of merchantability, fitness for a particular purpose, or + * non-infringement. SAMSUNG shall not be liable for any damages suffered by + * licensee arising out of or related to this software. + * + */ +#include +#include + +#define API_NAME_DEVICE_FLASH_GET_BRIGHTNESS "device_flash_get_brightness" +#define API_NAME_DEVICE_FLASH_SET_BRIGHTNESS "device_flash_set_brightness" +#define API_NAME_DEVICE_FLASH_GET_MAX_BRIGHTNESS "device_flash_get_max_brightness" + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + + +static void utc_system_device_flash_get_brightness_p(void); +static void utc_system_device_flash_get_brightness_n(void); +static void utc_system_device_flash_set_brightness_p(void); +static void utc_system_device_flash_set_brightness_n(void); +static void utc_system_device_flash_get_max_brightness_p(void); +static void utc_system_device_flash_get_max_brightness_n(void); + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_system_device_flash_get_brightness_p, POSITIVE_TC_IDX}, + { utc_system_device_flash_get_brightness_n, NEGATIVE_TC_IDX }, + { utc_system_device_flash_set_brightness_p, POSITIVE_TC_IDX}, + { utc_system_device_flash_set_brightness_n, NEGATIVE_TC_IDX }, + { utc_system_device_flash_get_max_brightness_p, POSITIVE_TC_IDX}, + { utc_system_device_flash_get_max_brightness_n, NEGATIVE_TC_IDX }, + { NULL, 0}, +}; + +static void startup(void) +{ + /* start of TC */ +} + +static void cleanup(void) +{ + /* end of TC */ +} + +/** + * @brief Positive test case of device_flash_get_brightness() + */ +static void utc_system_device_flash_get_brightness_p(void) +{ + int brightness; + int error = DEVICE_ERROR_NONE; + error = device_flash_get_brightness(&brightness); + + dts_check_eq(API_NAME_DEVICE_FLASH_GET_BRIGHTNESS, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_flash_get_brightness() + */ +static void utc_system_device_flash_get_brightness_n(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_flash_get_brightness(NULL); + + dts_check_ne(API_NAME_DEVICE_FLASH_GET_BRIGHTNESS, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Positive test case of device_flash_set_brightness() + */ +static void utc_system_device_flash_set_brightness_p(void) +{ + int max; + int error = DEVICE_ERROR_NONE; + + if (device_flash_get_max_brightness(&max) != DEVICE_ERROR_NONE) + dts_fail(API_NAME_DEVICE_FLASH_SET_BRIGHTNESS); + + error = device_flash_set_brightness(max); + + dts_check_eq(API_NAME_DEVICE_FLASH_SET_BRIGHTNESS, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_flash_set_brightness() + */ +static void utc_system_device_flash_set_brightness_n(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_flash_set_brightness(-1); + + dts_check_ne(API_NAME_DEVICE_FLASH_SET_BRIGHTNESS, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Positive test case of device_flash_get_max_brightness() + */ +static void utc_system_device_flash_get_max_brightness_p(void) +{ + int max; + int error = DEVICE_ERROR_NONE; + error = device_flash_get_max_brightness(&max); + + dts_check_eq(API_NAME_DEVICE_FLASH_GET_MAX_BRIGHTNESS, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_flash_get_max_brightness() + */ +static void utc_system_device_flash_get_max_brightness_n(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_flash_get_max_brightness(NULL); + + dts_check_ne(API_NAME_DEVICE_FLASH_GET_MAX_BRIGHTNESS, error, DEVICE_ERROR_NONE); +} diff --git a/TC/testcase/utc_system_device_memory.c b/TC/testcase/utc_system_device_memory.c new file mode 100644 index 0000000..de46bae --- /dev/null +++ b/TC/testcase/utc_system_device_memory.c @@ -0,0 +1,104 @@ +/* + * + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * PROPRIETARY/CONFIDENTIAL + * + * This software is the confidential and proprietary information of SAMSUNG + * ELECTRONICS ("Confidential Information"). You agree and acknowledge that + * this software is owned by Samsung and you shall not disclose such + * Confidential Information and shall use it only in accordance with the terms + * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG + * make no representations or warranties about the suitability of the software, + * either express or implied, including but not limited to the implied + * warranties of merchantability, fitness for a particular purpose, or + * non-infringement. SAMSUNG shall not be liable for any damages suffered by + * licensee arising out of or related to this software. + * + */ +#include +#include + +#define API_NAME_DEVICE_MEMORY_GET_TOTAL "device_memory_get_total" +#define API_NAME_DEVICE_MEMORY_GET_AVAILABLE "device_memory_get_available" + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + + +static void utc_system_device_memory_get_total_p(void); +static void utc_system_device_memory_get_total_n(void); +static void utc_system_device_memory_get_available_p(void); +static void utc_system_device_memory_get_available_n(void); + + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_system_device_memory_get_total_p, POSITIVE_TC_IDX }, + { utc_system_device_memory_get_total_n, NEGATIVE_TC_IDX }, + { utc_system_device_memory_get_available_p, POSITIVE_TC_IDX }, + { utc_system_device_memory_get_available_n, NEGATIVE_TC_IDX }, + { NULL, 0}, +}; + +static void startup(void) +{ + /* start of TC */ +} + +static void cleanup(void) +{ + /* end of TC */ +} + +/** + * @brief Positive test case of device_memory_get_total() + */ +static void utc_system_device_memory_get_total_p(void) +{ + unsigned int total; + int error = DEVICE_ERROR_NONE; + error = device_memory_get_total(&total); + + dts_check_eq(API_NAME_DEVICE_MEMORY_GET_TOTAL, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_memory_get_total() + */ +static void utc_system_device_memory_get_total_n(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_memory_get_total(NULL); + + dts_check_ne(API_NAME_DEVICE_MEMORY_GET_TOTAL, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Positive test case of device_memory_get_available() + */ +static void utc_system_device_memory_get_available_p(void) +{ + unsigned int avail; + int error = DEVICE_ERROR_NONE; + error = device_memory_get_available(&avail); + + dts_check_eq(API_NAME_DEVICE_MEMORY_GET_AVAILABLE, error, DEVICE_ERROR_NONE); +} + +/** + * @brief Negative test case of device_memory_get_available() + */ +static void utc_system_device_memory_get_available_n(void) +{ + int error = DEVICE_ERROR_NONE; + error = device_memory_get_available(NULL); + + dts_check_ne(API_NAME_DEVICE_MEMORY_GET_AVAILABLE, error, DEVICE_ERROR_NONE); +} diff --git a/capi-system-device.pc.in b/capi-system-device.pc.in index d0610b9..73a86a8 100644 --- a/capi-system-device.pc.in +++ b/capi-system-device.pc.in @@ -4,12 +4,11 @@ prefix=@PREFIX@ exec_prefix=/usr libdir=/usr/lib -includedir=/usr/include/system +includedir=/usr/include Name: @PC_NAME@ Description: @PACKAGE_DESCRIPTION@ Version: @VERSION@ -Requires: @PC_REQUIRED@ +Requires: @PC_REQUIRED@ Libs: -L${libdir} @PC_LDFLAGS@ -Cflags: -I${includedir} - +Cflags: -I${includedir} -I/usr/include/system diff --git a/doc/device_doc.h b/doc/device_doc.h new file mode 100755 index 0000000..15325f8 --- /dev/null +++ b/doc/device_doc.h @@ -0,0 +1,149 @@ +/* + * 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_DOC_H__ +#define __TIZEN_SYSTEM_DEVICE_DOC_H__ + +/** + * @ingroup CAPI_SYSTEM_FRAMEWORK + * @defgroup CAPI_SYSTEM_DEVICE_MODULE Device + * @brief The DEVICE API provides functions to control devices or to get status of devices. + * + * @section CAPI_SYSTEM_DEVICE_MODULE_HEADER Required Header + * \#include \n + * \#include \n + * \#include \n + * \#include \n + * \#include \n + * \#include + * + * @section CAPI_SYSTEM_DEVICE_MODULE_OVERVIEW Overview + * The DEVICE API provides functions to control devices or to get status of devices. + * + * This API allows checking of the following parameters: + * - Battery + * - Display + * - Haptic + * - LED + * - Power + */ + +/** + * @ingroup CAPI_SYSTEM_DEVICE_MODULE + * @defgroup CAPI_SYSTEM_DEVICE_BATTERY_MODULE Battery + * @brief The Battery API provides functions to get information about the battery. + * + * @section CAPI_SYSTEM_DEVICE_BATTERY_MODULE_HEADER Required Header + * \#include \n + * \#include \n + * + * @section CAPI_SYSTEM_DEVICE_BATTERY_MODULE_OVERVIEW Overview + * The Battery API provides the way to get the current battery capacity value, battery state and charging state. + * It also supports the API for an application to receive the battery events from the system. + * To receive the battery event it should be described by the callback function. + * + */ + +/** + * @ingroup CAPI_SYSTEM_DEVICE_MODULE + * @defgroup CAPI_SYSTEM_DEVICE_DISPLAY_MODULE Display + * @brief The Display API provides functions to control the display status. + * + * @section CAPI_SYSTEM_DEVICE_DISPLAY_MODULE_HEADER Required Header + * \#include \n + * \#include \n + * + * @section CAPI_SYSTEM_DEVICE_DISPLAY_MODULE_OVERVIEW Overview + * The Display API provides the way to get supported display count and the display brightness. + * It also supports the API to set the display brightness. + * Application can receive the display event by callback function from the system. + * + */ + +/** + * @ingroup CAPI_SYSTEM_DEVICE_MODULE + * @defgroup CAPI_SYSTEM_DEVICE_HAPTIC_MODULE Haptic + * @brief The Haptic API provides functions to control a vibrator. + * + * @section CAPI_SYSTEM_DEVICE_HAPTIC_MODULE_HEADER Required Header + * \#include \n + * + * @section CAPI_SYSTEM_DEVICE_HAPTIC_MODULE_OVERVIEW Overview + * The Haptic API provides the way to control vibration functionality of a device. + * It allows the management of the device's vibrator parameters, such as the vibration count and level. + * + */ + +/** + * @ingroup CAPI_SYSTEM_DEVICE_MODULE + * @defgroup CAPI_SYSTEM_DEVICE_LED_MODULE Led + * @brief The Led API provides functions to control the attached led device. + * + * @section CAPI_SYSTEM_DEVICE_LED_MODULE_HEADER Required Header + * \#include \n + * + * @section CAPI_SYSTEM_DEVICE_LED_MODULE_OVERVIEW Overview + * The Led API provides the way to control the attached LED device such as the camera flash and service LED. + * It supports to turn on the camera flash and set the pattern to the service LED which is located to the front of a device. + * @section CAPI_SYSTEM_DEVICE_LED_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/led\n + * - http://tizen.org/feature/camera.back.flash\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a devrice supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @ingroup CAPI_SYSTEM_DEVICE_MODULE + * @defgroup CAPI_SYSTEM_DEVICE_POWER_MODULE Power + * @brief The Power API provides functions to control the power service. + * + * @section CAPI_SYSTEM_DEVICE_POWER_MODULE_HEADER Required Header + * \#include \n + * + * @section CAPI_SYSTEM_DEVICE_POWER_MODULE_OVERVIEW Overview + * The Power API provides the way to control the power service. + * It can be made to hold the specific state to avoid changing display and CPU state internally. + * + */ + +/** + * @ingroup CAPI_SYSTEM_DEVICE_MODULE + * @defgroup CAPI_SYSTEM_DEVICE_CALLBACK_MODULE Callback + * @brief The Callback API provides functions to observe the changing of device state. + * + * @section CAPI_SYSTEM_DEVICE_CALLBACK_MODULE_HEADER Required Header + * \#include \n + * + * @section CAPI_SYSTEM_DEVICE_CALLBACK_MODULE_OVERVIEW Overview + * The Callback API provides the way to observe the changing of device state. + * + * This API allows observing of the following events: + * - Battery capacity + * - Battery level + * - Battery charging + * - Display state + */ + +#endif /* __TIZEN_SYSTEM_DEVICE_DOC_H__ */ diff --git a/include/battery.h b/include/battery.h new file mode 100755 index 0000000..4449e4d --- /dev/null +++ b/include/battery.h @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2014 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_BATTERY_H__ +#define __TIZEN_SYSTEM_BATTERY_H__ + +#include +#include "device-error.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_BATTERY_MODULE + * @{ + */ + +/** + * @brief Enumeration for the battery level status. + * @since_tizen 2.3 + */ +typedef enum +{ + 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. */ + 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. */ + DEVICE_BATTERY_LEVEL_LOW, /**< The battery has little charge left. */ + DEVICE_BATTERY_LEVEL_HIGH, /**< The battery status is not to be careful. */ + DEVICE_BATTERY_LEVEL_FULL, /**< The battery status is full. */ +} device_battery_level_e; + +/** + * @brief Gets the battery charge percentage. + * @details It returns an integer value from @c 0 to @c 100 that indicates remaining battery charge + * as a percentage of the maximum level. + * + * @since_tizen 2.3 + * + * @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 (@c 0 ~ @c 100) + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + */ +int device_battery_get_percent(int *percent); + +/** + * @brief Gets the charging state. + * + * @since_tizen 2.3 + * + * @param[out] charging The battery charging state + * + * @return @c 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_add_callback + * @see device_remove_callback + * @see #DEVICE_CALLBACK_BATTERY_CHARGING + */ +int device_battery_is_charging(bool *charging); + +/** + * @brief Gets the battery level status. + * + * @since_tizen 2.3 + * + * @param[out] status The battery level status + * + * @return @c 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_level_e + * @see device_add_callback + * @see device_remove_callback + * @see #DEVICE_CALLBACK_BATTERY_LEVEL + */ +int device_battery_get_level_status(device_battery_level_e *status); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif // __TIZEN_SYSTEM_BATTERY_H__ diff --git a/include/callback.h b/include/callback.h new file mode 100755 index 0000000..3394862 --- /dev/null +++ b/include/callback.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2014 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_CALLBACK_H__ +#define __TIZEN_SYSTEM_CALLBACK_H__ + +#include +#include "device-error.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_CALLBACK_MODULE + * @{ + */ + +/** + * @brief Enumeration for the device state callback. + * @since_tizen 2.3 + */ +typedef enum +{ + DEVICE_CALLBACK_BATTERY_CAPACITY, /**< Called when a battery charge percentage is changed */ + DEVICE_CALLBACK_BATTERY_LEVEL, /**< Called when a battery level is changed */ + DEVICE_CALLBACK_BATTERY_CHARGING, /**< Called when battery charging state is changed */ + DEVICE_CALLBACK_DISPLAY_STATE, /**< Called when a display state is changed */ + DEVICE_CALLBACK_MAX +} device_callback_e; + +/** + * @brief Called when a device status is changed. + * @details Each device callback has a different output param type. \n + * So you need to check below output param before using this function. \n + * callback enum output type \n + * DEVICE_CALLBACK_BATTERY_CAPACITY int \n + * DEVICE_CALLBACK_BATTERY_LEVEL int \n + * DEVICE_CALLBACK_BATTERY_CHARGING bool \n + * DEVICE_CALLBACK_DISPLAY_STATE int + * + * @since_tizen 2.3 + * + * @param[out] type The device type to monitor + * @param[out] value The changed value \n + * @param[out] user_data The user data passed from the callback registration function + */ +typedef void (*device_changed_cb)(device_callback_e type, void *value, void *user_data); + +/** + * @brief Adds a callback to the observing device state. + * + * @since_tizen 2.3 + * + * @param[in] type The device type to monitor + * @param[in] callback The callback function to add + * @param[in] user_data The user data to be passed to the callback function + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_ALREADY_IN_PROGRESS Operation already + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + */ +int device_add_callback(device_callback_e type, device_changed_cb callback, void *user_data); + +/** + * @brief Removes a device callback function. + * + * @since_tizen 2.3 + * + * @param[in] type The device type to monitor + * @param[in] callback The callback function to remove + * + * @return @c 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_remove_callback(device_callback_e type, device_changed_cb callback); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif // __TIZEN_SYSTEM_CALLBACK_H__ diff --git a/include/device-error.h b/include/device-error.h new file mode 100755 index 0000000..08dd5b8 --- /dev/null +++ b/include/device-error.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014 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_ERROR_H__ +#define __TIZEN_SYSTEM_DEVICE_ERROR_H__ + +#include + +#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_OPERATION_FAILED = TIZEN_ERROR_NOT_PERMITTED, /**< Operation not permitted */ + DEVICE_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ + DEVICE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + DEVICE_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_ALREADY_IN_PROGRESS, /**< Operation already in progress */ + DEVICE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported in this device */ + DEVICE_ERROR_NOT_INITIALIZED = TIZEN_ERROR_DEVICE | 0x13, /**< Not initialized */ +} device_error_e; + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif // __TIZEN_SYSTEM_DEVICE_ERROR_H__ diff --git a/include/device.h b/include/device.h index 93fabd3..e991e23 100755 --- a/include/device.h +++ b/include/device.h @@ -21,7 +21,7 @@ #define __TIZEN_SYSTEM_DEVICE_H__ #include -#include +#include "device-error.h" #ifdef __cplusplus extern "C" { @@ -33,17 +33,6 @@ extern "C" { * @{ */ -/** - * @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 */ @@ -119,15 +108,6 @@ typedef void (*device_battery_cb)(int percent, void *user_data); */ 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 Called when an battery level changed * @@ -195,25 +175,6 @@ int device_battery_warning_unset_cb(void); */ 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 * @@ -267,53 +228,6 @@ int device_battery_unset_cb(void); */ 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 battery level status. * diff --git a/include/device_doc.h b/include/device_doc.h deleted file mode 100755 index 00bad5b..0000000 --- a/include/device_doc.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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_DOC_H__ -#define __TIZEN_SYSTEM_DEVICE_DOC_H__ - -/** - * @defgroup CAPI_SYSTEM_DEVICE_MODULE - * @brief The DEVICE API provides functions to control devices or to get status of devices. - * @ingroup CAPI_SYSTEM_FRAMEWORK - * - * @section CAPI_SYSTEM_DEVICE_MODULE_HEADER Required Header - * \#include - * - * @section CAPI_SYSTEM_DEVICE_MODULE_OVERVIEW Overview - * The DEVICE API provides function to control devices or to get status of devices. - * - * This API allows checking the following parameters: - * - Battery - * - Display - * - Flash (Camera torch light) - * - Memory - * - CPU - * - */ - -#endif /* __TIZEN_SYSTEM_DEVICE_DOC_H__ */ diff --git a/include/device_log.h b/include/device_log.h deleted file mode 100644 index 8752926..0000000 --- a/include/device_log.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 __DEVICE_LOG_H__ -#define __DEVICE_LOG_H__ - -#ifdef FEATURE_DEVICE_DLOG - #define LOG_TAG "SYSTEM_DEVICE" - #include - #define DEVICE_LOG(fmt, args...) SLOGD(fmt, ##args) - #define DEVICE_ERROR(fmt, args...) SLOGE(fmt, ##args) -#else - #define DEVICE_LOG(x, ...) - #define DEVICE_ERROR(x, ...) -#endif - -#endif /* __DEVICE_LOG_H__ */ diff --git a/include/display.h b/include/display.h new file mode 100755 index 0000000..6d47413 --- /dev/null +++ b/include/display.h @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2014 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_DISPLAY_H__ +#define __TIZEN_SYSTEM_DISPLAY_H__ + +#include "device-error.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_DISPLAY_MODULE + * @{ + */ + +/** + * @brief Gets the number of display devices. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * + * @param[out] device_number The total number of displays + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * + * @see device_display_get_brightness() + * @see device_display_set_brightness() + * @see device_display_get_max_brightness() + */ +int device_display_get_numbers(int *device_number); + +/** + * @brief Gets the maximum brightness value that can be set. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * + * @param[in] display_index The index of the display \n + * It can be greater than or equal to @c 0 and less than + * the number of displays returned by device_display_get_numbers(). \n + * The index zero is always assigned to the main display. + * @param[out] max_brightness The maximum brightness value of the display + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * + * @see device_display_get_numbers() + * @see device_display_set_brightness() + * @see device_display_get_brightness() + */ +int device_display_get_max_brightness(int display_index, int *max_brightness); + +/** + * @brief Gets the display brightness value. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * + * @param[in] display_index The index of the display \n + * It can be greater than or equal to @c 0 and less than + * the number of displays returned by device_display_get_numbers(). \n + * The index zero is always assigned to the main display. + * @param[out] brightness The current brightness value of the display + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * + * @see device_display_get_numbers() + * @see device_display_set_brightness() + * @see device_display_get_max_brightness() + */ +int device_display_get_brightness(int display_index, int *brightness); + +/** + * @brief Sets the display brightness value. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * + * @param[in] display_index The index of the display \n + * It can be greater than or equal to @c 0 and less than + * the number of displays returned by device_display_get_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_display_get_max_brightness(). + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * + * @see device_display_get_numbers() + * @see device_display_get_max_brightness() + * @see device_display_get_brightness() + */ +int device_display_set_brightness(int display_index, int brightness); + +/** + * @brief Enumeration for the available display states. + * @details An application cannot put the device into the power off state or the suspend state. + * @since_tizen 2.3 + */ +typedef enum +{ + DISPLAY_STATE_NORMAL, /**< Normal state */ + DISPLAY_STATE_SCREEN_DIM, /**< Screen dim state */ + DISPLAY_STATE_SCREEN_OFF, /**< Screen off state */ +} display_state_e; + +/** + * @brief Gets the current display state. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * + * @param[out] state the display state + * + * @return @c 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_add_callback + * @see device_remove_callback + * @see #DEVICE_CALLBACK_DISPLAY_STATE + */ +int device_display_get_state(display_state_e *state); + +/** + * @brief Changes the display state by force. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * + * @param[in] state the display state + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * + * @see device_power_request_lock() + * @see device_power_release_lock() + * @see device_add_callback + * @see device_remove_callback + * @see #DEVICE_CALLBACK_DISPLAY_STATE + * + * @par Example + * @code + * ... + * result = device_display_change_state(DISPLAY_STATE_SCREEN_OFF); + * if( result < 0 ) + * printf("[ERROR] return value result =%d, \n",result); + * else + * printf("[SUCCESS] return value result =%d \n",result); + * ... + * @endcode + */ +int device_display_change_state(display_state_e state); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif // __TIZEN_SYSTEM_DISPLAY_H__ diff --git a/include/haptic.h b/include/haptic.h new file mode 100755 index 0000000..30d5cc5 --- /dev/null +++ b/include/haptic.h @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2014 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_HAPTIC_H__ +#define __TIZEN_SYSTEM_HAPTIC_H__ + +#include "device-error.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_HAPTIC_MODULE + * @{ + */ + +/** + * @brief The haptic device handle. + */ +typedef void* haptic_device_h; + +/** + * @brief The haptic effect handle. + */ +typedef void* haptic_effect_h; + +/** + * @brief Gets the number of vibrators. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/haptic + * + * @param[in] device_number The number of vibrators + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_haptic_get_count(int *device_number); + +/** + * @brief Opens a haptic-vibration device. + * @details Internally, it makes a connection to the vibrator. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/haptic + * + * @remarks You must close the Haptic API using device_haptic_close(). + * + * @param[in] device_index The index of device what you want to vibrate + * @param[out] device_handle The handle of vibrator + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + * + * @see device_haptic_close() + */ +int device_haptic_open(int device_index, haptic_device_h *device_handle); + +/** + * @brief Closes a haptic-vibration device. + * @details Internally, it disconnects the connection to the vibrator. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/haptic + * + * @param[in] device_handle The device handle from device_haptic_open() + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + * + * @see device_haptic_open() + */ +int device_haptic_close(haptic_device_h device_handle); + +/** + * @brief Vibrates during the specified time with a constant intensity. + * @details This function can be used to start monotonous vibration for the specified time. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/haptic + * + * @remarks @a feedback level is reserved for auto changing to save variable in the settings. + * @remarks @a effect_handle effect_handle value can be @c 0(zero). + * + * @param[in] device_handle The device handle from device_haptic_open() + * @param[in] duration The play duration in milliseconds + * @param[in] feedback The amount of the intensity variation (@c 0 ~ @c 100) + * @param[out] effect_handle The pointer to the variable that will receive a handle to the playing effect + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + * + * @see device_haptic_stop() + */ + +int device_haptic_vibrate(haptic_device_h device_handle, + int duration, int feedback, haptic_effect_h *effect_handle); + +/** + * @brief Stops all vibration effects which are being played. + * @details This function can be used to stop all effects started by device_haptic_vibrate(). + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/haptic + * + * @param[in] device_handle The device handle from device_haptic_open() + * @param[in] effect_handle The effect handle from device_haptic_vibrate() + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + * + * @see device_haptic_vibrate() + */ +int device_haptic_stop(haptic_device_h device_handle, haptic_effect_h effect_handle); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif // __TIZEN_SYSTEM_HAPTIC_H__ diff --git a/include/led.h b/include/led.h new file mode 100755 index 0000000..718a4bf --- /dev/null +++ b/include/led.h @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2014 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_LED_H__ +#define __TIZEN_SYSTEM_LED_H__ + +#include "device-error.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_LED_MODULE + * @{ + */ + +/** + * @brief Gets the max brightness value of a LED that is located next to the camera. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/led + * + * @param[out] max_brightness The max brightness value of the LED + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_flash_get_max_brightness(int *max_brightness); + +/** + * @brief Gets the brightness value of a LED that is located next to the camera. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/led + * + * @param[out] brightness The brightness value of LED (@c 0 ~ MAX) + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_flash_get_brightness(int *brightness); + +/** + * @brief Sets the brightness value of a LED that is located next to the camera. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/led + * + * @param[in] brightness The brightness value of LED (@c 0 ~ MAX) + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_flash_set_brightness(int brightness); + +/** + * @brief Enumeration for custom LED flags. + * @since_tizen 2.3 + */ +typedef enum { + LED_CUSTOM_DUTY_ON = 1 << 0, /**< blink LED */ + LED_CUSTOM_DEFAULT = (LED_CUSTOM_DUTY_ON), /**< Default flag */ +} led_custom_flags; + +/** + * @brief Plays the custom effect of the service LED that is located to the front of a device. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/led + * + * @param[in] on Turn on time in milliseconds + * @param[in] off Turn off time in milliseconds + * @param[in] color The Color value \n + * The first byte means opaque and the other 3 bytes are RGB values. + * @param[in] flags The combination of enum #led_custom_flags + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_led_play_custom(int on, int off, unsigned int color, unsigned int flags); + +/** + * @brief Stops the custom effect of the service LED that is located to the front of a device. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/led + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + */ +int device_led_stop_custom(void); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif // __TIZEN_SYSTEM_LED_H__ diff --git a/include/power.h b/include/power.h new file mode 100755 index 0000000..48d9483 --- /dev/null +++ b/include/power.h @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2014 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_POWER_H__ +#define __TIZEN_SYSTEM_POWER_H__ + +#include +#include "device-error.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_POWER_MODULE + * @{ + */ + +/** + * @brief Enumeration for lock type. + * @details Each enum ensures that the suitable device is on + * until all the lock requests have been released or after a timeout. \n + * CPU Brightness \n + * POWER_LOCK_CPU ON OFF \n + * POWER_LOCK_DISPLAY ON ON(normal) \n + * POWER_LOCK_DISPLAY_DIM ON ON(dim) + * + * @since_tizen 2.3 + * + * @remarks An application can lock the specific type. + * @remarks These enums are mutually exclusive. + * @remarks You cannot combine with an enum below. + * + */ +typedef enum +{ + POWER_LOCK_CPU, /**< CPU lock */ + POWER_LOCK_DISPLAY, /**< Display normal lock */ + POWER_LOCK_DISPLAY_DIM, /**< Display dim lock */ +} power_lock_e; + +/** + * @brief Locks the given lock state for a specified time. + * @details After the given @a timeout_ms (in milliseconds), unlock the given lock state automatically. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * + * @remarks If the process dies, then every lock will be removed. + * + * @param[in] type The power type to request lock + * @param[in] timeout_ms The positive number in milliseconds or @c 0 for permanent lock \n + * So you must release the permanent lock of power state with #device_power_release_lock() if @a timeout_ms is zero. + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * + * @see device_power_release_lock() + */ +int device_power_request_lock(power_lock_e type, int timeout_ms); + +/** + * @brief Releases the given lock state locked before. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * + * @param[in] type The power type to release lock + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * + * @see device_power_request_lock() + */ +int device_power_release_lock(power_lock_e type); + +/** + * @brief Changes the current power state to the normal/dim state. + * + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * + * @param[in] dim Set @c true to set the dim state, + * otherwise set @c false to not set the dim state + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * + * @post The device will be in #DISPLAY_STATE_NORMAL state. + */ +int device_power_wakeup(bool dim); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif // __TIZEN_SYSTEM_POWER_H__ diff --git a/packaging/capi-system-device.spec b/packaging/capi-system-device.spec index 103f2fc..44d1570 100644 --- a/packaging/capi-system-device.spec +++ b/packaging/capi-system-device.spec @@ -7,14 +7,13 @@ License: Apache License, Version 2.0 Source0: %{name}-%{version}.tar.gz Source1: capi-system-device.manifest BuildRequires: cmake -%if "%{_repository}" == "wearable" BuildRequires: pkgconfig(deviced) -%else -BuildRequires: pkgconfig(devman) -%endif BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(dbus-1) +BuildRequires: pkgconfig(dbus-glib-1) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -41,12 +40,7 @@ export CFLAGS+=" -DTIZEN_ENGINEER_MODE" %endif cp %{SOURCE1} . MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` -%if "%{_repository}" == "wearable" -%define ARCH wearable -%else -%define ARCH mobile -%endif -cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DARCH=%{ARCH} +cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} make %{?jobs:-j%jobs} @@ -68,6 +62,7 @@ cp LICENSE %{buildroot}/usr/share/license/%{name} %{_datadir}/license/%{name} %files devel -%{_includedir}/system/device.h +%{_includedir}/device/*.h +%{_includedir}/system/*.h %{_libdir}/pkgconfig/*.pc %{_libdir}/libcapi-system-device.so diff --git a/src/battery.c b/src/battery.c new file mode 100644 index 0000000..a8c34af --- /dev/null +++ b/src/battery.c @@ -0,0 +1,87 @@ +/* + * 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. + */ + + +#include +#include +#include +#include +#include + +#include "battery.h" +#include "common.h" +#include "dbus.h" + +#define METHOD_GET_PERCENT "GetPercent" + +int device_battery_get_percent(int *percent) +{ + int ret; + + if (!percent) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, + METHOD_GET_PERCENT, NULL, NULL); + if (ret < 0) + return errno_to_device_error(ret); + + *percent = ret; + return DEVICE_ERROR_NONE; +} + +int device_battery_is_charging(bool *charging) +{ + int ret, val; + + if (!charging) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &val); + if (ret < 0 || val < 0 || val > 1) + return DEVICE_ERROR_OPERATION_FAILED; + + *charging = val; + return DEVICE_ERROR_NONE; +} + +int device_battery_get_level_status(device_battery_level_e *status) +{ + int val, ret; + + if (!status) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &val); + if (ret < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + if (val == VCONFKEY_SYSMAN_BAT_LEVEL_EMPTY) + *status = DEVICE_BATTERY_LEVEL_EMPTY; + else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_CRITICAL) + *status = DEVICE_BATTERY_LEVEL_CRITICAL; + else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_LOW) + *status = DEVICE_BATTERY_LEVEL_LOW; + else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_HIGH) + *status = DEVICE_BATTERY_LEVEL_HIGH; + else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_FULL) + *status = DEVICE_BATTERY_LEVEL_FULL; + else + return DEVICE_ERROR_OPERATION_FAILED; + + return DEVICE_ERROR_NONE; +} diff --git a/src/callback.c b/src/callback.c new file mode 100644 index 0000000..39dd5ef --- /dev/null +++ b/src/callback.c @@ -0,0 +1,236 @@ +/* + * 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. + */ + + +#include +#include +#include +#include +#include + +#include "callback.h" +#include "battery.h" +#include "display.h" +#include "common.h" +#include "dbus.h" +#include "list.h" + +struct device_cb_info { + device_changed_cb cb; + void *data; +}; + +static dd_list *device_cb_list[DEVICE_CALLBACK_MAX]; + +static void battery_capacity_cb(keynode_t *key, void *data) +{ + static device_callback_e type = DEVICE_CALLBACK_BATTERY_CAPACITY; + struct device_cb_info *cb_info; + dd_list *elem; + int val; + + val = vconf_keynode_get_int(key); + + /* invoke the each callback with value */ + DD_LIST_FOREACH(device_cb_list[type], elem, cb_info) + cb_info->cb(type, (void*)val, cb_info->data); +} + +static void battery_charging_cb(keynode_t *key, void *data) +{ + static device_callback_e type = DEVICE_CALLBACK_BATTERY_CHARGING; + struct device_cb_info *cb_info; + dd_list *elem; + int val; + + val = vconf_keynode_get_int(key); + + /* invoke the each callback with value */ + DD_LIST_FOREACH(device_cb_list[type], elem, cb_info) + cb_info->cb(type, (void*)val, cb_info->data); +} + +static void battery_level_cb(keynode_t *key, void *data) +{ + static device_callback_e type = DEVICE_CALLBACK_BATTERY_LEVEL; + struct device_cb_info *cb_info; + dd_list *elem; + int val, status; + + val = vconf_keynode_get_int(key); + + if (val == VCONFKEY_SYSMAN_BAT_LEVEL_EMPTY) + status = DEVICE_BATTERY_LEVEL_EMPTY; + else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_CRITICAL) + status = DEVICE_BATTERY_LEVEL_CRITICAL; + else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_LOW) + status = DEVICE_BATTERY_LEVEL_LOW; + else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_HIGH) + status = DEVICE_BATTERY_LEVEL_HIGH; + else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_FULL) + status = DEVICE_BATTERY_LEVEL_FULL; + else + status = -1; + + /* invoke the each callback with value */ + DD_LIST_FOREACH(device_cb_list[type], elem, cb_info) + cb_info->cb(type, (void*)status, cb_info->data); +} + +static void display_changed_cb(keynode_t *key, void *data) +{ + static device_callback_e type = DEVICE_CALLBACK_DISPLAY_STATE; + struct device_cb_info *cb_info; + dd_list *elem; + display_state_e state; + int val; + + val = vconf_keynode_get_int(key); + + switch(val) { + case 1: state = DISPLAY_STATE_NORMAL; + break; + case 2: state = DISPLAY_STATE_SCREEN_DIM; + break; + case 3: state = DISPLAY_STATE_SCREEN_OFF; + break; + default: state = -1; + break; + } + + /* invoke the each callback with value */ + DD_LIST_FOREACH(device_cb_list[type], elem, cb_info) + cb_info->cb(type, (void*)state, cb_info->data); +} + +static int register_request(device_callback_e type) +{ + switch (type) { + case DEVICE_CALLBACK_BATTERY_CAPACITY: + return vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, + battery_capacity_cb, NULL); + case DEVICE_CALLBACK_BATTERY_LEVEL: + return vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, + battery_level_cb, NULL); + case DEVICE_CALLBACK_BATTERY_CHARGING: + return vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, + battery_charging_cb, NULL); + case DEVICE_CALLBACK_DISPLAY_STATE: + return vconf_notify_key_changed(VCONFKEY_PM_STATE, + display_changed_cb, NULL); + default: + break; + } + + return -EINVAL; +} + +static int release_request(device_callback_e type) +{ + switch (type) { + case DEVICE_CALLBACK_BATTERY_CAPACITY: + return vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, + battery_capacity_cb); + case DEVICE_CALLBACK_BATTERY_LEVEL: + return vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, + battery_level_cb); + case DEVICE_CALLBACK_BATTERY_CHARGING: + return vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, + battery_charging_cb); + case DEVICE_CALLBACK_DISPLAY_STATE: + return vconf_ignore_key_changed(VCONFKEY_PM_STATE, + display_changed_cb); + default: + break; + } + + return -EINVAL; +} + +int device_add_callback(device_callback_e type, device_changed_cb cb, void *data) +{ + struct device_cb_info *cb_info; + dd_list *elem; + int ret, n; + + if (type < 0 || type >= DEVICE_CALLBACK_MAX) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (!cb) + return DEVICE_ERROR_INVALID_PARAMETER; + + /* check if it is the first request */ + n = DD_LIST_LENGTH(device_cb_list[type]); + if (n == 0) { + ret = register_request(type); + if (ret < 0) + return DEVICE_ERROR_OPERATION_FAILED; + } + + /* check for the same request */ + DD_LIST_FOREACH(device_cb_list[type], elem, cb_info) { + if (cb_info->cb == cb) + return DEVICE_ERROR_ALREADY_IN_PROGRESS; + } + + /* add device changed callback to list (local) */ + cb_info = malloc(sizeof(struct device_cb_info)); + if (!cb_info) + return DEVICE_ERROR_OPERATION_FAILED; + + cb_info->cb = cb; + cb_info->data = data; + + DD_LIST_APPEND(device_cb_list[type], cb_info); + + return DEVICE_ERROR_NONE; +} + +int device_remove_callback(device_callback_e type, device_changed_cb cb) +{ + struct device_cb_info *cb_info; + dd_list *elem; + int ret, n; + + if (type < 0 || type >= DEVICE_CALLBACK_MAX) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (!cb) + return DEVICE_ERROR_INVALID_PARAMETER; + + /* search for the same element with callback */ + DD_LIST_FOREACH(device_cb_list[type], elem, cb_info) { + if (cb_info->cb == cb) + break; + } + + if (!cb_info) + return DEVICE_ERROR_INVALID_PARAMETER; + + /* remove device callback from list (local) */ + DD_LIST_REMOVE(device_cb_list[type], cb_info); + free(cb_info); + + /* check if this callback is last element */ + n = DD_LIST_LENGTH(device_cb_list[type]); + if (n == 0) { + ret = release_request(type); + if (ret < 0) + return DEVICE_ERROR_OPERATION_FAILED; + } + + return DEVICE_ERROR_NONE; +} diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..dd01165 --- /dev/null +++ b/src/common.h @@ -0,0 +1,50 @@ +/* + * 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 __COMMON_H__ +#define __COMMON_H__ + +#ifdef FEATURE_DEVICE_DLOG + #define LOG_TAG "SYSTEM_DEVICE" + #include + #define _D(fmt, args...) SLOGD(fmt, ##args) + #define _I(fmt, args...) SLOGI(fmt, ##args) + #define _E(fmt, args...) SLOGE(fmt, ##args) +#else + #define _D(x, ...) + #define _I(x, ...) + #define _E(x, ...) +#endif + +#ifndef __CONSTRUCTOR__ +#define __CONSTRUCTOR__ __attribute__ ((constructor)) +#endif + +#include "device-error.h" + +static inline int errno_to_device_error(int err) +{ + if (err == -ECOMM) + return DEVICE_ERROR_PERMISSION_DENIED; + else if (err == -ENODEV || err == -ENOENT) + return DEVICE_ERROR_NOT_SUPPORTED; + else if (err < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + return DEVICE_ERROR_NONE; +} + +#endif /* __COMMON_H__ */ diff --git a/src/cpu.c b/src/cpu.c new file mode 100644 index 0000000..688c694 --- /dev/null +++ b/src/cpu.c @@ -0,0 +1,171 @@ +/* + * 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. + */ + + + +#include +#include +#include +#include +#include "device.h" +#include "common.h" + +#define PROC_STAT "/proc/stat" + +#define PROC_CPU_PRESENT "/sys/devices/system/cpu/present" +#define PROC_SCALING_CUR_FREQ "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq" +#define PROC_SCALING_MAX_FREQ "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq" + + +int device_cpu_get_count(int *cpu_cnt) +{ + FILE *fp; + int ret; + int st, ed; + + if (cpu_cnt == NULL) + return DEVICE_ERROR_INVALID_PARAMETER; + + fp = fopen(PROC_CPU_PRESENT, "r"); + if (!fp) + return DEVICE_ERROR_OPERATION_FAILED; + + ret = fscanf(fp, "%u-%u", &st, &ed); + fclose(fp); + if (ret != 2) + return DEVICE_ERROR_OPERATION_FAILED; + + *cpu_cnt = ed+1; + return DEVICE_ERROR_NONE; +} + +static int _get_systime(device_system_time_s *st) +{ + FILE *fp; + char buf[4096]; + char *s; + + assert(st); + + fp = fopen(PROC_STAT, "r"); + if (!fp) + return -1; + + s = fgets(buf, sizeof(buf), fp); + fclose(fp); + if (!s) + return -1; + + s = strchr(buf, ' '); + if (!s) + return -1; + + s++; + st->user = strtol(s, &s, 10); + st->nice = strtol(s, &s, 10); + st->system = strtol(s, &s, 10); + st->idle = strtol(s, &s, 10); + st->iowait = strtol(s, &s, 10); + st->irq = strtol(s, &s, 10); + st->softirq = strtol(s, &s, 10); + + return 0; +} + +int device_cpu_get_system_time(device_system_time_s *time) +{ + int ret; + device_system_time_s st; + + if (time == NULL) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = _get_systime(&st); + if (ret < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + st.total = st.user+st.nice+st.system+st.idle+st.iowait+st.irq+st.softirq; + *time = st; + return DEVICE_ERROR_NONE; +} + +static int _get_uint(const char *path, unsigned int *val) +{ + FILE *fp; + unsigned int num; + int ret; + + assert(path); + assert(val); + + fp = fopen(path, "r"); + if (!fp) + return -1; + + ret = fscanf(fp, "%u", &num); + fclose(fp); + if (ret != 1) + return -1; + + *val = num; + return 0; +} + +int device_cpu_get_current_freq(int cpu, unsigned int *cur_freq) +{ + char path[FILENAME_MAX]; + int ret; + int count; + unsigned int cur; + + if (cur_freq == NULL) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = device_cpu_get_count(&count); + if (ret != DEVICE_ERROR_NONE || cpu < 0 || cpu >= count) + return DEVICE_ERROR_INVALID_PARAMETER; + + snprintf(path, sizeof(path), PROC_SCALING_CUR_FREQ, cpu); + ret = _get_uint(path, &cur); + if (ret < 0) + cur = 0; + + *cur_freq = cur; + return DEVICE_ERROR_NONE; +} + +int device_cpu_get_max_freq(int cpu, unsigned int *max_freq) +{ + char path[FILENAME_MAX]; + int ret; + int count; + unsigned int max; + + if (max_freq == NULL) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = device_cpu_get_count(&count); + if (ret != DEVICE_ERROR_NONE || cpu < 0 || cpu >= count) + return DEVICE_ERROR_INVALID_PARAMETER; + + snprintf(path, sizeof(path), PROC_SCALING_MAX_FREQ, cpu); + ret = _get_uint(path, &max); + if (ret < 0) + max = 0; + + *max_freq = max; + return DEVICE_ERROR_NONE; +} diff --git a/src/dbus.c b/src/dbus.c new file mode 100644 index 0000000..bf54116 --- /dev/null +++ b/src/dbus.c @@ -0,0 +1,235 @@ +/* + * system-dbus + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. + * + * 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. + */ + + +#include +#include +#include +#include +#include + +#include "common.h" +#include "dbus.h" + +#define DBUS_REPLY_TIMEOUT (-1) + +struct pending_call_data { + dbus_pending_cb func; + void *data; +}; + +static int append_variant(DBusMessageIter *iter, const char *sig, char *param[]) +{ + char *ch; + int i; + int int_type; + uint64_t int64_type; + + if (!sig || !param) + return 0; + + for (ch = (char*)sig, i = 0; *ch != '\0'; ++i, ++ch) { + switch (*ch) { + case 'i': + int_type = atoi(param[i]); + dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &int_type); + break; + case 'u': + int_type = strtoul(param[i], NULL, 10); + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &int_type); + break; + case 't': + int64_type = atoll(param[i]); + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT64, &int64_type); + break; + case 's': + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, ¶m[i]); + break; + default: + return -EINVAL; + } + } + + return 0; +} + +int dbus_method_sync(const char *dest, const char *path, + const char *interface, const char *method, + const char *sig, char *param[]) +{ + DBusConnection *conn; + DBusMessage *msg; + DBusMessageIter iter; + DBusMessage *reply; + DBusError err; + int ret, result; + + conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (!conn) { + _E("dbus_bus_get error"); + return -EPERM; + } + + msg = dbus_message_new_method_call(dest, path, interface, method); + if (!msg) { + _E("dbus_message_new_method_call(%s:%s-%s)", + path, interface, method); + return -EBADMSG; + } + + dbus_message_iter_init_append(msg, &iter); + ret = append_variant(&iter, sig, param); + if (ret < 0) { + _E("append_variant error(%d) %s %s:%s-%s", + ret, dest, path, interface, method); + dbus_message_unref(msg); + return ret; + } + + dbus_error_init(&err); + + reply = dbus_connection_send_with_reply_and_block(conn, msg, DBUS_REPLY_TIMEOUT, &err); + dbus_message_unref(msg); + if (!reply) { + _E("dbus_connection_send error(%s:%s) %s %s:%s-%s", + err.name, err.message, dest, path, interface, method); + dbus_error_free(&err); + return -ECOMM; + } + + ret = dbus_message_get_args(reply, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID); + dbus_message_unref(reply); + if (!ret) { + _E("no message : [%s:%s] %s %s:%s-%s", + err.name, err.message, dest, path, interface, method); + dbus_error_free(&err); + return -ENOMSG; + } + + return result; +} + +static void cb_pending(DBusPendingCall *pending, void *user_data) +{ + DBusMessage *msg; + DBusError err; + struct pending_call_data *data = user_data; + int ret; + + ret = dbus_pending_call_get_completed(pending); + if (!ret) { + _I("dbus_pending_call_get_completed() fail"); + dbus_pending_call_unref(pending); + return; + } + + dbus_error_init(&err); + msg = dbus_pending_call_steal_reply(pending); + if (!msg) { + _E("no message : [%s:%s]", err.name, err.message); + + if (data->func) { + dbus_set_error(&err, "org.tizen.system.deviced.NoReply", + "There was no reply to this method call"); + data->func(data->data, NULL, &err); + dbus_error_free(&err); + } + return; + } + + ret = dbus_set_error_from_message(&err, msg); + if (ret) { + _E("error msg : [%s:%s]", err.name, err.message); + + if (data->func) + data->func(data->data, NULL, &err); + dbus_error_free(&err); + } else { + if (data->func) + data->func(data->data, msg, &err); + } + + dbus_message_unref(msg); + dbus_pending_call_unref(pending); +} + +int dbus_method_async_with_reply(const char *dest, const char *path, + const char *interface, const char *method, + const char *sig, char *param[], dbus_pending_cb cb, int timeout, void *data) +{ + DBusConnection *conn; + DBusMessage *msg; + DBusMessageIter iter; + DBusPendingCall *pending = NULL; + struct pending_call_data *pdata; + int ret; + + conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (!conn) { + _E("dbus_bus_get error"); + return -EPERM; + } + + /* this function should be invoked to receive dbus messages + * does nothing if it's already been done */ + dbus_connection_setup_with_g_main(conn, NULL); + + msg = dbus_message_new_method_call(dest, path, interface, method); + if (!msg) { + _E("dbus_message_new_method_call(%s:%s-%s)", + path, interface, method); + return -EBADMSG; + } + + dbus_message_iter_init_append(msg, &iter); + ret = append_variant(&iter, sig, param); + if (ret < 0) { + _E("append_variant error(%d)%s %s:%s-%s", + ret, dest, path, interface, method); + dbus_message_unref(msg); + return ret; + } + + ret = dbus_connection_send_with_reply(conn, msg, &pending, timeout); + if (!ret) { + dbus_message_unref(msg); + _E("dbus_connection_send error(%s %s:%s-%s)", + dest, path, interface, method); + return -ECOMM; + } + + dbus_message_unref(msg); + + if (cb && pending) { + pdata = malloc(sizeof(struct pending_call_data)); + if (!pdata) + return -ENOMEM; + + pdata->func = cb; + pdata->data = data; + + ret = dbus_pending_call_set_notify(pending, cb_pending, pdata, free); + if (!ret) { + free(pdata); + dbus_pending_call_cancel(pending); + return -ECOMM; + } + } + + return 0; +} diff --git a/src/dbus.h b/src/dbus.h new file mode 100644 index 0000000..1e3fead --- /dev/null +++ b/src/dbus.h @@ -0,0 +1,55 @@ +/* + * system-dbus + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. + * + * 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 __DBUS_H__ +#define __DBUS_H__ + +#include + +#define DEVICED_BUS_NAME "org.tizen.system.deviced" +#define DEVICED_OBJECT_PATH "/Org/Tizen/System/DeviceD" +#define DEVICED_INTERFACE_NAME DEVICED_BUS_NAME + +/* Display service: start/stop display(pm), get/set brightness operations about display */ +#define DEVICED_PATH_DISPLAY DEVICED_OBJECT_PATH"/Display" +#define DEVICED_INTERFACE_DISPLAY DEVICED_INTERFACE_NAME".display" + +/* Battery service */ +#define DEVICED_PATH_BATTERY DEVICED_OBJECT_PATH"/Battery" +#define DEVICED_INTERFACE_BATTERY DEVICED_INTERFACE_NAME".Battery" + +/* Haptic service: operatioins about haptic */ +#define DEVICED_PATH_HAPTIC DEVICED_OBJECT_PATH"/Haptic" +#define DEVICED_INTERFACE_HAPTIC DEVICED_INTERFACE_NAME".haptic" + +/* Led service: play/stop led operations about led */ +#define DEVICED_PATH_LED DEVICED_OBJECT_PATH"/Led" +#define DEVICED_INTERFACE_LED DEVICED_INTERFACE_NAME".Led" + +int dbus_method_sync(const char *dest, const char *path, + const char *interface, const char *method, + const char *sig, char *param[]); + +typedef void (*dbus_pending_cb)(void *data, DBusMessage *msg, DBusError *err); + +int dbus_method_async_with_reply(const char *dest, const char *path, + const char *interface, const char *method, + const char *sig, char *param[], dbus_pending_cb cb, int timeout, void *data); + +#endif diff --git a/src/device.c b/src/device.c new file mode 100644 index 0000000..b309667 --- /dev/null +++ b/src/device.c @@ -0,0 +1,289 @@ +/* + * 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. + */ + + +#include +#include +#include +#include +#include +#include + +#include "device.h" +#include "common.h" + +#define CHECK_ERR(val) \ + do { \ + if (val < 0) { \ + if (errno == ENODEV) \ + return DEVICE_ERROR_NOT_SUPPORTED; \ + return DEVICE_ERROR_OPERATION_FAILED; \ + } \ + } while(0) + +int device_get_display_numbers(int* device_number) +{ + if(device_number == NULL) + return DEVICE_ERROR_INVALID_PARAMETER; + + *device_number = display_get_count(); + CHECK_ERR(*device_number); + + return DEVICE_ERROR_NONE; +} + +int device_get_brightness(int disp_idx, int* value) +{ + int val, max_id, ret; + + if(value == NULL) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = device_get_display_numbers(&max_id); + if (ret != DEVICE_ERROR_NONE) + return ret; + + if(disp_idx < 0 || disp_idx >= max_id) + return DEVICE_ERROR_INVALID_PARAMETER; + + val = display_get_brightness(); + CHECK_ERR(val); + + *value = val; + return DEVICE_ERROR_NONE; +} + +int device_set_brightness(int disp_idx, int new_value) +{ + int max_value, val, max_id, ret; + + if(new_value < 0) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = device_get_display_numbers(&max_id); + if (ret != DEVICE_ERROR_NONE) + return ret; + + if(disp_idx < 0 || disp_idx >= max_id) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = device_get_max_brightness(disp_idx, &max_value); + if (ret != DEVICE_ERROR_NONE) + return ret; + + if(new_value > max_value) + return DEVICE_ERROR_INVALID_PARAMETER; + + val = display_set_brightness(new_value); + CHECK_ERR(val); + + return DEVICE_ERROR_NONE; +} + +int device_get_max_brightness(int disp_idx, int* max_value) +{ + int val, max_id, ret; + + if(max_value == NULL) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = device_get_display_numbers(&max_id); + _E("max id : %d", max_id); + if (ret != DEVICE_ERROR_NONE) + return ret; + + if(disp_idx < 0 || disp_idx >= max_id) + return DEVICE_ERROR_INVALID_PARAMETER; + + val = display_get_max_brightness(); + CHECK_ERR(val); + + *max_value = val; + return DEVICE_ERROR_NONE; +} + +int device_set_brightness_from_settings(int disp_idx) +{ + int max_id, val, ret; + + ret = device_get_display_numbers(&max_id); + if (ret != DEVICE_ERROR_NONE) + return ret; + + if(disp_idx < 0 || disp_idx >= max_id) + return DEVICE_ERROR_INVALID_PARAMETER; + + val = display_release_brightness(); + CHECK_ERR(val); + + return DEVICE_ERROR_NONE; +} + +int device_set_brightness_to_settings(int disp_idx, int new_value) +{ + int max_value, val, max_id, ret; + + if(new_value < 0) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = device_get_display_numbers(&max_id); + if (ret != DEVICE_ERROR_NONE) + return ret; + + if(disp_idx < 0 || disp_idx >= max_id) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = device_get_max_brightness(disp_idx, &max_value); + if (ret != DEVICE_ERROR_NONE) + return ret; + + if(new_value > max_value) + return DEVICE_ERROR_INVALID_PARAMETER; + + val = display_set_brightness_with_setting(new_value); + CHECK_ERR(val); + + return DEVICE_ERROR_NONE; +} + +int device_battery_is_full(bool* full) +{ + if (full == NULL) + return DEVICE_ERROR_INVALID_PARAMETER; + + int f = battery_is_full(); + CHECK_ERR(f); + + *full = (f == 1) ? true : false; + return DEVICE_ERROR_NONE; +} + +static device_battery_cb changed_callback = NULL; +static void* changed_callback_user_data = NULL; + +static void battery_changed_inside_cb(keynode_t* key, void* user_data) +{ + char* keyname = vconf_keynode_get_name(key); + + if (keyname != NULL && changed_callback != NULL && strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_CAPACITY) == 0) { + int percent = 0; + if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &percent) == 0) { + changed_callback(percent, changed_callback_user_data); + } + } +} + +int device_battery_set_cb(device_battery_cb callback, void* user_data) +{ + // VCONFKEY_SYSMAN_BATTERY_CAPACITY + int err; + if (callback == NULL) + return DEVICE_ERROR_INVALID_PARAMETER; + + changed_callback = callback; + changed_callback_user_data = user_data; + + err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery_changed_inside_cb, NULL); + if (err < 0) + return DEVICE_ERROR_INVALID_PARAMETER; + + return DEVICE_ERROR_NONE; +} + +int device_battery_unset_cb(void) +{ + int err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery_changed_inside_cb); + if (err < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + changed_callback = NULL; + changed_callback_user_data = NULL; + + return DEVICE_ERROR_NONE; +} + +int device_battery_get_warning_status(device_battery_warn_e *status) +{ + if (status == NULL) + return DEVICE_ERROR_INVALID_PARAMETER; + + int value, err; + + err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &value); + if (err < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + if (value == VCONFKEY_SYSMAN_BAT_POWER_OFF) { + *status = DEVICE_BATTERY_WARN_EMPTY; + } else if (value == VCONFKEY_SYSMAN_BAT_CRITICAL_LOW) { + *status = DEVICE_BATTERY_WARN_CRITICAL; + } else if (value == VCONFKEY_SYSMAN_BAT_WARNING_LOW) { + *status = DEVICE_BATTERY_WARN_LOW; + } else if (value == VCONFKEY_SYSMAN_BAT_NORMAL) { + *status = DEVICE_BATTERY_WARN_NORMAL; + } else if (value == VCONFKEY_SYSMAN_BAT_FULL) { + *status = DEVICE_BATTERY_WARN_FULL; + } else { + return DEVICE_ERROR_OPERATION_FAILED; + } + + return DEVICE_ERROR_NONE; +} + +static device_battery_warn_cb warn_changed_callback = NULL; +static void* warn_changed_callback_user_data = NULL; + +static void battery_warn_changed_inside_cb(keynode_t* key, void* user_data) +{ + char* keyname = vconf_keynode_get_name(key); + + if (keyname != NULL && warn_changed_callback != NULL && strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_STATUS_LOW) == 0) { + int bat_state = 0; + if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state) == 0) { + warn_changed_callback(bat_state-1, warn_changed_callback_user_data); + } + } +} + +int device_battery_warning_set_cb(device_battery_warn_cb callback, void* user_data) +{ + // VCONFKEY_SYSMAN_BATTERY_STATUS_LOW + int err; + + if (callback == NULL) + return DEVICE_ERROR_INVALID_PARAMETER; + + warn_changed_callback = callback; + warn_changed_callback_user_data = user_data; + + err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery_warn_changed_inside_cb, NULL); + if (err < 0) + return DEVICE_ERROR_INVALID_PARAMETER; + + return DEVICE_ERROR_NONE; +} + +int device_battery_warning_unset_cb(void) +{ + int err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery_warn_changed_inside_cb); + if (err < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + warn_changed_callback = NULL; + warn_changed_callback_user_data = NULL; + + return DEVICE_ERROR_NONE; +} diff --git a/src/display.c b/src/display.c new file mode 100644 index 0000000..ed47206 --- /dev/null +++ b/src/display.c @@ -0,0 +1,214 @@ +/* + * 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. + */ + + +#include +#include +#include + +#include "display.h" +#include "common.h" +#include "dbus.h" + +#define METHOD_GET_DISPLAY_COUNT "GetDisplayCount" +#define METHOD_GET_MAX_BRIGHTNESS "GetMaxBrightness" +#define METHOD_GET_BRIGHTNESS "GetBrightness" +#define METHOD_SET_BRIGHTNESS "SetBrightness" +#define METHOD_CHANGE_STATE "changestate" + +#define STR_LCD_OFF "lcdoff" +#define STR_LCD_DIM "lcddim" +#define STR_LCD_ON "lcdon" + +static int display_cnt = -1; +struct display { + int max; +} *display_arr; + +static int alloc_display(void) +{ + display_arr = malloc(sizeof(struct display) * display_cnt); + if (!display_arr) + return -ENOMEM; + memset(display_arr, -1, sizeof(struct display)); + return 0; +} + +int device_display_get_numbers(int *device_number) +{ + int ret; + + if (!device_number) + return DEVICE_ERROR_INVALID_PARAMETER; + + /* if it is a first request */ + if (display_cnt < 0) { + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_GET_DISPLAY_COUNT, NULL, NULL); + if (ret < 0) + return errno_to_device_error(ret); + display_cnt = ret; + alloc_display(); + } + + *device_number = display_cnt; + _I("device_number : %d", *device_number); + return DEVICE_ERROR_NONE; +} + +int device_display_get_max_brightness(int display_index, int *max_brightness) +{ + int ret; + + if (!max_brightness) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (display_cnt < 0) + device_display_get_numbers(&display_cnt); + + if (display_index < 0 || display_index >= display_cnt) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (!display_arr && alloc_display() < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + if (display_arr[display_index].max < 0) { + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_GET_MAX_BRIGHTNESS, NULL, NULL); + if (ret < 0) + return errno_to_device_error(ret); + display_arr[display_index].max = ret; + } + + *max_brightness = display_arr[display_index].max; + return DEVICE_ERROR_NONE; +} + +int device_display_get_brightness(int display_index, int *brightness) +{ + int ret; + + if (!brightness) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (display_cnt < 0) + device_display_get_numbers(&display_cnt); + + if (display_index < 0 || display_index >= display_cnt) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_GET_BRIGHTNESS, NULL, NULL); + if (ret < 0) + return errno_to_device_error(ret); + + *brightness = ret; + return DEVICE_ERROR_NONE; +} + +int device_display_set_brightness(int display_index, int brightness) +{ + char *arr[1]; + char str_val[32]; + int ret, max; + + if (display_cnt < 0) + device_display_get_numbers(&display_cnt); + + if (display_index < 0 || display_index >= display_cnt) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (display_arr[display_index].max < 0) + device_display_get_max_brightness(display_index, &max); + + if (brightness < 0 || brightness > display_arr[display_index].max) + return DEVICE_ERROR_INVALID_PARAMETER; + + snprintf(str_val, sizeof(str_val), "%d", brightness); + arr[0] = str_val; + + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_SET_BRIGHTNESS, "i", arr); + if (ret < 0) + return errno_to_device_error(ret); + + return DEVICE_ERROR_NONE; +} + +int device_display_get_state(display_state_e *state) +{ + int ret, val; + + if (!state) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = vconf_get_int(VCONFKEY_PM_STATE, &val); + if (ret < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + if (val == VCONFKEY_PM_STATE_NORMAL) + *state = DISPLAY_STATE_NORMAL; + else if (val == VCONFKEY_PM_STATE_LCDDIM) + *state = DISPLAY_STATE_SCREEN_DIM; + else if (val == VCONFKEY_PM_STATE_LCDOFF) + *state = DISPLAY_STATE_SCREEN_OFF; + else + return DEVICE_ERROR_OPERATION_FAILED; + + return DEVICE_ERROR_NONE; +} + +static char *get_state_str(display_state_e state) +{ + switch (state) { + case DISPLAY_STATE_NORMAL: + return STR_LCD_ON; + case DISPLAY_STATE_SCREEN_DIM: + return STR_LCD_DIM; + case DISPLAY_STATE_SCREEN_OFF: + return STR_LCD_OFF; + default: + break; + } + return NULL; +} + +int device_display_change_state(display_state_e state) +{ + char *str, *arr[1]; + int ret; + + if (state < DISPLAY_STATE_NORMAL || state > DISPLAY_STATE_SCREEN_OFF) + return DEVICE_ERROR_INVALID_PARAMETER; + + str = get_state_str(state); + if (!str) + return DEVICE_ERROR_INVALID_PARAMETER; + + arr[0] = str; + + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_CHANGE_STATE, "s", arr); + if (ret < 0) + return errno_to_device_error(ret); + + return DEVICE_ERROR_NONE; +} diff --git a/src/haptic.c b/src/haptic.c new file mode 100644 index 0000000..6d70a62 --- /dev/null +++ b/src/haptic.c @@ -0,0 +1,179 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. + * + * 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. + */ + + +#include +#include + +#include "haptic.h" +#include "common.h" +#include "dbus.h" + +#define METHOD_GET_COUNT "GetCount" +#define METHOD_OPEN_DEVICE "OpenDevice" +#define METHOD_CLOSE_DEVICE "CloseDevice" +#define METHOD_STOP_DEVICE "StopDevice" +#define METHOD_VIBRATE_MONOTONE "VibrateMonotone" + +enum feedback_e +{ + HAPTIC_FEEDBACK_MIN = 0, + HAPTIC_FEEDBACK_MAX = 100, +}; + +enum priority_e +{ + HAPTIC_PRIORITY_MIN = 0, + HAPTIC_PRIORITY_MIDDLE, + HAPTIC_PRIORITY_HIGH, +}; + +int device_haptic_get_count(int *device_number) +{ + int ret; + + if (!device_number) + return DEVICE_ERROR_INVALID_PARAMETER; + + /* request to deviced to get haptic count */ + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC, + METHOD_GET_COUNT, NULL, NULL); + if (ret < 0) + return errno_to_device_error(ret); + + *device_number = ret; + return DEVICE_ERROR_NONE; +} + +int device_haptic_open(int device_index, haptic_device_h *device_handle) +{ + char str_index[32]; + char *arr[1]; + int ret, max; + + ret = device_haptic_get_count(&max); + if (ret < 0) + return ret; + + if (device_index < 0 || device_index >= max) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (!device_handle) + return DEVICE_ERROR_INVALID_PARAMETER; + + snprintf(str_index, sizeof(str_index), "%d", device_index); + arr[0] = str_index; + + /* request to deviced to open haptic device */ + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC, + METHOD_OPEN_DEVICE, "i", arr); + if (ret < 0) + return errno_to_device_error(ret); + + *device_handle = (haptic_device_h)ret; + return DEVICE_ERROR_NONE; +} + +int device_haptic_close(haptic_device_h device_handle) +{ + char str_handle[32]; + char *arr[1]; + int ret; + + if (!device_handle) + return DEVICE_ERROR_INVALID_PARAMETER; + + snprintf(str_handle, sizeof(str_handle), "%u", (unsigned int)device_handle); + arr[0] = str_handle; + + /* request to deviced to open haptic device */ + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC, + METHOD_CLOSE_DEVICE, "u", arr); + if (ret < 0) + return errno_to_device_error(ret); + + return DEVICE_ERROR_NONE; +} + +int device_haptic_vibrate(haptic_device_h device_handle, int duration, int feedback, haptic_effect_h *effect_handle) +{ + char str_handle[32]; + char str_duration[32]; + char str_feedback[32]; + char str_priority[32]; + char *arr[4]; + int ret, priority; + + if (!device_handle) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (duration < 0) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (feedback < HAPTIC_FEEDBACK_MIN || feedback > HAPTIC_FEEDBACK_MAX) + return DEVICE_ERROR_INVALID_PARAMETER; + + priority = HAPTIC_PRIORITY_MIN; + + snprintf(str_handle, sizeof(str_handle), "%u", (unsigned int)device_handle); + arr[0] = str_handle; + snprintf(str_duration, sizeof(str_duration), "%d", duration); + arr[1] = str_duration; + snprintf(str_feedback, sizeof(str_feedback), "%d", feedback); + arr[2] = str_feedback; + snprintf(str_priority, sizeof(str_priority), "%d", priority); + arr[3] = str_priority; + + /* request to deviced to vibrate haptic device */ + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC, + METHOD_VIBRATE_MONOTONE, "uiii", arr); + if (ret < 0) + return errno_to_device_error(ret); + + if (effect_handle) + *effect_handle = (haptic_effect_h)ret; + + return DEVICE_ERROR_NONE; +} + +int device_haptic_stop(haptic_device_h device_handle, haptic_effect_h effect_handle) +{ + char str_handle[32]; + char *arr[1]; + int ret; + + if (!device_handle) + return DEVICE_ERROR_INVALID_PARAMETER; + + /* TODO : support to stop haptic effect */ + snprintf(str_handle, sizeof(str_handle), "%u", (unsigned int)device_handle); + arr[0] = str_handle; + + /* request to deviced to open haptic device */ + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC, + METHOD_STOP_DEVICE, "u", arr); + if (ret < 0) + return errno_to_device_error(ret); + + return DEVICE_ERROR_NONE; +} diff --git a/src/led.c b/src/led.c new file mode 100644 index 0000000..4e84b07 --- /dev/null +++ b/src/led.c @@ -0,0 +1,169 @@ +/* + * 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. + */ + + +#include +#include +#include +#include + +#include "led.h" +#include "common.h" +#include "dbus.h" + +#define METHOD_GET_MAX_BRIGHTNESS "GetMaxBrightness" +#define METHOD_GET_BRIGHTNESS "GetBrightness" +#define METHOD_SET_BRIGHTNESS "SetBrightness" +#define METHOD_PLAY_CUSTOM "playcustom" +#define METHOD_STOP_CUSTOM "stopcustom" + +#define FRONT_LED_FEATURE "tizen.org/feature/led" +#define CAMERA_LED_FEATURE "tizen.org/feature/camera.back.flash" + +static bool support_front_led; +static bool support_camera_led; + +static void __attribute__((constructor)) init(void) +{ + int ret; + bool val; + + ret = system_info_get_platform_bool(FRONT_LED_FEATURE, &val); + if (ret == SYSTEM_INFO_ERROR_NONE && val) + support_front_led = true; + + ret = system_info_get_platform_bool(CAMERA_LED_FEATURE, &val); + if (ret == SYSTEM_INFO_ERROR_NONE && val) + support_camera_led = true; +} + +int device_flash_get_max_brightness(int *max_brightness) +{ + int ret; + + if (!support_camera_led) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (!max_brightness) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_LED, DEVICED_INTERFACE_LED, + METHOD_GET_MAX_BRIGHTNESS, NULL, NULL); + if (ret < 0) + return errno_to_device_error(ret); + + *max_brightness = ret; + return DEVICE_ERROR_NONE; +} + +int device_flash_get_brightness(int *brightness) +{ + int ret; + + if (!support_camera_led) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (!brightness) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_LED, DEVICED_INTERFACE_LED, + METHOD_GET_BRIGHTNESS, NULL, NULL); + if (ret < 0) + return errno_to_device_error(ret); + + *brightness = ret; + return DEVICE_ERROR_NONE; +} + +int device_flash_set_brightness(int brightness) +{ + char *arr[2]; + char buf_val[32]; + char buf_noti[32]; + int max, ret; + + if (!support_camera_led) + return DEVICE_ERROR_NOT_SUPPORTED; + + ret = device_flash_get_max_brightness(&max); + if (ret < 0) + return ret; + + if (brightness < 0 || brightness > max) + return DEVICE_ERROR_INVALID_PARAMETER; + + snprintf(buf_val, sizeof(buf_val), "%d", brightness); + arr[0] = buf_val; + snprintf(buf_noti, sizeof(buf_noti), "%d", 0); + arr[1] = buf_noti; + + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_LED, DEVICED_INTERFACE_LED, + METHOD_SET_BRIGHTNESS, "ii", arr); + if (ret < 0) + return errno_to_device_error(ret); + + return DEVICE_ERROR_NONE; +} + +int device_led_play_custom(int on, int off, unsigned int color, unsigned int flags) +{ + char *arr[4]; + char str_on[32], str_off[32]; + char str_color[32], str_flags[32]; + int ret; + + if (!support_front_led) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (on < 0 || off < 0) + return DEVICE_ERROR_INVALID_PARAMETER; + + snprintf(str_on, sizeof(str_on), "%d", on); + arr[0] = str_on; + snprintf(str_off, sizeof(str_off), "%d", off); + arr[1] = str_off; + snprintf(str_color, sizeof(str_color), "%lu", (long unsigned int)color); + arr[2] = str_color; + snprintf(str_flags, sizeof(str_flags), "%lu", (long unsigned int)flags); + arr[3] = str_flags; + + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_LED, DEVICED_INTERFACE_LED, + METHOD_PLAY_CUSTOM, "iiuu", arr); + if (ret < 0) + return errno_to_device_error(ret); + + return DEVICE_ERROR_NONE; +} + +int device_led_stop_custom(void) +{ + int ret; + + if (!support_front_led) + return DEVICE_ERROR_NOT_SUPPORTED; + + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_LED, DEVICED_INTERFACE_LED, + METHOD_STOP_CUSTOM, NULL, NULL); + if (ret < 0) + return errno_to_device_error(ret); + + return DEVICE_ERROR_NONE; +} diff --git a/src/list.h b/src/list.h new file mode 100644 index 0000000..712ca70 --- /dev/null +++ b/src/list.h @@ -0,0 +1,83 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2013 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 __LIST_H__ +#define __LIST_H__ + +#include + +#define EINA_LIST_APPEND(a, b) \ + a = eina_list_append(a, b) + +#define EINA_LIST_REMOVE(a, b) \ + a = eina_list_remove(a, b) + +#define EINA_LIST_REMOVE_LIST(a, b) \ + a = eina_list_remove_list(a, b) + +#define EINA_LIST_FREE_LIST(a) \ + a = eina_list_free(a) + +#define EINA_LIST_PROMOTE_LIST(a, b) \ + a = eina_list_promote_list(a, b) + +#ifdef EINA_LIST +#include +typedef Eina_List dd_list; +#define DD_LIST_PREPEND(a, b) \ + a = eina_list_prepend(a, b) +#define DD_LIST_APPEND(a, b) \ + a = eina_list_append(a, b) +#define DD_LIST_REMOVE(a, b) \ + a = eina_list_remove(a, b) +#define DD_LIST_LENGTH(a) \ + eina_list_count(a) +#define DD_LIST_NTH(a, b) \ + eina_list_nth(a, b) +#define DD_LIST_FREE_LIST(a) \ + a = eina_list_free(a) +#define DD_LIST_FOREACH(head, elem, node) \ + EINA_LIST_FOREACH(head, elem, node) +#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \ + EINA_LIST_FOREACH_SAFE(head, elem, elem_next, node) + +#else +#include +typedef GList dd_list; +#define DD_LIST_PREPEND(a, b) \ + a = g_list_prepend(a, (gpointer)b) +#define DD_LIST_APPEND(a, b) \ + a = g_list_append(a, (gpointer)b) +#define DD_LIST_REMOVE(a, b) \ + a = g_list_remove(a, (gpointer)b) +#define DD_LIST_LENGTH(a) \ + g_list_length(a) +#define DD_LIST_NTH(a, b) \ + g_list_nth_data(a, b) +#define DD_LIST_FREE_LIST(a) \ + g_list_free(a) +#define DD_LIST_FOREACH(head, elem, node) \ + for (elem = head, node = NULL; elem && ((node = elem->data) != NULL); elem = elem->next, node = NULL) +#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \ + for (elem = head, elem_next = g_list_next(elem), node = NULL; \ + elem && ((node = elem->data) != NULL); \ + elem = elem_next, elem_next = g_list_next(elem), node = NULL) + +#endif + +#endif diff --git a/src/memory.c b/src/memory.c new file mode 100644 index 0000000..fde09e6 --- /dev/null +++ b/src/memory.c @@ -0,0 +1,136 @@ +/* + * 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. + */ + + + +#include +#include +#include +#include +#include "device.h" +#include "common.h" + +#define PROC_MEMORY "/proc/meminfo" + +enum { + _MI_TOTAL, + _MI_FREE, + _MI_BUF, + _MI_CACHED, + _MI_SWAP, + _MI_SHMEM, + _MI_MAX, +}; + +struct meminfo { + unsigned long l[_MI_MAX]; +}; + +static const char *_mi_str[] = { + [_MI_TOTAL] = "MemTotal", + [_MI_FREE] = "MemFree", + [_MI_BUF] = "Buffers", + [_MI_CACHED] = "Cached", + [_MI_SWAP] = "SwapCached", + [_MI_SHMEM] = "Shmem", +}; + +static inline int _get_idx(const char *name) +{ + int i; + + for (i = 0; i < sizeof(_mi_str)/sizeof(_mi_str[0]); ++i) { + if (name && _mi_str[i] && !strcmp(name, _mi_str[i])) + return i; + } + + return -1; +} + +static int _get_meminfo(struct meminfo *mi) +{ + FILE *fp; + char buf[4096]; + char *s, *name, *num; + int idx; + + assert(mi); + + fp = fopen(PROC_MEMORY, "r"); + if (!fp) + return -1; + + memset(mi, 0, sizeof(*mi)); + + while (!feof(fp)) { + s = fgets(buf, sizeof(buf), fp); + if (!s) + break; + + s = strchr(buf, ':'); + if (!s) + continue; + + *s = '\0'; + name = buf; + + s++; + while (*s == ' ') + s++; + num = s; + + idx = _get_idx(name); + if (idx < 0) + continue; + + mi->l[idx] = strtol(num, NULL, 10); + } + + fclose(fp); + return 0; +} + +int device_memory_get_total(unsigned int *total_mem) +{ + struct meminfo mi; + int ret; + + if (total_mem == NULL) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = _get_meminfo(&mi); + if (ret < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + *total_mem = mi.l[_MI_TOTAL]; + return DEVICE_ERROR_NONE; +} + +int device_memory_get_available(unsigned int *avail_mem) +{ + struct meminfo mi; + int ret; + + if (avail_mem == NULL) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = _get_meminfo(&mi); + if (ret < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + *avail_mem = mi.l[_MI_FREE] + mi.l[_MI_BUF] + mi.l[_MI_CACHED] + mi.l[_MI_SWAP] - mi.l[_MI_SHMEM]; + return DEVICE_ERROR_NONE; +} diff --git a/src/mobile/battery.c b/src/mobile/battery.c deleted file mode 100644 index 555cecc..0000000 --- a/src/mobile/battery.c +++ /dev/null @@ -1,410 +0,0 @@ -/* - * capi-system-device - * Copyright (c) 2012 Samsung Electronics Co., Ltd. - * - * 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. - */ - - -#include -#include -#include -#include -#include "device.h" -#include "device_log.h" - -#define CHECK_ERR(val) \ - do { \ - if (val == DEVMAN_ERROR_NOT_SUPPORTED) \ - return DEVICE_ERROR_NOT_SUPPORTED; \ - else if (val == DEVMAN_ERROR_OPERATION_FAILED) \ - return DEVICE_ERROR_OPERATION_FAILED; \ - } while(0) - -int device_battery_get_percent(int* percent) -{ - if (percent == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - int pct = device_get_battery_pct(); - CHECK_ERR(pct); - - *percent = pct; - return DEVICE_ERROR_NONE; -} - -int device_battery_get_detail(int* percent) -{ - if (percent == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - int pct = device_get_battery_pct_raw(); - CHECK_ERR(pct); - - *percent = pct; - return DEVICE_ERROR_NONE; -} - -int device_battery_is_full(bool* full) -{ - if (full == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - int f = device_is_battery_full(); - CHECK_ERR(f); - - *full = (f == 1) ? true : false; - return DEVICE_ERROR_NONE; -} - -int device_battery_is_charging(bool *charging) -{ - // VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW - int value, err; - - if (charging == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - if (value == 1) { - *charging = true; - } else if (value == 0) { - *charging = false; - } else { - return DEVICE_ERROR_OPERATION_FAILED; - } - - return DEVICE_ERROR_NONE; -} - -static device_battery_cb changed_callback = NULL; -static void* changed_callback_user_data = NULL; - -static void battery_changed_inside_cb(keynode_t* key, void* user_data) -{ - char* keyname = vconf_keynode_get_name(key); - - if (keyname != NULL && changed_callback != NULL && strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_CAPACITY) == 0) { - int percent = 0; - if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &percent) == 0) { - changed_callback(percent, changed_callback_user_data); - } - } -} - -int device_battery_set_cb(device_battery_cb callback, void* user_data) -{ - // VCONFKEY_SYSMAN_BATTERY_CAPACITY - int err; - if (callback == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - changed_callback = callback; - changed_callback_user_data = user_data; - - err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery_changed_inside_cb, NULL); - if (err < 0) - return DEVICE_ERROR_INVALID_PARAMETER; - - return DEVICE_ERROR_NONE; -} - -int device_battery_unset_cb(void) -{ - int err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery_changed_inside_cb); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - changed_callback = NULL; - changed_callback_user_data = NULL; - - return DEVICE_ERROR_NONE; -} - -int device_battery_get_warning_status(device_battery_warn_e *status) -{ - if (status == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - int value, err; - - err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &value); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - if (value == VCONFKEY_SYSMAN_BAT_POWER_OFF) { - *status = DEVICE_BATTERY_WARN_EMPTY; - } else if (value == VCONFKEY_SYSMAN_BAT_CRITICAL_LOW) { - *status = DEVICE_BATTERY_WARN_CRITICAL; - } else if (value == VCONFKEY_SYSMAN_BAT_WARNING_LOW) { - *status = DEVICE_BATTERY_WARN_LOW; - } else if (value == VCONFKEY_SYSMAN_BAT_NORMAL) { - *status = DEVICE_BATTERY_WARN_NORMAL; - } else if (value == VCONFKEY_SYSMAN_BAT_FULL) { - *status = DEVICE_BATTERY_WARN_FULL; - } else { - return DEVICE_ERROR_OPERATION_FAILED; - } - - return DEVICE_ERROR_NONE; -} - -static device_battery_warn_cb warn_changed_callback = NULL; -static void* warn_changed_callback_user_data = NULL; -static device_battery_level_cb level_changed_callback = NULL; -static void* level_changed_callback_user_data = NULL; - -static void battery_warn_changed_inside_cb(keynode_t* key, void* user_data) -{ - char* keyname = vconf_keynode_get_name(key); - - if (keyname != NULL && warn_changed_callback != NULL && strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_STATUS_LOW) == 0) { - int bat_state = 0; - if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state) == 0) { - warn_changed_callback(bat_state-1, warn_changed_callback_user_data); - } - } -} - -static void battery_level_changed_inside_cb(keynode_t* key, void* user_data) -{ - char* keyname; - keyname = vconf_keynode_get_name(key); - - if (keyname != NULL && level_changed_callback != NULL && - strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS) == 0) { - int bat_state = 0; - if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &bat_state) == 0) { - level_changed_callback(bat_state, level_changed_callback_user_data); - } - } -} - -int device_battery_warning_set_cb(device_battery_warn_cb callback, void* user_data) -{ - // VCONFKEY_SYSMAN_BATTERY_STATUS_LOW - int err; - - if (callback == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - warn_changed_callback = callback; - warn_changed_callback_user_data = user_data; - - err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery_warn_changed_inside_cb, NULL); - if (err < 0) - return DEVICE_ERROR_INVALID_PARAMETER; - - return DEVICE_ERROR_NONE; -} - -int device_battery_warning_unset_cb(void) -{ - int err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery_warn_changed_inside_cb); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - warn_changed_callback = NULL; - warn_changed_callback_user_data = NULL; - - return DEVICE_ERROR_NONE; -} - -static device_battery_remaining_time_changed_cb timetofull_changed_cb = NULL; -static device_battery_remaining_time_changed_cb timetoempty_changed_cb = NULL; -static void* timetofull_cb_user_data = NULL; -static void* timetoempty_cb_user_data = NULL; - -static void device_battery_time_timetofull_inside_cb(keynode_t* key, void* user_data) -{ - char* keyname = vconf_keynode_get_name(key); - int time = -1, err= -1; - - if (keyname == NULL) - return; - - if (strcmp(keyname, VCONFKEY_PM_BATTERY_TIMETOFULL) == 0) { - if (timetofull_changed_cb != NULL) { - err = device_battery_get_remaining_time( - DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED, &time); - if ((err == DEVICE_ERROR_NONE) && (time >= 0)) - timetofull_changed_cb(time, timetofull_cb_user_data); - } - } -} - -static void device_battery_time_timetoempty_inside_cb(keynode_t* key, void* user_data) -{ - char* keyname = vconf_keynode_get_name(key); - int time = -1, err= -1; - - if (keyname == NULL) - return; - - if (strcmp(keyname, VCONFKEY_PM_BATTERY_TIMETOEMPTY) == 0) { - if (timetoempty_changed_cb != NULL) { - err = device_battery_get_remaining_time( - DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED, &time); - if ((err == DEVICE_ERROR_NONE) && (time >= 0)) - timetoempty_changed_cb(time, timetoempty_cb_user_data); - } - } -} - -int device_battery_get_remaining_time(device_battery_remaining_time_type_e type, int* time) -{ - bool charging = false; - int err = -1; - - err = device_battery_is_charging(&charging); - if (err != DEVICE_ERROR_NONE) - return DEVICE_ERROR_OPERATION_FAILED; - - switch(type) { - case DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED: - if (charging == false) { - return DEVICE_ERROR_OPERATION_FAILED; - } else { - err = vconf_get_int(VCONFKEY_PM_BATTERY_TIMETOFULL, time); - if (err < 0 || time < 0) { - return DEVICE_ERROR_OPERATION_FAILED; - } - } - break; - case DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED: - if (charging == true) { - return DEVICE_ERROR_OPERATION_FAILED; - } else { - err = vconf_get_int(VCONFKEY_PM_BATTERY_TIMETOEMPTY, time); - if (err < 0 || time < 0) { - return DEVICE_ERROR_OPERATION_FAILED; - } - } - break; - default: - return DEVICE_ERROR_INVALID_PARAMETER; - } - return DEVICE_ERROR_NONE; -} - -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) -{ - int err; - - if (callback == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - switch(type) { - case DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED: - timetofull_changed_cb = callback; - timetofull_cb_user_data = user_data; - err = vconf_notify_key_changed(VCONFKEY_PM_BATTERY_TIMETOFULL, - device_battery_time_timetofull_inside_cb, NULL); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - break; - case DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED: - timetoempty_changed_cb = callback; - timetoempty_cb_user_data = user_data; - err = vconf_notify_key_changed(VCONFKEY_PM_BATTERY_TIMETOEMPTY, - device_battery_time_timetoempty_inside_cb, NULL); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - break; - default: - return DEVICE_ERROR_INVALID_PARAMETER; - } - return DEVICE_ERROR_NONE; -} - -int device_battery_unset_remaining_time_changed_cb(device_battery_remaining_time_type_e type) -{ - int err; - - switch(type) { - case DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED: - err = vconf_ignore_key_changed(VCONFKEY_PM_BATTERY_TIMETOFULL, - device_battery_time_timetofull_inside_cb); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - timetofull_changed_cb = NULL; - timetofull_cb_user_data = NULL; - break; - case DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED: - err = vconf_ignore_key_changed(VCONFKEY_PM_BATTERY_TIMETOEMPTY, - device_battery_time_timetoempty_inside_cb); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - timetoempty_changed_cb = NULL; - timetoempty_cb_user_data = NULL; - break; - default: - return DEVICE_ERROR_INVALID_PARAMETER; - } - return DEVICE_ERROR_NONE; -} - -int device_battery_get_level_status(device_battery_level_e *status) -{ - int value, err; - - if (status == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - - err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &value); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - if (value == VCONFKEY_SYSMAN_BAT_LEVEL_EMPTY) { - *status = DEVICE_BATTERY_LEVEL_EMPTY; - } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_CRITICAL) { - *status = DEVICE_BATTERY_LEVEL_CRITICAL; - } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_LOW) { - *status = DEVICE_BATTERY_LEVEL_LOW; - } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_HIGH) { - *status = DEVICE_BATTERY_LEVEL_HIGH; - } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_FULL) { - *status = DEVICE_BATTERY_LEVEL_FULL; - } else { - return DEVICE_ERROR_OPERATION_FAILED; - } - - return DEVICE_ERROR_NONE; -} - -int device_battery_level_set_cb(device_battery_level_cb callback, void* user_data) -{ - int err; - - - if (callback == NULL) { - err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, - battery_level_changed_inside_cb); - } else { - - err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, - battery_level_changed_inside_cb, NULL); - } - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - level_changed_callback = callback; - level_changed_callback_user_data = user_data; - - return DEVICE_ERROR_NONE; -} diff --git a/src/mobile/cpu.c b/src/mobile/cpu.c deleted file mode 100644 index 5754026..0000000 --- a/src/mobile/cpu.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * capi-system-device - * Copyright (c) 2012 Samsung Electronics Co., Ltd. - * - * 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. - */ - - -#include -#include -#include -#include -#include "device.h" -#include "device_log.h" - -#define PROC_STAT "/proc/stat" - -#define PROC_CPU_PRESENT "/sys/devices/system/cpu/present" -#define PROC_SCALING_CUR_FREQ "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq" -#define PROC_SCALING_MAX_FREQ "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq" - - -int device_cpu_get_count(int *cpu_cnt) -{ - FILE *fp; - int ret; - int st, ed; - - if (cpu_cnt == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - fp = fopen(PROC_CPU_PRESENT, "r"); - if (!fp) - return DEVICE_ERROR_OPERATION_FAILED; - - ret = fscanf(fp, "%u-%u", &st, &ed); - fclose(fp); - if (ret != 2) - return DEVICE_ERROR_OPERATION_FAILED; - - *cpu_cnt = ed+1; - return DEVICE_ERROR_NONE; -} - -static int _get_systime(device_system_time_s *st) -{ - FILE *fp; - char buf[4096]; - char *s; - - assert(st); - - fp = fopen(PROC_STAT, "r"); - if (!fp) - return -1; - - s = fgets(buf, sizeof(buf), fp); - fclose(fp); - if (!s) - return -1; - - s = strchr(buf, ' '); - if (!s) - return -1; - - s++; - st->user = strtol(s, &s, 10); - st->nice = strtol(s, &s, 10); - st->system = strtol(s, &s, 10); - st->idle = strtol(s, &s, 10); - st->iowait = strtol(s, &s, 10); - st->irq = strtol(s, &s, 10); - st->softirq = strtol(s, &s, 10); - - return 0; -} - -int device_cpu_get_system_time(device_system_time_s *time) -{ - int ret; - device_system_time_s st; - - if (time == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = _get_systime(&st); - if (ret < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - st.total = st.user+st.nice+st.system+st.idle+st.iowait+st.irq+st.softirq; - *time = st; - return DEVICE_ERROR_NONE; -} - -static int _get_uint(const char *path, unsigned int *val) -{ - FILE *fp; - unsigned int num; - int ret; - - assert(path); - assert(val); - - fp = fopen(path, "r"); - if (!fp) - return -1; - - ret = fscanf(fp, "%u", &num); - fclose(fp); - if (ret != 1) - return -1; - - *val = num; - return 0; -} - -int device_cpu_get_current_freq(int cpu, unsigned int *cur_freq) -{ - char path[FILENAME_MAX]; - int ret; - int count; - unsigned int cur; - - if (cur_freq == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = device_cpu_get_count(&count); - if (ret != DEVICE_ERROR_NONE || cpu < 0 || cpu >= count) - return DEVICE_ERROR_INVALID_PARAMETER; - - snprintf(path, sizeof(path), PROC_SCALING_CUR_FREQ, cpu); - ret = _get_uint(path, &cur); - if (ret < 0) - cur = 0; - - *cur_freq = cur; - return DEVICE_ERROR_NONE; -} - -int device_cpu_get_max_freq(int cpu, unsigned int *max_freq) -{ - char path[FILENAME_MAX]; - int ret; - int count; - unsigned int max; - - if (max_freq == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = device_cpu_get_count(&count); - if (ret != DEVICE_ERROR_NONE || cpu < 0 || cpu >= count) - return DEVICE_ERROR_INVALID_PARAMETER; - - snprintf(path, sizeof(path), PROC_SCALING_MAX_FREQ, cpu); - ret = _get_uint(path, &max); - if (ret < 0) - max = 0; - - *max_freq = max; - return DEVICE_ERROR_NONE; -} diff --git a/src/mobile/device.c b/src/mobile/device.c deleted file mode 100644 index d4fb899..0000000 --- a/src/mobile/device.c +++ /dev/null @@ -1,211 +0,0 @@ -/* - * capi-system-device - * Copyright (c) 2012 Samsung Electronics Co., Ltd. - * - * 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. - */ - - -#include -#include -#include "device.h" -#include "device_log.h" - -#define CHECK_ERR(val) \ - do { \ - if (val == DEVMAN_ERROR_NOT_SUPPORTED) \ - return DEVICE_ERROR_NOT_SUPPORTED; \ - else if (val == DEVMAN_ERROR_OPERATION_FAILED) \ - return DEVICE_ERROR_OPERATION_FAILED; \ - } while(0) - -static int _display[] = { - DEV_DISPLAY_0, - DEV_DISPLAY_1, -}; - -int device_get_display_numbers(int* device_number) -{ - if(device_number == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - *device_number = device_get_display_count(); - CHECK_ERR(*device_number); - - return DEVICE_ERROR_NONE; -} - -int device_get_brightness(int disp_idx, int* value) -{ - int val, disp, max_id, ret; - - if(value == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = device_get_display_numbers(&max_id); - if (ret != DEVICE_ERROR_NONE) - return ret; - - if(disp_idx < 0 || disp_idx >= max_id) - return DEVICE_ERROR_INVALID_PARAMETER; - - disp = _display[disp_idx]; - val = device_get_display_brt(disp); - CHECK_ERR(val); - - *value = val; - return DEVICE_ERROR_NONE; -} - -int device_set_brightness(int disp_idx, int new_value) -{ - int max_value, val; - int disp, max_id, ret; - - if(new_value < 0) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = device_get_display_numbers(&max_id); - if (ret != DEVICE_ERROR_NONE) - return ret; - - if(disp_idx < 0 || disp_idx >= max_id) - return DEVICE_ERROR_INVALID_PARAMETER; - - disp = _display[disp_idx]; - ret = device_get_max_brightness(disp, &max_value); - if (ret != DEVICE_ERROR_NONE) - return ret; - - if(new_value > max_value) - return DEVICE_ERROR_INVALID_PARAMETER; - - val = device_set_display_brt(disp, new_value); - CHECK_ERR(val); - - return DEVICE_ERROR_NONE; -} - -int device_get_max_brightness(int disp_idx, int* max_value) -{ - int val, disp, max_id, ret; - - if(max_value == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = device_get_display_numbers(&max_id); - if (ret != DEVICE_ERROR_NONE) - return ret; - - if(disp_idx < 0 || disp_idx >= max_id) - return DEVICE_ERROR_INVALID_PARAMETER; - - disp = _display[disp_idx]; - val = device_get_max_brt(disp); - CHECK_ERR(val); - - *max_value = val; - return DEVICE_ERROR_NONE; -} - -int device_set_brightness_from_settings(int disp_idx) -{ - int max_id, disp, val, ret; - - ret = device_get_display_numbers(&max_id); - if (ret != DEVICE_ERROR_NONE) - return ret; - - if(disp_idx < 0 || disp_idx >= max_id) - return DEVICE_ERROR_INVALID_PARAMETER; - - disp = _display[disp_idx]; - val = device_release_brt_ctrl(disp); - CHECK_ERR(val); - - return DEVICE_ERROR_NONE; -} - -int device_set_brightness_to_settings(int disp_idx, int new_value) -{ - int max_value, val; - int disp, max_id, ret; - - if(new_value < 0) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = device_get_display_numbers(&max_id); - if (ret != DEVICE_ERROR_NONE) - return ret; - - if(disp_idx < 0 || disp_idx >= max_id) - return DEVICE_ERROR_INVALID_PARAMETER; - - disp = _display[disp_idx]; - ret = device_get_max_brightness(disp, &max_value); - if (ret != DEVICE_ERROR_NONE) - return ret; - - if(new_value > max_value) - return DEVICE_ERROR_INVALID_PARAMETER; - - val = device_set_display_brt_with_settings(disp, new_value); - CHECK_ERR(val); - - return DEVICE_ERROR_NONE; -} - -int device_flash_get_brightness(int *brightness) -{ - int value; - - if (brightness == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - value = device_get_led_brt(); - CHECK_ERR(value); - - *brightness = value; - return DEVICE_ERROR_NONE; -} - -int device_flash_set_brightness(int brightness) -{ - int max_value, value, ret; - - ret = device_flash_get_max_brightness(&max_value); - if (ret != DEVICE_ERROR_NONE) - return ret; - - if (brightness < 0 || brightness > max_value) - return DEVICE_ERROR_INVALID_PARAMETER; - - value = device_set_led_brt(brightness); - CHECK_ERR(value); - - return DEVICE_ERROR_NONE; -} - -int device_flash_get_max_brightness(int *max_brightness) -{ - int value; - - if (max_brightness == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - value = device_get_max_led(); - CHECK_ERR(value); - - *max_brightness = value; - return DEVICE_ERROR_NONE; -} diff --git a/src/mobile/memory.c b/src/mobile/memory.c deleted file mode 100644 index 04c0a7d..0000000 --- a/src/mobile/memory.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * capi-system-device - * Copyright (c) 2012 Samsung Electronics Co., Ltd. - * - * 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. - */ - - -#include -#include -#include -#include -#include "device.h" -#include "device_log.h" - -#define PROC_MEMORY "/proc/meminfo" - -enum { - _MI_TOTAL, - _MI_FREE, - _MI_BUF, - _MI_CACHED, - _MI_SWAP, - _MI_SHMEM, - _MI_MAX, -}; - -struct meminfo { - unsigned long l[_MI_MAX]; -}; - -static const char *_mi_str[] = { - [_MI_TOTAL] = "MemTotal", - [_MI_FREE] = "MemFree", - [_MI_BUF] = "Buffers", - [_MI_CACHED] = "Cached", - [_MI_SWAP] = "SwapCached", - [_MI_SHMEM] = "Shmem", -}; - -static inline int _get_idx(const char *name) -{ - int i; - - for (i = 0; i < sizeof(_mi_str)/sizeof(_mi_str[0]); ++i) { - if (name && _mi_str[i] && !strcmp(name, _mi_str[i])) - return i; - } - - return -1; -} - -static int _get_meminfo(struct meminfo *mi) -{ - FILE *fp; - char buf[4096]; - char *s, *name, *num; - int idx; - - assert(mi); - - fp = fopen(PROC_MEMORY, "r"); - if (!fp) - return -1; - - memset(mi, 0, sizeof(*mi)); - - while (!feof(fp)) { - s = fgets(buf, sizeof(buf), fp); - if (!s) - break; - - s = strchr(buf, ':'); - if (!s) - continue; - - *s = '\0'; - name = buf; - - s++; - while (*s == ' ') - s++; - num = s; - - idx = _get_idx(name); - if (idx < 0) - continue; - - mi->l[idx] = strtol(num, NULL, 10); - } - - fclose(fp); - return 0; -} - -int device_memory_get_total(unsigned int *total_mem) -{ - struct meminfo mi; - int ret; - - if (total_mem == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = _get_meminfo(&mi); - if (ret < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - *total_mem = mi.l[_MI_TOTAL]; - return DEVICE_ERROR_NONE; -} - -int device_memory_get_available(unsigned int *avail_mem) -{ - struct meminfo mi; - int ret; - - if (avail_mem == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = _get_meminfo(&mi); - if (ret < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - *avail_mem = mi.l[_MI_FREE] + mi.l[_MI_BUF] + mi.l[_MI_CACHED] + mi.l[_MI_SWAP] - mi.l[_MI_SHMEM]; - return DEVICE_ERROR_NONE; -} diff --git a/src/power.c b/src/power.c new file mode 100644 index 0000000..8fc1831 --- /dev/null +++ b/src/power.c @@ -0,0 +1,217 @@ +/* + * 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. + */ + + +#include +#include +#include +#include + +#include "power.h" +#include "display.h" +#include "common.h" +#include "dbus.h" + +/** + * Parameters for device_power_request_lock() + */ +#define STAY_CUR_STATE 0x1 +#define GOTO_STATE_NOW 0x2 +#define HOLD_KEY_BLOCK 0x4 +#define STANDBY_MODE 0x8 + +/** + * Parameters for device_power_request_unlock() + */ +#define PM_SLEEP_MARGIN 0x0 /**< keep guard time for unlock */ +#define PM_RESET_TIMER 0x1 /**< reset timer for unlock */ +#define PM_KEEP_TIMER 0x2 /**< keep timer for unlock */ + +#define METHOD_LOCK_STATE "lockstate" +#define METHOD_UNLOCK_STATE "unlockstate" +#define METHOD_CHANGE_STATE "changestate" + +#define STR_STAYCURSTATE "staycurstate" +#define STR_GOTOSTATENOW "gotostatenow" + +#define STR_HOLDKEYBLOCK "holdkeyblock" +#define STR_STANDBYMODE "standbymode" +#define STR_NULL "NULL" + +#define STR_SLEEP_MARGIN "sleepmargin" +#define STR_RESET_TIMER "resettimer" +#define STR_KEEP_TIMER "keeptimer" + +#define STR_LCD_OFF "lcdoff" +#define STR_LCD_DIM "lcddim" +#define STR_LCD_ON "lcdon" + +static char *get_state_str(display_state_e state) +{ + switch (state) { + case DISPLAY_STATE_NORMAL: + return STR_LCD_ON; + case DISPLAY_STATE_SCREEN_DIM: + return STR_LCD_DIM; + case DISPLAY_STATE_SCREEN_OFF: + return STR_LCD_OFF; + default: + break; + } + return NULL; +} + +static void lock_cb(void *data, DBusMessage *msg, DBusError *unused) +{ + DBusError err; + int ret, val; + + if (!msg) + return; + + dbus_error_init(&err); + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); + if (!ret) { + _E("no message [%s:%s]", err.name, err.message); + dbus_error_free(&err); + return; + } + + _D("%s-%s : %d", DEVICED_INTERFACE_DISPLAY, METHOD_LOCK_STATE, val); +} + +static int lock_state(display_state_e state, unsigned int flag, int timeout_ms) +{ + char *arr[4]; + char str_timeout[32]; + + arr[0] = get_state_str(state); + if (!arr[0]) + return -EINVAL; + + if (flag & GOTO_STATE_NOW) + arr[1] = STR_GOTOSTATENOW; + else + arr[1] = STR_STAYCURSTATE; + + if (flag & HOLD_KEY_BLOCK) + arr[2] = STR_HOLDKEYBLOCK; + else if (flag & STANDBY_MODE) + arr[2] = STR_STANDBYMODE; + else + arr[2] = STR_NULL; + + snprintf(str_timeout, sizeof(str_timeout), "%d", timeout_ms); + arr[3] = str_timeout; + + return dbus_method_async_with_reply(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_LOCK_STATE, "sssi", arr, lock_cb, -1, NULL); +} + +static void unlock_cb(void *data, DBusMessage *msg, DBusError *unused) +{ + DBusError err; + int ret, val; + + if (!msg) + return; + + dbus_error_init(&err); + ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); + if (!ret) { + _E("no message [%s:%s]", err.name, err.message); + dbus_error_free(&err); + return; + } + + _D("%s-%s : %d", DEVICED_INTERFACE_DISPLAY, METHOD_UNLOCK_STATE, val); +} + +static int unlock_state(display_state_e state, unsigned int flag) +{ + char *arr[2]; + + arr[0] = get_state_str(state); + if (!arr[0]) + return -EINVAL; + + if (flag == PM_SLEEP_MARGIN) + arr[1] = STR_SLEEP_MARGIN; + else if (flag == PM_RESET_TIMER) + arr[1] = STR_RESET_TIMER; + else if (flag == PM_KEEP_TIMER) + arr[1] = STR_KEEP_TIMER; + else + return -EINVAL; + + return dbus_method_async_with_reply(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_UNLOCK_STATE, "ss", arr, unlock_cb, -1, NULL); +} + +int device_power_request_lock(power_lock_e type, int timeout_ms) +{ + int ret; + + if (timeout_ms < 0) + return DEVICE_ERROR_INVALID_PARAMETER; + + if (type == POWER_LOCK_CPU) + ret = lock_state(DISPLAY_STATE_SCREEN_OFF, STAY_CUR_STATE, timeout_ms); + else if (type == POWER_LOCK_DISPLAY) + ret = lock_state(DISPLAY_STATE_NORMAL, STAY_CUR_STATE, timeout_ms); + else if (type == POWER_LOCK_DISPLAY_DIM) + ret = lock_state(DISPLAY_STATE_SCREEN_DIM, STAY_CUR_STATE, timeout_ms); + else + return DEVICE_ERROR_INVALID_PARAMETER; + + if (ret == -ECOMM) + return DEVICE_ERROR_PERMISSION_DENIED; + else if (ret < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + return DEVICE_ERROR_NONE; +} + +int device_power_release_lock(power_lock_e type) +{ + int ret; + + if (type == POWER_LOCK_CPU) + ret = unlock_state(DISPLAY_STATE_SCREEN_OFF, PM_SLEEP_MARGIN); + else if (type == POWER_LOCK_DISPLAY) + ret = unlock_state(DISPLAY_STATE_NORMAL, PM_KEEP_TIMER); + else if (type == POWER_LOCK_DISPLAY_DIM) + ret = unlock_state(DISPLAY_STATE_SCREEN_DIM, PM_KEEP_TIMER); + else + return DEVICE_ERROR_INVALID_PARAMETER; + + if (ret == -ECOMM) + return DEVICE_ERROR_PERMISSION_DENIED; + else if (ret < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + return DEVICE_ERROR_NONE; +} + +int device_power_wakeup(bool dim) +{ + if (dim) + return device_display_change_state(DISPLAY_STATE_SCREEN_DIM); + + return device_display_change_state(DISPLAY_STATE_NORMAL); +} diff --git a/src/wearable/battery.c b/src/wearable/battery.c deleted file mode 100644 index dffc0a7..0000000 --- a/src/wearable/battery.c +++ /dev/null @@ -1,411 +0,0 @@ -/* - * 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. - */ - - -#include -#include -#include -#include -#include -#include "device.h" -#include "device_log.h" - -#define CHECK_ERR(val) \ - do { \ - if (val < 0) { \ - if (errno == ENODEV) \ - return DEVICE_ERROR_NOT_SUPPORTED; \ - return DEVICE_ERROR_OPERATION_FAILED; \ - } \ - } while(0) - -int device_battery_get_percent(int* percent) -{ - if (percent == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - int pct = battery_get_percent(); - CHECK_ERR(pct); - - *percent = pct; - return DEVICE_ERROR_NONE; -} - -int device_battery_get_detail(int* percent) -{ - if (percent == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - int pct = battery_get_percent_raw(); - CHECK_ERR(pct); - - *percent = pct; - return DEVICE_ERROR_NONE; -} - -int device_battery_is_full(bool* full) -{ - if (full == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - int f = battery_is_full(); - CHECK_ERR(f); - - *full = (f == 1) ? true : false; - return DEVICE_ERROR_NONE; -} - -int device_battery_is_charging(bool *charging) -{ - // VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW - int value, err; - - if (charging == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - if (value == 1) { - *charging = true; - } else if (value == 0) { - *charging = false; - } else { - return DEVICE_ERROR_OPERATION_FAILED; - } - - return DEVICE_ERROR_NONE; -} - -static device_battery_cb changed_callback = NULL; -static void* changed_callback_user_data = NULL; - -static void battery_changed_inside_cb(keynode_t* key, void* user_data) -{ - char* keyname = vconf_keynode_get_name(key); - - if (keyname != NULL && changed_callback != NULL && strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_CAPACITY) == 0) { - int percent = 0; - if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &percent) == 0) { - changed_callback(percent, changed_callback_user_data); - } - } -} - -int device_battery_set_cb(device_battery_cb callback, void* user_data) -{ - // VCONFKEY_SYSMAN_BATTERY_CAPACITY - int err; - if (callback == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - changed_callback = callback; - changed_callback_user_data = user_data; - - err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery_changed_inside_cb, NULL); - if (err < 0) - return DEVICE_ERROR_INVALID_PARAMETER; - - return DEVICE_ERROR_NONE; -} - -int device_battery_unset_cb(void) -{ - int err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery_changed_inside_cb); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - changed_callback = NULL; - changed_callback_user_data = NULL; - - return DEVICE_ERROR_NONE; -} - -int device_battery_get_warning_status(device_battery_warn_e *status) -{ - if (status == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - int value, err; - - err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &value); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - if (value == VCONFKEY_SYSMAN_BAT_POWER_OFF) { - *status = DEVICE_BATTERY_WARN_EMPTY; - } else if (value == VCONFKEY_SYSMAN_BAT_CRITICAL_LOW) { - *status = DEVICE_BATTERY_WARN_CRITICAL; - } else if (value == VCONFKEY_SYSMAN_BAT_WARNING_LOW) { - *status = DEVICE_BATTERY_WARN_LOW; - } else if (value == VCONFKEY_SYSMAN_BAT_NORMAL) { - *status = DEVICE_BATTERY_WARN_NORMAL; - } else if (value == VCONFKEY_SYSMAN_BAT_FULL) { - *status = DEVICE_BATTERY_WARN_FULL; - } else { - return DEVICE_ERROR_OPERATION_FAILED; - } - - return DEVICE_ERROR_NONE; -} - -static device_battery_warn_cb warn_changed_callback = NULL; -static void* warn_changed_callback_user_data = NULL; -static device_battery_level_cb level_changed_callback = NULL; -static void* level_changed_callback_user_data = NULL; - -static void battery_warn_changed_inside_cb(keynode_t* key, void* user_data) -{ - char* keyname = vconf_keynode_get_name(key); - - if (keyname != NULL && warn_changed_callback != NULL && strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_STATUS_LOW) == 0) { - int bat_state = 0; - if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state) == 0) { - warn_changed_callback(bat_state-1, warn_changed_callback_user_data); - } - } -} - -static void battery_level_changed_inside_cb(keynode_t* key, void* user_data) -{ - char* keyname; - keyname = vconf_keynode_get_name(key); - - if (keyname != NULL && level_changed_callback != NULL && - strcmp(keyname, VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS) == 0) { - int bat_state = 0; - if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &bat_state) == 0) { - level_changed_callback(bat_state, level_changed_callback_user_data); - } - } -} - -int device_battery_warning_set_cb(device_battery_warn_cb callback, void* user_data) -{ - // VCONFKEY_SYSMAN_BATTERY_STATUS_LOW - int err; - - if (callback == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - warn_changed_callback = callback; - warn_changed_callback_user_data = user_data; - - err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery_warn_changed_inside_cb, NULL); - if (err < 0) - return DEVICE_ERROR_INVALID_PARAMETER; - - return DEVICE_ERROR_NONE; -} - -int device_battery_warning_unset_cb(void) -{ - int err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery_warn_changed_inside_cb); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - warn_changed_callback = NULL; - warn_changed_callback_user_data = NULL; - - return DEVICE_ERROR_NONE; -} - -static device_battery_remaining_time_changed_cb timetofull_changed_cb = NULL; -static device_battery_remaining_time_changed_cb timetoempty_changed_cb = NULL; -static void* timetofull_cb_user_data = NULL; -static void* timetoempty_cb_user_data = NULL; - -static void device_battery_time_timetofull_inside_cb(keynode_t* key, void* user_data) -{ - char* keyname = vconf_keynode_get_name(key); - int time = -1, err= -1; - - if (keyname == NULL) - return; - - if (strcmp(keyname, VCONFKEY_PM_BATTERY_TIMETOFULL) == 0) { - if (timetofull_changed_cb != NULL) { - err = device_battery_get_remaining_time( - DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED, &time); - if ((err == DEVICE_ERROR_NONE) && (time >= 0)) - timetofull_changed_cb(time, timetofull_cb_user_data); - } - } -} - -static void device_battery_time_timetoempty_inside_cb(keynode_t* key, void* user_data) -{ - char* keyname = vconf_keynode_get_name(key); - int time = -1, err= -1; - - if (keyname == NULL) - return; - - if (strcmp(keyname, VCONFKEY_PM_BATTERY_TIMETOEMPTY) == 0) { - if (timetoempty_changed_cb != NULL) { - err = device_battery_get_remaining_time( - DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED, &time); - if ((err == DEVICE_ERROR_NONE) && (time >= 0)) - timetoempty_changed_cb(time, timetoempty_cb_user_data); - } - } -} - -int device_battery_get_remaining_time(device_battery_remaining_time_type_e type, int* time) -{ - bool charging = false; - int err = -1; - - err = device_battery_is_charging(&charging); - if (err != DEVICE_ERROR_NONE) - return DEVICE_ERROR_OPERATION_FAILED; - - switch(type) { - case DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED: - if (charging == false) { - return DEVICE_ERROR_OPERATION_FAILED; - } else { - err = vconf_get_int(VCONFKEY_PM_BATTERY_TIMETOFULL, time); - if (err < 0 || *time < 0) { - return DEVICE_ERROR_OPERATION_FAILED; - } - } - break; - case DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED: - if (charging == true) { - return DEVICE_ERROR_OPERATION_FAILED; - } else { - err = vconf_get_int(VCONFKEY_PM_BATTERY_TIMETOEMPTY, time); - if (err < 0 || *time < 0) { - return DEVICE_ERROR_OPERATION_FAILED; - } - } - break; - default: - return DEVICE_ERROR_INVALID_PARAMETER; - } - return DEVICE_ERROR_NONE; -} - -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) -{ - int err; - - if (callback == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - switch(type) { - case DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED: - timetofull_changed_cb = callback; - timetofull_cb_user_data = user_data; - err = vconf_notify_key_changed(VCONFKEY_PM_BATTERY_TIMETOFULL, - device_battery_time_timetofull_inside_cb, NULL); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - break; - case DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED: - timetoempty_changed_cb = callback; - timetoempty_cb_user_data = user_data; - err = vconf_notify_key_changed(VCONFKEY_PM_BATTERY_TIMETOEMPTY, - device_battery_time_timetoempty_inside_cb, NULL); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - break; - default: - return DEVICE_ERROR_INVALID_PARAMETER; - } - return DEVICE_ERROR_NONE; -} - -int device_battery_unset_remaining_time_changed_cb(device_battery_remaining_time_type_e type) -{ - int err; - - switch(type) { - case DEVICE_BATTERY_REMAINING_TIME_TO_FULLY_CHARGED: - err = vconf_ignore_key_changed(VCONFKEY_PM_BATTERY_TIMETOFULL, - device_battery_time_timetofull_inside_cb); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - timetofull_changed_cb = NULL; - timetofull_cb_user_data = NULL; - break; - case DEVICE_BATTERY_REMAINING_TIME_TO_DISCHARGED: - err = vconf_ignore_key_changed(VCONFKEY_PM_BATTERY_TIMETOEMPTY, - device_battery_time_timetoempty_inside_cb); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - timetoempty_changed_cb = NULL; - timetoempty_cb_user_data = NULL; - break; - default: - return DEVICE_ERROR_INVALID_PARAMETER; - } - return DEVICE_ERROR_NONE; -} - -int device_battery_get_level_status(device_battery_level_e *status) -{ - int value, err; - - if (status == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - - err = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &value); - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - if (value == VCONFKEY_SYSMAN_BAT_LEVEL_EMPTY) { - *status = DEVICE_BATTERY_LEVEL_EMPTY; - } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_CRITICAL) { - *status = DEVICE_BATTERY_LEVEL_CRITICAL; - } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_LOW) { - *status = DEVICE_BATTERY_LEVEL_LOW; - } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_HIGH) { - *status = DEVICE_BATTERY_LEVEL_HIGH; - } else if (value == VCONFKEY_SYSMAN_BAT_LEVEL_FULL) { - *status = DEVICE_BATTERY_LEVEL_FULL; - } else { - return DEVICE_ERROR_OPERATION_FAILED; - } - - return DEVICE_ERROR_NONE; -} - -int device_battery_level_set_cb(device_battery_level_cb callback, void* user_data) -{ - int err; - - - if (callback == NULL) { - err = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, - battery_level_changed_inside_cb); - } else { - - err = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, - battery_level_changed_inside_cb, NULL); - } - if (err < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - level_changed_callback = callback; - level_changed_callback_user_data = user_data; - - return DEVICE_ERROR_NONE; -} diff --git a/src/wearable/cpu.c b/src/wearable/cpu.c deleted file mode 100644 index d013992..0000000 --- a/src/wearable/cpu.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * 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. - */ - - - -#include -#include -#include -#include -#include "device.h" -#include "device_log.h" - -#define PROC_STAT "/proc/stat" - -#define PROC_CPU_PRESENT "/sys/devices/system/cpu/present" -#define PROC_SCALING_CUR_FREQ "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq" -#define PROC_SCALING_MAX_FREQ "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq" - - -int device_cpu_get_count(int *cpu_cnt) -{ - FILE *fp; - int ret; - int st, ed; - - if (cpu_cnt == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - fp = fopen(PROC_CPU_PRESENT, "r"); - if (!fp) - return DEVICE_ERROR_OPERATION_FAILED; - - ret = fscanf(fp, "%u-%u", &st, &ed); - fclose(fp); - if (ret != 2) - return DEVICE_ERROR_OPERATION_FAILED; - - *cpu_cnt = ed+1; - return DEVICE_ERROR_NONE; -} - -static int _get_systime(device_system_time_s *st) -{ - FILE *fp; - char buf[4096]; - char *s; - - assert(st); - - fp = fopen(PROC_STAT, "r"); - if (!fp) - return -1; - - s = fgets(buf, sizeof(buf), fp); - fclose(fp); - if (!s) - return -1; - - s = strchr(buf, ' '); - if (!s) - return -1; - - s++; - st->user = strtol(s, &s, 10); - st->nice = strtol(s, &s, 10); - st->system = strtol(s, &s, 10); - st->idle = strtol(s, &s, 10); - st->iowait = strtol(s, &s, 10); - st->irq = strtol(s, &s, 10); - st->softirq = strtol(s, &s, 10); - - return 0; -} - -int device_cpu_get_system_time(device_system_time_s *time) -{ - int ret; - device_system_time_s st; - - if (time == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = _get_systime(&st); - if (ret < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - st.total = st.user+st.nice+st.system+st.idle+st.iowait+st.irq+st.softirq; - *time = st; - return DEVICE_ERROR_NONE; -} - -static int _get_uint(const char *path, unsigned int *val) -{ - FILE *fp; - unsigned int num; - int ret; - - assert(path); - assert(val); - - fp = fopen(path, "r"); - if (!fp) - return -1; - - ret = fscanf(fp, "%u", &num); - fclose(fp); - if (ret != 1) - return -1; - - *val = num; - return 0; -} - -int device_cpu_get_current_freq(int cpu, unsigned int *cur_freq) -{ - char path[FILENAME_MAX]; - int ret; - int count; - unsigned int cur; - - if (cur_freq == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = device_cpu_get_count(&count); - if (ret != DEVICE_ERROR_NONE || cpu < 0 || cpu >= count) - return DEVICE_ERROR_INVALID_PARAMETER; - - snprintf(path, sizeof(path), PROC_SCALING_CUR_FREQ, cpu); - ret = _get_uint(path, &cur); - if (ret < 0) - cur = 0; - - *cur_freq = cur; - return DEVICE_ERROR_NONE; -} - -int device_cpu_get_max_freq(int cpu, unsigned int *max_freq) -{ - char path[FILENAME_MAX]; - int ret; - int count; - unsigned int max; - - if (max_freq == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = device_cpu_get_count(&count); - if (ret != DEVICE_ERROR_NONE || cpu < 0 || cpu >= count) - return DEVICE_ERROR_INVALID_PARAMETER; - - snprintf(path, sizeof(path), PROC_SCALING_MAX_FREQ, cpu); - ret = _get_uint(path, &max); - if (ret < 0) - max = 0; - - *max_freq = max; - return DEVICE_ERROR_NONE; -} diff --git a/src/wearable/device.c b/src/wearable/device.c deleted file mode 100644 index a332d47..0000000 --- a/src/wearable/device.c +++ /dev/null @@ -1,201 +0,0 @@ -/* - * 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. - */ - - -#include -#include -#include -#include -#include "device.h" -#include "device_log.h" - -#define CHECK_ERR(val) \ - do { \ - if (val < 0) { \ - if (errno == ENODEV) \ - return DEVICE_ERROR_NOT_SUPPORTED; \ - return DEVICE_ERROR_OPERATION_FAILED; \ - } \ - } while(0) - -int device_get_display_numbers(int* device_number) -{ - if(device_number == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - *device_number = display_get_count(); - CHECK_ERR(*device_number); - - return DEVICE_ERROR_NONE; -} - -int device_get_brightness(int disp_idx, int* value) -{ - int val, max_id, ret; - - if(value == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = device_get_display_numbers(&max_id); - if (ret != DEVICE_ERROR_NONE) - return ret; - - if(disp_idx < 0 || disp_idx >= max_id) - return DEVICE_ERROR_INVALID_PARAMETER; - - val = display_get_brightness(); - CHECK_ERR(val); - - *value = val; - return DEVICE_ERROR_NONE; -} - -int device_set_brightness(int disp_idx, int new_value) -{ - int max_value, val, max_id, ret; - - if(new_value < 0) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = device_get_display_numbers(&max_id); - if (ret != DEVICE_ERROR_NONE) - return ret; - - if(disp_idx < 0 || disp_idx >= max_id) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = device_get_max_brightness(disp_idx, &max_value); - if (ret != DEVICE_ERROR_NONE) - return ret; - - if(new_value > max_value) - return DEVICE_ERROR_INVALID_PARAMETER; - - val = display_set_brightness(new_value); - CHECK_ERR(val); - - return DEVICE_ERROR_NONE; -} - -int device_get_max_brightness(int disp_idx, int* max_value) -{ - int val, max_id, ret; - - if(max_value == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = device_get_display_numbers(&max_id); - if (ret != DEVICE_ERROR_NONE) - return ret; - - if(disp_idx < 0 || disp_idx >= max_id) - return DEVICE_ERROR_INVALID_PARAMETER; - - val = display_get_max_brightness(); - CHECK_ERR(val); - - *max_value = val; - return DEVICE_ERROR_NONE; -} - -int device_set_brightness_from_settings(int disp_idx) -{ - int max_id, val, ret; - - ret = device_get_display_numbers(&max_id); - if (ret != DEVICE_ERROR_NONE) - return ret; - - if(disp_idx < 0 || disp_idx >= max_id) - return DEVICE_ERROR_INVALID_PARAMETER; - - val = display_release_brightness(); - CHECK_ERR(val); - - return DEVICE_ERROR_NONE; -} - -int device_set_brightness_to_settings(int disp_idx, int new_value) -{ - int max_value, val, max_id, ret; - - if(new_value < 0) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = device_get_display_numbers(&max_id); - if (ret != DEVICE_ERROR_NONE) - return ret; - - if(disp_idx < 0 || disp_idx >= max_id) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = device_get_max_brightness(disp_idx, &max_value); - if (ret != DEVICE_ERROR_NONE) - return ret; - - if(new_value > max_value) - return DEVICE_ERROR_INVALID_PARAMETER; - - val = display_set_brightness_with_setting(new_value); - CHECK_ERR(val); - - return DEVICE_ERROR_NONE; -} - -int device_flash_get_brightness(int *brightness) -{ - int value; - - if (brightness == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - value = led_get_brightness(); - CHECK_ERR(value); - - *brightness = value; - return DEVICE_ERROR_NONE; -} - -int device_flash_set_brightness(int brightness) -{ - int max_value, value, ret; - - ret = device_flash_get_max_brightness(&max_value); - if (ret != DEVICE_ERROR_NONE) - return ret; - - if (brightness < 0 || brightness > max_value) - return DEVICE_ERROR_INVALID_PARAMETER; - - value = led_set_brightness(brightness); - CHECK_ERR(value); - - return DEVICE_ERROR_NONE; -} - -int device_flash_get_max_brightness(int *max_brightness) -{ - int value; - - if (max_brightness == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - value = led_get_max_brightness(); - CHECK_ERR(value); - - *max_brightness = value; - return DEVICE_ERROR_NONE; -} diff --git a/src/wearable/memory.c b/src/wearable/memory.c deleted file mode 100644 index 8e71a23..0000000 --- a/src/wearable/memory.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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. - */ - - - -#include -#include -#include -#include -#include "device.h" -#include "device_log.h" - -#define PROC_MEMORY "/proc/meminfo" - -enum { - _MI_TOTAL, - _MI_FREE, - _MI_BUF, - _MI_CACHED, - _MI_SWAP, - _MI_SHMEM, - _MI_MAX, -}; - -struct meminfo { - unsigned long l[_MI_MAX]; -}; - -static const char *_mi_str[] = { - [_MI_TOTAL] = "MemTotal", - [_MI_FREE] = "MemFree", - [_MI_BUF] = "Buffers", - [_MI_CACHED] = "Cached", - [_MI_SWAP] = "SwapCached", - [_MI_SHMEM] = "Shmem", -}; - -static inline int _get_idx(const char *name) -{ - int i; - - for (i = 0; i < sizeof(_mi_str)/sizeof(_mi_str[0]); ++i) { - if (name && _mi_str[i] && !strcmp(name, _mi_str[i])) - return i; - } - - return -1; -} - -static int _get_meminfo(struct meminfo *mi) -{ - FILE *fp; - char buf[4096]; - char *s, *name, *num; - int idx; - - assert(mi); - - fp = fopen(PROC_MEMORY, "r"); - if (!fp) - return -1; - - memset(mi, 0, sizeof(*mi)); - - while (!feof(fp)) { - s = fgets(buf, sizeof(buf), fp); - if (!s) - break; - - s = strchr(buf, ':'); - if (!s) - continue; - - *s = '\0'; - name = buf; - - s++; - while (*s == ' ') - s++; - num = s; - - idx = _get_idx(name); - if (idx < 0) - continue; - - mi->l[idx] = strtol(num, NULL, 10); - } - - fclose(fp); - return 0; -} - -int device_memory_get_total(unsigned int *total_mem) -{ - struct meminfo mi; - int ret; - - if (total_mem == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = _get_meminfo(&mi); - if (ret < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - *total_mem = mi.l[_MI_TOTAL]; - return DEVICE_ERROR_NONE; -} - -int device_memory_get_available(unsigned int *avail_mem) -{ - struct meminfo mi; - int ret; - - if (avail_mem == NULL) - return DEVICE_ERROR_INVALID_PARAMETER; - - ret = _get_meminfo(&mi); - if (ret < 0) - return DEVICE_ERROR_OPERATION_FAILED; - - *avail_mem = mi.l[_MI_FREE] + mi.l[_MI_BUF] + mi.l[_MI_CACHED] + mi.l[_MI_SWAP] - mi.l[_MI_SHMEM]; - return DEVICE_ERROR_NONE; -} -- cgit v1.2.3