Linux bluetooth development
 help / color / mirror / Atom feed
From: Anderson Lizardo <anderson.lizardo@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: Anderson Lizardo <anderson.lizardo@openbossa.org>
Subject: [PATCH 03/15] GATT server: add initial D-Bus interface
Date: Wed, 16 Mar 2011 21:00:27 -0400	[thread overview]
Message-ID: <1300323639-13296-4-git-send-email-anderson.lizardo@openbossa.org> (raw)
In-Reply-To: <1300323639-13296-1-git-send-email-anderson.lizardo@openbossa.org>

---
 plugins/gatt-profile.c |   96 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 96 insertions(+), 0 deletions(-)

diff --git a/plugins/gatt-profile.c b/plugins/gatt-profile.c
index 025a3c5..fc6b08e 100644
--- a/plugins/gatt-profile.c
+++ b/plugins/gatt-profile.c
@@ -26,15 +26,111 @@
 #include <config.h>
 #endif
 
+#include <errno.h>
+
+#include <gdbus.h>
+
 #include "plugin.h"
+#include "adapter.h"
+#include "log.h"
+
+#define GATT_PROFILE_INTERFACE "org.bluez.GattProfile"
+
+static DBusConnection *connection = NULL;
+static const char *any_path = NULL;
+
+static DBusMessage *add_profile(DBusConnection *conn, DBusMessage *msg,
+								void *user_data)
+{
+	/* TODO */
+
+	return dbus_message_new_method_return(msg);
+}
+
+static GDBusMethodTable gatt_profile_methods[] = {
+	{ "AddProfile", "s", "", add_profile },
+	{ }
+};
+
+static int register_interface(const char *path, struct btd_adapter *adapter)
+{
+	DBG("path %s", path);
+
+	if (!g_dbus_register_interface(connection, path, GATT_PROFILE_INTERFACE,
+					gatt_profile_methods, NULL, NULL, NULL,
+					NULL)) {
+		error("D-Bus failed to register %s interface",
+							GATT_PROFILE_INTERFACE);
+		return -EIO;
+	}
+
+	DBG("Registered interface %s on path %s", GATT_PROFILE_INTERFACE, path);
+
+	return 0;
+}
+
+static void unregister_interface(const char *path)
+{
+	DBG("path %s", path);
+
+	g_dbus_unregister_interface(connection, path, GATT_PROFILE_INTERFACE);
+}
+
+static int gatt_profile_probe(struct btd_adapter *adapter)
+{
+	register_interface(adapter_get_path(adapter), adapter);
+
+	return 0;
+}
+
+static void gatt_profile_remove(struct btd_adapter *adapter)
+{
+	unregister_interface(adapter_get_path(adapter));
+}
+
+static struct btd_adapter_driver gatt_profile_driver = {
+	.name = "gatt-profile",
+	.probe = gatt_profile_probe,
+	.remove = gatt_profile_remove,
+};
 
 static int gatt_profile_init(void)
 {
+	int err;
+
+	connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return -EIO;
+
+	any_path = btd_adapter_any_request_path();
+	if (any_path != NULL) {
+		if (register_interface(any_path, NULL) < 0) {
+			btd_adapter_any_release_path();
+			any_path = NULL;
+		}
+	}
+
+	err = btd_register_adapter_driver(&gatt_profile_driver);
+	if (err < 0) {
+		dbus_connection_unref(connection);
+		return err;
+	}
+
 	return 0;
 }
 
 static void gatt_profile_exit(void)
 {
+	btd_unregister_adapter_driver(&gatt_profile_driver);
+
+	if (any_path != NULL) {
+		unregister_interface(any_path);
+
+		btd_adapter_any_release_path();
+		any_path = NULL;
+	}
+
+	dbus_connection_unref(connection);
 }
 
 BLUETOOTH_PLUGIN_DEFINE(gatt_profile, VERSION, BLUETOOTH_PLUGIN_PRIORITY_HIGH,
-- 
1.7.0.4


  parent reply	other threads:[~2011-03-17  1:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-17  1:00 [RFC][PATCH 00/15] Attribute server management API Anderson Lizardo
2011-03-17  1:00 ` [PATCH 01/15] Remove built-in example attribute server Anderson Lizardo
2011-03-17  1:00 ` [PATCH 02/15] GATT server: add profile API plugin skeleton Anderson Lizardo
2011-03-17  1:00 ` Anderson Lizardo [this message]
2011-03-17  1:00 ` [PATCH 04/15] GATT server: add initial XML parsing Anderson Lizardo
2011-03-17  1:00 ` [PATCH 05/15] GATT server: parse primary/secondary services Anderson Lizardo
2011-03-17  1:00 ` [PATCH 06/15] GATT server: parse and resolve service includes Anderson Lizardo
2011-03-17  1:00 ` [PATCH 07/15] GATT server: parse characteristics Anderson Lizardo
2011-03-17  1:00 ` [PATCH 08/15] GATT server: parse characteristic value Anderson Lizardo
2011-03-17  1:00 ` [PATCH 09/15] GATT server: add test/test-gatt-profile example Anderson Lizardo
2011-03-17  1:00 ` [PATCH 10/15] Add attrib_db_find_avail() function to attribute server Anderson Lizardo
2011-03-17  1:00 ` [PATCH 11/15] GATT server: add service registration Anderson Lizardo
2011-03-17  1:00 ` [PATCH 12/15] GATT server: add service includes registration Anderson Lizardo
2011-03-17  1:00 ` [PATCH 13/15] GATT server: add characteristic registration Anderson Lizardo
2011-03-17  1:00 ` [PATCH 14/15] GATT server: add characteristic descriptor registration Anderson Lizardo
2011-03-17  1:00 ` [PATCH 15/15] GATT server: add disconnect watch Anderson Lizardo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1300323639-13296-4-git-send-email-anderson.lizardo@openbossa.org \
    --to=anderson.lizardo@openbossa.org \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox