From d3b7401e549727cf72a2939d4e7e6c86088ae76b Mon Sep 17 00:00:00 2001 From: Manuel Bachmann Date: Wed, 13 Aug 2014 16:48:13 +0200 Subject: [PATCH] Use new Bluetooth-frwk bt_agent_reply_sync() APIs Modify "bluetooth-notification-test" and "notification-display-service" to use the new APIs of "bluetooth-frwk" to send replies to its "bluetooth-service". This adds an explicit dep. to "bluetooth-frwk". Change-Id: I78a98a7f9792f1feb9d92737b5f085c57241897d Signed-off-by: Manuel Bachmann --- bluetooth_notification_client.c | 304 +++++++----------------------------- configure.ac | 2 +- notification_display_service.c | 49 +++--- packaging/notification-service.spec | 3 +- 4 files changed, 87 insertions(+), 271 deletions(-) diff --git a/bluetooth_notification_client.c b/bluetooth_notification_client.c index 1b8ab7c..8794ba7 100644 --- a/bluetooth_notification_client.c +++ b/bluetooth_notification_client.c @@ -2,107 +2,29 @@ #include #include -#include -#include -#include #include #ifdef HAVE_WAYLAND #include #endif -typedef enum { - BT_AGENT_ACCEPT, - BT_AGENT_REJECT, - BT_AGENT_CANCEL, - BT_CORE_AGENT_TIMEOUT, -} bt_agent_accept_type_t; - - -typedef void (*bt_notification)(DBusGProxy *proxy); - -static DBusGProxy* -__bluetooth_create_agent_proxy(DBusGConnection *sys_conn, const char *path) -{ - return dbus_g_proxy_new_for_name (sys_conn, - "org.projectx.bt", - path, - "org.bluez.Agent1"); -} - -static DBusGProxy* -__bluetooth_create_obex_proxy(DBusGConnection *sys_conn) -{ - return dbus_g_proxy_new_for_name(sys_conn, - "org.bluez.frwk_agent", - "/org/obex/ops_agent", - "org.openobex.Agent"); -} - -static void -__notify_passkey_confirm_request_accept_cb( DBusGProxy* agent_proxy) -{ - dbus_g_proxy_call_no_reply( agent_proxy, "ReplyConfirmation", - G_TYPE_UINT, BT_AGENT_ACCEPT, - G_TYPE_INVALID, G_TYPE_INVALID); - -} - -static void -__notify_passkey_confirm_request_cancel_cb(DBusGProxy* agent_proxy) -{ - - dbus_g_proxy_call_no_reply( agent_proxy, "ReplyConfirmation", - G_TYPE_UINT, BT_AGENT_CANCEL, - G_TYPE_INVALID, G_TYPE_INVALID); - -} - -static void -__notify_push_authorize_request_accept_cb(DBusGProxy* obex_proxy) -{ - - dbus_g_proxy_call_no_reply( obex_proxy, "ReplyAuthorize", - G_TYPE_UINT, BT_AGENT_ACCEPT, - G_TYPE_INVALID, G_TYPE_INVALID); - -} - -static void -__notify_push_authorize_request_cancel_cb(DBusGProxy* obex_proxy) -{ - - dbus_g_proxy_call_no_reply( obex_proxy, "ReplyAuthorize", - G_TYPE_UINT, BT_AGENT_CANCEL, - G_TYPE_INVALID, G_TYPE_INVALID); - -} - -static void -__notify_authorize_request_accept_cb(DBusGProxy* agent_proxy) -{ +#include - dbus_g_proxy_call_no_reply( agent_proxy, "ReplyAuthorize", - G_TYPE_UINT, BT_AGENT_ACCEPT, - G_TYPE_INVALID, G_TYPE_INVALID); -} +#include +#include -static void -__notify_authorize_request_cancel_cb(DBusGProxy* agent_proxy) -{ +#define POPUP_TYPE_INFO "user_info_popup" +#define POPUP_TYPE_USERCONFIRM "user_confirm_popup" +#define POPUP_TYPE_USERPROMPT "user_agreement_popup" - dbus_g_proxy_call_no_reply( agent_proxy, "ReplyAuthorize", - G_TYPE_UINT, BT_AGENT_CANCEL, - G_TYPE_INVALID, G_TYPE_INVALID); +static void display_user_information_popup(void) {}; -} +static void display_user_prompt_popup(void) {}; -static int -__display_notification(bt_notification cb_1, bt_notification cb_2, DBusGProxy *proxy) +static void display_user_confirmation_popup(void) { - notification_error_e err = NOTIFICATION_ERROR_NONE; - int bt_yesno; - bt_yesno = 1; + int bt_yesno = 1; + char line[4]; #ifdef HAVE_WAYLAND @@ -115,28 +37,31 @@ __display_notification(bt_notification cb_1, bt_notification cb_2, DBusGProxy *p wlmessage_destroy(wlmessage); if (bt_yesno == 1) - (cb_1) (proxy); + bt_agent_reply_sync(0); else if (bt_yesno == 0) - (cb_2) (proxy); + bt_agent_reply_sync(1); #else fprintf(stdout, "Do you confirm yes or no ? "); while ( bt_yesno != 0){ if (!fgets(line, sizeof(line), stdin)) continue; - if ( strcmp(line,"yes") == 0){ - (cb_1) (proxy); + if ( strncmp("yes", line, 3) == 0) { + LOGD("user accepts to pair with device "); + bt_agent_reply_sync(0); bt_yesno = 0; - } else if ( strcmp(line,"no") == 0){ - (cb_2) (proxy); + } else if ( strncmp("no", line, 2) == 0) { + LOGD("user rejects to pair with device "); + bt_agent_reply_sync(1); bt_yesno = 0; } else { - fprintf(stdout," yes or no :"); + fprintf(stdout," yes or no ?\n"); + continue; } } #endif - err = notification_delete_all_by_type("bluetooth-frwk-bt-service", NOTIFICATION_TYPE_NOTI); + err = notification_delete_all_by_type("bt-agent", NOTIFICATION_TYPE_NOTI); if (err != NOTIFICATION_ERROR_NONE) { - fprintf(stdout, "Unable to remove notifications"); + LOGE("Unable to remove notifications"); } } @@ -146,25 +71,32 @@ static void __noti_changed_cb(void *data, notification_type_e type) notification_h noti = NULL; notification_list_h notification_list = NULL; notification_list_h get_list = NULL; - int count = 0, group_id = 0, priv_id = 0, show_noti = 0, num = 1; + notification_error_e noti_err = NOTIFICATION_ERROR_NONE; + + LOGD("listen to new notifications..."); + + int count = 0, group_id = 0, priv_id = 0, num = 1; char *pkgname = NULL; char *title = NULL; char *str_count = NULL; char *content= NULL; bundle *user_data = NULL; - DBusGConnection *sys_conn; - DBusGProxy *agent_proxy; - DBusGProxy *obex_proxy; - const char *device_name = NULL; const char *passkey = NULL; - const char *file = NULL; const char *agent_path; const char *event_type = NULL; - notification_get_list(NOTIFICATION_TYPE_NOTI, -1, ¬ification_list); + char *popup_type = NULL; + + noti_err = notification_get_list(NOTIFICATION_TYPE_NOTI, -1, ¬ification_list); + if (noti_err != NOTIFICATION_ERROR_NONE) { + LOGE("notification_get_list() failed (error code = %d)", noti_err); + } + if (notification_list) { + LOGD("new notificiation received"); + get_list = notification_list_get_head(notification_list); noti = notification_list_get_data(get_list); notification_get_id(noti, &group_id, &priv_id); @@ -185,162 +117,42 @@ static void __noti_changed_cb(void *data, notification_type_e type) fprintf(stdout, "NOTIFICATION: %s - %s - %s - %i - %i \n", pkgname, title, content, count, num); - event_type = bundle_get_val(user_data, "event-type"); - - if(!strcasecmp(event_type, "pin-request")) { - /* Not implemented */ - fprintf(stdout," Not implemented\n"); - - } else if (!strcasecmp(event_type, "passkey-confirm-request")){ - device_name = (gchar*) bundle_get_val(user_data, "device-name"); - passkey = (gchar*) bundle_get_val(user_data, "passkey"); - agent_path = bundle_get_val(user_data, "agent-path"); - - sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); - if (sys_conn == NULL) { - fprintf(stdout,"ERROR: Can't get on system bus"); - return; - } - - agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path); - if (!agent_proxy){ - fprintf(stdout,"create new agent_proxy failed\n"); - return; - } - - __display_notification(__notify_passkey_confirm_request_accept_cb, __notify_passkey_confirm_request_cancel_cb,agent_proxy); - } else if (!strcasecmp(event_type, "passkey-request")) { - /* Not implemented */ - fprintf(stdout," Not implemented\n"); - - } else if (!strcasecmp(event_type, "passkey-display-request")) { - /* Not implemented */ - fprintf(stdout," Not implemented\n"); - - } else if (!strcasecmp(event_type, "authorize-request")) { - device_name = (gchar*) bundle_get_val(user_data, "device-name"); - agent_path = bundle_get_val(user_data, "agent-path"); - - sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); - if (sys_conn == NULL) { - fprintf(stdout,"ERROR: Can't get on system bus"); - return; - } - - agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path); - if (!agent_proxy){ - fprintf(stdout,"create new agent_proxy failed\n"); - return; - } + notification_get_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, &popup_type); + LOGD("'%s' notification type [%s]", pkgname, popup_type); - __display_notification( __notify_authorize_request_accept_cb, __notify_authorize_request_cancel_cb,agent_proxy); - } else if (!strcasecmp(event_type, "app-confirm-request")) { - /* Not implemented */ - fprintf(stdout," Not implemented\n"); + if (!strcasecmp(POPUP_TYPE_INFO, popup_type)) + display_user_information_popup(); + else if (!strcasecmp(POPUP_TYPE_USERCONFIRM, popup_type)) + display_user_confirmation_popup(); + else if (!strcasecmp(POPUP_TYPE_USERPROMPT, popup_type)) + display_user_prompt_popup(); + else + LOGE("popup type is not recognized !"); - } else if (!strcasecmp(event_type, "push-authorize-request")) { - file = (gchar*) bundle_get_val(user_data, "file"); - device_name = (gchar*) bundle_get_val(user_data, "device-name"); - sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); - if (sys_conn == NULL) { - fprintf(stdout,"ERROR: Can't get on system bus"); - return; - } - - obex_proxy = __bluetooth_create_obex_proxy(sys_conn); - if (!obex_proxy){ - fprintf(stdout,"create new obex_proxy failed\n"); - return; - } - - __display_notification( __notify_push_authorize_request_accept_cb, __notify_push_authorize_request_cancel_cb,obex_proxy); - } else if (!strcasecmp(event_type, "confirm-overwrite-request")) { - /* Not implemented */ - fprintf(stdout," Not implemented\n"); - - } else if (!strcasecmp(event_type, "keyboard-passkey-request")) { - /* Not implemented */ - fprintf(stdout," Not implemented\n"); - - } else if (!strcasecmp(event_type, "bt-information")) { - /* Not implemented */ - fprintf(stdout," Not implemented\n"); - - } else if (!strcasecmp(event_type, "exchange-request")) { - device_name = (gchar*) bundle_get_val(user_data, "device-name"); - agent_path = bundle_get_val(user_data, "agent-path"); - - sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); - if (sys_conn == NULL) { - fprintf(stdout,"ERROR: Can't get on system bus"); - return; - } - - agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path); - if (!agent_proxy){ - fprintf(stdout,"create new agent_proxy failed\n"); - return; - } - - __display_notification( __notify_authorize_request_accept_cb, __notify_authorize_request_cancel_cb,agent_proxy); - } else if (!strcasecmp(event_type, "phonebook-request")) { - device_name = bundle_get_val(user_data, "device-name"); - agent_path = bundle_get_val(user_data, "agent-path"); - - sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); - if (sys_conn == NULL) { - fprintf(stdout,"ERROR: Can't get on system bus"); - return; - } - - agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path); - if (!agent_proxy){ - fprintf(stdout,"create new agent_proxy failed\n"); - return; - } - - __display_notification( __notify_authorize_request_accept_cb, __notify_authorize_request_cancel_cb,agent_proxy); - } else if (!strcasecmp(event_type, "message-request")) { - device_name = bundle_get_val(user_data, "device-name"); - agent_path = bundle_get_val(user_data, "agent-path"); - - sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); - if (sys_conn == NULL) { - fprintf(stdout,"ERROR: Can't get on system bus"); - return; - } - - agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path); - if (!agent_proxy){ - fprintf(stdout,"create new agent_proxy failed\n"); - return; - } - - __display_notification( __notify_authorize_request_accept_cb, __notify_authorize_request_cancel_cb,agent_proxy); + if (notification_list != NULL) { + notification_free_list(notification_list); + notification_list = NULL; } - } - if (notification_list != NULL) { - notification_free_list(notification_list); - notification_list = NULL; - } - - return; + } + return; } int main(int argc, char **argv) { if (!ecore_init()) { - fprintf(stderr, "ERROR: Cannot init Ecore!\n"); + LOGE("ERROR: Cannot init Ecore!\n"); return -1; } + bt_initialize(); + + bt_agent_register_sync(); + notification_resister_changed_cb(__noti_changed_cb, NULL); ecore_main_loop_begin(); - shutdown: - ecore_shutdown(); - return 0; + return 1; } diff --git a/configure.ac b/configure.ac index 258e7c9..b799120 100644 --- a/configure.ac +++ b/configure.ac @@ -15,7 +15,7 @@ AM_CONDITIONAL(HAVE_WAYLAND, test x$enable_wayland = xyes) if test "x$enable_wayland" = "xyes"; then wayland_libs="libwlmessage" fi -PKG_CHECK_MODULES([TIZEN], [eina ecore com-core notification dbus-1 bluetooth-api $wayland_libs]) +PKG_CHECK_MODULES([TIZEN], [eina ecore com-core notification dbus-1 capi-network-bluetooth glib-2.0 gio-2.0 dlog $wayland_libs]) AC_SUBST(TIZEN_CFLAGS) AC_SUBST(TIZEN_LIBS) diff --git a/notification_display_service.c b/notification_display_service.c index ea25bdc..a6f1970 100644 --- a/notification_display_service.c +++ b/notification_display_service.c @@ -9,6 +9,11 @@ #ifdef HAVE_WAYLAND #include #endif +#include + +#define POPUP_TYPE_INFO "user_info_popup" +#define POPUP_TYPE_USERCONFIRM "user_confirm_popup" +#define POPUP_TYPE_USERPROMPT "user_agreement_popup" int fd, wd; @@ -48,17 +53,21 @@ void display_notifications () /* react specifically to the source framework and event (TODO : plugins !) */ if (!strcmp(pkgname, "bt-agent")) { +printf("ON EST EN BLUETOOTH\n"); notification_get_text (noti, NOTIFICATION_TEXT_TYPE_INFO_1, &info1); if (info1) { - if ( (!strcmp(info1, "RequestPinCode")) || (!strcmp(info1, "RequestPasskey")) ) { - type = NOTIF_TYPE_USERPROMPT; + if (!strcasecmp(POPUP_TYPE_INFO, info1)) { + type = NOTIF_TYPE_INFO; } - else if (!strcmp(info1, "RequestConfirmation")) { + else if (!strcasecmp(POPUP_TYPE_USERCONFIRM, info1)) { type = NOTIF_TYPE_USERCONFIRM; content = strdup("Please confirm"); } + else if (!strcasecmp(POPUP_TYPE_USERPROMPT, info1)) { + type = NOTIF_TYPE_USERPROMPT; + } } - } + } else { printf ("ON N'EST PAS EN BLUETOOTH !\n"); } # ifdef HAVE_WAYLAND struct wlmessage *wlmessage = wlmessage_create (); @@ -85,26 +94,16 @@ void display_notifications () wlmessage_destroy (wlmessage); return; } else if ((clicked_button == 1) && (type == NOTIF_TYPE_USERCONFIRM)) { + printf("CLIQUE SUR OUI !\n"); if (!strcmp(pkgname, "bt-agent")) { - struct sockaddr_un addr; - int socket_fd, nbytes; - char buffer[256]; - - socket_fd = socket(PF_UNIX, SOCK_STREAM, 0); - - memset (&addr, 0, sizeof(struct sockaddr_un)); - addr.sun_family = AF_UNIX; - snprintf (addr.sun_path, UNIX_PATH_MAX, "/tmp/.bluetooth.service"); - - if (connect (socket_fd, - (struct sockaddr *)&addr, - sizeof(struct sockaddr_un)) != 0) { - fprintf(stderr, "Cannot connect to /tmp/.bluetooth.service\n"); - } else { - nbytes = snprintf(buffer, 256, "1 clicked"); - write (socket_fd, buffer, nbytes); - close (socket_fd); - } + printf("ON ENVOIE SYNC(0)\n"); + bt_agent_reply_sync(0); + } + } else if ((clicked_button == 0) && (type == NOTIF_TYPE_USERCONFIRM)) { + printf("CLIQUE SUR NON !\n"); + if (!strcmp(pkgname, "bt-agent")) { + printf("ON ENVOIE SYNC(1)\n"); + bt_agent_reply_sync(1); } } wlmessage_destroy (wlmessage); @@ -125,6 +124,10 @@ int main (int argc, char **argv) { char buffer[8192]; + bt_initialize(); + + bt_agent_register_sync(); + /* display notifications once, so it stays useful without inotify */ display_notifications (); diff --git a/packaging/notification-service.spec b/packaging/notification-service.spec index 7426af7..062cccc 100644 --- a/packaging/notification-service.spec +++ b/packaging/notification-service.spec @@ -14,7 +14,8 @@ BuildRequires: pkgconfig(notification) BuildRequires: pkgconfig(notification-service) BuildRequires: pkgconfig(dbus-1) BuildRequires: pkgconfig(dbus-glib-1) -BuildRequires: pkgconfig(bluetooth-api) +BuildRequires: pkgconfig(dlog) +BuildRequires: bluetooth-frwk-devel BuildRequires: pkgconfig(bundle) %if %{with wayland} BuildRequires: pkgconfig(libwlmessage) -- 2.7.4