2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FSys_BatteryImpl.cpp
20 * @brief This is the implementation file for _BatteryImpl class.
24 #include <runtime_info.h>
26 #include <FSysDeviceManager.h>
28 #include <FBaseSysLog.h>
29 #include <FBase_NativeError.h>
30 #include <FSys_BatteryImpl.h>
31 #include <FSys_Types.h>
33 #include "FSys_SystemInfoImpl.h"
35 using namespace Tizen::Base;
37 namespace Tizen { namespace System
40 _BatteryImpl::_BatteryImpl(void)
44 _BatteryImpl::~_BatteryImpl(void)
49 _BatteryImpl::IsCharging(bool& charging)
51 bool chargeState = false;
53 ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_BATTERY_IS_CHARGING, &chargeState);
54 SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "[E_SYSTEM] runtime_info_get_value_bool returns %d.", ret);
55 charging = chargeState;
60 _BatteryImpl::GetCurrentLevelInPercentage(int& level)
65 ret = device_battery_get_percent(&batteryLevel);
66 SysTryReturnResult(NID_SYS, ret == DEVICE_ERROR_NONE, E_SYSTEM, "Failed to get the device battery percentage");
74 _BatteryImpl::GetCurrentLevel(BatteryLevel& level)
78 device_battery_warn_e batteryStatus;
80 result r = device_battery_get_percent(&batteryLevel);
81 SysTryReturnResult(NID_SYS, !IsFailed(r), r, "Failed to get the device battery percentage");
83 if (batteryLevel == _BATTERY_LEVEL_FULL)
89 ret = device_battery_get_warning_status(&batteryStatus);
91 switch (batteryStatus)
93 case DEVICE_BATTERY_WARN_NORMAL:
96 case DEVICE_BATTERY_WARN_LOW:
99 case DEVICE_BATTERY_WARN_CRITICAL:
100 level = BATTERY_CRITICAL;
102 case DEVICE_BATTERY_WARN_EMPTY:
103 level = BATTERY_EMPTY;
106 SysLogException(NID_SYS, E_SYSTEM, "There is a system error occured.");