45d21e8b235988478f32e2da0afbece02baa7e89
[platform/framework/native/appfw.git] / src / system-server / power / FSys_PowerManager.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                FSys_PowerManager.cpp
19  * @brief               This is the implementation file for _PowerManager class.
20  */
21
22 #include <device.h>
23 #include <system_info.h>
24
25 #include <FBaseSysLog.h>
26 #include "FSys_PowerManager.h"
27
28 using namespace Tizen::Base;
29
30 namespace Tizen { namespace System
31 {
32
33 _PowerManager::_PowerManager()
34 {
35 }
36
37 _PowerManager::~_PowerManager()
38 {
39 }
40
41 result
42 _PowerManager::ChangeBrightness(int brightness)
43 {
44         int ret = DEVICE_ERROR_NONE;
45         int maxBrightness;
46
47         ret = device_get_max_brightness(0, &maxBrightness);
48         SysTryReturnResult(NID_SYS, ret == DEVICE_ERROR_NONE, E_SYSTEM, "It failed to get the device max brightness");
49         SysTryReturnResult(NID_SYS, (brightness >= 0 && brightness <= maxBrightness), E_OUT_OF_RANGE,
50                                   "[E_OUT_OF_RANGE] The specified brightness is out of range.[%d]", brightness);
51
52         if (brightness == 0)
53         {
54                 ret = device_set_brightness_from_settings(0);
55         }
56         else
57         {
58                 ret = device_set_brightness(0, brightness);
59         }
60
61         SysTryReturnResult(NID_SYS, ret == DEVICE_ERROR_NONE, E_SYSTEM, "It is failed to change brightness. error code [%d]", ret);
62
63         return E_SUCCESS;
64 }
65 } } // Tizen::System