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");
53 static int __esd_send_system_event(const char *event_name, bundle *b, const char *key)
58 (esd_sent_item *)g_hash_table_lookup(esd_sent_table, event_name);
60 if (item && __esd_event_data_compare(item->event_data, b, key) == 0) {
61 _D("skip send: same with previous data");
63 ret = eventsystem_send_system_event(event_name, b);
65 _E("failed to send event");
70 bundle_free(item->event_data);
71 item->event_data = bundle_dup(b);
73 item = calloc(1, sizeof(esd_sent_item));
75 _E("memory alloc failed");
79 item->event_name = strdup(event_name);
80 if (item->event_name == NULL) {
86 item->event_data = bundle_dup(b);
89 g_hash_table_insert(esd_sent_table, item->event_name, item);
96 static void __esd_vconfcb_location_use_mylocation(keynode_t *node, void *user_data)
101 const char *key = NULL;
102 const char *val = NULL;
104 _D("vconfcb called");
106 ret = vconf_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION, &enabled);
107 if (ret != VCONF_OK) {
108 _E("failed to get vconf (%d)", ret);
112 key = EVT_KEY_LOCATION_ENABLE_STATE;
115 val = EVT_VAL_LOCATION_ENABLED;
117 val = EVT_VAL_LOCATION_DISABLED;
121 bundle_add_str(b, key, val);
123 if (__esd_send_system_event(SYS_EVENT_LOCATION_ENABLE_STATE, b, key) != ES_R_OK) {
124 _E("failed to send event");
132 static void __esd_vconfcb_location_enabled(keynode_t *node, void *user_data)
137 const char *key = NULL;
138 const char *val = NULL;
140 _D("vconfcb called");
142 ret = vconf_get_int(VCONFKEY_LOCATION_ENABLED, &enabled);
143 if (ret != VCONF_OK) {
144 _E("failed to get vconf (%d)", ret);
148 key = EVT_KEY_GPS_ENABLE_STATE;
151 val = EVT_VAL_GPS_ENABLED;
153 val = EVT_VAL_GPS_DISABLED;
157 bundle_add_str(b, key, val);
159 if (__esd_send_system_event(SYS_EVENT_GPS_ENABLE_STATE, b, key) != ES_R_OK) {
160 _E("failed to send event");
168 static void __esd_vconfcb_location_network_enabled(keynode_t *node, void *user_data)
173 const char *key = NULL;
174 const char *val = NULL;
176 _D("vconfcb called");
178 ret = vconf_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &enabled);
179 if (ret != VCONF_OK) {
180 _E("failed to get vconf (%d)", ret);
184 key = EVT_KEY_NPS_ENABLE_STATE;
187 val = EVT_VAL_NPS_ENABLED;
189 val = EVT_VAL_NPS_DISABLED;
193 bundle_add_str(b, key, val);
195 if (__esd_send_system_event(SYS_EVENT_NPS_ENABLE_STATE, b, key) != ES_R_OK) {
196 _E("failed to send event");
204 static void __esd_vconfcb_language_set(keynode_t *node, void *user_data)
208 const char *key = NULL;
210 _D("vconfcb called");
212 str = vconf_get_str(VCONFKEY_LANGSET);
214 _E("failed to get vconf str");
218 key = EVT_KEY_LANGUAGE_SET;
221 bundle_add_str(b, key, str);
223 if (__esd_send_system_event(SYS_EVENT_LANGUAGE_SET, b, key) != ES_R_OK) {
224 _E("failed to send event");
232 static void __esd_vconfcb_hour_format(keynode_t *node, void *user_data)
237 const char *key = NULL;
238 const char *val = NULL;
240 _D("vconfcb called");
242 ret = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &hours);
243 if (ret != VCONF_OK) {
244 _E("failed to get vconf (%d)", ret);
248 key = EVT_KEY_HOUR_FORMAT;
250 if (hours == VCONFKEY_TIME_FORMAT_24)
251 val = EVT_VAL_HOURFORMAT_24;
253 val = EVT_VAL_HOURFORMAT_12;
256 bundle_add_str(b, key, val);
258 if (__esd_send_system_event(SYS_EVENT_HOUR_FORMAT, b, key) != ES_R_OK) {
259 _E("failed to send event");
267 static void __esd_vconfcb_region_format(keynode_t *node, void *user_data)
271 const char *key = NULL;
273 _D("vconfcb called");
275 str = vconf_get_str(VCONFKEY_REGIONFORMAT);
277 _E("failed to get vconf str");
281 key = EVT_KEY_REGION_FORMAT;
284 bundle_add_str(b, key, str);
286 if (__esd_send_system_event(SYS_EVENT_REGION_FORMAT, b, key) != ES_R_OK) {
287 _E("failed to send event");
295 static void __esd_vconfcb_vibration_status(keynode_t *node, void *user_data)
298 int vibration_on = 0;
304 _D("vconfcb called");
306 ret = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vibration_on);
307 if (ret != VCONF_OK) {
308 _E("failed to get vconf (%d)", ret);
312 ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_on);
313 if (ret != VCONF_OK) {
314 _E("failed to get vconf (%d)", ret);
319 key = EVT_KEY_VIBRATION_STATE;
320 val = EVT_VAL_VIBRATION_ON;
322 bundle_add_str(b, key, val);
323 if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) {
324 _E("failed to send event");
330 key = EVT_KEY_SILENT_MODE;
331 val = EVT_VAL_SILENTMODE_OFF;
333 bundle_add_str(b, key, val);
334 if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) {
335 _E("failed to send event");
341 key = EVT_KEY_VIBRATION_STATE;
342 val = EVT_VAL_VIBRATION_OFF;
344 bundle_add_str(b, key, val);
345 if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) {
346 _E("failed to send event");
353 key = EVT_KEY_SILENT_MODE;
354 val = EVT_VAL_SILENTMODE_ON;
356 bundle_add_str(b, key, val);
357 if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) {
358 _E("failed to send event");
367 static void __esd_vconfcb_sound_status(keynode_t *node, void *user_data)
370 int vibration_on = 0;
376 _D("vconfcb called");
378 ret = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vibration_on);
379 if (ret != VCONF_OK) {
380 _E("failed to get vconf (%d)", ret);
384 ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_on);
385 if (ret != VCONF_OK) {
386 _E("failed to get vconf (%d)", ret);
391 key = EVT_KEY_VIBRATION_STATE;
392 val = EVT_VAL_VIBRATION_OFF;
394 bundle_add_str(b, key, val);
395 if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) {
396 _E("failed to send event");
402 key = EVT_KEY_SILENT_MODE;
403 val = EVT_VAL_SILENTMODE_OFF;
405 bundle_add_str(b, key, val);
406 if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) {
407 _E("failed to send event");
414 key = EVT_KEY_SILENT_MODE;
415 val = EVT_VAL_SILENTMODE_ON;
417 bundle_add_str(b, key, val);
418 if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) {
419 _E("failed to send event");
428 static void __esd_vconfcb_auto_rotate(keynode_t *node, void *user_data)
433 const char *key = NULL;
434 const char *val = NULL;
436 _D("vconfcb called");
438 ret = vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &enabled);
439 if (ret != VCONF_OK) {
440 _E("failed to get vconf (%d)", ret);
444 key = EVT_KEY_SCREEN_AUTOROTATE_STATE;
447 val = EVT_VAL_SCREEN_AUTOROTATE_ON;
449 val = EVT_VAL_SCREEN_AUTOROTATE_OFF;
452 bundle_add_str(b, key, val);
454 if (__esd_send_system_event(SYS_EVENT_SCREEN_AUTOROTATE_STATE, b, key) != ES_R_OK) {
455 _E("failed to send event");
463 static void __esd_vconfcb_mobiledata_state(keynode_t *node, void *user_data)
468 const char *key = NULL;
469 const char *val = NULL;
471 _D("vconfcb called");
473 ret = vconf_get_bool(VCONFKEY_3G_ENABLE, &enabled);
474 if (ret != VCONF_OK) {
475 _E("failed to get vconf (%d)", ret);
479 key = EVT_KEY_MOBILE_DATA_STATE;
482 val = EVT_VAL_MOBILE_DATA_ON;
484 val = EVT_VAL_MOBILE_DATA_OFF;
487 bundle_add_str(b, key, val);
489 if (__esd_send_system_event(SYS_EVENT_MOBILE_DATA_STATE, b, key) != ES_R_OK) {
490 _E("failed to send event");
498 static void __esd_vconfcb_roaming_state(keynode_t *node, void *user_data)
503 const char *key = NULL;
504 const char *val = NULL;
506 _D("vconfcb called");
508 ret = vconf_get_bool(VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, &enabled);
509 if (ret != VCONF_OK) {
510 _E("failed to get vconf (%d)", ret);
514 key = EVT_KEY_DATA_ROAMING_STATE;
517 val = EVT_VAL_DATA_ROAMING_ON;
519 val = EVT_VAL_DATA_ROAMING_OFF;
522 bundle_add_str(b, key, val);
524 if (__esd_send_system_event(SYS_EVENT_DATA_ROAMING_STATE, b, key) != ES_R_OK) {
525 _E("failed to send event");
533 static void __esd_vconfcb_font_set(keynode_t *node, void *user_data)
537 const char *key = NULL;
539 _D("vconfcb called");
541 str = vconf_get_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME);
543 _E("failed to get vconf str");
547 key = EVT_KEY_FONT_SET;
550 bundle_add_str(b, key, str);
552 if (__esd_send_system_event(SYS_EVENT_FONT_SET, b, key) != ES_R_OK) {
553 _E("failed to send event");
561 static struct esd_vconf_handler vconf_callbacks[] = {
562 {VCONFKEY_LOCATION_USE_MY_LOCATION, __esd_vconfcb_location_use_mylocation},
563 {VCONFKEY_LOCATION_ENABLED, __esd_vconfcb_location_enabled},
564 {VCONFKEY_LOCATION_NETWORK_ENABLED, __esd_vconfcb_location_network_enabled},
565 {VCONFKEY_LANGSET, __esd_vconfcb_language_set},
566 {VCONFKEY_REGIONFORMAT_TIME1224, __esd_vconfcb_hour_format},
567 {VCONFKEY_REGIONFORMAT, __esd_vconfcb_region_format},
568 {VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, __esd_vconfcb_vibration_status},
569 {VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, __esd_vconfcb_sound_status},
570 {VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __esd_vconfcb_auto_rotate},
571 {VCONFKEY_3G_ENABLE, __esd_vconfcb_mobiledata_state},
572 {VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, __esd_vconfcb_roaming_state},
573 {VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, __esd_vconfcb_font_set},
576 static int vconfcbs_size = sizeof(vconf_callbacks)/sizeof(struct esd_vconf_handler);
578 int __esd_register_vconf_callbacks(void)
582 int result = ES_R_OK;
584 #if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 36)
588 esd_sent_table = g_hash_table_new(g_str_hash, g_str_equal);
590 _D("vconf callbacks size(%d)", vconfcbs_size);
591 for (i = 0; i < vconfcbs_size; i++) {
592 ret = vconf_notify_key_changed(vconf_callbacks[i].key,
593 vconf_callbacks[i].esd_vconfcb_fn, NULL);
594 if (ret != VCONF_OK) {
595 _E("failed to register vconf callback (%s)", vconf_callbacks[i].key);