7 #include <eventsystem.h>
9 #include "eventsystem_daemon.h"
11 /* table item : sent system-event by esd */
12 static GHashTable *esd_sent_table;
14 typedef struct __esd_sent_table_item {
19 struct esd_vconf_handler {
21 void (*esd_vconfcb_fn) (keynode_t *node, void *user_data);
24 static int __esd_event_data_compare(bundle *b1, bundle *b2, const char *key)
32 if (bundle_get_count(b1) == bundle_get_count(b2)) {
33 tmp1 = bundle_get_str(b1, key, &str1);
34 tmp2 = bundle_get_str(b2, key, &str2);
35 if (tmp1 == BUNDLE_ERROR_NONE && tmp2 == BUNDLE_ERROR_NONE) {
36 if (strcmp(str1, str2) != 0) {
37 _D("new event_data : value check");
42 _D("new event_data : bundle_count check");
47 _D("same event_data");
52 static int __esd_send_system_event(const char *event_name, bundle *b, const char *key)
56 (esd_sent_item *)g_hash_table_lookup(esd_sent_table, event_name);
58 if (item && __esd_event_data_compare(item->event_data, b, key) == 0) {
59 _D("skip send: same with previous data");
61 ret = eventsystem_send_system_event(event_name, b);
63 _E("failed to send event");
68 bundle_free(item->event_data);
69 item->event_data = bundle_dup(b);
71 item = calloc(1, sizeof(esd_sent_item));
73 _E("memory alloc failed");
77 item->event_name = strdup(event_name);
78 if (item->event_name == NULL) {
84 item->event_data = bundle_dup(b);
87 g_hash_table_insert(esd_sent_table, item->event_name, item);
94 static void __esd_vconfcb_location_use_mylocation(keynode_t *node, void *user_data)
99 const char *key = NULL;
100 const char *val = NULL;
102 _D("vconfcb called");
104 ret = vconf_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION, &enabled);
105 if (ret != VCONF_OK) {
106 _E("failed to get vconf (%d)", ret);
110 key = EVT_KEY_LOCATION_ENABLE_STATE;
113 val = EVT_VAL_LOCATION_ENABLED;
115 val = EVT_VAL_LOCATION_DISABLED;
118 bundle_add_str(b, key, val);
120 if (__esd_send_system_event(SYS_EVENT_LOCATION_ENABLE_STATE, b, key) != ES_R_OK)
121 _E("failed to send event");
127 static void __esd_vconfcb_location_enabled(keynode_t *node, void *user_data)
132 const char *key = NULL;
133 const char *val = NULL;
135 _D("vconfcb called");
137 ret = vconf_get_int(VCONFKEY_LOCATION_ENABLED, &enabled);
138 if (ret != VCONF_OK) {
139 _E("failed to get vconf (%d)", ret);
143 key = EVT_KEY_GPS_ENABLE_STATE;
146 val = EVT_VAL_GPS_ENABLED;
148 val = EVT_VAL_GPS_DISABLED;
151 bundle_add_str(b, key, val);
153 if (__esd_send_system_event(SYS_EVENT_GPS_ENABLE_STATE, b, key) != ES_R_OK)
154 _E("failed to send event");
160 static void __esd_vconfcb_location_network_enabled(keynode_t *node, void *user_data)
165 const char *key = NULL;
166 const char *val = NULL;
168 _D("vconfcb called");
170 ret = vconf_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &enabled);
171 if (ret != VCONF_OK) {
172 _E("failed to get vconf (%d)", ret);
176 key = EVT_KEY_NPS_ENABLE_STATE;
179 val = EVT_VAL_NPS_ENABLED;
181 val = EVT_VAL_NPS_DISABLED;
184 bundle_add_str(b, key, val);
186 if (__esd_send_system_event(SYS_EVENT_NPS_ENABLE_STATE, b, key) != ES_R_OK)
187 _E("failed to send event");
193 static void __esd_vconfcb_language_set(keynode_t *node, void *user_data)
197 const char *key = NULL;
199 _D("vconfcb called");
201 str = vconf_get_str(VCONFKEY_LANGSET);
203 _E("failed to get vconf str");
207 key = EVT_KEY_LANGUAGE_SET;
210 bundle_add_str(b, key, str);
212 if (__esd_send_system_event(SYS_EVENT_LANGUAGE_SET, b, key) != ES_R_OK)
213 _E("failed to send event");
221 static void __esd_vconfcb_hour_format(keynode_t *node, void *user_data)
226 const char *key = NULL;
227 const char *val = NULL;
229 _D("vconfcb called");
231 ret = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &hours);
232 if (ret != VCONF_OK) {
233 _E("failed to get vconf (%d)", ret);
237 key = EVT_KEY_HOUR_FORMAT;
239 if (hours == VCONFKEY_TIME_FORMAT_24)
240 val = EVT_VAL_HOURFORMAT_24;
242 val = EVT_VAL_HOURFORMAT_12;
245 bundle_add_str(b, key, val);
247 if (__esd_send_system_event(SYS_EVENT_HOUR_FORMAT, b, key) != ES_R_OK)
248 _E("failed to send event");
254 static void __esd_vconfcb_region_format(keynode_t *node, void *user_data)
258 const char *key = NULL;
260 _D("vconfcb called");
262 str = vconf_get_str(VCONFKEY_REGIONFORMAT);
264 _E("failed to get vconf str");
268 key = EVT_KEY_REGION_FORMAT;
271 bundle_add_str(b, key, str);
273 if (__esd_send_system_event(SYS_EVENT_REGION_FORMAT, b, key) != ES_R_OK)
274 _E("failed to send event");
282 static void __esd_vconfcb_vibration_status(keynode_t *node, void *user_data)
285 int vibration_on = 0;
291 _D("vconfcb called");
293 ret = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vibration_on);
294 if (ret != VCONF_OK) {
295 _E("failed to get vconf (%d)", ret);
299 ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_on);
300 if (ret != VCONF_OK) {
301 _E("failed to get vconf (%d)", ret);
306 key = EVT_KEY_VIBRATION_STATE;
307 val = EVT_VAL_VIBRATION_ON;
309 bundle_add_str(b, key, val);
310 if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK)
311 _E("failed to send event");
316 key = EVT_KEY_SILENT_MODE;
317 val = EVT_VAL_SILENTMODE_OFF;
319 bundle_add_str(b, key, val);
320 if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK)
321 _E("failed to send event");
326 key = EVT_KEY_VIBRATION_STATE;
327 val = EVT_VAL_VIBRATION_OFF;
329 bundle_add_str(b, key, val);
330 if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK)
331 _E("failed to send event");
337 key = EVT_KEY_SILENT_MODE;
338 val = EVT_VAL_SILENTMODE_ON;
340 bundle_add_str(b, key, val);
341 if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK)
342 _E("failed to send event");
350 static void __esd_vconfcb_sound_status(keynode_t *node, void *user_data)
353 int vibration_on = 0;
359 _D("vconfcb called");
361 ret = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vibration_on);
362 if (ret != VCONF_OK) {
363 _E("failed to get vconf (%d)", ret);
367 ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_on);
368 if (ret != VCONF_OK) {
369 _E("failed to get vconf (%d)", ret);
374 key = EVT_KEY_VIBRATION_STATE;
375 val = EVT_VAL_VIBRATION_OFF;
377 bundle_add_str(b, key, val);
378 if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK)
379 _E("failed to send event");
384 key = EVT_KEY_SILENT_MODE;
385 val = EVT_VAL_SILENTMODE_OFF;
387 bundle_add_str(b, key, val);
388 if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK)
389 _E("failed to send event");
395 key = EVT_KEY_SILENT_MODE;
396 val = EVT_VAL_SILENTMODE_ON;
398 bundle_add_str(b, key, val);
399 if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK)
400 _E("failed to send event");
408 static void __esd_vconfcb_auto_rotate(keynode_t *node, void *user_data)
413 const char *key = NULL;
414 const char *val = NULL;
416 _D("vconfcb called");
418 ret = vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &enabled);
419 if (ret != VCONF_OK) {
420 _E("failed to get vconf (%d)", ret);
424 key = EVT_KEY_SCREEN_AUTOROTATE_STATE;
427 val = EVT_VAL_SCREEN_AUTOROTATE_ON;
429 val = EVT_VAL_SCREEN_AUTOROTATE_OFF;
432 bundle_add_str(b, key, val);
434 if (__esd_send_system_event(SYS_EVENT_SCREEN_AUTOROTATE_STATE, b, key) != ES_R_OK)
435 _E("failed to send event");
441 static void __esd_vconfcb_mobiledata_state(keynode_t *node, void *user_data)
446 const char *key = NULL;
447 const char *val = NULL;
449 _D("vconfcb called");
451 ret = vconf_get_bool(VCONFKEY_3G_ENABLE, &enabled);
452 if (ret != VCONF_OK) {
453 _E("failed to get vconf (%d)", ret);
457 key = EVT_KEY_MOBILE_DATA_STATE;
460 val = EVT_VAL_MOBILE_DATA_ON;
462 val = EVT_VAL_MOBILE_DATA_OFF;
465 bundle_add_str(b, key, val);
467 if (__esd_send_system_event(SYS_EVENT_MOBILE_DATA_STATE, b, key) != ES_R_OK)
468 _E("failed to send event");
474 static void __esd_vconfcb_roaming_state(keynode_t *node, void *user_data)
479 const char *key = NULL;
480 const char *val = NULL;
482 _D("vconfcb called");
484 ret = vconf_get_bool(VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, &enabled);
485 if (ret != VCONF_OK) {
486 _E("failed to get vconf (%d)", ret);
490 key = EVT_KEY_DATA_ROAMING_STATE;
493 val = EVT_VAL_DATA_ROAMING_ON;
495 val = EVT_VAL_DATA_ROAMING_OFF;
498 bundle_add_str(b, key, val);
500 if (__esd_send_system_event(SYS_EVENT_DATA_ROAMING_STATE, b, key) != ES_R_OK)
501 _E("failed to send event");
507 static void __esd_vconfcb_font_set(keynode_t *node, void *user_data)
511 const char *key = NULL;
513 _D("vconfcb called");
515 str = vconf_get_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME);
517 _E("failed to get vconf str");
521 key = EVT_KEY_FONT_SET;
524 bundle_add_str(b, key, str);
526 if (__esd_send_system_event(SYS_EVENT_FONT_SET, b, key) != ES_R_OK)
527 _E("failed to send event");
535 static struct esd_vconf_handler vconf_callbacks[] = {
536 {VCONFKEY_LOCATION_USE_MY_LOCATION, __esd_vconfcb_location_use_mylocation},
537 {VCONFKEY_LOCATION_ENABLED, __esd_vconfcb_location_enabled},
538 {VCONFKEY_LOCATION_NETWORK_ENABLED, __esd_vconfcb_location_network_enabled},
539 {VCONFKEY_LANGSET, __esd_vconfcb_language_set},
540 {VCONFKEY_REGIONFORMAT_TIME1224, __esd_vconfcb_hour_format},
541 {VCONFKEY_REGIONFORMAT, __esd_vconfcb_region_format},
542 {VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, __esd_vconfcb_vibration_status},
543 {VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, __esd_vconfcb_sound_status},
544 {VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __esd_vconfcb_auto_rotate},
545 {VCONFKEY_3G_ENABLE, __esd_vconfcb_mobiledata_state},
546 {VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, __esd_vconfcb_roaming_state},
547 {VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, __esd_vconfcb_font_set},
550 static int vconfcbs_size = sizeof(vconf_callbacks)/sizeof(struct esd_vconf_handler);
552 int __esd_register_vconf_callbacks(void)
556 int result = ES_R_OK;
558 #if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 36)
562 esd_sent_table = g_hash_table_new(g_str_hash, g_str_equal);
564 _D("vconf callbacks size(%d)", vconfcbs_size);
565 for (i = 0; i < vconfcbs_size; i++) {
566 ret = vconf_notify_key_changed(vconf_callbacks[i].key,
567 vconf_callbacks[i].esd_vconfcb_fn, NULL);
568 if (ret != VCONF_OK) {
569 _E("failed to register vconf callback (%s)", vconf_callbacks[i].key);