Revert "Move power manager to system server so."
authorHokwon Song <hokwon.song@samsung.com>
Tue, 25 Jun 2013 10:33:32 +0000 (10:33 +0000)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Tue, 25 Jun 2013 10:33:32 +0000 (10:33 +0000)
This reverts commit 10eb46d57d636609c79dae60fdaeadf58873808d

Change-Id: I1ca5d05d448d67a4d86ed6513369011982fd4127

CMakeLists.txt
inc/FSys_SystemService.h
src/FSys_SystemService.cpp
src/system/FSys_PowerManager.cpp [new file with mode: 0644]
src/system/FSys_PowerManager.h [new file with mode: 0644]

index fad2c9e..92850ce 100644 (file)
@@ -78,6 +78,7 @@ SET (${this_target}_SOURCE_FILES
        src/system/FSys_DeviceId.cpp
        src/system/FSys_SystemInfo.cpp
        src/system/FSys_RuntimeInfo.cpp
+       src/system/FSys_PowerManager.cpp
        src/FSys_SettingService.cpp
        src/setting/FSys_SettingApplicationProvider.cpp
        src/setting/FSys_Icu.cpp
index 278d399..38ce3ba 100644 (file)
@@ -24,6 +24,7 @@
 #include <FBase.h>
 
 #include "FApp_ICommunicationRequestListener.h"
+#include "FSys_PowerManager.h"
 
 #include "FSys_SystemInfo.h"
 #include "FSys_RuntimeInfo.h"
@@ -54,6 +55,7 @@ public:
 
 private:
        Tizen::App::_CommunicationDispatcher*   __pCommunicationDispatcher;
+       Tizen::System::_PowerManager*           __pPowerManager;
        Tizen::System::_SystemInfo              __systemInfo;
        Tizen::System::_RuntimeInfo             __runtimeInfo;
        static _SystemService*                  __pSystemService;
index a3001ba..7158b3d 100644 (file)
@@ -75,6 +75,7 @@ Tizen::System::_SystemService* Tizen::System::_SystemService::__pSystemService =
 _SystemService::_SystemService()
        : _ICommunicationRequestListener()
        , __pCommunicationDispatcher(null)
+       , __pPowerManager(null)
 {
        result r = E_SUCCESS;
        _AppManagerImpl* pAppManagerImpl = null;
@@ -85,6 +86,9 @@ _SystemService::_SystemService()
        r = __pCommunicationDispatcher->AddCommunicationEventListener(*this);
        SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "It is failed to add event listener");
 
+       __pPowerManager = _PowerManager::GetInstance();
+       SysTryCatch(NID_SYS, __pPowerManager != null, r = E_SYSTEM, E_SYSTEM, "_pPowerManager initiate is failed");
+
        pAppManagerImpl = _AppManagerImpl::GetInstance();
        SysTryCatch(NID_SYS, pAppManagerImpl != null, r = E_SYSTEM, E_SYSTEM, "It is failed to get _AppManagerImpl class.");
 
@@ -140,6 +144,15 @@ _SystemService::GetId(void)
 void
 _SystemService::OnActiveAppChanged(const AppId& appId)
 {
+       AppId smallAppId;
+
+       result r = E_SUCCESS;
+       r = appId.SubString(0, 10, smallAppId);
+
+       if(__pPowerManager != null && r == E_SUCCESS)
+       {
+               __pPowerManager->OnActiveAppChanged(smallAppId);
+       }
 }
 
 void
@@ -261,6 +274,14 @@ _SystemService::OnRequestOccured(AppId appId, int pid, ArrayList* request, Array
                        }
                }
        }
