diff options
-rw-r--r-- | TC/testcase/utc_system_device_battery.c | 31 | ||||
-rw-r--r-- | TC/testcase/utc_system_device_brightness.c | 31 | ||||
-rwxr-xr-x | include/device.h | 51 | ||||
-rw-r--r-- | packaging/capi-system-device.spec | 2 | ||||
-rw-r--r-- | src/battery.c | 67 |
5 files changed, 149 insertions, 33 deletions
diff --git a/TC/testcase/utc_system_device_battery.c b/TC/testcase/utc_system_device_battery.c index b92fb59..a93ba00 100644 --- a/TC/testcase/utc_system_device_battery.c +++ b/TC/testcase/utc_system_device_battery.c @@ -1,21 +1,20 @@ /* - * 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. + * + * 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 <tet_api.h> #include <device.h> diff --git a/TC/testcase/utc_system_device_brightness.c b/TC/testcase/utc_system_device_brightness.c index 61ed563..3914e9f 100644 --- a/TC/testcase/utc_system_device_brightness.c +++ b/TC/testcase/utc_system_device_brightness.c @@ -1,21 +1,20 @@ /* - * 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. + * + * 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 <tet_api.h> #include <device.h> #include <power.h> diff --git a/include/device.h b/include/device.h index f53c087..93fabd3 100755 --- a/include/device.h +++ b/include/device.h @@ -66,6 +66,19 @@ typedef enum } device_battery_remaining_time_type_e; /** + * @brief Enumerations of the battery level status + */ +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 Structure of the time information system spent, measured in units of USER_HZ */ typedef struct { @@ -116,6 +129,15 @@ typedef void (*device_battery_warn_cb)(device_battery_warn_e status, void *user_ typedef void (*device_battery_remaining_time_changed_cb)(int time, void* user_data); /** + * @brief Called when an battery level changed + * + * @param[in] status The remaining battery level (empty[0~1] critical[2~5] low[6~15] high[16~94] full[95~100]) + * @param[in] user_data The user data passed from the callback registration function + * + */ +typedef void (*device_battery_level_cb)(device_battery_level_e status, void *user_data); + +/** * @brief Gets the battery warning status. * * @param[out] status The battery warning status. @@ -293,6 +315,35 @@ int device_battery_set_remaining_time_changed_cb( int device_battery_unset_remaining_time_changed_cb(device_battery_remaining_time_type_e type); /** + * @brief Gets the battery level status. + * + * @param[out] status The battery level status. + * @return 0 on success, otherwise a negative error value. + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * + * @see device_battery_level_e + * @see device_battery_level_set_cb() + */ +int device_battery_get_level_status(device_battery_level_e *status); + +/** + * @brief Set/Unset callback to be observing battery level. + * + * @param[in] callback The callback function to set, if you input NULL, observing is disabled + * @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_OPERATION_FAILED Operation failed + * + * @see device_battery_level_e + * @see device_battery_get_level_status() + */ +int device_battery_level_set_cb(device_battery_level_cb callback, void* user_data); + +/** * @brief Gets the number of display devices. * * @return The number of display devices that the device provides. diff --git a/packaging/capi-system-device.spec b/packaging/capi-system-device.spec index 9a443e4..ae79227 100644 --- a/packaging/capi-system-device.spec +++ b/packaging/capi-system-device.spec @@ -1,7 +1,7 @@ Name: capi-system-device Summary: A Device library in TIZEN C API Version: 0.1.0 -Release: 18 +Release: 19 Group: System/Libraries License: Apache License, Version 2.0 Source0: %{name}-%{version}.tar.gz diff --git a/src/battery.c b/src/battery.c index 61cf854..555cecc 100644 --- a/src/battery.c +++ b/src/battery.c @@ -164,6 +164,8 @@ int device_battery_get_warning_status(device_battery_warn_e *status) 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) { @@ -177,6 +179,20 @@ static void battery_warn_changed_inside_cb(keynode_t* key, void* 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 @@ -341,3 +357,54 @@ int device_battery_unset_remaining_time_changed_cb(device_battery_remaining_time } 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; +} |