runtime-info: added process Memory and CPU usage APIs
[platform/core/api/runtime-info.git] / src / runtime_info_locale.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20
21 #include <vconf.h>
22 #include <dlog.h>
23
24 #include <runtime_info.h>
25 #include <runtime_info_private.h>
26
27 #ifdef LOG_TAG
28 #undef LOG_TAG
29 #endif
30
31 #define LOG_TAG "CAPI_SYSTEM_RUNTIME_INFO"
32
33 static const char *VCONF_24HOUR_FORMAT = VCONFKEY_REGIONFORMAT_TIME1224;
34 static const char *VCONF_FIRST_DAY_OF_WEEK = VCONFKEY_SETAPPL_WEEKOFDAY_FORMAT_INT;
35 static const char *VCONF_LANGUAGE = VCONFKEY_LANGSET;
36 static const char *VCONF_REGION = VCONFKEY_REGIONFORMAT;
37
38 int runtime_info_24hour_format_get_value(runtime_info_value_h value)
39 {
40         int vconf_value;
41
42         if (runtime_info_vconf_get_value_int(VCONF_24HOUR_FORMAT, &vconf_value))
43                 return RUNTIME_INFO_ERROR_IO_ERROR;
44
45         switch (vconf_value) {
46         case VCONFKEY_TIME_FORMAT_12:
47                 value->b = false;
48                 break;
49
50         case VCONFKEY_TIME_FORMAT_24:
51                 value->b = true;
52                 break;
53
54         default:
55                 return RUNTIME_INFO_ERROR_IO_ERROR;
56         }
57
58         return RUNTIME_INFO_ERROR_NONE;
59 }
60
61 int runtime_info_24hour_format_set_event_cb()
62 {
63         return runtime_info_vconf_set_event_cb(VCONF_24HOUR_FORMAT, RUNTIME_INFO_KEY_24HOUR_CLOCK_FORMAT_ENABLED, 0);
64 }
65
66 void runtime_info_24hour_format_unset_event_cb()
67 {
68         runtime_info_vconf_unset_event_cb(VCONF_24HOUR_FORMAT, 0);
69 }
70
71 int runtime_info_first_day_of_week_get_value(runtime_info_value_h value)
72 {
73         int vconf_value;
74
75         if (runtime_info_vconf_get_value_int(VCONF_FIRST_DAY_OF_WEEK, &vconf_value))
76                 return RUNTIME_INFO_ERROR_IO_ERROR;
77
78         switch (vconf_value) {
79         case SETTING_WEEKOFDAY_FORMAT_SUNDAY:
80                 value->i = RUNTIME_INFO_FIRST_DAY_OF_WEEK_SUNDAY;
81                 break;
82
83         case SETTING_WEEKOFDAY_FORMAT_MONDAY:
84                 value->i = RUNTIME_INFO_FIRST_DAY_OF_WEEK_MONDAY;
85                 break;
86
87         case SETTING_WEEKOFDAY_FORMAT_TUESDAY:
88                 value->i = RUNTIME_INFO_FIRST_DAY_OF_WEEK_TUESDAY;
89                 break;
90
91         case SETTING_WEEKOFDAY_FORMAT_WEDNESDAY:
92                 value->i = RUNTIME_INFO_FIRST_DAY_OF_WEEK_WEDNESDAY;
93                 break;
94
95         case SETTING_WEEKOFDAY_FORMAT_THURSDAY:
96                 value->i = RUNTIME_INFO_FIRST_DAY_OF_WEEK_THURSDAY;
97                 break;
98
99         case SETTING_WEEKOFDAY_FORMAT_FRIDAY:
100                 value->i = RUNTIME_INFO_FIRST_DAY_OF_WEEK_FRIDAY;
101                 break;
102
103         case SETTING_WEEKOFDAY_FORMAT_SATURDAY:
104                 value->i = RUNTIME_INFO_FIRST_DAY_OF_WEEK_SATURDAY;
105                 break;
106
107         default:
108                 return RUNTIME_INFO_ERROR_IO_ERROR;
109         }
110
111         return RUNTIME_INFO_ERROR_NONE;
112 }
113
114 int runtime_info_first_day_of_week_set_event_cb()
115 {
116         return runtime_info_vconf_set_event_cb(VCONF_FIRST_DAY_OF_WEEK, RUNTIME_INFO_KEY_FIRST_DAY_OF_WEEK, 0);
117 }
118
119 void runtime_info_first_day_of_week_unset_event_cb()
120 {
121         runtime_info_vconf_unset_event_cb(VCONF_FIRST_DAY_OF_WEEK, 0);
122 }
123
124 int runtime_info_language_get_value(runtime_info_value_h value)
125 {
126         char *vconf_value;
127         char *token = NULL;
128
129         if (runtime_info_vconf_get_value_string(VCONF_LANGUAGE, &vconf_value))
130                 return RUNTIME_INFO_ERROR_IO_ERROR;
131
132         token = strchr(vconf_value, '.');
133
134         if(token)
135                 *token = '\0';
136
137         value->s = vconf_value;
138
139         return RUNTIME_INFO_ERROR_NONE;
140 }
141
142 int runtime_info_language_set_event_cb()
143 {
144         return runtime_info_vconf_set_event_cb(VCONF_LANGUAGE, RUNTIME_INFO_KEY_LANGUAGE, 0);
145 }
146
147 void runtime_info_language_unset_event_cb()
148 {
149         runtime_info_vconf_unset_event_cb(VCONF_LANGUAGE, 0);
150 }
151
152 int runtime_info_region_get_value(runtime_info_value_h value)
153 {
154         char *vconf_value;
155
156         if (runtime_info_vconf_get_value_string(VCONF_REGION, &vconf_value))
157                 return RUNTIME_INFO_ERROR_IO_ERROR;
158
159         value->s = vconf_value;
160
161         return RUNTIME_INFO_ERROR_NONE;
162 }
163
164 int runtime_info_region_set_event_cb()
165 {
166         return runtime_info_vconf_set_event_cb(VCONF_REGION, RUNTIME_INFO_KEY_REGION, 0);
167 }
168
169 void runtime_info_region_unset_event_cb()
170 {
171         runtime_info_vconf_unset_event_cb(VCONF_REGION, 0);
172 }
173