+       else if(command->Contains(_SYSTEM_COMMAND_POWER) == true)
+       {
+               if(__pPowerManager != null)
+               {
+                       __pPowerManager->OnRequestOccured(appId, request, response);
+                       return;
+               }
+       }
        else if(*command == _SYSTEM_COMMAND_CHANGE_TIME)
        {
                SysLog(NID_SYS, "Change system time");
@@ -354,5 +375,9 @@ void
 _SystemService::OnApplicationTerminated(const AppId& appId, int pid)
 {
        SysLog(NID_SYS, "Application (%ls) is terminated.", appId.GetPointer());
+       if(__pPowerManager != null)
+       {
+               __pPowerManager->OnApplicationTerminated(appId);
+       }
 }
 
diff --git a/src/system/FSys_PowerManager.cpp b/src/system/FSys_PowerManager.cpp
new file mode 100644 (file)
index 0000000..f89d8db
--- /dev/null
@@ -0,0 +1,201 @@
+//
+// 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.
+//
+
+/**
+ * @file               FSys_PowerManager.cpp
+ * @brief              This is the implementation file for _PowerManager class.
+ */
+#include <unique_ptr.h>
+#include <new>
+
+#include <device.h>
+#include <system_info.h>
+
+#include <FBaseSysLog.h>
+
+#include "FSys_PowerManager.h"
+
+using namespace std;
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::Io;
+
+namespace {
+       static const wchar_t* _POWER_BRIGHTNESS_CHANGE = L"osp.system.command.power.change.brightness";
+       static const wchar_t* _POWER_BRIGHTNESS_RESTORE = L"osp.system.command.power.restore.brightness";
+       static const int _POWER_COMMAND_ID = 1;
+       static const wchar_t* _POWER_OK = L"osp.system.result.ok";
+       static const wchar_t* _POWER_ERROR = L"osp.system.result.error";
+}
+
+namespace Tizen { namespace System
+{
+
+_PowerManager* _PowerManager::__pPowerManager = null;
+
+_PowerManager::_PowerManager()
+{
+       __appBrightnessList.Construct();
+}
+
+_PowerManager::~_PowerManager()
+{
+       __appBrightnessList.RemoveAll(true);
+}
+
+_PowerManager*
+_PowerManager::GetInstance()
+{
+
+       if(__pPowerManager == null)
+       {
+               __pPowerManager = new (std::nothrow) _PowerManager();
+       }
+
+       return __pPowerManager;
+}
+
+result
+_PowerManager::ChangeBrightness(void)
+{
+
+       int ret = DEVICE_ERROR_NONE;
+       result r = E_OBJ_NOT_FOUND;
+
+       SysLog(NID_SYS, "Current Active App is [%ls]", __activeAppId.GetPointer());
+
+       if(__appBrightnessList.GetCount() > 0)
+       {
+               Integer* brightness = (Integer*)__appBrightnessList.GetValue(__activeAppId);
+
+               if(brightness != null)
+               {
+                       SysLog(NID_SYS, "Brightness is [%d]", brightness->ToInt());
+                       ret = device_set_brightness(0, brightness->ToInt());
+                       if(ret == DEVICE_ERROR_NONE)
+                       {
+                               r = E_SUCCESS;
+                       }
+                       else
+                       {
+                               SysLogException(NID_SYS, E_SYSTEM, "It is failed to change brightness.");
+                               r = E_SYSTEM;
+                       }
+               }
+       }
+
+       if(r == E_OBJ_NOT_FOUND)
+       {
+               SysLog(NID_SYS, "Current Active App does not have brightness.");
+               ret = device_set_brightness_from_settings(0);
+               r = E_SUCCESS;
+       }
+
+       return r;
+}
+
+result
+_PowerManager::OnActiveAppChanged(const AppId& appId)
+{
+       result r = E_SUCCESS;
+
+       if(__activeAppId != appId)
+       {
+               __activeAppId = appId;
+               r = ChangeBrightness();
+       }
+       else
+       {
+               SysLog(NID_SYS, "Current App[%ls] is already a");
+       }
+
+       return r;
+}
+
+result
+_PowerManager::OnApplicationTerminated(const AppId& appId)
+{
+       result r = E_SUCCESS;
+       String requiredAppId;
+       appId.SubString(0, 10, requiredAppId);
+
+       __appBrightnessList.Remove(requiredAppId, true);
+       r = ChangeBrightness();
+
+       return r;
+}
+
+result
+_PowerManager::OnRequestOccured(AppId appId, ArrayList* request, ArrayList* response)
+{
+       result r = E_SUCCESS;
+
+       String* command = (String*)request->GetAt(_POWER_COMMAND_ID);
+
+       SysTryCatch(NID_SYS, command != null, r = E_SYSTEM, r, "command is empty.");
+
+       if(*command == _POWER_BRIGHTNESS_CHANGE)
+       {
+               SysTryCatch(NID_SYS, __activeAppId == appId, r = E_SUCCESS, r, "It is not active application[%ls]. Current Active App is [%ls].", appId.GetPointer(), __activeAppId.GetPointer());
+               int brightness = 0;
+               String* brightnessBuffer = (String*)request->GetAt(_POWER_COMMAND_ID + 1);
+               Integer::Parse(*brightnessBuffer, brightness);
+
+               __appBrightnessList.Remove(appId, true);
+
+               unique_ptr<Integer> pBrightness(new (std::nothrow) Integer(brightness));
+               unique_ptr<String> pAppId(new (std::nothrow) String(appId));
+
+               r = __appBrightnessList.Add(*pAppId, *pBrightness);
+               SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to add requested App Id(%ls) and Brightness(%d) on the managed app list.", pAppId->GetPointer(), pBrightness->ToInt());
+               pAppId.release();
+               pBrightness.release();
+               r = ChangeBrightness();
+       }
+       else if(*command == _POWER_BRIGHTNESS_RESTORE)
+       {
+               __appBrightnessList.Remove(appId, true);
+               r = ChangeBrightness();
+       }
+       else
+       {
+               SysLogException(NID_SYS, E_SYSTEM, "Required command[%ls] is not proccess on _PowerManager.", command->GetPointer());
+               r = E_SYSTEM;
+       }
+
+CATCH:
+       unique_ptr<String> resultId(new (std::nothrow) String());
+
+       SysTryReturnResult(NID_SYS, resultId != null, E_SYSTEM, "It is failed to allocate memory for response message creating.");
+
+       if(r == E_SUCCESS)
+       {
+               resultId->Append(_POWER_OK);
+       }
+       else
+       {
+               resultId->Append(_POWER_ERROR);
+       }
+
+       response->Add(*resultId.release());
+
+       return r;
+}
+
+} } // Tizen::System
diff --git a/src/system/FSys_PowerManager.h b/src/system/FSys_PowerManager.h
new file mode 100644 (file)
index 0000000..f7b6d3d
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// 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.
+//
+
+/**
+ * @file               FSys_PowerManager.h
+ * @brief              This is the header file for the _PowerManager class.
+ */
+
+#ifndef _FSYS_SERVICE_SYS_POWER_MANAGER_H_
+#define _FSYS_SERVICE_SYS_POWER_MANAGER_H_
+
+#include <FApp.h>
+#include <FBase.h>
+
+namespace Tizen { namespace System
+{
+
+class _PowerManager
+{
+public:
+       result OnRequestOccured(Tizen::App::AppId appId, Tizen::Base::Collection::ArrayList* request, Tizen::Base::Collection::ArrayList* response);
+       result OnActiveAppChanged(const Tizen::App::AppId& appId);
+       result OnApplicationTerminated(const Tizen::App::AppId& appId);
+
+public:
+       static _PowerManager* GetInstance(void);
+
+private:
+       _PowerManager();
+       ~_PowerManager();
+       result ChangeBrightness(void);
+
+private:
+       Tizen::App::AppId                       __activeAppId;
+       Tizen::Base::Collection::HashMap        __appBrightnessList;
+
+       static _PowerManager*                   __pPowerManager;
+};
+
+} } // Tizen::System
+
+#endif  // _FSYS_SERVICE_SYS_POWER_MANAGER_H_