Fix re-register issue on PowerManager
authorJoohyun Kim <joohyune.kim@samsung.com>
Wed, 3 Jul 2013 12:22:21 +0000 (21:22 +0900)
committerJoohyun Kim <joohyune.kim@samsung.com>
Wed, 3 Jul 2013 12:22:21 +0000 (21:22 +0900)
Change-Id: Id6c4a7443880f20ff388eb98431bdecd396558e1
Signed-off-by: Joohyun Kim <joohyune.kim@samsung.com>
src/system/FSys_PowerManagerImpl.cpp

index 54874e1..f96379a 100644 (file)
@@ -444,7 +444,7 @@ _PowerManagerImpl::KeepCpuAwake(bool enable)
 result
 _PowerManagerImpl::InitBatteryEvent(void)
 {
-       int ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, BatteryLevelVConfCallback, null); 
+       int ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, BatteryLevelVConfCallback, null);
        SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It failed to set the battery event");
 
        return E_SUCCESS;
@@ -655,10 +655,15 @@ _PowerManagerImpl::AddScreenEventListener(IScreenEventListener& listener, bool i
                pSceenEventList->Construct();
                int errorCode = 0;
                errorCode = vconf_notify_key_changed(VCONFKEY_PM_CURRENT_BRIGHTNESS, ScreenEventVConfCallback, null);
-               SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It failed to add ScreenEvent listener.");
+               SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It failed to add ScreenEvent listener on VCONFKEY_PM_CURRENT_BRIGHTNESS.");
 
                errorCode = power_set_changed_cb(PowerChangedCallback, null);
-               SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It failed to add ScreenEvent listener.");
+               if(errorCode != POWER_ERROR_NONE)
+               {
+                       SysLogException(NID_SYS, E_SYSTEM, "It is failed to register power callback. So unregister VCONFKEY_PM_CURRENT_BRIGHTNESS also.");
+                       vconf_ignore_key_changed(VCONFKEY_PM_CURRENT_BRIGHTNESS, ScreenEventVConfCallback);
+               }
+               SysTryReturnResult(NID_SYS, errorCode == POWER_ERROR_NONE, E_SYSTEM, "It failed to add ScreenEvent listener.");
                __pSceenEventList = pSceenEventList.release();
                SysLog(NID_SYS,"It successed to register power_set_changed_cb");
        }
@@ -683,13 +688,8 @@ _PowerManagerImpl::RemoveScreenEventListener(IScreenEventListener& listener)
        SysTryReturnResult(NID_SYS,__pSceenEventList != null, E_OBJ_NOT_FOUND, "IScreenEventListener list is empty");
 
        r = __pSceenEventList->Remove(&listener);
-
-       if (__pSceenEventList->GetCount() == 0)
-       {
-               delete __pSceenEventList;
-               __pSceenEventList = null;
-       }
-       return r;
+       SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_OBJ_NOT_FOUND, "listener is not exist.");
+       return E_SUCCESS;
 }
 
 
@@ -715,18 +715,18 @@ _PowerManagerImpl::AddChargingEventListener(IChargingEventListener& listener, bo
 
         if (__pChargingEventList == null)
         {
-                __pChargingEventList = new ArrayListT<IChargingEventListener*>;
-                SysTryReturnResult(NID_SYS, __pChargingEventList, E_SYSTEM, "Memory allocation failed");
-                __pChargingEventList->Construct();
-                int errorCode = 0;
-               errorCode = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_BATTERY_IS_CHARGING, RuntimeInfoChangedCallback, null);
-               if (errorCode != 0)
-                {
-                        SysLog(NID_SYS, "It failed to register battery charging  event");
+                int errorCode = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_BATTERY_IS_CHARGING, RuntimeInfoChangedCallback, null);
+               SysTryReturnResult(NID_SYS, errorCode == RUNTIME_INFO_ERROR_NONE, E_SYSTEM, "It is failed to register RUNTIME_INFO_KEY_BATTERY_IS_CHARGING.");
+
+               __pChargingEventList = new ArrayListT<IChargingEventListener*>;
+               SysTryReturnResult(NID_SYS, __pChargingEventList, E_SYSTEM, "Memory allocation failed");
+               r = __pChargingEventList->Construct();
+               if(r != E_SUCCESS)
+               {
                        delete __pChargingEventList;
                        __pChargingEventList = null;
-                       return E_SYSTEM;
-                }
+               }
+               SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to construct charging event list.");
         }
 
        if (isSet == false || __pChargingEventList->GetCount() == 0)
@@ -747,15 +747,10 @@ _PowerManagerImpl::RemoveChargingEventListener(IChargingEventListener& listener)
         result r = E_SUCCESS;
 
         SysTryReturnResult(NID_SYS,__pChargingEventList != null, E_OBJ_NOT_FOUND, "__pChargingEventList list is empty");
-
         r = __pChargingEventList->Remove(&listener);
+       SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_OBJ_NOT_FOUND, "listener is not exist.");
 
-        if (__pChargingEventList->GetCount() == 0)
-        {
-                delete __pChargingEventList;
-                __pChargingEventList = null;
-        }
-        return r;
+        return E_SUCCESS;
 }
 
 result
@@ -959,12 +954,7 @@ _PowerManagerImpl::RemoveBootEventListener(IBootEventListener& listener)
        SysTryReturnResult(NID_SYS,__pBootEventList != null, E_OBJ_NOT_FOUND, "IBootEventListener list is empty");
 
        r = __pBootEventList->Remove(&listener);
-
-       if (__pBootEventList->GetCount() == 0)
-       {
-               delete __pBootEventList;
-               __pBootEventList = null;
-       }
+       SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_OBJ_NOT_FOUND, "IBootEventListener list is empty");
 
        return E_SUCCESS;
 }