From 3080ba797e0810cfa8cd0843074d02a4bf41eee5 Mon Sep 17 00:00:00 2001 From: Hokwon Song Date: Thu, 25 Jul 2013 12:24:11 +0900 Subject: [PATCH] Update PowerManager [dep:osp-common-service, osp-appfw, osp-appservice] Change-Id: I42511ce3ac7cd4af875f01d5d5cd2dbc9e8e2463 Signed-off-by: Hokwon Song --- src/system-server/CMakeLists.txt | 1 + src/system-server/inc/FSys_PowerManager.h | 41 +++++++++++++++++ src/system-server/power/FSys_PowerManager.cpp | 65 +++++++++++++++++++++++++++ src/system/FSys_PowerManagerImpl.cpp | 22 ++++++++- 4 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 src/system-server/inc/FSys_PowerManager.h create mode 100644 src/system-server/power/FSys_PowerManager.cpp diff --git a/src/system-server/CMakeLists.txt b/src/system-server/CMakeLists.txt index 4c3a936..feadf23 100644 --- a/src/system-server/CMakeLists.txt +++ b/src/system-server/CMakeLists.txt @@ -29,6 +29,7 @@ SET (${this_target}_SOURCE_FILES setting/providers/FSys_SettingVibrationProvider.cpp runtime/FSys_RuntimeInfo.cpp device/FSys_DeviceManager.cpp + power/FSys_PowerManager.cpp ) INCLUDE(FindPkgConfig) diff --git a/src/system-server/inc/FSys_PowerManager.h b/src/system-server/inc/FSys_PowerManager.h new file mode 100644 index 0000000..77aa6ce --- /dev/null +++ b/src/system-server/inc/FSys_PowerManager.h @@ -0,0 +1,41 @@ +// +// 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 +#include + +namespace Tizen { namespace System +{ +class _OSP_EXPORT_ _PowerManager +{ +public: + static result ChangeBrightness(int brightness); +private: + _PowerManager(); + virtual ~_PowerManager(); +}; + +} } // Tizen::System + +#endif // _FSYS_SERVICE_SYS_POWER_MANAGER__H_ diff --git a/src/system-server/power/FSys_PowerManager.cpp b/src/system-server/power/FSys_PowerManager.cpp new file mode 100644 index 0000000..45d21e8 --- /dev/null +++ b/src/system-server/power/FSys_PowerManager.cpp @@ -0,0 +1,65 @@ +// +// 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 +#include + +#include +#include "FSys_PowerManager.h" + +using namespace Tizen::Base; + +namespace Tizen { namespace System +{ + +_PowerManager::_PowerManager() +{ +} + +_PowerManager::~_PowerManager() +{ +} + +result +_PowerManager::ChangeBrightness(int brightness) +{ + int ret = DEVICE_ERROR_NONE; + int maxBrightness; + + ret = device_get_max_brightness(0, &maxBrightness); + SysTryReturnResult(NID_SYS, ret == DEVICE_ERROR_NONE, E_SYSTEM, "It failed to get the device max brightness"); + SysTryReturnResult(NID_SYS, (brightness >= 0 && brightness <= maxBrightness), E_OUT_OF_RANGE, + "[E_OUT_OF_RANGE] The specified brightness is out of range.[%d]", brightness); + + if (brightness == 0) + { + ret = device_set_brightness_from_settings(0); + } + else + { + ret = device_set_brightness(0, brightness); + } + + SysTryReturnResult(NID_SYS, ret == DEVICE_ERROR_NONE, E_SYSTEM, "It is failed to change brightness. error code [%d]", ret); + + return E_SUCCESS; +} +} } // Tizen::System diff --git a/src/system/FSys_PowerManagerImpl.cpp b/src/system/FSys_PowerManagerImpl.cpp index f96379a..fbeb815 100644 --- a/src/system/FSys_PowerManagerImpl.cpp +++ b/src/system/FSys_PowerManagerImpl.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -64,6 +65,7 @@ static const int _DEVICE_POWER_LEVEL_OFF = 0; static const int _APPID_LENGTH = 10; static const int _DEACTIVATED_BRIGHTNESS_CONTROL = -1; static const float _BRIGHTNESS_RESOLUTION = 10.0; +static const wchar_t* POWER_MANAGER_SERVICE_ID = L"osp.sys.ipcserver.powermanager"; #ifndef VCONFKEY_SERVICE_READY #define VCONFKEY_SERVICE_READY "memory/deviced/boot_power_on" @@ -475,7 +477,15 @@ _PowerManagerImpl::RestoreScreenBrightness(void) unique_ptr<_IpcClient> pIpcClient (new (std::nothrow) _IpcClient()); SysTryReturn(NID_SYS, pIpcClient != null, E_OUT_OF_MEMORY, r, "It is failed to create IPC instance."); - r = pIpcClient->Construct(_COMMUNICATION_DISPATCHER_IPC_ID); + if(Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_powermanager") == true) + { + SysLog(NID_SYS, "PowerManager is serviced by common-service"); + r = pIpcClient->Construct(POWER_MANAGER_SERVICE_ID); + } + else + { + r = pIpcClient->Construct(_COMMUNICATION_DISPATCHER_IPC_ID); + } SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] It failed to create IpcClient", GetErrorMessage(r)); requestMessage.Construct(); @@ -526,7 +536,15 @@ _PowerManagerImpl::SetScreenBrightness(int brightness) unique_ptr<_IpcClient> pIpcClient (new (std::nothrow) _IpcClient()); SysTryReturn(NID_SYS, pIpcClient != null, E_OUT_OF_MEMORY, r, "It is failed to create IPC instance."); - r = pIpcClient->Construct(_COMMUNICATION_DISPATCHER_IPC_ID); + if(Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_powermanager") == true) + { + SysLog(NID_SYS, "PowerManager is serviced by common-service"); + r = pIpcClient->Construct(POWER_MANAGER_SERVICE_ID); + } + else + { + r = pIpcClient->Construct(_COMMUNICATION_DISPATCHER_IPC_ID); + } SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] It failed to create IpcClient", GetErrorMessage(r)); requestMessage.Construct(); -- 2.7.4