4 * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include <bundle_internal.h>
25 #include <eventsystem.h>
26 #include "location-log.h"
27 #include "location-setting.h"
30 static unsigned int g_event_req_id;
33 gint location_setting_get_key_val(keynode_t *key)
35 g_return_val_if_fail(key, -1);
37 switch (vconf_keynode_get_type(key)) {
39 val = vconf_keynode_get_int(key);
40 LOCATION_SECLOG("changed [%s]:[%d]", vconf_keynode_get_name(key), val);
43 LOCATION_LOGW("Unused type(%d)", vconf_keynode_get_type(key));
49 gint location_setting_get_int(const gchar *path)
51 g_return_val_if_fail(path, 0);
53 if (vconf_get_int(path, &val))
54 LOCATION_SECLOG("failed [%s]", path);
59 gboolean location_setting_get_bool(const gchar *path)
61 g_return_val_if_fail(path, FALSE);
63 if (vconf_get_bool(path, &val))
64 LOCATION_SECLOG("failed [%s]", path);
70 static char *__convert_event_from_vconf(const char *vconf)
73 if (g_strcmp0(vconf, VCONFKEY_LOCATION_USE_MY_LOCATION) == 0)
74 event = g_strdup(SYS_EVENT_LOCATION_ENABLE_STATE);
75 else if (g_strcmp0(vconf, VCONFKEY_LOCATION_ENABLED) == 0)
76 event = g_strdup(SYS_EVENT_GPS_ENABLE_STATE);
77 else if (g_strcmp0(vconf, VCONFKEY_LOCATION_NETWORK_ENABLED) == 0)
78 event = g_strdup(SYS_EVENT_NPS_ENABLE_STATE);
83 static void __event_handler(const char *event_name, bundle *data, void *self)
85 const char *value = NULL;
87 if (g_strcmp0(event_name, SYS_EVENT_LOCATION_ENABLE_STATE) == 0)
88 value = bundle_get_val(data, EVT_KEY_LOCATION_ENABLE_STATE);
89 else if (g_strcmp0(event_name, SYS_EVENT_GPS_ENABLE_STATE) == 0)
90 value = bundle_get_val(data, EVT_KEY_GPS_ENABLE_STATE);
91 else if (g_strcmp0(event_name, SYS_EVENT_NPS_ENABLE_STATE) == 0)
92 value = bundle_get_val(data, EVT_KEY_NPS_ENABLE_STATE);
94 LOCATION_SECLOG("[%s: %s]", event_name, value);
98 gint location_setting_add_notify(const gchar *path, SettingCB setting_cb, gpointer self)
100 g_return_val_if_fail(path, -1);
101 g_return_val_if_fail(self, -1);
104 const char *event_name = NULL;
105 event_name = __convert_event_from_vconf(path);
107 if (eventsystem_register_event(event_name, &g_event_req_id, (eventsystem_handler) __event_handler, NULL) != ES_R_OK)
108 LOCATION_SECLOG("eventsystem_register_event failed");
110 if (vconf_notify_key_changed(path, setting_cb, self)) {
111 LOCATION_SECLOG("vconf notify add failed [%s]", path);
114 LOCATION_SECLOG("vconf notify added [%s]", path);
118 gint location_setting_ignore_notify(const gchar *path, SettingCB setting_cb)
120 g_return_val_if_fail(path, -1);
121 g_return_val_if_fail(setting_cb, -1);
124 if (eventsystem_unregister_event(g_event_req_id) != ES_R_OK)
125 LOCATION_SECLOG("eventsystem_unregister_event failed");
128 if (vconf_ignore_key_changed(path, setting_cb)) {
129 LOCATION_SECLOG("vconf notify remove failed [%s]", path);
132 LOCATION_SECLOG("vconf notify removed [%s]", path);
136 gint location_state_add_notify(const gchar *path, SettingCB setting_cb, gpointer self)
138 g_return_val_if_fail(path, -1);
139 g_return_val_if_fail(self, -1);
141 if (vconf_notify_key_changed(path, setting_cb, self)) {
142 LOCATION_SECLOG("vconf notify add failed [%s]", path);
145 LOCATION_SECLOG("vconf notify added [%s]", path);
149 gint location_state_ignore_notify(const gchar *path, SettingCB setting_cb)
151 g_return_val_if_fail(path, -1);
152 g_return_val_if_fail(setting_cb, -1);
154 if (vconf_ignore_key_changed(path, setting_cb)) {
155 LOCATION_SECLOG("vconf notify remove failed [%s]", path);
158 LOCATION_SECLOG("vconf notify removed [%s]", path);