public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Bastien Nocera <hadess@hadess.net>
To: linux-bluetooth@vger.kernel.org
Subject: First pass at HAL device class plugin
Date: Tue, 23 Sep 2008 17:06:25 -0700	[thread overview]
Message-ID: <1222214785.10497.127.camel@snoogens.fab.redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 137 bytes --]

Probably doesn't work, and it's missing some exported functionality to
set the device class on the actual adapter (and have it written).

[-- Attachment #2: 0001-First-pass-at-a-HAL-plugin-to-set-the-device-class.patch --]
[-- Type: text/x-patch, Size: 3866 bytes --]

>From bb925e0a397dbbec2a60f39e65ff19c3d5e58d0b Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Tue, 23 Sep 2008 17:03:06 -0700
Subject: [PATCH] First pass at a HAL plugin to set the device class

---
 plugins/hal-adapter-class.c |  126 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 126 insertions(+), 0 deletions(-)
 create mode 100644 plugins/hal-adapter-class.c

diff --git a/plugins/hal-adapter-class.c b/plugins/hal-adapter-class.c
new file mode 100644
index 0000000..c5dae5c
--- /dev/null
+++ b/plugins/hal-adapter-class.c
@@ -0,0 +1,126 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2004-2008  Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <bluetooth/bluetooth.h>
+
+#include <glib.h>
+#include <hal/libhal.h>
+#include <gdbus.h>
+
+#include "plugin.h"
+#include "adapter.h"
+#include "logging.h"
+
+static guint32 get_form_factor(LibHalContext *ctx)
+{
+	char *formfactor;
+	guint32 ret;
+
+	ret = 1 << 8; /* Computer major class */
+	formfactor = libhal_device_get_property_string(ctx,
+				"/org/freedesktop/Hal/devices/computer",
+						"system.formfactor", NULL);
+
+	if (formfactor == NULL)
+		return ret;
+
+	if (g_str_equal(formfactor, "laptop"))
+		ret += (1 << 2) + (1 << 3);
+	else if (g_str_equal(formfactor, "desktop"))
+		ret += 1 << 2;
+	else if (g_str_equal(formfactor, "server"))
+		ret += 1 << 3;
+	else if (g_str_equal(formfactor, "handheld"))
+		ret += 1 << 4;
+
+	g_free (formfactor);
+
+	return ret;
+}
+
+static int hal_adapter_class_probe(struct btd_adapter *adapter)
+{
+	DBusConnection *conn;
+	LibHalContext *ctx = NULL;
+	guint32 class;
+
+	conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+
+	ctx = libhal_ctx_new();
+	if (libhal_ctx_set_dbus_connection(ctx, conn) == FALSE) {
+		libhal_ctx_free(ctx);
+		dbus_connection_unref(conn);
+		return -EIO;
+	}
+
+	if (libhal_ctx_init(ctx, NULL) == FALSE) {
+		g_warning("Unable to init HAL context");
+		libhal_ctx_free(ctx);
+		dbus_connection_unref(conn);
+		return -EIO;
+	}
+
+	class = get_form_factor (ctx);
+	debug ("0: 0x%X", class);
+#if 0
+	adapter_set_class (adapter, class);
+	dbus_g_proxy_call(object, "SetMajorClass", NULL,
+		G_TYPE_STRING, "computer", G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_call(object, "SetMinorClass", NULL,
+		G_TYPE_STRING, formfactor, G_TYPE_INVALID, G_TYPE_INVALID);
+	g_free (formfactor);
+#endif
+	libhal_ctx_free(ctx);
+	dbus_connection_unref(conn);
+
+	return 0;
+}
+
+static struct btd_adapter_driver hal_adapter_class = {
+	.name	= "hal-adapter-class",
+	.probe	= hal_adapter_class_probe,
+	.remove	= NULL,
+};
+
+static int hal_adapter_class_init(void)
+{
+	debug("Setup HAL Adapter Class plugin");
+
+	return btd_register_adapter_driver(&hal_adapter_class);
+}
+
+static void hal_adapter_class_exit(void)
+{
+	debug("Cleanup HAL Adapter Class plugin");
+
+	btd_unregister_adapter_driver(&hal_adapter_class);
+}
+
+BLUETOOTH_PLUGIN_DEFINE("hal", hal_adapter_class_init, hal_adapter_class_exit)
-- 
1.6.0.1


             reply	other threads:[~2008-09-24  0:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-24  0:06 Bastien Nocera [this message]
2008-09-24  0:17 ` First pass at HAL device class plugin Bastien Nocera

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=1222214785.10497.127.camel@snoogens.fab.redhat.com \
    --to=hadess@hadess.net \
    --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