Add Bluetooth-client-notification to test bluetooth pairing
authorJean-Benoit MARTIN <jean-benoit.martin@eurogiciel.fr>
Fri, 20 Sep 2013 12:17:26 +0000 (14:17 +0200)
committerJean-Benoit MARTIN <jean-benoit.martin@eurogiciel.fr>
Fri, 20 Sep 2013 15:29:59 +0000 (17:29 +0200)
Change-Id: I1b079a270fe39ca04cb6774e97db19e21f7f9d25

Makefile.am
bluetooth_notification_client.c [new file with mode: 0644]
configure.ac
packaging/notification-service.spec

index 5b7257b..28b715c 100644 (file)
@@ -1,4 +1,4 @@
-bin_PROGRAMS = notification-service sample-display-client send-notification
+bin_PROGRAMS = notification-service sample-display-client send-notification bluetooth_notification_client
 
 AM_CFLAGS = $(GCC_CFLAGS)
 AM_CPPFLAGS = $(GCC_CFLAGS)
@@ -18,6 +18,10 @@ sample_display_client_SOURCES = sample_display_client.c
 sample_display_client_CFLAGS = -I. $(TIZEN_CFLAGS)
 sample_display_client_LDADD = $(TIZEN_LIBS)
 
+bluetooth_notification_client_SOURCES = bluetooth_notification_client.c
+bluetooth_notification_client_CFLAGS = -I. $(TIZEN_CFLAGS)
+bluetooth_notification_client_LDADD = $(TIZEN_LIBS)
+
 SCRIPT_IN_FILES = \
      notifications.service.in \
      notifications.socket.in
diff --git a/bluetooth_notification_client.c b/bluetooth_notification_client.c
new file mode 100644 (file)
index 0000000..50a3095
--- /dev/null
@@ -0,0 +1,327 @@
+#include <Ecore.h>
+#include <notification.h>
+#include <unistd.h>
+
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <bundle.h>
+
+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.Agent");
+}
+
+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)
+{
+
+         dbus_g_proxy_call_no_reply( agent_proxy, "ReplyAuthorize",
+                                     G_TYPE_UINT, BT_AGENT_ACCEPT,
+                                     G_TYPE_INVALID, G_TYPE_INVALID);
+}
+
+static void
+__notify_authorize_request_cancel_cb(DBusGProxy* agent_proxy)
+{
+
+         dbus_g_proxy_call_no_reply( agent_proxy, "ReplyAuthorize",
+                                     G_TYPE_UINT, BT_AGENT_CANCEL,
+                                     G_TYPE_INVALID, G_TYPE_INVALID);
+
+}
+
+static int
+__display_notification(bt_notification cb_1, bt_notification cb_2, DBusGProxy *proxy)
+{
+
+         notification_error_e err = NOTIFICATION_ERROR_NONE;
+         int bt_yesno;
+         bt_yesno = 1;
+         char line[256];
+
+         fprintf(stdout, "Do you confirm yes or no ? ");
+         while ( bt_yesno != 0){
+                 gets(line);
+                 if ( strcmp(line,"yes") == 0){
+                         (cb_1) (proxy);
+                         bt_yesno = 0;
+                 } else if ( strcmp(line,"no") == 0){
+                         (cb_2) (proxy);
+                         bt_yesno = 0;
+                 } else {
+                         fprintf(stdout," yes or no :");
+                 }
+         }
+         err = notification_delete_all_by_type("bluetooth-frwk-bt-service", NOTIFICATION_TYPE_NOTI);
+         if (err != NOTIFICATION_ERROR_NONE) {
+                  fprintf(stdout, "Unable to remove notifications");
+         }
+
+}
+
+static int __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;
+         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, &notification_list);
+         if (notification_list) {
+                get_list = notification_list_get_head(notification_list);
+                noti = notification_list_get_data(get_list);
+                notification_get_id(noti, &group_id, &priv_id);
+                notification_get_pkgname(noti, &pkgname);
+                if(pkgname == NULL){
+                       notification_get_application(noti, &pkgname);
+                }
+
+                notification_get_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &str_count);
+                if (!str_count) {
+                        count = 0;
+                } else {
+                        count = atoi(str_count);
+                }
+                notification_get_title(noti, &title, NULL);
+                notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT , &content);
+                notification_get_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,NULL, &user_data);
+
+                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 EXIT_FAILURE;
+                        }
+
+                        agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
+                        if (!agent_proxy){
+                                fprintf(stdout,"create new agent_proxy failed\n");
+                                return EXIT_FAILURE;
+                        }
+
+                         __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 EXIT_FAILURE;
+                        }
+
+                        agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
+                        if (!agent_proxy){
+                                fprintf(stdout,"create new agent_proxy failed\n");
+                                return EXIT_FAILURE;
+                        }
+
+                        __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");
+
+                } 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 EXIT_FAILURE;
+                        }
+
+                        obex_proxy = __bluetooth_create_obex_proxy(sys_conn);
+                        if (!obex_proxy){
+                                fprintf(stdout,"create new obex_proxy failed\n");
+                                return EXIT_FAILURE;
+                        }
+
+                        __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 EXIT_FAILURE;
+                        }
+
+                        agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
+                        if (!agent_proxy){
+                                fprintf(stdout,"create new agent_proxy failed\n");
+                                return EXIT_FAILURE;
+                        }
+
+                        __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 EXIT_FAILURE;
+                        }
+
+                        agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
+                        if (!agent_proxy){
+                                fprintf(stdout,"create new agent_proxy failed\n");
+                                return EXIT_FAILURE;
+                        }
+
+                        __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 EXIT_FAILURE;
+                        }
+
+                        agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
+                        if (!agent_proxy){
+                                fprintf(stdout,"create new agent_proxy failed\n");
+                                return EXIT_FAILURE;
+                        }
+
+                        __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;
+        }
+
+        return EXIT_SUCCESS;
+}
+
+int
+main(int argc, char **argv)
+{
+    if (!ecore_init()) {
+        fprintf(stderr, "ERROR: Cannot init Ecore!\n");
+        return -1;
+    }
+
+    notification_resister_changed_cb(__noti_changed_cb, NULL);
+    ecore_main_loop_begin();
+
+ shutdown:
+    ecore_shutdown();
+    return 0;
+}
+
index 394cdfe..56dec67 100644 (file)
@@ -10,7 +10,7 @@ LT_PREREQ([2.2])
 LT_INIT([disable-static])
 
 PKG_PROG_PKG_CONFIG()
-PKG_CHECK_MODULES([TIZEN], [eina ecore com-core notification])
+PKG_CHECK_MODULES([TIZEN], [eina ecore com-core notification dbus-1 bluetooth-api])
 AC_SUBST(TIZEN_CFLAGS)
 AC_SUBST(TIZEN_LIBS)
 
index 8d629db..f1657e8 100644 (file)
@@ -9,6 +9,10 @@ BuildRequires: pkgconfig(eina)
 BuildRequires: pkgconfig(ecore) 
 BuildRequires: pkgconfig(com-core) 
 BuildRequires: pkgconfig(notification)
+BuildRequires: dbus-devel
+BuildRequires: pkgconfig(dbus-glib-1)
+BuildRequires: bluetooth-frwk-devel
+BuildRequires: bundle-devel
 
 %description
 Headless notification service that collects incoming notifications from the
@@ -45,3 +49,4 @@ rm -rf %{buildroot}
 %defattr(-,root,root,-)
 %{_bindir}/sample-display-client
 %{_bindir}/send-notification
+%{_bindir}/bluetooth_notification_client