Update PowerManager [dep:osp-common-service, osp-appfw, osp-appservice]
authorHokwon Song <hokwon.song@samsung.com>
Thu, 25 Jul 2013 03:24:11 +0000 (12:24 +0900)
committerHokwon Song <hokwon.song@samsung.com>
Thu, 25 Jul 2013 03:24:11 +0000 (12:24 +0900)
Change-Id: I42511ce3ac7cd4af875f01d5d5cd2dbc9e8e2463
Signed-off-by: Hokwon Song <hokwon.song@samsung.com>
src/system-server/CMakeLists.txt
src/system-server/inc/FSys_PowerManager.h [new file with mode: 0644]
src/system-server/power/FSys_PowerManager.cpp [new file with mode: 0644]
src/system/FSys_PowerManagerImpl.cpp

index 4c3a936..feadf23 100644 (file)
@@ -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 (file)
index 0000000..77aa6ce
--- /dev/null
@@ -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 <FApp.h>
+#include <FBase.h>
+
+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 (file)
index 0000000..45d21e8
--- /dev/null
@@ -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 <device.h>
+#include <system_info.h>
+
+#include <FBaseSysLog.h>
+#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
index f96379a..fbeb815 100644 (file)
@@ -27,6 +27,7 @@
 #include <runtime_info.h>
 #include <vconf.h>
 
+#include <FIo.h>
 #include <FAppIActiveAppEventListener.h>
 #include <FBaseSysLog.h>
 #include <FBaseColArrayListT.h>
@@ -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();