dundee: Add BlueZ Profile handler
authorPaulo Borges <paulo.borges@openbossa.org>
Wed, 20 Mar 2013 22:26:39 +0000 (19:26 -0300)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Sun, 24 Mar 2013 12:22:17 +0000 (13:22 +0100)
This patch declares the external dundee Profile handler. It
contains the initial implementation of the D-Bus Profile1
interface and methods responsible for handling Bluetooth
connections.

dundee/bluez5.c

index 37ac4d0..e927835 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdint.h>
 #include <sys/socket.h>
 #include <gdbus.h>
+#include <errno.h>
 
 #include "dundee.h"
 #include "plugins/bluez5.h"
@@ -42,6 +43,59 @@ struct bluetooth_device {
        char *name;
 };
 
+static DBusMessage *profile_new_connection(DBusConnection *conn,
+                                       DBusMessage *msg, void *user_data)
+{
+       DBG("");
+
+       return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+                                               ".NotImplemented",
+                                               "Implementation not provided");
+}
+
+static DBusMessage *profile_release(DBusConnection *conn,
+                                       DBusMessage *msg, void *user_data)
+{
+       DBG("");
+
+       return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+                                               ".NotImplemented",
+                                               "Implementation not provided");
+}
+
+static DBusMessage *profile_cancel(DBusConnection *conn,
+                                       DBusMessage *msg, void *user_data)
+{
+       DBG("");
+
+       return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+                                               ".NotImplemented",
+                                               "Implementation not provided");
+}
+
+static DBusMessage *profile_disconnection(DBusConnection *conn,
+                                       DBusMessage *msg, void *user_data)
+{
+       DBG("");
+
+       return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+                                               ".NotImplemented",
+                                               "Implementation not provided");
+}
+
+static const GDBusMethodTable profile_methods[] = {
+       { GDBUS_ASYNC_METHOD("NewConnection",
+                               GDBUS_ARGS({ "device", "o"}, { "fd", "h"},
+                                               { "fd_properties", "a{sv}" }),
+                               NULL, profile_new_connection) },
+       { GDBUS_METHOD("Release", NULL, NULL, profile_release) },
+       { GDBUS_METHOD("Cancel", NULL, NULL, profile_cancel) },
+       { GDBUS_METHOD("RequestDisconnection",
+                               GDBUS_ARGS({"device", "o"}), NULL,
+                               profile_disconnection) },
+       { }
+};
+
 static void bluetooth_device_destroy(gpointer user_data)
 {
        struct bluetooth_device *bt_device = user_data;
@@ -235,6 +289,15 @@ int __dundee_bluetooth_init(void)
 
        DBG("");
 
+       if (!g_dbus_register_interface(conn, DUN_DT_PROFILE_PATH,
+                                       BLUEZ_PROFILE_INTERFACE,
+                                       profile_methods, NULL,
+                                       NULL, NULL, NULL)) {
+               ofono_error("Register Profile interface failed: %s",
+                                               DUN_DT_PROFILE_PATH);
+               return -EIO;
+       }
+
        bluez = g_dbus_client_new(conn, BLUEZ_SERVICE, BLUEZ_MANAGER_PATH);
        g_dbus_client_set_connect_watch(bluez, connect_handler, NULL);
        g_dbus_client_set_proxy_handlers(bluez, proxy_added, NULL, NULL, NULL);
@@ -247,8 +310,13 @@ int __dundee_bluetooth_init(void)
 
 void __dundee_bluetooth_cleanup(void)
 {
+       DBusConnection *conn = ofono_dbus_get_connection();
+
        DBG("");
 
+       g_dbus_unregister_interface(conn, DUN_DT_PROFILE_PATH,
+                                               BLUEZ_PROFILE_INTERFACE);
+
        g_dbus_client_unref(bluez);
        g_hash_table_destroy(registered_devices);
 }