Tizen 2.0 Release
[pkgs/o/oma-ds-service.git] / src / agent / common / common_vconf.c
1 /*
2  * oma-ds-agent
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 /**
19  *   @Common_Util.c
20  *   @version                                                                   0.1
21  *   @brief                                                                             This file is the source file of implementation of wrapping vconf function
22  */
23
24 #include <vconf.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <glib.h>
28 #include <string.h>
29
30 #include <sync_agent.h>
31
32 #include "common/common_vconf.h"
33
34 char *get_vconf_str(char *base_key, char *key)
35 {
36         _EXTERN_FUNC_ENTER;
37
38         char path[128];
39         char *value = NULL;
40
41         snprintf(path, sizeof(path), "%s%s", base_key, key);
42         value = vconf_get_str(path);
43
44         if (value != NULL) {
45                 if (strcmp(value, "") == 0) {
46
47                         if (value != NULL)
48                                 free(value);
49
50                         _EXTERN_FUNC_EXIT;
51                         return NULL;
52                 } else {
53                         _EXTERN_FUNC_EXIT;
54                         return value;
55                 }
56         } else {
57                 _EXTERN_FUNC_EXIT;
58                 return NULL;
59         }
60
61 }
62
63 char *get_vconf_str_key(char *key)
64 {
65         _EXTERN_FUNC_ENTER;
66
67         char *value = NULL;
68         value = vconf_get_str(key);
69
70         if (value != NULL) {
71                 if (strcmp(value, "") == 0) {
72
73                         if (value != NULL)
74                                 free(value);
75
76                         _EXTERN_FUNC_EXIT;
77                         return NULL;
78                 } else {
79                         _EXTERN_FUNC_EXIT;
80                         return value;
81                 }
82         } else {
83                 _EXTERN_FUNC_EXIT;
84                 return NULL;
85         }
86 }
87
88 bool get_vconf_int(char *base_key, char *key, int *value)
89 {
90         _EXTERN_FUNC_ENTER;
91
92         char path[128];
93         int temp = 0;
94         int result;
95
96         snprintf(path, sizeof(path), "%s%s", base_key, key);
97         result = vconf_get_int(path, &temp);
98
99         _EXTERN_FUNC_EXIT;
100
101         if (result == 0) {
102                 *value = temp;
103                 return true;
104         } else
105                 return false;
106 }
107
108 bool get_vconf_int_key(char *key, int *value)
109 {
110         _EXTERN_FUNC_ENTER;
111
112         int temp = 0;
113         int result;
114
115         result = vconf_get_int(key, &temp);
116
117         _EXTERN_FUNC_EXIT;
118
119         if (result == 0) {
120                 *value = temp;
121                 return true;
122         } else
123                 return false;
124 }
125
126 bool set_vconf_str(char *base_key, char *key, char *value)
127 {
128         _EXTERN_FUNC_ENTER;
129
130         char path[128];
131         int result;
132
133         snprintf(path, sizeof(path), "%s%s", base_key, key);
134         result = vconf_set_str(path, value);
135
136         _EXTERN_FUNC_EXIT;
137
138         if (result == 0)
139                 return true;
140         else
141                 return false;
142 }
143
144 bool set_vconf_str_key(char *key, char *value)
145 {
146         _EXTERN_FUNC_ENTER;
147
148         int result;
149         result = vconf_set_str(key, value);
150
151         _EXTERN_FUNC_EXIT;
152
153         if (result == 0)
154                 return true;
155         else
156                 return false;
157 }
158
159 bool set_vconf_int(char *base_key, char *key, int value)
160 {
161         _EXTERN_FUNC_ENTER;
162
163         char path[128];
164         int result;
165
166         snprintf(path, sizeof(path), "%s%s", base_key, key);
167         result = vconf_set_int(path, value);
168
169         _EXTERN_FUNC_EXIT;
170
171         if (result == 0)
172                 return true;
173         else
174                 return false;
175 }
176
177 bool set_vconf_int_key(char *key, int value)
178 {
179         _EXTERN_FUNC_ENTER;
180
181         int result;
182
183         result = vconf_set_int(key, value);
184
185         _EXTERN_FUNC_EXIT;
186
187         if (result == 0)
188                 return true;
189         else
190                 return false;
191 }