tizen beta release
[framework/location/libslp-location.git] / location / location-setting.c
1 /*
2  * libslp-location
3  *
4  * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Youngae Kang <youngae.kang@samsung.com>, Yunhan Kim <yhan.kim@samsung.com>,
7  *          Genie Kim <daejins.kim@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <glib.h>
27 #include "location/location-log.h"
28 #include "location/location-setting.h"
29
30
31 gint location_setting_get_key_val(keynode_t *key)
32 {
33         g_return_val_if_fail(key, -1);
34         int val = -1;
35         switch(vconf_keynode_get_type(key))
36         {
37                 case VCONF_TYPE_INT:
38                         val = vconf_keynode_get_int(key);
39                         LOCATION_LOGD("Setting changed [%s]:[%d]", vconf_keynode_get_name(key), val);
40                         break;
41                 default:
42                         LOCATION_LOGW("Unused type(%d)", vconf_keynode_get_type(key));
43                         break;
44         }
45         return val;
46 }
47
48 gint location_setting_get_int(const gchar* path)
49 {
50         g_return_val_if_fail(path, -1);
51         int val = -1;
52         if( vconf_get_int(path, &val)){
53                 LOCATION_LOGW("vconf_get_int: failed [%s]", path);
54                 val = -1;
55         } else if (val == 0)
56                 LOCATION_LOGD("vconf_get_int: [%s]:[%d]", path, val);
57         return val;
58 }
59
60 gboolean location_setting_get_bool(const gchar* path)
61 {
62         g_return_val_if_fail(path, -1);
63         gboolean val = FALSE;
64         if( vconf_get_bool(path, &val)){
65                 LOCATION_LOGW("vconf_get_int: failed [%s]", path);
66                 val = FALSE;
67         }
68         return val;
69 }
70
71 gchar *location_setting_get_string(const gchar* path)
72 {
73         g_return_val_if_fail(path, -1);
74         return vconf_get_str(path);
75 }
76
77 gint location_setting_add_notify(const gchar* path, SettingCB setting_cb, gpointer self)
78 {
79         g_return_val_if_fail(path, -1);
80         g_return_val_if_fail(self, -1);
81
82         if( vconf_notify_key_changed(path, setting_cb, self)){
83                 LOCATION_LOGW("vconf notify add failed [%s]", path);
84                 return -1;
85         }
86         LOCATION_LOGD("vconf notify added [%s]", path);
87         return 0;
88 }
89
90 gint location_setting_ignore_notify(const gchar* path, SettingCB setting_cb)
91 {
92         g_return_val_if_fail(path, -1);
93         g_return_val_if_fail(setting_cb, -1);
94
95         if( vconf_ignore_key_changed(path, setting_cb)){
96                 LOCATION_LOGW("vconf notify remove failed [%s]", path);
97                 return -1;
98         }
99         LOCATION_LOGD("vconf notify removed [%s]", path);
100         return 0;
101 }