4 * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
7 * Genie Kim <daejins.kim@samsung.com>
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
27 #include <bundle_internal.h>
28 #include <eventsystem.h>
29 #include "location-log.h"
30 #include "location-setting.h"
32 static unsigned int g_event_req_id;
35 gint location_setting_get_key_val(keynode_t *key)
37 g_return_val_if_fail(key, -1);
39 switch (vconf_keynode_get_type(key)) {
41 val = vconf_keynode_get_int(key);
42 LOCATION_SECLOG("changed [%s]:[%d]", vconf_keynode_get_name(key), val);
45 LOCATION_LOGW("Unused type(%d)", vconf_keynode_get_type(key));
51 gint location_setting_get_int(const gchar *path)
53 g_return_val_if_fail(path, 0);
55 if (vconf_get_int(path, &val))
56 LOCATION_SECLOG("failed [%s]", path);
61 gboolean location_setting_get_bool(const gchar *path)
63 g_return_val_if_fail(path, FALSE);
65 if (vconf_get_bool(path, &val))
66 LOCATION_SECLOG("failed [%s]", path);
71 gchar *location_setting_get_string(const gchar *path)
73 g_return_val_if_fail(path, NULL);
74 return vconf_get_str(path);
77 static char *__convert_event_from_vconf(const char *vconf)
80 if (g_strcmp0(vconf, VCONFKEY_LOCATION_USE_MY_LOCATION) == 0)
81 event = g_strdup(SYS_EVENT_LOCATION_ENABLE_STATE);
82 else if (g_strcmp0(vconf, VCONFKEY_LOCATION_ENABLED) == 0)
83 event = g_strdup(SYS_EVENT_GPS_ENABLE_STATE);
84 else if (g_strcmp0(vconf, VCONFKEY_LOCATION_NETWORK_ENABLED) == 0)
85 event = g_strdup(SYS_EVENT_NPS_ENABLE_STATE);
90 static void __event_handler(const char *event_name, bundle *data, void *self)
92 const char *value = NULL;
94 if (g_strcmp0(event_name, SYS_EVENT_LOCATION_ENABLE_STATE) == 0)
95 value = bundle_get_val(data, EVT_KEY_LOCATION_ENABLE_STATE);
96 else if (g_strcmp0(event_name, SYS_EVENT_GPS_ENABLE_STATE) == 0)
97 value = bundle_get_val(data, EVT_KEY_GPS_ENABLE_STATE);
98 else if (g_strcmp0(event_name, SYS_EVENT_NPS_ENABLE_STATE) == 0)
99 value = bundle_get_val(data, EVT_KEY_NPS_ENABLE_STATE);
101 LOCATION_SECLOG("[%s: %s]", event_name, value);
104 gint location_setting_add_notify(const gchar *path, SettingCB setting_cb, gpointer self)
106 g_return_val_if_fail(path, -1);
107 g_return_val_if_fail(self, -1);
109 const char *event_name = NULL;
110 event_name = __convert_event_from_vconf(path);
112 if (eventsystem_register_event(event_name, &g_event_req_id, (eventsystem_handler) __event_handler, NULL) != ES_R_OK) {
114 LOCATION_SECLOG("eventsystem_register_event failed");
118 if (vconf_notify_key_changed(path, setting_cb, self)) {
119 LOCATION_SECLOG("vconf notify add failed [%s]", path);
122 LOCATION_SECLOG("vconf notify added [%s]", path);
126 gint location_setting_ignore_notify(const gchar *path, SettingCB setting_cb)
128 g_return_val_if_fail(path, -1);
129 g_return_val_if_fail(setting_cb, -1);
131 if (eventsystem_unregister_event(g_event_req_id) != ES_R_OK) {
132 LOCATION_SECLOG("eventsystem_unregister_event failed");
136 if (vconf_ignore_key_changed(path, setting_cb)) {
137 LOCATION_SECLOG("vconf notify remove failed [%s]", path);
140 LOCATION_SECLOG("vconf notify removed [%s]", path);
144 gint location_state_add_notify(const gchar *path, SettingCB setting_cb, gpointer self)
146 g_return_val_if_fail(path, -1);
147 g_return_val_if_fail(self, -1);
149 if (vconf_notify_key_changed(path, setting_cb, self)) {
150 LOCATION_SECLOG("vconf notify add failed [%s]", path);
153 LOCATION_SECLOG("vconf notify added [%s]", path);
157 gint location_state_ignore_notify(const gchar *path, SettingCB setting_cb)
159 g_return_val_if_fail(path, -1);
160 g_return_val_if_fail(setting_cb, -1);
162 if (vconf_ignore_key_changed(path, setting_cb)) {
163 LOCATION_SECLOG("vconf notify remove failed [%s]", path);
166 LOCATION_SECLOG("vconf notify removed [%s]", path);