diff -urpN gnome/common/bluetooth-instance.c gnome-new/common/bluetooth-instance.c --- gnome/common/bluetooth-instance.c 1969-12-31 19:00:00.000000000 -0500 +++ gnome-new/common/bluetooth-instance.c 2007-12-16 18:30:54.000000000 -0500 @@ -0,0 +1,132 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2005-2007 Marcel Holtmann + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include + +#include "bluetooth-instance.h" +#include "app-instance-glue.h" + +G_DEFINE_TYPE(BluetoothInstance, bluetooth_instance, G_TYPE_OBJECT) + +#define BLUETOOTH_INSTANCE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), \ + BLUETOOTH_TYPE_INSTANCE, BluetoothInstancePrivate)) + +typedef struct _BluetoothInstancePrivate BluetoothInstancePrivate; + +struct _BluetoothInstancePrivate { + GtkWindow *window; + DBusGConnection *connection; +}; + +gboolean +bluetooth_instance_register(BluetoothInstance *self, + int *retval, gboolean singleton, gchar *path, gchar *service) +{ + BluetoothInstancePrivate *priv = BLUETOOTH_INSTANCE_GET_PRIVATE(self); + DBusGConnection *sc; + DBusGProxy *proxy; + GError *error = NULL; + guint request_result; + gboolean ret; + + sc = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + if (error != NULL) { + g_printerr("Connecting to session bus failed: %s\n", error->message); + g_error_free(error); + *retval = 1; + return FALSE; + } + + proxy = dbus_g_proxy_new_for_name(sc, DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); + + ret = dbus_g_proxy_call(proxy, "RequestName", NULL, + G_TYPE_STRING, service, G_TYPE_UINT, 0, G_TYPE_INVALID, + G_TYPE_UINT, &request_result, G_TYPE_INVALID); + + g_object_unref(G_OBJECT(proxy)); + if (!ret) { + g_printerr("Failed to request name on the session bus\n"); + dbus_g_connection_unref(sc); + *retval = 1; + return FALSE; + } + + if (request_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER && singleton) { + proxy = dbus_g_proxy_new_for_name(sc, service, path, "org.bluez.BluetoothInstance"); + dbus_g_proxy_call_no_reply(proxy, "Present", G_TYPE_INVALID, G_TYPE_INVALID); + g_object_unref(G_OBJECT(proxy)); + g_print("Another instance is already running.\n"); + dbus_g_connection_unref(sc); + *retval = 0; + return FALSE; + } + + dbus_g_connection_register_g_object(sc, path, G_OBJECT (self)); + priv->connection = sc; + return TRUE; +} + +void +bluetooth_instance_set_window (BluetoothInstance *self, GtkWindow *window) +{ + BluetoothInstancePrivate *priv = BLUETOOTH_INSTANCE_GET_PRIVATE(self); + priv->window = window; +} + +gboolean +bluetooth_instance_present(BluetoothInstance *self, GError **error) +{ + BluetoothInstancePrivate *priv = BLUETOOTH_INSTANCE_GET_PRIVATE(self); + if (priv->window) + gtk_window_present(priv->window); + return TRUE; +} + +static void +bluetooth_instance_init(BluetoothInstance *self) +{ +} + +static void +bluetooth_instance_finalize(GObject *self) +{ + BluetoothInstancePrivate *priv = BLUETOOTH_INSTANCE_GET_PRIVATE(self); + if (priv->connection) + dbus_g_connection_unref(priv->connection); +} + +static void +bluetooth_instance_class_init(BluetoothInstanceClass *klass) +{ + g_type_class_add_private(klass, sizeof(BluetoothInstancePrivate)); + G_OBJECT_CLASS(klass)->finalize = bluetooth_instance_finalize; + dbus_g_object_type_install_info(BLUETOOTH_TYPE_INSTANCE, + &dbus_glib_bluetooth_instance_object_info); +} + +BluetoothInstance * +bluetooth_instance_new(void) +{ + return g_object_new(BLUETOOTH_TYPE_INSTANCE, NULL); +} diff -urpN gnome/common/bluetooth-instance.h gnome-new/common/bluetooth-instance.h --- gnome/common/bluetooth-instance.h 1969-12-31 19:00:00.000000000 -0500 +++ gnome-new/common/bluetooth-instance.h 2007-12-16 18:30:54.000000000 -0500 @@ -0,0 +1,63 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2005-2007 Marcel Holtmann + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __BLUETOOTH_INSTANCE_H +#define __BLUETOOTH_INSTANCE_H + +#include + +G_BEGIN_DECLS + +#define BLUETOOTH_TYPE_INSTANCE (bluetooth_instance_get_type()) +#define BLUETOOTH_INSTANCE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + BLUETOOTH_TYPE_INSTANCE, BluetoothInstance)) +#define BLUETOOTH_INSTANCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ + BLUETOOTH_TYPE_INSTANCE, BluetoothInstanceClass)) +#define BLUETOOTH_IS_INSTANCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + BLUETOOTH_TYPE_INSTANCE)) +#define BLUETOOTH_IS_INSTANCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \ + BLUETOOTH_TYPE_INSTANCE)) +#define BLUETOOTH_GET_INSTANCE_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \ + BLUETOOTH_TYPE_INSTANCE, BluetoothInstanceClass)) + +typedef struct _BluetoothInstance BluetoothInstance; +typedef struct _BluetoothInstanceClass BluetoothInstanceClass; + +struct _BluetoothInstance { + GObject parent; +}; + +struct _BluetoothInstanceClass { + GObjectClass parent_class; +}; + +GType bluetooth_instance_get_type(void); +BluetoothInstance *bluetooth_instance_new(void); +void bluetooth_instance_set_window(BluetoothInstance *self, GtkWindow *window); +gboolean bluetooth_instance_present(BluetoothInstance *self, GError **error); +gboolean bluetooth_instance_register(BluetoothInstance *self, + int *retval, gboolean singleton, gchar *path, gchar *service); + +G_END_DECLS + +#endif /* __BLUETOOTH_INSTANCE_H */ diff -urpN gnome/common/bluetooth-instance.xml gnome-new/common/bluetooth-instance.xml --- gnome/common/bluetooth-instance.xml 1969-12-31 19:00:00.000000000 -0500 +++ gnome-new/common/bluetooth-instance.xml 2007-12-16 18:30:54.000000000 -0500 @@ -0,0 +1,8 @@ + + + + + + + + diff -urpN gnome/common/Makefile.am gnome-new/common/Makefile.am --- gnome/common/Makefile.am 2007-07-25 06:28:56.000000000 -0400 +++ gnome-new/common/Makefile.am 2007-12-16 18:31:09.000000000 -0500 @@ -3,12 +3,13 @@ noinst_LIBRARIES = libcommon.a libcommon_a_SOURCES = \ client.h client.c device-store.h device-store.c \ + bluetooth-instance.c bluetooth-instance.h \ bluetooth-device-selection.c bluetooth-device-selection.h AM_CFLAGS = @DBUS_CFLAGS@ @GTK_CFLAGS@ BUILT_SOURCES = marshal.h marshal.c dbus-glue.h \ - passkey-agent-glue.h auth-agent-glue.h + passkey-agent-glue.h auth-agent-glue.h app-instance-glue.h nodist_libcommon_a_SOURCES = $(BUILT_SOURCES) @@ -22,7 +23,8 @@ test_agent_LDADD = libcommon.a @DBUS_LIB test_deviceselection_LDADD = libcommon.a @GTK_LIBS@ @DBUS_LIBS@ -EXTRA_DIST = marshal.list dbus.xml passkey-agent.xml auth-agent.xml +EXTRA_DIST = marshal.list dbus.xml passkey-agent.xml auth-agent.xml \ + bluetooth-instance.xml MAINTAINERCLEANFILES = Makefile.in @@ -40,3 +42,6 @@ passkey-agent-glue.h: passkey-agent.xml auth-agent-glue.h: auth-agent.xml $(DBUS_BINDING_TOOL) --prefix=auth_agent --mode=glib-server --output=$@ $< + +app-instance-glue.h: bluetooth-instance.xml + $(DBUS_BINDING_TOOL) --prefix=bluetooth_instance --mode=glib-server --output=$@ $<