Split powermanager into system-server.so
authorHokwon Song <hokwon.song@samsung.com>
Tue, 25 Jun 2013 07:24:41 +0000 (16:24 +0900)
committerHokwon Song <hokwon.song@samsung.com>
Tue, 25 Jun 2013 07:38:39 +0000 (16:38 +0900)
Change-Id: I7a6624c803c272a0fa818d1cb6cc5dec5b6dca49
Signed-off-by: Hokwon Song <hokwon.song@samsung.com>
src/system-server/CMakeLists.txt
src/system-server/inc/FSys_IPowerManager.h [new file with mode: 0644]
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 c9cae01..81fe5d5 100644 (file)
@@ -13,12 +13,14 @@ INCLUDE_DIRECTORIES (
 SET (${this_target}_SOURCE_FILES
        system/FSys_SystemInfo.cpp
        dev/FSys_DeviceManager.cpp
+       power/FSys_PowerManager.cpp
        )
 
 INCLUDE(FindPkgConfig)
 pkg_check_modules(pkgs REQUIRED
        capi-system-media-key
         capi-network-bluetooth
+       capi-system-device
 )
 
 FOREACH(flag ${pkgs_CFLAGS})
@@ -45,6 +47,7 @@ ADD_LIBRARY (${this_target} SHARED ${${this_target}_SOURCE_FILES})
 TARGET_LINK_LIBRARIES(${this_target} osp-appfw)
 TARGET_LINK_LIBRARIES(${this_target} capi-network-bluetooth)
 TARGET_LINK_LIBRARIES(${this_target} capi-system-media-key)
+TARGET_LINK_LIBRARIES(${this_target} capi-system-device)
 
 SET_TARGET_PROPERTIES(${this_target}
                PROPERTIES
diff --git a/src/system-server/inc/FSys_IPowerManager.h b/src/system-server/inc/FSys_IPowerManager.h
new file mode 100644 (file)
index 0000000..4a2fc05
--- /dev/null
@@ -0,0 +1,45 @@
+//
+// 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 <FBase.h>
+#include <FSystem.h>
+
+#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/src/system-server/inc/FSys_PowerManager.h b/src/system-server/inc/FSys_PowerManager.h
new file mode 100644 (file)
index 0000000..f790ae7
--- /dev/null
@@ -0,0 +1,48 @@
+//
+// 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>
+#include "FSys_IPowerManager.h"
+
+namespace Tizen { namespace System
+{
+class _PowerManager
+       : public _IPowerManager
+{
+public:
+       static _PowerManager* GetInstance(void);
+       result ChangeBrightness(int brightness);
+
+private:
+       _PowerManager();
+       virtual ~_PowerManager();
+
+private:
+       static _PowerManager*                   __pPowerManager;
+};
+
+} } // 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..16ca17c
--- /dev/null
@@ -0,0 +1,104 @@
+//
+// 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 int _POWER_COMMAND_ID = 1;
+}
+
+namespace Tizen { namespace System
+{
+
+_PowerManager* _PowerManager::__pPowerManager = null;
+
+_PowerManager::_PowerManager()
+{
+}
+
+_PowerManager::~_PowerManager()
+{
+}
+
+_PowerManager*
+_PowerManager::GetInstance()
+{
+
+       if(__pPowerManager == null)
+       {
+               __pPowerManager = new (std::nothrow) _PowerManager();
+       }
+
+       return __pPowerManager;
+}
+
+result
+_PowerManager::ChangeBrightness(int brightness)
+{
+
+       int ret = DEVICE_ERROR_NONE;
+       result r = E_OBJ_NOT_FOUND;
+
+       if (brightness > 0)
+       {
+               SysLog(NID_SYS, "Brightness is [%d]", brightness);
+               ret = device_set_brightness(0, brightness);
+               if(ret == DEVICE_ERROR_NONE)
+               {
+                       r = E_SUCCESS;
+               }
+               else
+               {
+                       SysLogException(NID_SYS, E_SYSTEM, "It is failed to change brightness.");
+                       r = E_SYSTEM;
+               }
+       }
+       else if (brightness == 0)
+       {
+               SysLog(NID_SYS, "Current Active App does not have brightness.");
+               ret = device_set_brightness_from_settings(0);
+               r = E_SUCCESS;
+       }
+
+       return r;
+}
+
+
+extern "C" _OSP_EXPORT_ _IPowerManager* PowerManager_CreateInstance()
+{
+       return _PowerManager::GetInstance();
+}
+} } // Tizen::System
index 5e6f5fb..d0e6d72 100644 (file)
@@ -65,6 +65,8 @@ 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"
 #endif
@@ -473,9 +475,10 @@ _PowerManagerImpl::RestoreScreenBrightness(void)
        SysTryReturn(NID_SYS, IsActive() == true, E_SUCCESS, r, "It is not active app.");
 
        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);
+       r = pIpcClient->Construct(_POWER_MANAGER_SERVICE_ID);
        SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] It failed to create IpcClient", GetErrorMessage(r));
 
        requestMessage.Construct();
@@ -527,7 +530,7 @@ _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);
+       r = pIpcClient->Construct(_POWER_MANAGER_SERVICE_ID);
        SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] It failed to create IpcClient", GetErrorMessage(r));
 
        requestMessage.Construct();