From: Hokwon Song Date: Tue, 25 Jun 2013 10:33:18 +0000 (+0000) Subject: Revert "Add power manager stup." X-Git-Tag: submit/tizen_2.2/20130714.152833~3^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3003686c13433265a270d0a7c5f58e21ae7da269;p=framework%2Fosp%2Fcommon-service.git Revert "Add power manager stup." This reverts commit bff3b3155215779edf7634f752c697a2f54f4f89 Change-Id: I977a98cba173c71612582cc4058b3124a94ffff4 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b17bd7..1843966 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,6 @@ SET (${this_target}_SOURCE_FILES src/CommonServiceEntry.cpp src/FSys_DeviceManagerStub.cpp src/FSys_DeviceManagerServiceIpcEventForAsync.cpp - src/FSys_PowerManagerStub.cpp ) ## SET EXTRA COMPILER FLAGS diff --git a/inc/CommonService.h b/inc/CommonService.h index 72af473..2a803da 100644 --- a/inc/CommonService.h +++ b/inc/CommonService.h @@ -36,7 +36,6 @@ class _UiManagerStub; namespace Tizen { namespace System { class _DeviceManagerStub; -class _PowerManagerStub; }} /** * @class CommonService @@ -64,7 +63,6 @@ private: Tizen::App::_PackageManagerStub* __pPackageManagerStub; std::unique_ptr __pUiManagerStub; Tizen::System::_DeviceManagerStub* __pDeviceManagerStub; - Tizen::System::_PowerManagerStub* __pPowerManagerStub; }; #endif // _COMMON_SERVICE_H_ diff --git a/inc/FSys_IPowerManager.h b/inc/FSys_IPowerManager.h deleted file mode 100644 index 4a2fc05..0000000 --- a/inc/FSys_IPowerManager.h +++ /dev/null @@ -1,45 +0,0 @@ -// -// 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_IPowerManager.h - * @brief This is the header file of the _IPowerManager class. - * - * This header file contains the declarations of the _IPowerManager class. - */ -#include -#include - -#ifndef _FSYS_INTERNAL_IPOWER_MANAGER_H_ -#define _FSYS_INTERNAL_IPOWER_MANAGER_H_ - -namespace Tizen { namespace System { - -/** - * @class _IPowerManager - * @brief This class contains implementaion of device control. - * @since 2.1 - */ -class _OSP_EXPORT_ _IPowerManager -{ -protected: - virtual ~_IPowerManager(void) {}; -public: - virtual result ChangeBrightness(int brightness) = 0; -}; //_IPowerManager - -}} //Tizen::System -#endif /* _FSYS_INTERNAL_IPOWER_MANAGER_H_ */ diff --git a/inc/FSys_PowerManagerStub.h b/inc/FSys_PowerManagerStub.h deleted file mode 100644 index b8288ef..0000000 --- a/inc/FSys_PowerManagerStub.h +++ /dev/null @@ -1,84 +0,0 @@ -// -// Open Service Platform -// 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_PowerManagerStub.h - * @brief This is the header file of the _PowerManagerStub class. - * - * This header file contains the declarations of the _PowerManagerStub class. - */ - -#ifndef _FSYS_POWER_MANAGER_STUB_H_ -#define _FSYS_POWER_MANAGER_STUB_H_ - -#include -#include -#include -#include -#include -#include "FApp_IAppEventListener.h" - -namespace Tizen { namespace System -{ - -class _IPowerManager; - -class _OSP_EXPORT_ _PowerManagerStub - : public Tizen::Base::Object - , public Tizen::Io::_IIpcServerEventListener - , public Tizen::App::_IAppEventListener - , public Tizen::App::IActiveAppEventListener -{ -public: - static _PowerManagerStub* GetInstance(void); - - virtual ~_PowerManagerStub(void); - virtual void OnActiveAppChanged(const Tizen::App::AppId& appId); -private: - _PowerManagerStub(void); - result Construct(void); - - result ChangeBrightness(void); - - _PowerManagerStub(const _PowerManagerStub& rhs); - _PowerManagerStub& operator =(const _PowerManagerStub& rhs); - - bool OnRequestOccured(const Tizen::Base::Collection::ArrayList& request, Tizen::Base::Collection::ArrayList* response); - - virtual void OnIpcServerStarted(const Tizen::Io::_IpcServer& server) {} - virtual void OnIpcServerStopped(const Tizen::Io::_IpcServer& server) {} - virtual void OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId) {} - virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId) {} - virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message); - - virtual void OnApplicationLaunched(const Tizen::App::AppId& appId, int pid) {} - virtual void OnApplicationTerminated(const Tizen::App::AppId& appId, int pid); - -private: - std::unique_ptr __pIpcServer; - static _PowerManagerStub* __pPowerManagerStub; - Tizen::Base::Runtime::Mutex __Mutex; - Tizen::App::AppId __activeAppId; - Tizen::App::AppId __currentAppId; - Tizen::Base::Collection::HashMap __appBrightnessList; - void* __pSystemServiceDllHandle; - _IPowerManager* __pIPowerManager; -}; // _PowerManagerStub - -}} // Tizen::System - -#endif // _FSYS_POWER_MANAGER_STUB_H_ diff --git a/src/CommonService.cpp b/src/CommonService.cpp index 045f37d..92c8f0d 100644 --- a/src/CommonService.cpp +++ b/src/CommonService.cpp @@ -18,10 +18,9 @@ #include #include "CommonService.h" +#include "FSys_DeviceManagerStub.h" #include "FApp_PackageManagerStub.h" #include "FUi_UiManagerStub.h" -#include "FSys_PowerManagerStub.h" -#include "FSys_DeviceManagerStub.h" using namespace std; using namespace Tizen::App; @@ -32,7 +31,6 @@ using namespace Tizen::Ui; CommonService::CommonService(void) : __pPackageManagerStub(null) , __pDeviceManagerStub(null) - , __pPowerManagerStub(null) { } @@ -40,15 +38,7 @@ CommonService::CommonService(void) CommonService::~CommonService(void) { delete __pPackageManagerStub; - - if (__pDeviceManagerStub != null) - { - delete __pDeviceManagerStub; - } - if (__pPowerManagerStub != null) - { - delete __pPowerManagerStub; - } + delete __pDeviceManagerStub; } ServiceApp* @@ -135,8 +125,5 @@ CommonService::InitializeServices(void) __pUiManagerStub = move(pUiManagerStub); __pDeviceManagerStub = _DeviceManagerStub::CreateInstanceN(); - SysTryReturnVoidResult(NID_SYS, __pDeviceManagerStub, r, "[%s] Propagating.", GetErrorMessage(r)); - - __pPowerManagerStub = _PowerManagerStub::GetInstance(); - SysTryReturnVoidResult(NID_SYS, __pPowerManagerStub, r, "[%s] Propagating.", GetErrorMessage(r)); + SysTryReturnVoidResult(NID_UI, __pDeviceManagerStub, r, "[%s] Propagating.", GetErrorMessage(r)); } diff --git a/src/FSys_DeviceManagerStub.cpp b/src/FSys_DeviceManagerStub.cpp index 87691c7..7cd0e9d 100644 --- a/src/FSys_DeviceManagerStub.cpp +++ b/src/FSys_DeviceManagerStub.cpp @@ -51,8 +51,8 @@ _DeviceManagerServiceIpcEventForAsync* _DeviceManagerStub::__pDeviceManagerServi _DeviceManagerStub* _DeviceManagerStub::__pDeviceManagerStub = null; _DeviceManagerStub::_DeviceManagerStub(void) - : __pIpcServer(null) - , __pSystemServiceDllHandle(null) + : __pSystemServiceDllHandle(null) + , __pIpcServer(null) , __pIDeviceManager(null) { result r = E_SUCCESS; diff --git a/src/FSys_PowerManagerStub.cpp b/src/FSys_PowerManagerStub.cpp deleted file mode 100644 index 75e312a..0000000 --- a/src/FSys_PowerManagerStub.cpp +++ /dev/null @@ -1,256 +0,0 @@ -// -// Open Service Platform -// 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_PowerManagerStub.cpp - * @brief This is the implementation for the _PowerManagerStub class. - */ -#include -#include -#include -#include -#include - -#include "FApp_AppManagerImpl.h" -#include "FSys_IPowerManager.h" -#include "FSys_PowerManagerStub.h" - -using namespace std; -using namespace Tizen::Base; -using namespace Tizen::Base::Collection; -using namespace Tizen::Io; -using namespace Tizen::System; -using namespace Tizen::App; - -namespace { - static const wchar_t* POWER_MANAGER_SERVICE_ID = L"osp.sys.ipcserver.powermanager"; - static const wchar_t* POWER_MANAGER_SERVICE_MUTEX_ID = L"osp.sys.ipcserver.devicemanager"; - 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"; -} - -_PowerManagerStub* _PowerManagerStub::__pPowerManagerStub = null; - -_PowerManagerStub::_PowerManagerStub(void) - : __pIpcServer(null) - , __pSystemServiceDllHandle(null) - , __pIPowerManager(null) -{ - result r = E_SUCCESS; - r = __Mutex.Create(POWER_MANAGER_SERVICE_MUTEX_ID); - SysTryReturn(NID_SYS, r == E_SUCCESS, , r, "It is failed to create mutex. [%s] Propaged.", r); - - r = __appBrightnessList.Construct(); - SysTryReturn(NID_SYS, r == E_SUCCESS, , r, "It is failed to initiate power manager app list."); -} - -_PowerManagerStub::~_PowerManagerStub(void) -{ - if (__pIpcServer) - { - __pIpcServer->Stop(); - } - - if (__pSystemServiceDllHandle) - { - dlclose(__pSystemServiceDllHandle); - } - - __appBrightnessList.RemoveAll(); - - result r = __Mutex.Release(); - SysTryReturn(NID_SYS, r == E_SUCCESS, , r, "It is failed to release mutex. [%s] Propaged.", r); -} - -_PowerManagerStub* -_PowerManagerStub::GetInstance() -{ - if (__pPowerManagerStub == null) - { - __pPowerManagerStub = new (std::nothrow) _PowerManagerStub(); - result r = __pPowerManagerStub->Construct(); - SysTryReturn(NID_SYS, !IsFailed(r), null, r, "[%s] It is failed to get PowerManagerCommunicationStub.", GetErrorMessage(r)); - } - return __pPowerManagerStub; -} - -result -_PowerManagerStub::Construct(void) -{ - unique_ptr<_IpcServer> pIpcServer(new (std::nothrow) _IpcServer()); - SysTryReturnResult(NID_SYS, pIpcServer, E_OUT_OF_MEMORY, "Memory is insufficient."); - - result r = pIpcServer->Construct(String(POWER_MANAGER_SERVICE_ID), *this, true); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to construct."); - - r = pIpcServer->Start(); - SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to start."); - - __pIpcServer = move(pIpcServer); - - __pSystemServiceDllHandle = dlopen("libosp-system-server.so", RTLD_LAZY); - - if (!__pSystemServiceDllHandle) - { - SysLog(NID_SYS, "It is failed to load system service (%s).", dlerror()); - return E_SYSTEM; - } - - _IPowerManager* (*pFnPowerManager_CreateInstance)(void) = null; - pFnPowerManager_CreateInstance = reinterpret_cast< _IPowerManager* (*)(void) >(dlsym(__pSystemServiceDllHandle, "PowerManager_CreateInstance")); - SysTryReturn(NID_SYS, pFnPowerManager_CreateInstance, E_SYSTEM, E_SYSTEM, "It is failed to find PowerManager_CreateInstance."); - - __pIPowerManager = pFnPowerManager_CreateInstance(); - SysTryReturn(NID_SYS, __pIPowerManager, E_SYSTEM, E_SYSTEM,"It is failed to create PowerManager instance."); - - _AppManagerImpl* pAppManagerImpl = null; - pAppManagerImpl = _AppManagerImpl::GetInstance(); - SysTryReturn(NID_SYS, pAppManagerImpl != null, E_SYSTEM , E_SYSTEM, "It is failed to get _AppManagerImpl class."); - - r = pAppManagerImpl->AddActiveAppEventListener(*this); - SysTryReturn(NID_SYS, r == E_SUCCESS || r == E_OBJ_ALREADY_EXIST, E_SYSTEM, E_SYSTEM, "[%s] It is failed to add active app event listener",GetErrorMessage(r)); - - r = pAppManagerImpl->AddAppEventListener(*this); - SysTryReturn(NID_SYS, r == E_SUCCESS || r == E_OBJ_ALREADY_EXIST, E_SYSTEM, E_SYSTEM, "It is failed to add app event listener"); - - return E_SUCCESS; -} - -result -_PowerManagerStub::ChangeBrightness() -{ - result r = E_FAILURE; - - if(__appBrightnessList.GetCount() > 0) - { - Integer* brightness = (Integer*)__appBrightnessList.GetValue(__activeAppId); - - if(brightness != null) - { - r = __pIPowerManager->ChangeBrightness(brightness->ToInt()); - } - } - if (IsFailed(r)) - { - r = __pIPowerManager->ChangeBrightness(0); - } - - return r; -} -void -_PowerManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message) -{ - __Mutex.Acquire(); - __currentAppId = server.GetClientPackageId(); - IPC_BEGIN_MESSAGE_MAP(_PowerManagerStub, message) - IPC_MESSAGE_HANDLER_EX(IoService_Request, &server, OnRequestOccured) - IPC_END_MESSAGE_MAP_EX() - __Mutex.Release(); -} - -bool -_PowerManagerStub::OnRequestOccured(const ArrayList& request, ArrayList* response) -{ - bool isSuccess = false; - result r = E_SUCCESS; - - std::unique_ptr< String > pServiceId(new (std::nothrow) String(POWER_MANAGER_SERVICE_ID)); - std::unique_ptr< String > pCommand(new (std::nothrow) String(*((String*)request.GetAt(_POWER_COMMAND_ID)))); - SysTryCatch(NID_SYS, pCommand != null, r = E_SYSTEM, r, "pCommand is empty."); - - if(*pCommand == String(_POWER_BRIGHTNESS_CHANGE)) - { - SysTryCatch(NID_SYS, __activeAppId == __currentAppId, r = E_SUCCESS, r, - "It is not active application[%ls]. Current Active App is [%ls].", __currentAppId.GetPointer(), __activeAppId.GetPointer()); - int brightness = 0; - String* brightnessBuffer = (String*)request.GetAt(_POWER_COMMAND_ID + 1); - Integer::Parse(*brightnessBuffer, brightness); - - __appBrightnessList.Remove(__currentAppId, true); - - unique_ptr pBrightness(new (std::nothrow) Integer(brightness)); - unique_ptr pAppId(new (std::nothrow) String(__currentAppId)); - - 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(*pCommand == _POWER_BRIGHTNESS_RESTORE) - { - __appBrightnessList.Remove(__currentAppId, true); - r = ChangeBrightness(); - } - else - { - SysLogException(NID_SYS, E_SYSTEM, "Required pCommand[%ls] is not proccess on _PowerManager.", pCommand->GetPointer()); - r = E_SYSTEM; - } - - isSuccess = true; -CATCH: - unique_ptr pResultId(new (std::nothrow) String()); - SysTryReturn(NID_SYS, pResultId != null,false, E_SYSTEM, "It is failed to allocate memory for response message creating."); - - if(r == E_SUCCESS) - { - pResultId->Append(_POWER_OK); - } - else - { - pResultId->Append(_POWER_ERROR); - } - - response->Add(*pServiceId.release()); - response->Add(*pCommand.release()); - response->Add(*pResultId.release()); - - ArrayList* temp = const_cast(&request); - temp->RemoveAll(true); - return isSuccess; -} - -void -_PowerManagerStub::OnApplicationTerminated(const AppId& appId, int pid) -{ - String requiredAppId; - appId.SubString(0, 10, requiredAppId); - __appBrightnessList.Remove(requiredAppId, true); - ChangeBrightness(); -} - -void -_PowerManagerStub::OnActiveAppChanged(const AppId& appId) -{ - AppId smallAppId; - appId.SubString(0, 10, smallAppId); - - if(__activeAppId != smallAppId) - { - __activeAppId = smallAppId; - ChangeBrightness(); - } - else - { - SysLog(NID_SYS, "Current App[%ls] is already actived.", __activeAppId.GetPointer()); - } -}