2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
26 #define METHOD_GET_DISPLAY_COUNT "GetDisplayCount"
27 #define METHOD_GET_MAX_BRIGHTNESS "GetMaxBrightness"
28 #define METHOD_GET_BRIGHTNESS "GetBrightness"
29 #define METHOD_SET_BRIGHTNESS "SetBrightness"
30 #define METHOD_CHANGE_STATE "changestate"
32 #define STR_LCD_OFF "lcdoff"
33 #define STR_LCD_DIM "lcddim"
34 #define STR_LCD_ON "lcdon"
36 static int display_cnt = -1;
41 static int alloc_display(void)
48 display_arr = malloc(sizeof(struct display) * display_cnt);
52 for (i = 0; i < display_cnt; ++i)
53 display_arr[i].max = -1;
58 int device_display_get_numbers(int *device_number)
63 return DEVICE_ERROR_INVALID_PARAMETER;
65 /* if it is a first request */
66 if (display_cnt < 0) {
67 ret = dbus_method_sync(DEVICED_BUS_NAME,
68 DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
69 METHOD_GET_DISPLAY_COUNT, NULL, NULL);
71 return errno_to_device_error(ret);
76 *device_number = display_cnt;
77 _I("device_number : %d", *device_number);
78 return DEVICE_ERROR_NONE;
81 int device_display_get_max_brightness(int display_index, int *max_brightness)
86 return DEVICE_ERROR_INVALID_PARAMETER;
89 device_display_get_numbers(&display_cnt);
91 if (display_index < 0 || display_index >= display_cnt)
92 return DEVICE_ERROR_INVALID_PARAMETER;
94 if (!display_arr && alloc_display() < 0)
95 return DEVICE_ERROR_OPERATION_FAILED;
97 if (display_arr[display_index].max < 0) {
98 ret = dbus_method_sync(DEVICED_BUS_NAME,
99 DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
100 METHOD_GET_MAX_BRIGHTNESS, NULL, NULL);
102 return errno_to_device_error(ret);
103 display_arr[display_index].max = ret;
106 *max_brightness = display_arr[display_index].max;
107 return DEVICE_ERROR_NONE;
110 int device_display_get_brightness(int display_index, int *brightness)
115 return DEVICE_ERROR_INVALID_PARAMETER;
118 device_display_get_numbers(&display_cnt);
120 if (display_index < 0 || display_index >= display_cnt)
121 return DEVICE_ERROR_INVALID_PARAMETER;
123 ret = dbus_method_sync(DEVICED_BUS_NAME,
124 DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
125 METHOD_GET_BRIGHTNESS, NULL, NULL);
127 return errno_to_device_error(ret);
130 return DEVICE_ERROR_NONE;
133 int device_display_set_brightness(int display_index, int brightness)
140 device_display_get_numbers(&display_cnt);
142 if (display_index < 0 || display_index >= display_cnt)
143 return DEVICE_ERROR_INVALID_PARAMETER;
145 if (display_arr[display_index].max < 0)
146 device_display_get_max_brightness(display_index, &max);
148 if (brightness < 0 || brightness > display_arr[display_index].max)
149 return DEVICE_ERROR_INVALID_PARAMETER;
151 snprintf(str_val, sizeof(str_val), "%d", brightness);
154 ret = dbus_method_sync(DEVICED_BUS_NAME,
155 DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
156 METHOD_SET_BRIGHTNESS, "i", arr);
158 return errno_to_device_error(ret);
160 return DEVICE_ERROR_NONE;
163 int device_display_get_state(display_state_e *state)
168 return DEVICE_ERROR_INVALID_PARAMETER;
170 ret = vconf_get_int(VCONFKEY_PM_STATE, &val);
172 return DEVICE_ERROR_OPERATION_FAILED;
174 if (val == VCONFKEY_PM_STATE_NORMAL)
175 *state = DISPLAY_STATE_NORMAL;
176 else if (val == VCONFKEY_PM_STATE_LCDDIM)
177 *state = DISPLAY_STATE_SCREEN_DIM;
178 else if (val == VCONFKEY_PM_STATE_LCDOFF)
179 *state = DISPLAY_STATE_SCREEN_OFF;
181 return DEVICE_ERROR_OPERATION_FAILED;
183 return DEVICE_ERROR_NONE;
186 static char *get_state_str(display_state_e state)
189 case DISPLAY_STATE_NORMAL:
191 case DISPLAY_STATE_SCREEN_DIM:
193 case DISPLAY_STATE_SCREEN_OFF:
201 int device_display_change_state(display_state_e state)
206 if (state < DISPLAY_STATE_NORMAL || state > DISPLAY_STATE_SCREEN_OFF)
207 return DEVICE_ERROR_INVALID_PARAMETER;
209 str = get_state_str(state);
211 return DEVICE_ERROR_INVALID_PARAMETER;
215 ret = dbus_method_sync(DEVICED_BUS_NAME,
216 DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
217 METHOD_CHANGE_STATE, "s", arr);
219 return errno_to_device_error(ret);
221 return DEVICE_ERROR_NONE;