Tizen 2.1 base
[platform/core/api/runtime-info.git] / src / runtime_info_vconf.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 int runtime_info_vconf_get_value_int(const char *vconf_key, int *value)
34 {
35         return vconf_get_int(vconf_key, value);
36 }
37
38 int runtime_info_vconf_get_value_bool(const char *vconf_key, bool *value)
39 {
40         return vconf_get_bool(vconf_key, (int *)value);
41 }
42
43 int runtime_info_vconf_get_value_double(const char *vconf_key, double *value)
44 {
45         return vconf_get_dbl(vconf_key, value);
46 }
47
48 int runtime_info_vconf_get_value_string(const char *vconf_key, char **value)
49 {
50         char *str_value = NULL;
51
52         str_value = vconf_get_str(vconf_key);
53
54         if (str_value != NULL) {
55                 *value = str_value;
56                 return 0;
57         } else {
58                 return -1;
59         }
60 }
61
62 typedef void (*runtime_info_vconf_event_cb)(keynode_t *node, void *event_data);
63
64 static void runtime_info_vconf_event_cb0(keynode_t *node, void *event_data)
65 {
66         if (node != NULL)
67                 runtime_info_updated((runtime_info_key_e)event_data);
68 }
69
70 static void runtime_info_vconf_event_cb1(keynode_t *node, void *event_data)
71 {
72         if (node != NULL)
73                 runtime_info_updated((runtime_info_key_e)event_data);
74 }
75
76 static void runtime_info_vconf_event_cb2(keynode_t *node, void *event_data)
77 {
78         if (node != NULL)
79                 runtime_info_updated((runtime_info_key_e)event_data);
80 }
81
82 static void runtime_info_vconf_event_cb3(keynode_t *node, void *event_data)
83 {
84         if (node != NULL)
85                 runtime_info_updated((runtime_info_key_e)event_data);
86 }
87
88 static void runtime_info_vconf_event_cb4(keynode_t *node, void *event_data)
89 {
90         if (node != NULL)
91                 runtime_info_updated((runtime_info_key_e)event_data);
92 }
93
94 static runtime_info_vconf_event_cb runtime_info_vconf_get_event_cb_slot(int slot)
95 {
96         switch (slot) {
97         case 0:
98                 return runtime_info_vconf_event_cb0;
99
100         case 1:
101                 return runtime_info_vconf_event_cb1;
102
103         case 2:
104                 return runtime_info_vconf_event_cb2;
105
106         case 3:
107                 return runtime_info_vconf_event_cb3;
108
109         case 4:
110                 return runtime_info_vconf_event_cb4;
111
112         default:
113                 return NULL;
114         }
115 }
116
117 int runtime_info_vconf_set_event_cb(const char *vconf_key, runtime_info_key_e runtime_info_key, int slot)
118 {
119         runtime_info_vconf_event_cb vconf_event_cb;
120
121         vconf_event_cb = runtime_info_vconf_get_event_cb_slot(slot);
122
123         if (vconf_event_cb == NULL)
124                 return RUNTIME_INFO_ERROR_IO_ERROR;
125
126         if (vconf_notify_key_changed(vconf_key, vconf_event_cb, (void *)runtime_info_key))
127                 return RUNTIME_INFO_ERROR_IO_ERROR;
128
129         return RUNTIME_INFO_ERROR_NONE;
130 }
131
132 void runtime_info_vconf_unset_event_cb(const char *vconf_key, int slot)
133 {
134         runtime_info_vconf_event_cb vconf_event_cb;
135
136         vconf_event_cb = runtime_info_vconf_get_event_cb_slot(slot);
137
138         if (vconf_event_cb != NULL)
139                 vconf_ignore_key_changed(vconf_key, vconf_event_cb);
140 }