Tizen 2.1 base
[platform/core/system/power-manager.git] / pm_conf.c
1 /*
2  * power-manager
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16 */
17
18 #include <stdlib.h>
19 #include <string.h>
20 #include <stdio.h>
21
22 #include "pm_conf.h"
23
24 enum {
25         IDX_NAME = 0,
26         IDX_DEFAULT,
27         IDX_END
28 };
29
30 static char *def_values[][IDX_END] = {
31         {"PM_INPUT", "/dev/event0:/dev/event1"},
32         {"PM_TO_START", "0"},
33         {"PM_TO_NORMAL", "600"},
34         {"PM_TO_LCDDIM", "5"},
35         {"PM_TO_LCDOFF", "5"},
36         {"PM_TO_SLEEP", "0"},
37         {"PM_SYS_POWER", "/sys/power/state"},
38         {"PM_SYS_BRIGHT", "/sys/class/backlight/mobile-bl/brightness"},
39         {"PM_SYS_BRIGHT", "/sys/class/backlight/mobile-bl/max_brightness"},
40         {"PM_SYS_BLPWR", "/sys/class/backlight/mobile-bl/bl_power"},
41         {"PM_SYS_DIMBRT", "0"},
42         {"PM_SYS_BLON", "0"},
43         {"PM_SYS_BLOFF", "4"},
44         {"PM_SYS_FB_NORMAL", "1"},
45         {"PM_SYS_STATE", "mem"},
46         {"PM_EXEC_PRG", NULL},
47         {"PM_END", ""},
48 };
49
50 static char *_find_default(char *name)
51 {
52         char *ret = NULL;
53         int i = 0;
54
55         while (strcmp("PM_END", def_values[i][IDX_NAME])) {
56                 if (!strcmp(name, def_values[i][IDX_NAME])) {
57                         ret = def_values[i][IDX_DEFAULT];
58                         break;
59                 }
60                 i++;
61         }
62         return ret;
63 }
64
65 int get_env(char *name, char *buf, int size)
66 {
67         char *ret;
68
69         ret = getenv(name);
70         if ((ret == NULL) || (strlen(ret) > 1024)) {
71                 ret = _find_default(name);
72                 if (ret)
73                         snprintf(buf, size, "%s", ret);
74                 else
75                         snprintf(buf, size, "");
76         } else {
77                 snprintf(buf, size, "%s", ret);
78         }
79
80         return 0;
81 }