2 #include <notification.h>
7 #include <libwlmessage.h>
12 #include <bluetooth.h>
15 #define POPUP_TYPE_INFO "user_info_popup"
16 #define POPUP_TYPE_USERCONFIRM "user_confirm_popup"
17 #define POPUP_TYPE_USERPROMPT "user_agreement_popup"
19 static void display_user_information_popup(void) {};
21 static void display_user_prompt_popup(void) {};
23 static void display_user_confirmation_popup(void)
25 notification_error_e err = NOTIFICATION_ERROR_NONE;
31 struct wlmessage *wlmessage = wlmessage_create();
32 wlmessage_set_message(wlmessage, "Do you confirm ?");
33 wlmessage_add_button(wlmessage, 1, "Yes");
34 wlmessage_add_button(wlmessage, 0, "No");
35 wlmessage_set_default_button(wlmessage, 1);
36 bt_yesno = wlmessage_show(wlmessage, NULL);
37 wlmessage_destroy(wlmessage);
40 bt_agent_reply_sync(0);
41 else if (bt_yesno == 0)
42 bt_agent_reply_sync(1);
44 fprintf(stdout, "Do you confirm yes or no ? ");
45 while ( bt_yesno != 0){
46 if (!fgets(line, sizeof(line), stdin))
48 if ( strncmp("yes", line, 3) == 0) {
49 LOGD("user accepts to pair with device ");
50 bt_agent_reply_sync(0);
52 } else if ( strncmp("no", line, 2) == 0) {
53 LOGD("user rejects to pair with device ");
54 bt_agent_reply_sync(1);
57 fprintf(stdout," yes or no ?\n");
62 err = notification_delete_all_by_type("bt-agent", NOTIFICATION_TYPE_NOTI);
63 if (err != NOTIFICATION_ERROR_NONE) {
64 LOGE("Unable to remove notifications");
69 static void __noti_changed_cb(void *data, notification_type_e type)
71 notification_h noti = NULL;
72 notification_list_h notification_list = NULL;
73 notification_list_h get_list = NULL;
74 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
76 LOGD("listen to new notifications...");
78 int count = 0, group_id = 0, priv_id = 0, num = 1;
81 char *str_count = NULL;
83 bundle *user_data = NULL;
85 const char *device_name = NULL;
86 const char *passkey = NULL;
87 const char *agent_path;
88 const char *event_type = NULL;
90 char *popup_type = NULL;
92 noti_err = notification_get_list(NOTIFICATION_TYPE_NOTI, -1, ¬ification_list);
93 if (noti_err != NOTIFICATION_ERROR_NONE) {
94 LOGE("notification_get_list() failed (error code = %d)", noti_err);
97 if (notification_list) {
98 LOGD("new notificiation received");
100 get_list = notification_list_get_head(notification_list);
101 noti = notification_list_get_data(get_list);
102 notification_get_id(noti, &group_id, &priv_id);
103 notification_get_pkgname(noti, &pkgname);
105 notification_get_application(noti, &pkgname);
108 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &str_count);
112 count = atoi(str_count);
114 notification_get_title(noti, &title, NULL);
115 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT , &content);
116 notification_get_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,NULL, &user_data);
118 fprintf(stdout, "NOTIFICATION: %s - %s - %s - %i - %i \n", pkgname, title, content, count, num);
120 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, &popup_type);
121 LOGD("'%s' notification type [%s]", pkgname, popup_type);
123 if (!strcasecmp(POPUP_TYPE_INFO, popup_type))
124 display_user_information_popup();
125 else if (!strcasecmp(POPUP_TYPE_USERCONFIRM, popup_type))
126 display_user_confirmation_popup();
127 else if (!strcasecmp(POPUP_TYPE_USERPROMPT, popup_type))
128 display_user_prompt_popup();
130 LOGE("popup type is not recognized !");
133 if (notification_list != NULL) {
134 notification_free_list(notification_list);
135 notification_list = NULL;
142 main(int argc, char **argv)
145 LOGE("ERROR: Cannot init Ecore!\n");
151 bt_agent_register_sync();
153 notification_resister_changed_cb(__noti_changed_cb, NULL);
154 ecore_main_loop_begin();