2 #include <notification.h>
6 #include <dbus/dbus-glib.h>
7 #include <dbus/dbus-glib-lowlevel.h>
10 #include <libwlmessage.h>
16 BT_CORE_AGENT_TIMEOUT,
17 } bt_agent_accept_type_t;
20 typedef void (*bt_notification)(DBusGProxy *proxy);
23 __bluetooth_create_agent_proxy(DBusGConnection *sys_conn, const char *path)
25 return dbus_g_proxy_new_for_name (sys_conn,
32 __bluetooth_create_obex_proxy(DBusGConnection *sys_conn)
34 return dbus_g_proxy_new_for_name(sys_conn,
35 "org.bluez.frwk_agent",
36 "/org/obex/ops_agent",
37 "org.openobex.Agent");
41 __notify_passkey_confirm_request_accept_cb( DBusGProxy* agent_proxy)
43 dbus_g_proxy_call_no_reply( agent_proxy, "ReplyConfirmation",
44 G_TYPE_UINT, BT_AGENT_ACCEPT,
45 G_TYPE_INVALID, G_TYPE_INVALID);
50 __notify_passkey_confirm_request_cancel_cb(DBusGProxy* agent_proxy)
53 dbus_g_proxy_call_no_reply( agent_proxy, "ReplyConfirmation",
54 G_TYPE_UINT, BT_AGENT_CANCEL,
55 G_TYPE_INVALID, G_TYPE_INVALID);
60 __notify_push_authorize_request_accept_cb(DBusGProxy* obex_proxy)
63 dbus_g_proxy_call_no_reply( obex_proxy, "ReplyAuthorize",
64 G_TYPE_UINT, BT_AGENT_ACCEPT,
65 G_TYPE_INVALID, G_TYPE_INVALID);
70 __notify_push_authorize_request_cancel_cb(DBusGProxy* obex_proxy)
73 dbus_g_proxy_call_no_reply( obex_proxy, "ReplyAuthorize",
74 G_TYPE_UINT, BT_AGENT_CANCEL,
75 G_TYPE_INVALID, G_TYPE_INVALID);
80 __notify_authorize_request_accept_cb(DBusGProxy* agent_proxy)
83 dbus_g_proxy_call_no_reply( agent_proxy, "ReplyAuthorize",
84 G_TYPE_UINT, BT_AGENT_ACCEPT,
85 G_TYPE_INVALID, G_TYPE_INVALID);
89 __notify_authorize_request_cancel_cb(DBusGProxy* agent_proxy)
92 dbus_g_proxy_call_no_reply( agent_proxy, "ReplyAuthorize",
93 G_TYPE_UINT, BT_AGENT_CANCEL,
94 G_TYPE_INVALID, G_TYPE_INVALID);
99 __display_notification(bt_notification cb_1, bt_notification cb_2, DBusGProxy *proxy)
102 notification_error_e err = NOTIFICATION_ERROR_NONE;
106 struct wlmessage *wlmessage = wlmessage_create();
107 wlmessage_set_message(wlmessage, "Do you confirm ?");
108 wlmessage_add_button(wlmessage, 1, "Yes");
109 wlmessage_add_button(wlmessage, 0, "No");
110 wlmessage_set_default_button(wlmessage, 1);
111 bt_yesno = wlmessage_show(wlmessage, NULL);
112 wlmessage_destroy(wlmessage);
115 LOGD("user accepts to pair with device ");
117 } else if (bt_yesno == 0) {
118 LOGD("user rejects to pair with device ");
123 fprintf(stdout, "Do you confirm yes or no ? ");
124 while ( bt_yesno != 0){
125 if (!fgets(line, sizeof(line), stdin))
127 if (strncmp("yes", line, 3) == 0) {
128 LOGD("user accepts to pair with device ");
131 } else if (strncmp("no", line, 2) == 0) {
132 LOGD("user rejects to pair with device ");
136 fprintf(stdout," yes or no ?\n");
140 err = notification_delete_all_by_type("bluetooth-frwk-bt-service", NOTIFICATION_TYPE_NOTI);
141 if (err != NOTIFICATION_ERROR_NONE) {
142 LOGE("Unable to remove notifications");
147 static void __noti_changed_cb(void *data, notification_type_e type)
149 notification_h noti = NULL;
150 notification_list_h notification_list = NULL;
151 notification_list_h get_list = NULL;
152 int count = 0, group_id = 0, priv_id = 0, show_noti = 0, num = 1;
153 char *pkgname = NULL;
155 char *str_count = NULL;
157 bundle *user_data = NULL;
158 DBusGConnection *sys_conn;
159 DBusGProxy *agent_proxy;
160 DBusGProxy *obex_proxy;
163 const char *device_name = NULL;
164 const char *passkey = NULL;
165 const char *file = NULL;
166 const char *agent_path;
167 const char *event_type = NULL;
169 notification_get_list(NOTIFICATION_TYPE_NOTI, -1, ¬ification_list);
170 if (notification_list) {
171 get_list = notification_list_get_head(notification_list);
172 noti = notification_list_get_data(get_list);
173 notification_get_id(noti, &group_id, &priv_id);
174 notification_get_pkgname(noti, &pkgname);
176 notification_get_application(noti, &pkgname);
179 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &str_count);
183 count = atoi(str_count);
185 notification_get_title(noti, &title, NULL);
186 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT , &content);
187 notification_get_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,NULL, &user_data);
189 fprintf(stdout, "NOTIFICATION: %s - %s - %s - %i - %i \n", pkgname, title, content, count, num);
191 event_type = bundle_get_val(user_data, "event-type");
194 LOGD("Not a bluetooth-related notification...");
198 if(!strcasecmp(event_type, "pin-request")) {
199 /* Not implemented */
200 fprintf(stdout," Not implemented\n");
202 } else if (!strcasecmp(event_type, "passkey-confirm-request")){
203 device_name = (gchar*) bundle_get_val(user_data, "device-name");
204 passkey = (gchar*) bundle_get_val(user_data, "passkey");
205 agent_path = bundle_get_val(user_data, "agent-path");
207 sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
208 if (sys_conn == NULL) {
209 fprintf(stdout,"ERROR: Can't get on system bus");
213 agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
215 fprintf(stdout,"create new agent_proxy failed\n");
219 __display_notification(__notify_passkey_confirm_request_accept_cb, __notify_passkey_confirm_request_cancel_cb,agent_proxy);
220 } else if (!strcasecmp(event_type, "passkey-request")) {
221 /* Not implemented */
222 fprintf(stdout," Not implemented\n");
224 } else if (!strcasecmp(event_type, "passkey-display-request")) {
225 /* Not implemented */
226 fprintf(stdout," Not implemented\n");
228 } else if (!strcasecmp(event_type, "authorize-request")) {
229 device_name = (gchar*) bundle_get_val(user_data, "device-name");
230 agent_path = bundle_get_val(user_data, "agent-path");
232 sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
233 if (sys_conn == NULL) {
234 fprintf(stdout,"ERROR: Can't get on system bus");
238 agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
240 fprintf(stdout,"create new agent_proxy failed\n");
244 __display_notification( __notify_authorize_request_accept_cb, __notify_authorize_request_cancel_cb,agent_proxy);
245 } else if (!strcasecmp(event_type, "app-confirm-request")) {
246 /* Not implemented */
247 fprintf(stdout," Not implemented\n");
249 } else if (!strcasecmp(event_type, "push-authorize-request")) {
250 file = (gchar*) bundle_get_val(user_data, "file");
251 device_name = (gchar*) bundle_get_val(user_data, "device-name");
253 sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
254 if (sys_conn == NULL) {
255 fprintf(stdout,"ERROR: Can't get on system bus");
259 obex_proxy = __bluetooth_create_obex_proxy(sys_conn);
261 fprintf(stdout,"create new obex_proxy failed\n");
265 __display_notification( __notify_push_authorize_request_accept_cb, __notify_push_authorize_request_cancel_cb,obex_proxy);
266 } else if (!strcasecmp(event_type, "confirm-overwrite-request")) {
267 /* Not implemented */
268 fprintf(stdout," Not implemented\n");
270 } else if (!strcasecmp(event_type, "keyboard-passkey-request")) {
271 /* Not implemented */
272 fprintf(stdout," Not implemented\n");
274 } else if (!strcasecmp(event_type, "bt-information")) {
275 /* Not implemented */
276 fprintf(stdout," Not implemented\n");
278 } else if (!strcasecmp(event_type, "exchange-request")) {
279 device_name = (gchar*) bundle_get_val(user_data, "device-name");
280 agent_path = bundle_get_val(user_data, "agent-path");
282 sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
283 if (sys_conn == NULL) {
284 fprintf(stdout,"ERROR: Can't get on system bus");
288 agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
290 fprintf(stdout,"create new agent_proxy failed\n");
294 __display_notification( __notify_authorize_request_accept_cb, __notify_authorize_request_cancel_cb,agent_proxy);
295 } else if (!strcasecmp(event_type, "phonebook-request")) {
296 device_name = bundle_get_val(user_data, "device-name");
297 agent_path = bundle_get_val(user_data, "agent-path");
299 sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
300 if (sys_conn == NULL) {
301 fprintf(stdout,"ERROR: Can't get on system bus");
305 agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
307 fprintf(stdout,"create new agent_proxy failed\n");
311 __display_notification( __notify_authorize_request_accept_cb, __notify_authorize_request_cancel_cb,agent_proxy);
312 } else if (!strcasecmp(event_type, "message-request")) {
313 device_name = bundle_get_val(user_data, "device-name");
314 agent_path = bundle_get_val(user_data, "agent-path");
316 sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
317 if (sys_conn == NULL) {
318 fprintf(stdout,"ERROR: Can't get on system bus");
322 agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
324 fprintf(stdout,"create new agent_proxy failed\n");
328 __display_notification( __notify_authorize_request_accept_cb, __notify_authorize_request_cancel_cb,agent_proxy);
331 if (notification_list != NULL) {
332 notification_free_list(notification_list);
333 notification_list = NULL;
340 main(int argc, char **argv)
343 LOGE("ERROR: Cannot init Ecore!\n");
347 notification_resister_changed_cb(__noti_changed_cb, NULL);
348 ecore_main_loop_begin();