public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
@ 2007-12-03 15:33 Chris Rivera
  2007-12-03 16:25 ` Marcel Holtmann
  0 siblings, 1 reply; 19+ messages in thread
From: Chris Rivera @ 2007-12-03 15:33 UTC (permalink / raw)
  To: BlueZ development


[-- Attachment #1.1: Type: text/plain, Size: 130 bytes --]

I'm resending this patch since I haven't gotten a response in the original
thread in weeks.  Let me know if this looks OK.

Chris

[-- Attachment #1.2: Type: text/html, Size: 153 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bluez-gnome-singleton.patch --]
[-- Type: text/x-patch; name=bluez-gnome-singleton.patch, Size: 14037 bytes --]

Index: applet/bluetooth-applet.desktop.in
===================================================================
RCS file: /cvsroot/bluez/gnome/applet/bluetooth-applet.desktop.in,v
retrieving revision 1.1
diff -u -p -r1.1 bluetooth-applet.desktop.in
--- applet/bluetooth-applet.desktop.in	3 Apr 2007 08:09:01 -0000	1.1
+++ applet/bluetooth-applet.desktop.in	13 Nov 2007 17:04:15 -0000
@@ -3,7 +3,7 @@ Encoding=UTF-8
 _Name=Bluetooth Manager
 _Comment=Bluetooth Manager applet
 Icon=stock_bluetooth
-Exec=bluetooth-applet
+Exec=bluetooth-applet --singleton
 Terminal=false
 Type=Application
 Categories=
Index: applet/main.c
===================================================================
RCS file: /cvsroot/bluez/gnome/applet/main.c,v
retrieving revision 1.87
diff -u -p -r1.87 main.c
--- applet/main.c	29 Aug 2007 20:42:18 -0000	1.87
+++ applet/main.c	13 Nov 2007 17:04:16 -0000
@@ -32,9 +32,9 @@
 #include <string.h>
 
 #include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
 
 #ifdef HAVE_HAL
-#include <dbus/dbus-glib-lowlevel.h>
 #include <hal/libhal.h>
 #endif
 
@@ -1553,7 +1553,7 @@ static void about_callback(GtkWidget *it
 
 static void settings_callback(GObject *widget, gpointer user_data)
 {
-	const char *command = "bluetooth-properties";
+	const char *command = "bluetooth-properties --singleton";
 
 	if (!g_spawn_command_line_async(command, NULL))
 		g_printerr("Couldn't execute command: %s\n", command);
@@ -1642,7 +1642,7 @@ static void sendto_callback(GObject *wid
 #if 0
 static void wizard_callback(GObject *widget, gpointer user_data)
 {
-	const char *command = "bluetooth-wizard";
+	const char *command = "bluetooth-wizard --singleton";
 
 	if (!g_spawn_command_line_async(command, NULL))
 		g_printerr("Couldn't execute command: %s\n", command);
@@ -1783,11 +1783,70 @@ static void gconf_callback(GConfClient *
 		auto_authorize = gconf_value_get_bool(value);
 }
 
+static DBusGConnection *register_instance (int *retval, gboolean singleton)
+{
+	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 NULL;
+	}
+
+	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, "org.bluez.GnomeApplet",
+							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 NULL;
+	}
+
+	if (request_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+		*retval = 0;
+		
+		if (singleton) {
+			g_print("Another instance is already running.\n");
+			dbus_g_connection_unref(sc);
+			return NULL;
+		}
+	}
+
+	return sc;
+}
+
 int main(int argc, char *argv[])
 {
+	GOptionContext *ctx;
 	GtkWidget *menu;
 	GError *error = NULL;
+	DBusGConnection *session_conn = NULL;
 	char *str;
+	int retval = 0;
+	gboolean singleton = FALSE;
+
+	GOptionEntry entries[] = {
+        { "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+		  N_("Only allow one instance of this application"), NULL },
+        { NULL, 0, 0, 0, NULL, NULL, NULL }
+	};
 
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
@@ -1795,6 +1854,15 @@ int main(int argc, char *argv[])
 
 	gtk_init(&argc, &argv);
 
+	ctx = g_option_context_new("");
+	g_option_context_add_main_entries(ctx, entries, NULL);
+	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
+		g_printerr(_("parsing failed: %s\n"), error->message);
+		g_error_free(error);
+		g_option_context_free(ctx);
+		return retval;
+	}
+
 #ifdef HAVE_LIBNOTIFY
 	notify_init("bluetooth-manager");
 #endif
@@ -1806,6 +1874,10 @@ int main(int argc, char *argv[])
 		g_error_free(error);
 		exit(EXIT_FAILURE);
 	}
+	
+	session_conn = register_instance(&retval, singleton);
+	if (!session_conn)
+		exit(retval);
 
 	gconf = gconf_client_get_default();
 
@@ -1863,6 +1935,9 @@ int main(int argc, char *argv[])
 	g_list_foreach(adapter_list, adapter_free, NULL);
 
 	dbus_g_connection_unref(conn);
+	dbus_g_connection_unref(session_conn);
 
+	g_option_context_free(ctx);
+	
 	return 0;
 }
Index: properties/main.c
===================================================================
RCS file: /cvsroot/bluez/gnome/properties/main.c,v
retrieving revision 1.48
diff -u -p -r1.48 main.c
--- properties/main.c	31 Jul 2007 21:37:29 -0000	1.48
+++ properties/main.c	13 Nov 2007 17:04:16 -0000
@@ -32,6 +32,7 @@
 #include <string.h>
 
 #include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
 
 #include <glib/gi18n.h>
 
@@ -41,6 +42,9 @@
 #include "service.h"
 #include "adapter.h"
 
+#define PROPERTIES_DBUS_PATH "/org/bluez/GnomeProperties"
+#define PROPERTIES_DBUS_SERVICE "org.bluez.GnomeProperties"
+
 static void delete_callback(GtkWidget *window, GdkEvent *event,
 						gpointer user_data)
 {
@@ -58,7 +62,7 @@ static void close_callback(GtkWidget *bu
 	gtk_main_quit();
 }
 
-static void create_window(GtkWidget *notebook)
+static GtkWidget *create_window(GtkWidget *notebook)
 {
 	GtkWidget *window;
 	GtkWidget *widget;
@@ -108,6 +112,7 @@ static void create_window(GtkWidget *not
 						widget, _("General"));
 
 	gtk_widget_show_all(window);
+	return window;
 }
 
 static void name_owner_changed(DBusGProxy *object, const char *name,
@@ -139,19 +144,105 @@ static DBusGProxy *setup_manager(DBusGCo
 	return proxy;
 }
 
+static DBusHandlerResult MessageFunc (DBusConnection *c, DBusMessage *m, void *user_data)
+{
+	if (dbus_message_get_type(m) == DBUS_MESSAGE_TYPE_METHOD_CALL &&
+		!strncmp(PROPERTIES_DBUS_PATH, dbus_message_get_path(m), strlen(PROPERTIES_DBUS_PATH)) &&
+		!strncmp(PROPERTIES_DBUS_SERVICE, dbus_message_get_interface(m), strlen(PROPERTIES_DBUS_SERVICE)) &&
+		!strncmp("Present", dbus_message_get_member(m), 7)) {
+		GtkWindow *window = user_data;
+		gtk_window_present(window);
+	}
+
+	return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusGConnection *register_instance (int *retval, gboolean singleton)
+{
+	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 NULL;
+	}
+
+	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, PROPERTIES_DBUS_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 NULL;
+	}
+
+	if (request_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER && singleton) {
+		proxy = dbus_g_proxy_new_for_name(sc,
+										  PROPERTIES_DBUS_SERVICE,
+										  PROPERTIES_DBUS_PATH,
+										  PROPERTIES_DBUS_SERVICE);
+		dbus_g_proxy_call_no_reply(proxy, "Present", G_TYPE_INVALID, G_TYPE_INVALID);
+		g_object_unref(G_OBJECT(proxy));
+		*retval = 0;
+	
+		g_print("Another instance is already running.\n");
+		dbus_g_connection_unref(sc);
+		return NULL;
+	}
+
+	return sc;
+}
+
 int main(int argc, char *argv[])
 {
+	GOptionContext *ctx;
 	GtkWidget *notebook;
-	DBusGConnection *conn;
-	DBusGProxy *manager;
+	GtkWidget *window;
 	GError *error = NULL;
-
+	DBusGConnection *conn, *session_conn = NULL;
+	DBusGProxy *manager;
+	DBusObjectPathVTable vtable;
+	int retval = 0;
+	gboolean singleton = FALSE;
+
+	GOptionEntry entries[] = {
+        { "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+		  N_("Only allow one instance of this application"), NULL },
+        { NULL, 0, 0, 0, NULL, NULL, NULL }
+	};
+	
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 	textdomain(GETTEXT_PACKAGE);
 
 	gtk_init(&argc, &argv);
 
+	ctx = g_option_context_new("");
+	g_option_context_add_main_entries(ctx, entries, NULL);
+	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
+		g_printerr(_("parsing failed: %s\n"), error->message);
+		g_error_free(error);
+		g_option_context_free(ctx);
+		return retval;
+	}
+	
 	conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
 	if (error != NULL) {
 		g_printerr("Connecting to system bus failed: %s\n",
@@ -160,15 +251,24 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	}
 
+	session_conn = register_instance(&retval, singleton);
+	if (!session_conn)
+		exit(retval);
+
 	setup_general();
 
 	notebook = gtk_notebook_new();
-
+    
 	assign_adapter(notebook);
 
 	manager = setup_manager(conn);
 
-	create_window(notebook);
+	window = create_window(notebook);
+
+	vtable.message_function = MessageFunc;
+	vtable.unregister_function = NULL;
+	dbus_connection_register_object_path(dbus_g_connection_get_connection (session_conn),
+										 "/org/bluez/GnomeProperties", &vtable, window);
 
 	gtk_main();
 
@@ -181,6 +281,9 @@ int main(int argc, char *argv[])
 	g_object_unref(manager);
 
 	dbus_g_connection_unref(conn);
+	dbus_g_connection_unref(session_conn);
 
+	g_option_context_free(ctx);
+	
 	return 0;
 }
Index: wizard/main.c
===================================================================
RCS file: /cvsroot/bluez/gnome/wizard/main.c,v
retrieving revision 1.23
diff -u -p -r1.23 main.c
--- wizard/main.c	15 Aug 2007 07:04:03 -0000	1.23
+++ wizard/main.c	13 Nov 2007 17:04:16 -0000
@@ -26,8 +26,10 @@
 #endif
 
 #include <string.h>
+#include <stdlib.h>
 
 #include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
 
 #include <glib/gi18n.h>
 
@@ -39,6 +41,9 @@
 
 #include "bluetooth-device-selection.h"
 
+#define WIZARD_DBUS_PATH "/org/bluez/GnomeWizard"
+#define WIZARD_DBUS_SERVICE "org.bluez.GnomeWizard"
+
 static BluetoothClient *client;
 
 static gchar *address = NULL;
@@ -387,7 +392,7 @@ static void create_summary(GtkWidget *as
 	page_summary = vbox;
 }
 
-static void create_wizard(void)
+static GtkWidget *create_wizard(void)
 {
 	GtkWidget *assistant;
 
@@ -430,23 +435,126 @@ static void create_wizard(void)
 	gtk_widget_show_all(assistant);
 
 	gtk_assistant_update_buttons_state(GTK_ASSISTANT(assistant));
+	return assistant;
+}
+
+static DBusHandlerResult MessageFunc (DBusConnection *c, DBusMessage *m, void *user_data)
+{
+	if (dbus_message_get_type(m) == DBUS_MESSAGE_TYPE_METHOD_CALL &&
+		!strncmp(WIZARD_DBUS_PATH, dbus_message_get_path(m), strlen(WIZARD_DBUS_PATH)) &&
+		!strncmp(WIZARD_DBUS_SERVICE, dbus_message_get_interface(m), strlen(WIZARD_DBUS_SERVICE)) &&
+		!strncmp("Present", dbus_message_get_member(m), 7)) {
+		GtkWindow *window = user_data;
+		gtk_window_present(window);
+	}
+
+	return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusGConnection *register_instance (int *retval, gboolean singleton)
+{
+	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 NULL;
+	}
+
+	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, WIZARD_DBUS_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 NULL;
+	}
+
+	if (request_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER && singleton) {
+		proxy = dbus_g_proxy_new_for_name(sc,
+										  WIZARD_DBUS_SERVICE,
+										  WIZARD_DBUS_PATH,
+										  WIZARD_DBUS_SERVICE);
+		dbus_g_proxy_call_no_reply(proxy, "Present", G_TYPE_INVALID, G_TYPE_INVALID);
+		g_object_unref(G_OBJECT(proxy));
+		*retval = 0;
+		
+		g_print("Another instance is already running.\n");
+		dbus_g_connection_unref(sc);
+		return NULL;
+	}
+
+	return sc;
 }
 
 int main(int argc, char *argv[])
 {
+	GOptionContext *ctx;
+	GtkWidget *window;
+	DBusGConnection *session_conn = NULL;
+	GError *error = NULL;
+	DBusObjectPathVTable vtable;
+	int retval = 0;
+	gboolean singleton = FALSE;
+
+	GOptionEntry entries[] = {
+        { "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+		  N_("Only allow one instance of this application"), NULL },
+        { NULL, 0, 0, 0, NULL, NULL, NULL }
+	};
+	
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 	textdomain(GETTEXT_PACKAGE);
 
 	gtk_init(&argc, &argv);
 
+	ctx = g_option_context_new("");
+	g_option_context_add_main_entries(ctx, entries, NULL);
+	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
+		g_printerr(_("parsing failed: %s\n"), error->message);
+		g_error_free(error);
+		g_option_context_free(ctx);
+		return retval;
+	}
+	
+	session_conn = register_instance(&retval, singleton);
+	if (!session_conn)
+		exit(retval);
+
 	client = bluetooth_client_new();
 
-	create_wizard();
+	window = create_wizard();
+    
+	vtable.message_function = MessageFunc;
+	vtable.unregister_function = NULL;
+	dbus_connection_register_object_path(dbus_g_connection_get_connection (session_conn),
+										 WIZARD_DBUS_PATH, &vtable, window);
 
 	gtk_main();
 
 	g_object_unref(client);
 
+	dbus_g_connection_unref(session_conn);
+
+	g_option_context_free(ctx);
+	
 	return 0;
 }

[-- Attachment #3: Type: text/plain, Size: 309 bytes --]

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4

[-- Attachment #4: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-03 15:33 [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons Chris Rivera
@ 2007-12-03 16:25 ` Marcel Holtmann
  2007-12-03 16:50   ` Chris Rivera
  0 siblings, 1 reply; 19+ messages in thread
From: Marcel Holtmann @ 2007-12-03 16:25 UTC (permalink / raw)
  To: BlueZ development

Hi Chris,

> I'm resending this patch since I haven't gotten a response in the
> original thread in weeks.  Let me know if this looks OK.

I meant to look into it, but never got around it. Some small comments
about it. Don't make the applet a singleton. That is totally unneeded
since the applet will be loaded at login.

For the well known names use org.bluez.properties and org.bluez.wizard
and don't define constants for it. Simply use the string.

For the "Present" method. Don't use the D-Bus low-level calls. It should
be all dbus-glib. Which means we have to abstract that into an object. I
don't know if there is a well defined way for this. If it is, it might
be good to use that. If not, then propose something for freedesktop.org.

And we should probably have some generic methods inside common/ instead
of doing it again in every program.

Please follow the kernel coding style. I know it is odd for a GTK
application, but it makes it a lot easier for me.

Regards

Marcel



-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-03 16:25 ` Marcel Holtmann
@ 2007-12-03 16:50   ` Chris Rivera
  2007-12-03 16:59     ` Marcel Holtmann
  0 siblings, 1 reply; 19+ messages in thread
From: Chris Rivera @ 2007-12-03 16:50 UTC (permalink / raw)
  To: BlueZ development


[-- Attachment #1.1: Type: text/plain, Size: 1454 bytes --]

On Dec 3, 2007 11:25 AM, Marcel Holtmann <marcel@holtmann.org> wrote:

> Hi Chris,
>
> I meant to look into it, but never got around it. Some small comments
> about it. Don't make the applet a singleton. That is totally unneeded
> since the applet will be loaded at login.


I still think it should be a singleton.  You wouldn't ever want two applets
running unless you're testing, and we have the singleton flags for that.  I
don't think this hurts anything.


> For the well known names use org.bluez.properties and org.bluez.wizard
> and don't define constants for it. Simply use the string.


That's fine.


>
> For the "Present" method. Don't use the D-Bus low-level calls. It should
> be all dbus-glib. Which means we have to abstract that into an object. I
> don't know if there is a well defined way for this. If it is, it might
> be good to use that. If not, then propose something for freedesktop.org.


I thought about doing this, but it seems like overkill to define a GObject
to just expose one method.  GObject isn't exactly terse either.


>
>
> And we should probably have some generic methods inside common/ instead
> of doing it again in every program.
>
> Please follow the kernel coding style. I know it is odd for a GTK
> application, but it makes it a lot easier for me.
> <https://lists.sourceforge.net/lists/listinfo/bluez-devel>


Which parts of the patch violate the kernel coding style?  The function
parameter spacing?

Chris

[-- Attachment #1.2: Type: text/html, Size: 2388 bytes --]

[-- Attachment #2: Type: text/plain, Size: 309 bytes --]

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4

[-- Attachment #3: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-03 16:50   ` Chris Rivera
@ 2007-12-03 16:59     ` Marcel Holtmann
  2007-12-06 17:59       ` Chris Rivera
  0 siblings, 1 reply; 19+ messages in thread
From: Marcel Holtmann @ 2007-12-03 16:59 UTC (permalink / raw)
  To: BlueZ development

Hi Chris,

>         
>         I meant to look into it, but never got around it. Some small
>         comments
>         about it. Don't make the applet a singleton. That is totally
>         unneeded
>         since the applet will be loaded at login.
> 
> I still think it should be a singleton.  You wouldn't ever want two
> applets running unless you're testing, and we have the singleton flags
> for that.  I don't think this hurts anything. 

I am okay with that. Please abstract everything into common/. And don't
forget to document it in the manual pages.

>         For the "Present" method. Don't use the D-Bus low-level calls.
>         It should 
>         be all dbus-glib. Which means we have to abstract that into an
>         object. I
>         don't know if there is a well defined way for this. If it is,
>         it might
>         be good to use that. If not, then propose something for
>         freedesktop.org.
> 
> I thought about doing this, but it seems like overkill to define a
> GObject to just expose one method.  GObject isn't exactly terse
> either.

In a simple way you can use GObject for it. It is better than using the
low-level D-Bus calls.

>         And we should probably have some generic methods inside
>         common/ instead
>         of doing it again in every program.
>         
>         Please follow the kernel coding style. I know it is odd for a
>         GTK
>         application, but it makes it a lot easier for me. 
> 
> Which parts of the patch violate the kernel coding style?  The
> function parameter spacing?

Mainly the spacing.

Regards

Marcel



-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-03 16:59     ` Marcel Holtmann
@ 2007-12-06 17:59       ` Chris Rivera
  2007-12-17  3:08         ` Chris Rivera
  2007-12-17  5:47         ` Marcel Holtmann
  0 siblings, 2 replies; 19+ messages in thread
From: Chris Rivera @ 2007-12-06 17:59 UTC (permalink / raw)
  To: BlueZ development


[-- Attachment #1.1: Type: text/plain, Size: 1806 bytes --]

Attached is an updated patch with the changes that we talked about.

Chris

On Dec 3, 2007 11:59 AM, Marcel Holtmann <marcel@holtmann.org> wrote:

> Hi Chris,
>
> >
> >         I meant to look into it, but never got around it. Some small
> >         comments
> >         about it. Don't make the applet a singleton. That is totally
> >         unneeded
> >         since the applet will be loaded at login.
> >
> > I still think it should be a singleton.  You wouldn't ever want two
> > applets running unless you're testing, and we have the singleton flags
> > for that.  I don't think this hurts anything.
>
> I am okay with that. Please abstract everything into common/. And don't
> forget to document it in the manual pages.
>
> >         For the "Present" method. Don't use the D-Bus low-level calls.
> >         It should
> >         be all dbus-glib. Which means we have to abstract that into an
> >         object. I
> >         don't know if there is a well defined way for this. If it is,
> >         it might
> >         be good to use that. If not, then propose something for
> >         freedesktop.org.
> >
> > I thought about doing this, but it seems like overkill to define a
> > GObject to just expose one method.  GObject isn't exactly terse
> > either.
>
> In a simple way you can use GObject for it. It is better than using the
> low-level D-Bus calls.
>
> >         And we should probably have some generic methods inside
> >         common/ instead
> >         of doing it again in every program.
> >
> >         Please follow the kernel coding style. I know it is odd for a
> >         GTK
> >         application, but it makes it a lot easier for me.
> >
> > Which parts of the patch violate the kernel coding style?  The
> > function parameter spacing?
>
> Mainly the spacing.
>
>

[-- Attachment #1.2: Type: text/html, Size: 2822 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bluez-gnome-singleton.patch --]
[-- Type: text/x-patch; name=bluez-gnome-singleton.patch, Size: 18549 bytes --]

diff -urN gnome/applet/bluetooth-applet.1 gnome-new/applet/bluetooth-applet.1
--- gnome/applet/bluetooth-applet.1	2007-07-22 11:33:13.000000000 -0400
+++ gnome-new/applet/bluetooth-applet.1	2007-12-06 11:28:00.000000000 -0500
@@ -10,8 +10,9 @@
 .I bluetooth-applet
 is part of bluez-gnome, see also http://www.bluez.org
 .SH OPTIONS
-.I bluetooth-applet
-takes no options
+.TP 
+.BI \-\-singleton
+Ensure that only one instance is running.
 .SH AUTHOR
 Marcel Holtmann <marcel@holtmann.org>
 .SH LICENSE
diff -urN gnome/applet/bluetooth-applet.desktop.in gnome-new/applet/bluetooth-applet.desktop.in
--- gnome/applet/bluetooth-applet.desktop.in	2007-04-03 04:09:01.000000000 -0400
+++ gnome-new/applet/bluetooth-applet.desktop.in	2007-12-06 11:16:03.000000000 -0500
@@ -3,7 +3,7 @@
 _Name=Bluetooth Manager
 _Comment=Bluetooth Manager applet
 Icon=stock_bluetooth
-Exec=bluetooth-applet
+Exec=bluetooth-applet --singleton
 Terminal=false
 Type=Application
 Categories=
diff -urN gnome/applet/main.c gnome-new/applet/main.c
--- gnome/applet/main.c	2007-12-04 10:30:51.000000000 -0500
+++ gnome-new/applet/main.c	2007-12-06 11:16:03.000000000 -0500
@@ -49,6 +49,7 @@
 #endif
 
 #include "bluetooth-device-selection.h"
+#include "bluetooth-application-instance.h"
 
 #define PASSKEY_AGENT_PATH	"/org/bluez/passkey"
 #define AUTH_AGENT_PATH		"/org/bluez/auth"
@@ -1550,7 +1551,7 @@
 
 static void settings_callback(GObject *widget, gpointer user_data)
 {
-	const char *command = "bluetooth-properties";
+	const char *command = "bluetooth-properties --singleton";
 
 	if (!g_spawn_command_line_async(command, NULL))
 		g_printerr("Couldn't execute command: %s\n", command);
@@ -1639,7 +1640,7 @@
 #if 0
 static void wizard_callback(GObject *widget, gpointer user_data)
 {
-	const char *command = "bluetooth-wizard";
+	const char *command = "bluetooth-wizard --singleton";
 
 	if (!g_spawn_command_line_async(command, NULL))
 		g_printerr("Couldn't execute command: %s\n", command);
@@ -1782,9 +1783,19 @@
 
 int main(int argc, char *argv[])
 {
+	GOptionContext *ctx;
 	GtkWidget *menu;
 	GError *error = NULL;
+	BluetoothApplicationInstance *app;
 	char *str;
+	int retval = 0;
+	gboolean singleton = FALSE;
+
+	GOptionEntry entries[] = {
+		{ "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+		  N_("Only allow one instance of this application"), NULL },
+		{ NULL, 0, 0, 0, NULL, NULL, NULL }
+	};
 
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
@@ -1792,6 +1803,15 @@
 
 	gtk_init(&argc, &argv);
 
+	ctx = g_option_context_new("");
+	g_option_context_add_main_entries(ctx, entries, NULL);
+	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
+		g_printerr(_("parsing failed: %s\n"), error->message);
+		g_error_free(error);
+		g_option_context_free(ctx);
+		return retval;
+	}
+
 #ifdef HAVE_LIBNOTIFY
 	notify_init("bluetooth-manager");
 #endif
@@ -1804,6 +1824,11 @@
 		exit(EXIT_FAILURE);
 	}
 
+	app = bluetooth_application_instance_new();
+	if(!bluetooth_application_instance_register(app, &retval, singleton, 
+		"/org/bluez/Applet", "org.bluez.Applet"))
+		exit(retval);
+
 	gconf = gconf_client_get_default();
 
 #ifdef HAVE_HAL
@@ -1860,6 +1885,10 @@
 	g_list_foreach(adapter_list, adapter_free, NULL);
 
 	dbus_g_connection_unref(conn);
+    
+	g_object_unref(app);
 
+	g_option_context_free(ctx);
+	
 	return 0;
 }
diff -urN gnome/common/bluetooth-application-instance.c gnome-new/common/bluetooth-application-instance.c
--- gnome/common/bluetooth-application-instance.c	1969-12-31 19:00:00.000000000 -0500
+++ gnome-new/common/bluetooth-application-instance.c	2007-12-06 11:16:19.000000000 -0500
@@ -0,0 +1,132 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2005-2007  Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ *  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 <dbus/dbus-glib.h>
+
+#include "bluetooth-application-instance.h"
+#include "app-instance-glue.h"
+
+G_DEFINE_TYPE(BluetoothApplicationInstance, bluetooth_application_instance, G_TYPE_OBJECT)
+
+#define BLUETOOTH_APPLICATION_INSTANCE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
+										 BLUETOOTH_TYPE_APPLICATION_INSTANCE, BluetoothApplicationInstancePrivate))
+
+typedef struct _BluetoothApplicationInstancePrivate BluetoothApplicationInstancePrivate;
+
+struct _BluetoothApplicationInstancePrivate {
+	GtkWindow *window;
+	DBusGConnection *connection;
+};
+
+gboolean
+bluetooth_application_instance_register(BluetoothApplicationInstance *self,
+		int *retval, gboolean singleton, gchar *path, gchar *service)
+{
+	BluetoothApplicationInstancePrivate *priv = BLUETOOTH_APPLICATION_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.ApplicationInstance");
+		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_application_instance_set_window (BluetoothApplicationInstance *self, GtkWindow *window)
+{
+	BluetoothApplicationInstancePrivate *priv = BLUETOOTH_APPLICATION_INSTANCE_GET_PRIVATE(self);
+	priv->window = window;
+}
+
+gboolean
+bluetooth_application_instance_present(BluetoothApplicationInstance *self, GError **error)
+{
+	BluetoothApplicationInstancePrivate *priv = BLUETOOTH_APPLICATION_INSTANCE_GET_PRIVATE(self);
+	if (priv->window)
+		gtk_window_present(priv->window);
+	return TRUE;
+}
+
+static void
+bluetooth_application_instance_init(BluetoothApplicationInstance *self)
+{
+}
+
+static void
+bluetooth_application_instance_finalize(GObject *self)
+{
+	BluetoothApplicationInstancePrivate *priv = BLUETOOTH_APPLICATION_INSTANCE_GET_PRIVATE(self);
+	if (priv->connection)
+		dbus_g_connection_unref(priv->connection);
+}
+
+static void
+bluetooth_application_instance_class_init(BluetoothApplicationInstanceClass *klass)
+{
+	g_type_class_add_private(klass, sizeof(BluetoothApplicationInstancePrivate));
+	G_OBJECT_CLASS(klass)->finalize = bluetooth_application_instance_finalize;
+	dbus_g_object_type_install_info(BLUETOOTH_TYPE_APPLICATION_INSTANCE,
+			&dbus_glib_bluetooth_application_instance_object_info);
+}
+
+BluetoothApplicationInstance *
+bluetooth_application_instance_new(void)
+{
+	return g_object_new(BLUETOOTH_TYPE_APPLICATION_INSTANCE, NULL);
+}
diff -urN gnome/common/bluetooth-application-instance.h gnome-new/common/bluetooth-application-instance.h
--- gnome/common/bluetooth-application-instance.h	1969-12-31 19:00:00.000000000 -0500
+++ gnome-new/common/bluetooth-application-instance.h	2007-12-06 11:16:19.000000000 -0500
@@ -0,0 +1,63 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2005-2007  Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ *  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_APPLICATION_INSTANCE_H
+#define __BLUETOOTH_APPLICATION_INSTANCE_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define BLUETOOTH_TYPE_APPLICATION_INSTANCE (bluetooth_application_instance_get_type())
+#define BLUETOOTH_APPLICATION_INSTANCE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+				BLUETOOTH_TYPE_APPLICATION_INSTANCE, BluetoothApplicationInstance))
+#define BLUETOOTH_APPLICATION_INSTANCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \
+				BLUETOOTH_TYPE_APPLICATION_INSTANCE, BluetoothApplicationInstanceClass))
+#define BLUETOOTH_IS_APPLICATION_INSTANCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+						BLUETOOTH_TYPE_APPLICATION_INSTANCE))
+#define BLUETOOTH_IS_APPLICATION_INSTANCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \
+						BLUETOOTH_TYPE_APPLICATION_INSTANCE))
+#define BLUETOOTH_GET_APPLICATION_INSTANCE_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \
+				BLUETOOTH_TYPE_APPLICATION_INSTANCE, BluetoothApplicationInstanceClass))
+
+typedef struct _BluetoothApplicationInstance BluetoothApplicationInstance;
+typedef struct _BluetoothApplicationInstanceClass BluetoothApplicationInstanceClass;
+
+struct _BluetoothApplicationInstance {
+	GObject parent;
+};
+
+struct _BluetoothApplicationInstanceClass {
+	GObjectClass parent_class;
+};
+
+GType bluetooth_application_instance_get_type(void);
+BluetoothApplicationInstance *bluetooth_application_instance_new(void);
+void bluetooth_application_instance_set_window(BluetoothApplicationInstance *self, GtkWindow *window);
+gboolean bluetooth_application_instance_present(BluetoothApplicationInstance *self, GError **error);
+gboolean bluetooth_application_instance_register(BluetoothApplicationInstance *self,
+		int *retval, gboolean singleton, gchar *path, gchar *service);
+
+G_END_DECLS
+
+#endif /* __BLUETOOTH_APPLICATION_INSTANCE_H */
diff -urN gnome/common/bluetooth-application-instance.xml gnome-new/common/bluetooth-application-instance.xml
--- gnome/common/bluetooth-application-instance.xml	1969-12-31 19:00:00.000000000 -0500
+++ gnome-new/common/bluetooth-application-instance.xml	2007-12-06 11:16:19.000000000 -0500
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<node name="/">
+  <interface name="org.bluez.ApplicationInstance">
+    <method name="Present">
+    </method>
+  </interface>
+</node>
diff -urN 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-06 11:16:03.000000000 -0500
@@ -3,12 +3,13 @@
 
 libcommon_a_SOURCES = \
 		client.h client.c device-store.h device-store.c \
+		bluetooth-application-instance.c bluetooth-application-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_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-application-instance.xml
 
 MAINTAINERCLEANFILES = Makefile.in
 
@@ -40,3 +42,6 @@
 
 auth-agent-glue.h: auth-agent.xml
 	$(DBUS_BINDING_TOOL) --prefix=auth_agent --mode=glib-server --output=$@ $<
+
+app-instance-glue.h: bluetooth-application-instance.xml
+	$(DBUS_BINDING_TOOL) --prefix=bluetooth_application_instance --mode=glib-server --output=$@ $<
diff -urN gnome/properties/bluetooth-properties.1 gnome-new/properties/bluetooth-properties.1
--- gnome/properties/bluetooth-properties.1	2007-07-22 11:33:13.000000000 -0400
+++ gnome-new/properties/bluetooth-properties.1	2007-12-06 11:31:18.000000000 -0500
@@ -9,8 +9,9 @@
 .I bluetooth-properties
 is part of bluez-gnome, see also http://www.bluez.org
 .SH OPTIONS
-.I bluetooth-properties
-takes no options
+.TP 
+.BI \-\-singleton
+Ensure that only one instance is running.
 .SH AUTHOR
 Marcel Holtmann <marcel@holtmann.org>
 .SH LICENSE
diff -urN gnome/properties/main.c gnome-new/properties/main.c
--- gnome/properties/main.c	2007-07-31 17:37:29.000000000 -0400
+++ gnome-new/properties/main.c	2007-12-06 11:16:03.000000000 -0500
@@ -40,6 +40,7 @@
 #include "general.h"
 #include "service.h"
 #include "adapter.h"
+#include "bluetooth-application-instance.h"
 
 static void delete_callback(GtkWidget *window, GdkEvent *event,
 						gpointer user_data)
@@ -58,7 +59,7 @@
 	gtk_main_quit();
 }
 
-static void create_window(GtkWidget *notebook)
+static GtkWidget *create_window(GtkWidget *notebook)
 {
 	GtkWidget *window;
 	GtkWidget *widget;
@@ -108,6 +109,7 @@
 						widget, _("General"));
 
 	gtk_widget_show_all(window);
+	return window;
 }
 
 static void name_owner_changed(DBusGProxy *object, const char *name,
@@ -141,17 +143,37 @@
 
 int main(int argc, char *argv[])
 {
+	GOptionContext *ctx;
 	GtkWidget *notebook;
+	GtkWidget *window;
+	GError *error = NULL;
 	DBusGConnection *conn;
+	BluetoothApplicationInstance *app;
 	DBusGProxy *manager;
-	GError *error = NULL;
+	int retval = 0;
+	gboolean singleton = FALSE;
 
+	GOptionEntry entries[] = {
+		{ "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+		  N_("Only allow one instance of this application"), NULL },
+		{ NULL, 0, 0, 0, NULL, NULL, NULL }
+	};
+	
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 	textdomain(GETTEXT_PACKAGE);
 
 	gtk_init(&argc, &argv);
 
+	ctx = g_option_context_new("");
+	g_option_context_add_main_entries(ctx, entries, NULL);
+	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
+		g_printerr(_("parsing failed: %s\n"), error->message);
+		g_error_free(error);
+		g_option_context_free(ctx);
+		return retval;
+	}
+	
 	conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
 	if (error != NULL) {
 		g_printerr("Connecting to system bus failed: %s\n",
@@ -163,12 +185,18 @@
 	setup_general();
 
 	notebook = gtk_notebook_new();
-
+    
 	assign_adapter(notebook);
 
-	manager = setup_manager(conn);
+	window = create_window(notebook);
 
-	create_window(notebook);
+	app = bluetooth_application_instance_new();
+	bluetooth_application_instance_set_window(app, GTK_WINDOW(window));
+	if(!bluetooth_application_instance_register(app, &retval, singleton, 
+		"/org/bluez/Properties", "org.bluez.Properties"))
+		exit(retval);
+	
+	manager = setup_manager(conn);
 
 	gtk_main();
 
@@ -181,6 +209,10 @@
 	g_object_unref(manager);
 
 	dbus_g_connection_unref(conn);
+    
+	g_object_unref(app);
 
+	g_option_context_free(ctx);
+	
 	return 0;
 }
diff -urN gnome/wizard/bluetooth-wizard.1 gnome-new/wizard/bluetooth-wizard.1
--- gnome/wizard/bluetooth-wizard.1	2007-07-22 11:33:12.000000000 -0400
+++ gnome-new/wizard/bluetooth-wizard.1	2007-12-06 11:31:41.000000000 -0500
@@ -9,8 +9,9 @@
 .I bluetooth-wizard
 is part of bluez-gnome, see also http://www.bluez.org
 .SH OPTIONS
-.I bluetooth-wizard
-takes no options
+.TP 
+.BI \-\-singleton
+Ensure that only one instance is running.
 .SH AUTHOR
 Marcel Holtmann <marcel@holtmann.org>
 .SH LICENSE
diff -urN gnome/wizard/main.c gnome-new/wizard/main.c
--- gnome/wizard/main.c	2007-08-15 03:04:03.000000000 -0400
+++ gnome-new/wizard/main.c	2007-12-06 11:16:03.000000000 -0500
@@ -26,6 +26,7 @@
 #endif
 
 #include <string.h>
+#include <stdlib.h>
 
 #include <dbus/dbus-glib.h>
 
@@ -38,6 +39,7 @@
 #include "dbus-glue.h"
 
 #include "bluetooth-device-selection.h"
+#include "bluetooth-application-instance.h"
 
 static BluetoothClient *client;
 
@@ -387,7 +389,7 @@
 	page_summary = vbox;
 }
 
-static void create_wizard(void)
+static GtkWidget *create_wizard(void)
 {
 	GtkWidget *assistant;
 
@@ -430,23 +432,56 @@
 	gtk_widget_show_all(assistant);
 
 	gtk_assistant_update_buttons_state(GTK_ASSISTANT(assistant));
+	return assistant;
 }
 
 int main(int argc, char *argv[])
 {
+	GOptionContext *ctx;
+	GtkWidget *window;
+	BluetoothApplicationInstance *app;
+	GError *error = NULL;
+	int retval = 0;
+	gboolean singleton = FALSE;
+
+	GOptionEntry entries[] = {
+		{ "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+		  N_("Only allow one instance of this application"), NULL },
+		{ NULL, 0, 0, 0, NULL, NULL, NULL }
+	};
+	
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 	textdomain(GETTEXT_PACKAGE);
 
 	gtk_init(&argc, &argv);
 
+	ctx = g_option_context_new("");
+	g_option_context_add_main_entries(ctx, entries, NULL);
+	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
+		g_printerr(_("parsing failed: %s\n"), error->message);
+		g_error_free(error);
+		g_option_context_free(ctx);
+		return retval;
+	}
+	
 	client = bluetooth_client_new();
 
-	create_wizard();
+	window = create_wizard();
+    
+	app = bluetooth_application_instance_new();
+	bluetooth_application_instance_set_window(app, GTK_WINDOW(window));
+	if(!bluetooth_application_instance_register(app, &retval, singleton, 
+		"/org/bluez/Wizard", "org.bluez.Wizard"))
+		exit(retval);
 
 	gtk_main();
 
 	g_object_unref(client);
 
+	g_object_unref(app);
+
+	g_option_context_free(ctx);
+	
 	return 0;
 }

[-- Attachment #3: Type: text/plain, Size: 309 bytes --]

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4

[-- Attachment #4: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-06 17:59       ` Chris Rivera
@ 2007-12-17  3:08         ` Chris Rivera
  2007-12-17  5:47         ` Marcel Holtmann
  1 sibling, 0 replies; 19+ messages in thread
From: Chris Rivera @ 2007-12-17  3:08 UTC (permalink / raw)
  To: BlueZ development


[-- Attachment #1.1: Type: text/plain, Size: 2004 bytes --]

Anyone?  Anyone?

On Dec 6, 2007 12:59 PM, Chris Rivera <chrismrivera@gmail.com> wrote:

> Attached is an updated patch with the changes that we talked about.
>
> Chris
>
>
> On Dec 3, 2007 11:59 AM, Marcel Holtmann <marcel@holtmann.org> wrote:
>
> > Hi Chris,
> >
> > >
> > >         I meant to look into it, but never got around it. Some small
> > >         comments
> > >         about it. Don't make the applet a singleton. That is totally
> > >         unneeded
> > >         since the applet will be loaded at login.
> > >
> > > I still think it should be a singleton.  You wouldn't ever want two
> > > applets running unless you're testing, and we have the singleton flags
> > > for that.  I don't think this hurts anything.
> >
> > I am okay with that. Please abstract everything into common/. And don't
> > forget to document it in the manual pages.
> >
> > >         For the "Present" method. Don't use the D-Bus low-level calls.
> > >         It should
> > >         be all dbus-glib. Which means we have to abstract that into an
> >
> > >         object. I
> > >         don't know if there is a well defined way for this. If it is,
> > >         it might
> > >         be good to use that. If not, then propose something for
> > >         freedesktop.org.
> > >
> > > I thought about doing this, but it seems like overkill to define a
> > > GObject to just expose one method.  GObject isn't exactly terse
> > > either.
> >
> > In a simple way you can use GObject for it. It is better than using the
> > low-level D-Bus calls.
> >
> > >         And we should probably have some generic methods inside
> > >         common/ instead
> > >         of doing it again in every program.
> > >
> > >         Please follow the kernel coding style. I know it is odd for a
> > >         GTK
> > >         application, but it makes it a lot easier for me.
> > >
> > > Which parts of the patch violate the kernel coding style?  The
> > > function parameter spacing?
> >
> > Mainly the spacing.
> >
> >
>

[-- Attachment #1.2: Type: text/html, Size: 3187 bytes --]

[-- Attachment #2: Type: text/plain, Size: 308 bytes --]

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

[-- Attachment #3: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-06 17:59       ` Chris Rivera
  2007-12-17  3:08         ` Chris Rivera
@ 2007-12-17  5:47         ` Marcel Holtmann
  2007-12-17 15:54           ` Chris Rivera
  1 sibling, 1 reply; 19+ messages in thread
From: Marcel Holtmann @ 2007-12-17  5:47 UTC (permalink / raw)
  To: BlueZ development

Hi Chris,

> Attached is an updated patch with the changes that we talked about.

the patch looks good, but using bluetooth_application_instance is too
long for my taste. Use bluetooth_instance to make this shorter.

Also use org.bluez.properties etc. for the service names
and /org/bluez/properties etc. for the object path.

I also like to have multiple separate patches. One that add the generic
instance code and then additional patches that adds support for it to
every application. This makes it a lot easier for me to review and apply
it.

Regards

Marcel



-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-17  5:47         ` Marcel Holtmann
@ 2007-12-17 15:54           ` Chris Rivera
  2007-12-17 18:53             ` Marcel Holtmann
  0 siblings, 1 reply; 19+ messages in thread
From: Chris Rivera @ 2007-12-17 15:54 UTC (permalink / raw)
  To: BlueZ development


[-- Attachment #1.1: Type: text/plain, Size: 1202 bytes --]

Updated patches attached.

Chris

On Dec 17, 2007 12:47 AM, Marcel Holtmann <marcel@holtmann.org> wrote:

> Hi Chris,
>
> > Attached is an updated patch with the changes that we talked about.
>
> the patch looks good, but using bluetooth_application_instance is too
> long for my taste. Use bluetooth_instance to make this shorter.
>
> Also use org.bluez.properties etc. for the service names
> and /org/bluez/properties etc. for the object path.
>
> I also like to have multiple separate patches. One that add the generic
> instance code and then additional patches that adds support for it to
> every application. This makes it a lot easier for me to review and apply
> it.
>
> Regards
>
> Marcel
>
>
>
> -------------------------------------------------------------------------
> SF.Net email is sponsored by:
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services
> for just about anything Open Source.
>
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>

[-- Attachment #1.2: Type: text/html, Size: 1839 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bluez-gnome-singleton-instance.patch --]
[-- Type: text/x-patch; name=bluez-gnome-singleton-instance.patch, Size: 8651 bytes --]

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 <marcel@holtmann.org>
+ *
+ *
+ *  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 <dbus/dbus-glib.h>
+
+#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 <marcel@holtmann.org>
+ *
+ *
+ *  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 <gtk/gtk.h>
+
+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 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<node name="/">
+  <interface name="org.bluez.BluetoothInstance">
+    <method name="Present">
+    </method>
+  </interface>
+</node>
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=$@ $<

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: bluez-gnome-singleton-apps.patch --]
[-- Type: text/x-patch; name=bluez-gnome-singleton-apps.patch, Size: 9483 bytes --]

diff -urpN gnome/applet/bluetooth-applet.1 gnome-new/applet/bluetooth-applet.1
--- gnome/applet/bluetooth-applet.1	2007-07-22 11:33:13.000000000 -0400
+++ gnome-new/applet/bluetooth-applet.1	2007-12-16 18:31:09.000000000 -0500
@@ -10,8 +10,9 @@ whenever a passkey (aka PIN) is required
 .I bluetooth-applet
 is part of bluez-gnome, see also http://www.bluez.org
 .SH OPTIONS
-.I bluetooth-applet
-takes no options
+.TP 
+.BI \-\-singleton
+Ensure that only one instance is running.
 .SH AUTHOR
 Marcel Holtmann <marcel@holtmann.org>
 .SH LICENSE
diff -urpN gnome/applet/bluetooth-applet.desktop.in gnome-new/applet/bluetooth-applet.desktop.in
--- gnome/applet/bluetooth-applet.desktop.in	2007-04-03 04:09:01.000000000 -0400
+++ gnome-new/applet/bluetooth-applet.desktop.in	2007-12-16 18:31:09.000000000 -0500
@@ -3,7 +3,7 @@ Encoding=UTF-8
 _Name=Bluetooth Manager
 _Comment=Bluetooth Manager applet
 Icon=stock_bluetooth
-Exec=bluetooth-applet
+Exec=bluetooth-applet --singleton
 Terminal=false
 Type=Application
 Categories=
diff -urpN gnome/applet/main.c gnome-new/applet/main.c
--- gnome/applet/main.c	2007-12-04 10:30:51.000000000 -0500
+++ gnome-new/applet/main.c	2007-12-16 18:31:09.000000000 -0500
@@ -49,6 +49,7 @@
 #endif
 
 #include "bluetooth-device-selection.h"
+#include "bluetooth-instance.h"
 
 #define PASSKEY_AGENT_PATH	"/org/bluez/passkey"
 #define AUTH_AGENT_PATH		"/org/bluez/auth"
@@ -1550,7 +1551,7 @@ static void about_callback(GtkWidget *it
 
 static void settings_callback(GObject *widget, gpointer user_data)
 {
-	const char *command = "bluetooth-properties";
+	const char *command = "bluetooth-properties --singleton";
 
 	if (!g_spawn_command_line_async(command, NULL))
 		g_printerr("Couldn't execute command: %s\n", command);
@@ -1639,7 +1640,7 @@ static void sendto_callback(GObject *wid
 #if 0
 static void wizard_callback(GObject *widget, gpointer user_data)
 {
-	const char *command = "bluetooth-wizard";
+	const char *command = "bluetooth-wizard --singleton";
 
 	if (!g_spawn_command_line_async(command, NULL))
 		g_printerr("Couldn't execute command: %s\n", command);
@@ -1782,9 +1783,19 @@ static void gconf_callback(GConfClient *
 
 int main(int argc, char *argv[])
 {
+	GOptionContext *ctx;
 	GtkWidget *menu;
 	GError *error = NULL;
+	BluetoothInstance *app;
 	char *str;
+	int retval = 0;
+	gboolean singleton = FALSE;
+
+	GOptionEntry entries[] = {
+		{ "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+		  N_("Only allow one instance of this application"), NULL },
+		{ NULL, 0, 0, 0, NULL, NULL, NULL }
+	};
 
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
@@ -1792,6 +1803,15 @@ int main(int argc, char *argv[])
 
 	gtk_init(&argc, &argv);
 
+	ctx = g_option_context_new("");
+	g_option_context_add_main_entries(ctx, entries, NULL);
+	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
+		g_printerr(_("parsing failed: %s\n"), error->message);
+		g_error_free(error);
+		g_option_context_free(ctx);
+		return retval;
+	}
+
 #ifdef HAVE_LIBNOTIFY
 	notify_init("bluetooth-manager");
 #endif
@@ -1804,6 +1824,11 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	}
 
+	app = bluetooth_instance_new();
+	if(!bluetooth_instance_register(app, &retval, singleton, 
+		"/org/bluez/applet", "org.bluez.applet"))
+		exit(retval);
+
 	gconf = gconf_client_get_default();
 
 #ifdef HAVE_HAL
@@ -1860,6 +1885,10 @@ int main(int argc, char *argv[])
 	g_list_foreach(adapter_list, adapter_free, NULL);
 
 	dbus_g_connection_unref(conn);
+    
+	g_object_unref(app);
 
+	g_option_context_free(ctx);
+	
 	return 0;
 }
diff -urpN gnome/properties/bluetooth-properties.1 gnome-new/properties/bluetooth-properties.1
--- gnome/properties/bluetooth-properties.1	2007-07-22 11:33:13.000000000 -0400
+++ gnome-new/properties/bluetooth-properties.1	2007-12-16 18:31:09.000000000 -0500
@@ -9,8 +9,9 @@ will display a dialog for changing Bluet
 .I bluetooth-properties
 is part of bluez-gnome, see also http://www.bluez.org
 .SH OPTIONS
-.I bluetooth-properties
-takes no options
+.TP 
+.BI \-\-singleton
+Ensure that only one instance is running.
 .SH AUTHOR
 Marcel Holtmann <marcel@holtmann.org>
 .SH LICENSE
diff -urpN gnome/properties/main.c gnome-new/properties/main.c
--- gnome/properties/main.c	2007-07-31 17:37:29.000000000 -0400
+++ gnome-new/properties/main.c	2007-12-16 18:31:09.000000000 -0500
@@ -40,6 +40,7 @@
 #include "general.h"
 #include "service.h"
 #include "adapter.h"
+#include "bluetooth-instance.h"
 
 static void delete_callback(GtkWidget *window, GdkEvent *event,
 						gpointer user_data)
@@ -58,7 +59,7 @@ static void close_callback(GtkWidget *bu
 	gtk_main_quit();
 }
 
-static void create_window(GtkWidget *notebook)
+static GtkWidget *create_window(GtkWidget *notebook)
 {
 	GtkWidget *window;
 	GtkWidget *widget;
@@ -108,6 +109,7 @@ static void create_window(GtkWidget *not
 						widget, _("General"));
 
 	gtk_widget_show_all(window);
+	return window;
 }
 
 static void name_owner_changed(DBusGProxy *object, const char *name,
@@ -141,17 +143,37 @@ static DBusGProxy *setup_manager(DBusGCo
 
 int main(int argc, char *argv[])
 {
+	GOptionContext *ctx;
 	GtkWidget *notebook;
+	GtkWidget *window;
+	GError *error = NULL;
 	DBusGConnection *conn;
+	BluetoothInstance *app;
 	DBusGProxy *manager;
-	GError *error = NULL;
+	int retval = 0;
+	gboolean singleton = FALSE;
 
+	GOptionEntry entries[] = {
+		{ "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+		  N_("Only allow one instance of this application"), NULL },
+		{ NULL, 0, 0, 0, NULL, NULL, NULL }
+	};
+	
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 	textdomain(GETTEXT_PACKAGE);
 
 	gtk_init(&argc, &argv);
 
+	ctx = g_option_context_new("");
+	g_option_context_add_main_entries(ctx, entries, NULL);
+	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
+		g_printerr(_("parsing failed: %s\n"), error->message);
+		g_error_free(error);
+		g_option_context_free(ctx);
+		return retval;
+	}
+	
 	conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
 	if (error != NULL) {
 		g_printerr("Connecting to system bus failed: %s\n",
@@ -163,12 +185,18 @@ int main(int argc, char *argv[])
 	setup_general();
 
 	notebook = gtk_notebook_new();
-
+    
 	assign_adapter(notebook);
 
-	manager = setup_manager(conn);
+	window = create_window(notebook);
 
-	create_window(notebook);
+	app = bluetooth_instance_new();
+	bluetooth_instance_set_window(app, GTK_WINDOW(window));
+	if(!bluetooth_instance_register(app, &retval, singleton, 
+		"/org/bluez/properties", "org.bluez.properties"))
+		exit(retval);
+	
+	manager = setup_manager(conn);
 
 	gtk_main();
 
@@ -181,6 +209,10 @@ int main(int argc, char *argv[])
 	g_object_unref(manager);
 
 	dbus_g_connection_unref(conn);
+    
+	g_object_unref(app);
 
+	g_option_context_free(ctx);
+	
 	return 0;
 }
diff -urpN gnome/wizard/bluetooth-wizard.1 gnome-new/wizard/bluetooth-wizard.1
--- gnome/wizard/bluetooth-wizard.1	2007-07-22 11:33:12.000000000 -0400
+++ gnome-new/wizard/bluetooth-wizard.1	2007-12-16 18:31:09.000000000 -0500
@@ -9,8 +9,9 @@ will display a wizard for setting up Blu
 .I bluetooth-wizard
 is part of bluez-gnome, see also http://www.bluez.org
 .SH OPTIONS
-.I bluetooth-wizard
-takes no options
+.TP 
+.BI \-\-singleton
+Ensure that only one instance is running.
 .SH AUTHOR
 Marcel Holtmann <marcel@holtmann.org>
 .SH LICENSE
diff -urpN gnome/wizard/main.c gnome-new/wizard/main.c
--- gnome/wizard/main.c	2007-08-15 03:04:03.000000000 -0400
+++ gnome-new/wizard/main.c	2007-12-16 18:31:09.000000000 -0500
@@ -26,6 +26,7 @@
 #endif
 
 #include <string.h>
+#include <stdlib.h>
 
 #include <dbus/dbus-glib.h>
 
@@ -38,6 +39,7 @@
 #include "dbus-glue.h"
 
 #include "bluetooth-device-selection.h"
+#include "bluetooth-instance.h"
 
 static BluetoothClient *client;
 
@@ -387,7 +389,7 @@ static void create_summary(GtkWidget *as
 	page_summary = vbox;
 }
 
-static void create_wizard(void)
+static GtkWidget *create_wizard(void)
 {
 	GtkWidget *assistant;
 
@@ -430,23 +432,56 @@ static void create_wizard(void)
 	gtk_widget_show_all(assistant);
 
 	gtk_assistant_update_buttons_state(GTK_ASSISTANT(assistant));
+	return assistant;
 }
 
 int main(int argc, char *argv[])
 {
+	GOptionContext *ctx;
+	GtkWidget *window;
+	BluetoothInstance *app;
+	GError *error = NULL;
+	int retval = 0;
+	gboolean singleton = FALSE;
+
+	GOptionEntry entries[] = {
+		{ "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+		  N_("Only allow one instance of this application"), NULL },
+		{ NULL, 0, 0, 0, NULL, NULL, NULL }
+	};
+	
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 	textdomain(GETTEXT_PACKAGE);
 
 	gtk_init(&argc, &argv);
 
+	ctx = g_option_context_new("");
+	g_option_context_add_main_entries(ctx, entries, NULL);
+	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
+		g_printerr(_("parsing failed: %s\n"), error->message);
+		g_error_free(error);
+		g_option_context_free(ctx);
+		return retval;
+	}
+	
 	client = bluetooth_client_new();
 
-	create_wizard();
+	window = create_wizard();
+    
+	app = bluetooth_instance_new();
+	bluetooth_instance_set_window(app, GTK_WINDOW(window));
+	if(!bluetooth_instance_register(app, &retval, singleton, 
+		"/org/bluez/wizard", "org.bluez.wizard"))
+		exit(retval);
 
 	gtk_main();
 
 	g_object_unref(client);
 
+	g_object_unref(app);
+
+	g_option_context_free(ctx);
+	
 	return 0;
 }

[-- Attachment #4: Type: text/plain, Size: 308 bytes --]

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

[-- Attachment #5: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-17 15:54           ` Chris Rivera
@ 2007-12-17 18:53             ` Marcel Holtmann
  2007-12-17 19:29               ` Chris Rivera
  0 siblings, 1 reply; 19+ messages in thread
From: Marcel Holtmann @ 2007-12-17 18:53 UTC (permalink / raw)
  To: BlueZ development

Hi Chris,

> Updated patches attached.

I added the generic singleton instance patch to the CVS. I did some
minor modifications. The interface name is org.bluez.Instance. No need
to duplicate the word Bluetooth here. And I removed the retval parameter
from the register function. It is useless. Use the return value for it.
If it is TRUE, everything is okay. If FALSE, cleanup and exit(1).

Please update the application patches and resend them. And double check
the whitespace stuff. I had to fix some of them in your other patch. Use
an editor that has a visual representation of tabs and whitespaces. It
really helps.

Regards

Marcel



-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-17 18:53             ` Marcel Holtmann
@ 2007-12-17 19:29               ` Chris Rivera
  2007-12-17 20:17                 ` Marcel Holtmann
  0 siblings, 1 reply; 19+ messages in thread
From: Chris Rivera @ 2007-12-17 19:29 UTC (permalink / raw)
  To: BlueZ development


[-- Attachment #1.1: Type: text/plain, Size: 906 bytes --]

On Dec 17, 2007 1:53 PM, Marcel Holtmann <marcel@holtmann.org> wrote:

> Hi Chris,
>
> > Updated patches attached.
>
> I added the generic singleton instance patch to the CVS. I did some
> minor modifications. The interface name is org.bluez.Instance. No need
> to duplicate the word Bluetooth here. And I removed the retval parameter
> from the register function. It is useless. Use the return value for it.
> If it is TRUE, everything is okay. If FALSE, cleanup and exit(1).
>
>
>
I wanted to distinguish between an instance already running and actual DBUS
errors.  If an instance is already running then we can exit with 0 since the
intended action was successful (the launched application is now in the
foreground).  If, however, there are errors connecting to the bus then we
exit with 1.  It isn't a big deal though.  I've attached an updated apps
patch that gets rid of the retval parameter.

Chris

[-- Attachment #1.2: Type: text/html, Size: 1189 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bluez-gnome-singleton-apps.patch --]
[-- Type: text/x-patch; name=bluez-gnome-singleton-apps.patch, Size: 9435 bytes --]

diff -urpN gnome/applet/bluetooth-applet.1 gnome-new/applet/bluetooth-applet.1
--- gnome/applet/bluetooth-applet.1	2007-07-22 11:33:13.000000000 -0400
+++ gnome-new/applet/bluetooth-applet.1	2007-12-16 18:31:09.000000000 -0500
@@ -10,8 +10,9 @@ whenever a passkey (aka PIN) is required
 .I bluetooth-applet
 is part of bluez-gnome, see also http://www.bluez.org
 .SH OPTIONS
-.I bluetooth-applet
-takes no options
+.TP 
+.BI \-\-singleton
+Ensure that only one instance is running.
 .SH AUTHOR
 Marcel Holtmann <marcel@holtmann.org>
 .SH LICENSE
diff -urpN gnome/applet/bluetooth-applet.desktop.in gnome-new/applet/bluetooth-applet.desktop.in
--- gnome/applet/bluetooth-applet.desktop.in	2007-04-03 04:09:01.000000000 -0400
+++ gnome-new/applet/bluetooth-applet.desktop.in	2007-12-16 18:31:09.000000000 -0500
@@ -3,7 +3,7 @@ Encoding=UTF-8
 _Name=Bluetooth Manager
 _Comment=Bluetooth Manager applet
 Icon=stock_bluetooth
-Exec=bluetooth-applet
+Exec=bluetooth-applet --singleton
 Terminal=false
 Type=Application
 Categories=
diff -urpN gnome/applet/main.c gnome-new/applet/main.c
--- gnome/applet/main.c	2007-12-04 10:30:51.000000000 -0500
+++ gnome-new/applet/main.c	2007-12-16 22:11:44.000000000 -0500
@@ -49,6 +49,7 @@
 #endif
 
 #include "bluetooth-device-selection.h"
+#include "bluetooth-instance.h"
 
 #define PASSKEY_AGENT_PATH	"/org/bluez/passkey"
 #define AUTH_AGENT_PATH		"/org/bluez/auth"
@@ -1550,7 +1551,7 @@ static void about_callback(GtkWidget *it
 
 static void settings_callback(GObject *widget, gpointer user_data)
 {
-	const char *command = "bluetooth-properties";
+	const char *command = "bluetooth-properties --singleton";
 
 	if (!g_spawn_command_line_async(command, NULL))
 		g_printerr("Couldn't execute command: %s\n", command);
@@ -1639,7 +1640,7 @@ static void sendto_callback(GObject *wid
 #if 0
 static void wizard_callback(GObject *widget, gpointer user_data)
 {
-	const char *command = "bluetooth-wizard";
+	const char *command = "bluetooth-wizard --singleton";
 
 	if (!g_spawn_command_line_async(command, NULL))
 		g_printerr("Couldn't execute command: %s\n", command);
@@ -1782,9 +1783,18 @@ static void gconf_callback(GConfClient *
 
 int main(int argc, char *argv[])
 {
+	GOptionContext *ctx;
 	GtkWidget *menu;
 	GError *error = NULL;
+	BluetoothInstance *app;
 	char *str;
+	gboolean singleton = FALSE;
+
+	GOptionEntry entries[] = {
+		{ "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+		  N_("Only allow one instance of this application"), NULL },
+		{ NULL, 0, 0, 0, NULL, NULL, NULL }
+	};
 
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
@@ -1792,6 +1802,15 @@ int main(int argc, char *argv[])
 
 	gtk_init(&argc, &argv);
 
+	ctx = g_option_context_new("");
+	g_option_context_add_main_entries(ctx, entries, NULL);
+	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
+		g_printerr(_("parsing failed: %s\n"), error->message);
+		g_error_free(error);
+		g_option_context_free(ctx);
+		exit(EXIT_FAILURE);
+	}
+
 #ifdef HAVE_LIBNOTIFY
 	notify_init("bluetooth-manager");
 #endif
@@ -1804,6 +1823,11 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	}
 
+	app = bluetooth_instance_new();
+	if(!bluetooth_instance_register(app, singleton, 
+		"/org/bluez/applet", "org.bluez.applet"))
+		exit(EXIT_FAILURE);
+
 	gconf = gconf_client_get_default();
 
 #ifdef HAVE_HAL
@@ -1860,6 +1884,10 @@ int main(int argc, char *argv[])
 	g_list_foreach(adapter_list, adapter_free, NULL);
 
 	dbus_g_connection_unref(conn);
+    
+	g_object_unref(app);
 
+	g_option_context_free(ctx);
+	
 	return 0;
 }
diff -urpN gnome/properties/bluetooth-properties.1 gnome-new/properties/bluetooth-properties.1
--- gnome/properties/bluetooth-properties.1	2007-07-22 11:33:13.000000000 -0400
+++ gnome-new/properties/bluetooth-properties.1	2007-12-16 18:31:09.000000000 -0500
@@ -9,8 +9,9 @@ will display a dialog for changing Bluet
 .I bluetooth-properties
 is part of bluez-gnome, see also http://www.bluez.org
 .SH OPTIONS
-.I bluetooth-properties
-takes no options
+.TP 
+.BI \-\-singleton
+Ensure that only one instance is running.
 .SH AUTHOR
 Marcel Holtmann <marcel@holtmann.org>
 .SH LICENSE
diff -urpN gnome/properties/main.c gnome-new/properties/main.c
--- gnome/properties/main.c	2007-07-31 17:37:29.000000000 -0400
+++ gnome-new/properties/main.c	2007-12-16 22:13:19.000000000 -0500
@@ -40,6 +40,7 @@
 #include "general.h"
 #include "service.h"
 #include "adapter.h"
+#include "bluetooth-instance.h"
 
 static void delete_callback(GtkWidget *window, GdkEvent *event,
 						gpointer user_data)
@@ -58,7 +59,7 @@ static void close_callback(GtkWidget *bu
 	gtk_main_quit();
 }
 
-static void create_window(GtkWidget *notebook)
+static GtkWidget *create_window(GtkWidget *notebook)
 {
 	GtkWidget *window;
 	GtkWidget *widget;
@@ -108,6 +109,7 @@ static void create_window(GtkWidget *not
 						widget, _("General"));
 
 	gtk_widget_show_all(window);
+	return window;
 }
 
 static void name_owner_changed(DBusGProxy *object, const char *name,
@@ -141,17 +143,36 @@ static DBusGProxy *setup_manager(DBusGCo
 
 int main(int argc, char *argv[])
 {
+	GOptionContext *ctx;
 	GtkWidget *notebook;
+	GtkWidget *window;
+	GError *error = NULL;
 	DBusGConnection *conn;
+	BluetoothInstance *app;
 	DBusGProxy *manager;
-	GError *error = NULL;
+	gboolean singleton = FALSE;
 
+	GOptionEntry entries[] = {
+		{ "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+		  N_("Only allow one instance of this application"), NULL },
+		{ NULL, 0, 0, 0, NULL, NULL, NULL }
+	};
+	
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 	textdomain(GETTEXT_PACKAGE);
 
 	gtk_init(&argc, &argv);
 
+	ctx = g_option_context_new("");
+	g_option_context_add_main_entries(ctx, entries, NULL);
+	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
+		g_printerr(_("parsing failed: %s\n"), error->message);
+		g_error_free(error);
+		g_option_context_free(ctx);
+		exit(EXIT_FAILURE);
+	}
+	
 	conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
 	if (error != NULL) {
 		g_printerr("Connecting to system bus failed: %s\n",
@@ -163,12 +184,18 @@ int main(int argc, char *argv[])
 	setup_general();
 
 	notebook = gtk_notebook_new();
-
+    
 	assign_adapter(notebook);
 
-	manager = setup_manager(conn);
+	window = create_window(notebook);
 
-	create_window(notebook);
+	app = bluetooth_instance_new();
+	bluetooth_instance_set_window(app, GTK_WINDOW(window));
+	if(!bluetooth_instance_register(app, singleton, 
+		"/org/bluez/properties", "org.bluez.properties"))
+		exit(EXIT_FAILURE);
+	
+	manager = setup_manager(conn);
 
 	gtk_main();
 
@@ -181,6 +208,10 @@ int main(int argc, char *argv[])
 	g_object_unref(manager);
 
 	dbus_g_connection_unref(conn);
+    
+	g_object_unref(app);
 
+	g_option_context_free(ctx);
+	
 	return 0;
 }
diff -urpN gnome/wizard/bluetooth-wizard.1 gnome-new/wizard/bluetooth-wizard.1
--- gnome/wizard/bluetooth-wizard.1	2007-07-22 11:33:12.000000000 -0400
+++ gnome-new/wizard/bluetooth-wizard.1	2007-12-16 18:31:09.000000000 -0500
@@ -9,8 +9,9 @@ will display a wizard for setting up Blu
 .I bluetooth-wizard
 is part of bluez-gnome, see also http://www.bluez.org
 .SH OPTIONS
-.I bluetooth-wizard
-takes no options
+.TP 
+.BI \-\-singleton
+Ensure that only one instance is running.
 .SH AUTHOR
 Marcel Holtmann <marcel@holtmann.org>
 .SH LICENSE
diff -urpN gnome/wizard/main.c gnome-new/wizard/main.c
--- gnome/wizard/main.c	2007-08-15 03:04:03.000000000 -0400
+++ gnome-new/wizard/main.c	2007-12-16 22:12:13.000000000 -0500
@@ -26,6 +26,7 @@
 #endif
 
 #include <string.h>
+#include <stdlib.h>
 
 #include <dbus/dbus-glib.h>
 
@@ -38,6 +39,7 @@
 #include "dbus-glue.h"
 
 #include "bluetooth-device-selection.h"
+#include "bluetooth-instance.h"
 
 static BluetoothClient *client;
 
@@ -387,7 +389,7 @@ static void create_summary(GtkWidget *as
 	page_summary = vbox;
 }
 
-static void create_wizard(void)
+static GtkWidget *create_wizard(void)
 {
 	GtkWidget *assistant;
 
@@ -430,23 +432,55 @@ static void create_wizard(void)
 	gtk_widget_show_all(assistant);
 
 	gtk_assistant_update_buttons_state(GTK_ASSISTANT(assistant));
+	return assistant;
 }
 
 int main(int argc, char *argv[])
 {
+	GOptionContext *ctx;
+	GtkWidget *window;
+	BluetoothInstance *app;
+	GError *error = NULL;
+	gboolean singleton = FALSE;
+
+	GOptionEntry entries[] = {
+		{ "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+		  N_("Only allow one instance of this application"), NULL },
+		{ NULL, 0, 0, 0, NULL, NULL, NULL }
+	};
+	
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 	textdomain(GETTEXT_PACKAGE);
 
 	gtk_init(&argc, &argv);
 
+	ctx = g_option_context_new("");
+	g_option_context_add_main_entries(ctx, entries, NULL);
+	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
+		g_printerr(_("parsing failed: %s\n"), error->message);
+		g_error_free(error);
+		g_option_context_free(ctx);
+		exit(EXIT_FAILURE);
+	}
+	
 	client = bluetooth_client_new();
 
-	create_wizard();
+	window = create_wizard();
+    
+	app = bluetooth_instance_new();
+	bluetooth_instance_set_window(app, GTK_WINDOW(window));
+	if(!bluetooth_instance_register(app, singleton, 
+		"/org/bluez/wizard", "org.bluez.wizard"))
+		exit(EXIT_FAILURE);
 
 	gtk_main();
 
 	g_object_unref(client);
 
+	g_object_unref(app);
+
+	g_option_context_free(ctx);
+	
 	return 0;
 }

[-- Attachment #3: Type: text/plain, Size: 308 bytes --]

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

[-- Attachment #4: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-17 19:29               ` Chris Rivera
@ 2007-12-17 20:17                 ` Marcel Holtmann
  2007-12-17 20:47                   ` Chris Rivera
  0 siblings, 1 reply; 19+ messages in thread
From: Marcel Holtmann @ 2007-12-17 20:17 UTC (permalink / raw)
  To: BlueZ development

Hi Chris,

> I wanted to distinguish between an instance already running and actual
> DBUS errors.  If an instance is already running then we can exit with
> 0 since the intended action was successful (the launched application
> is now in the foreground).  If, however, there are errors connecting
> to the bus then we exit with 1.  It isn't a big deal though.  I've
> attached an updated apps patch that gets rid of the retval parameter. 

I think that is simply too complicated. If we use --singleton, it all
has to come into place. And if D-Bus fails, the application is not good
anyway. So I don't see the real benefit. If at any time later it will be
needed, we can introduce it then.

Please use use gtk_init_with_args and make the GOptionEntry data global
and static. Look at bluetooth-analyzer for an example.

Also don't translate config options and errors that are printed on the
command line. We only translate stuff inside the UI. The normal user
won't see these anyway.

Regards

Marcel



-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-17 20:17                 ` Marcel Holtmann
@ 2007-12-17 20:47                   ` Chris Rivera
  2007-12-17 21:01                     ` Marcel Holtmann
  0 siblings, 1 reply; 19+ messages in thread
From: Chris Rivera @ 2007-12-17 20:47 UTC (permalink / raw)
  To: BlueZ development


[-- Attachment #1.1: Type: text/plain, Size: 811 bytes --]

On Dec 17, 2007 3:17 PM, Marcel Holtmann <marcel@holtmann.org> wrote:

>
> I think that is simply too complicated. If we use --singleton, it all
> has to come into place. And if D-Bus fails, the application is not good
> anyway. So I don't see the real benefit. If at any time later it will be
> needed, we can introduce it then.
>

Agreed.


>
> Please use use gtk_init_with_args and make the GOptionEntry data global
> and static. Look at bluetooth-analyzer for an example.
>

This would force the singleton flag variable to be global.  Is this what you
want?


>
> Also don't translate config options and errors that are printed on the
> command line. We only translate stuff inside the UI. The normal user
> won't see these anyway.
> <https://lists.sourceforge.net/lists/listinfo/bluez-devel>
>

OK.

Chris

[-- Attachment #1.2: Type: text/html, Size: 1503 bytes --]

[-- Attachment #2: Type: text/plain, Size: 308 bytes --]

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

[-- Attachment #3: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-17 20:47                   ` Chris Rivera
@ 2007-12-17 21:01                     ` Marcel Holtmann
  2007-12-18 18:37                       ` Chris Rivera
  0 siblings, 1 reply; 19+ messages in thread
From: Marcel Holtmann @ 2007-12-17 21:01 UTC (permalink / raw)
  To: BlueZ development

Hi Chris,

>         Please use use gtk_init_with_args and make the GOptionEntry
>         data global 
>         and static. Look at bluetooth-analyzer for an example.
> 
> This would force the singleton flag variable to be global.  Is this
> what you want?

what is the difference? It is fine to have it global. I don't see any
problem with it. I don't wanna introduce any complexity if it is not
needed.

Regards

Marcel



-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-17 21:01                     ` Marcel Holtmann
@ 2007-12-18 18:37                       ` Chris Rivera
  2007-12-18 19:10                         ` Marcel Holtmann
  0 siblings, 1 reply; 19+ messages in thread
From: Chris Rivera @ 2007-12-18 18:37 UTC (permalink / raw)
  To: BlueZ development


[-- Attachment #1.1: Type: text/plain, Size: 1056 bytes --]

Updated patch attached.

Chris

On Dec 17, 2007 4:01 PM, Marcel Holtmann <marcel@holtmann.org> wrote:

> Hi Chris,
>
> >         Please use use gtk_init_with_args and make the GOptionEntry
> >         data global
> >         and static. Look at bluetooth-analyzer for an example.
> >
> > This would force the singleton flag variable to be global.  Is this
> > what you want?
>
> what is the difference? It is fine to have it global. I don't see any
> problem with it. I don't wanna introduce any complexity if it is not
> needed.
>
> Regards
>
> Marcel
>
>
>
> -------------------------------------------------------------------------
> SF.Net email is sponsored by:
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services
> for just about anything Open Source.
>
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>

[-- Attachment #1.2: Type: text/html, Size: 1751 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bluez-gnome-singleton-apps.patch --]
[-- Type: text/x-patch; name=bluez-gnome-singleton-apps.patch, Size: 9127 bytes --]

diff -urpN gnome/applet/bluetooth-applet.1 gnome-new/applet/bluetooth-applet.1
--- gnome/applet/bluetooth-applet.1	2007-07-22 11:33:13.000000000 -0400
+++ gnome-new/applet/bluetooth-applet.1	2007-12-16 18:31:09.000000000 -0500
@@ -10,8 +10,9 @@ whenever a passkey (aka PIN) is required
 .I bluetooth-applet
 is part of bluez-gnome, see also http://www.bluez.org
 .SH OPTIONS
-.I bluetooth-applet
-takes no options
+.TP 
+.BI \-\-singleton
+Ensure that only one instance is running.
 .SH AUTHOR
 Marcel Holtmann <marcel@holtmann.org>
 .SH LICENSE
diff -urpN gnome/applet/bluetooth-applet.desktop.in gnome-new/applet/bluetooth-applet.desktop.in
--- gnome/applet/bluetooth-applet.desktop.in	2007-04-03 04:09:01.000000000 -0400
+++ gnome-new/applet/bluetooth-applet.desktop.in	2007-12-16 18:31:09.000000000 -0500
@@ -3,7 +3,7 @@ Encoding=UTF-8
 _Name=Bluetooth Manager
 _Comment=Bluetooth Manager applet
 Icon=stock_bluetooth
-Exec=bluetooth-applet
+Exec=bluetooth-applet --singleton
 Terminal=false
 Type=Application
 Categories=
diff -urpN gnome/applet/main.c gnome-new/applet/main.c
--- gnome/applet/main.c	2007-12-04 10:30:51.000000000 -0500
+++ gnome-new/applet/main.c	2007-12-17 19:16:29.000000000 -0500
@@ -49,6 +49,7 @@
 #endif
 
 #include "bluetooth-device-selection.h"
+#include "bluetooth-instance.h"
 
 #define PASSKEY_AGENT_PATH	"/org/bluez/passkey"
 #define AUTH_AGENT_PATH		"/org/bluez/auth"
@@ -1550,7 +1551,7 @@ static void about_callback(GtkWidget *it
 
 static void settings_callback(GObject *widget, gpointer user_data)
 {
-	const char *command = "bluetooth-properties";
+	const char *command = "bluetooth-properties --singleton";
 
 	if (!g_spawn_command_line_async(command, NULL))
 		g_printerr("Couldn't execute command: %s\n", command);
@@ -1639,7 +1640,7 @@ static void sendto_callback(GObject *wid
 #if 0
 static void wizard_callback(GObject *widget, gpointer user_data)
 {
-	const char *command = "bluetooth-wizard";
+	const char *command = "bluetooth-wizard --singleton";
 
 	if (!g_spawn_command_line_async(command, NULL))
 		g_printerr("Couldn't execute command: %s\n", command);
@@ -1780,17 +1781,34 @@ static void gconf_callback(GConfClient *
 		auto_authorize = gconf_value_get_bool(value);
 }
 
+static gboolean singleton = FALSE;
+static GOptionEntry options[] = {
+	{ "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+	  "Only allow one instance of this application", NULL },
+	{ NULL, 0, 0, 0, NULL, NULL, NULL }
+};
+
 int main(int argc, char *argv[])
 {
 	GtkWidget *menu;
 	GError *error = NULL;
+	BluetoothInstance *app;
 	char *str;
 
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 	textdomain(GETTEXT_PACKAGE);
 
-	gtk_init(&argc, &argv);
+	if (gtk_init_with_args(&argc, &argv, "",
+				options, GETTEXT_PACKAGE, &error) == FALSE) {
+		if (error) {
+			g_print("%s\n", error->message);
+			g_error_free(error);
+		} else
+			g_print("An unknown error occurred\n");
+
+		gtk_exit(1);
+	}
 
 #ifdef HAVE_LIBNOTIFY
 	notify_init("bluetooth-manager");
@@ -1804,6 +1822,11 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	}
 
+	app = bluetooth_instance_new();
+	if(!bluetooth_instance_register(app, singleton, 
+		"/org/bluez/applet", "org.bluez.applet"))
+		exit(EXIT_FAILURE);
+
 	gconf = gconf_client_get_default();
 
 #ifdef HAVE_HAL
@@ -1860,6 +1883,8 @@ int main(int argc, char *argv[])
 	g_list_foreach(adapter_list, adapter_free, NULL);
 
 	dbus_g_connection_unref(conn);
+    
+	g_object_unref(app);
 
 	return 0;
 }
diff -urpN gnome/properties/bluetooth-properties.1 gnome-new/properties/bluetooth-properties.1
--- gnome/properties/bluetooth-properties.1	2007-07-22 11:33:13.000000000 -0400
+++ gnome-new/properties/bluetooth-properties.1	2007-12-16 18:31:09.000000000 -0500
@@ -9,8 +9,9 @@ will display a dialog for changing Bluet
 .I bluetooth-properties
 is part of bluez-gnome, see also http://www.bluez.org
 .SH OPTIONS
-.I bluetooth-properties
-takes no options
+.TP 
+.BI \-\-singleton
+Ensure that only one instance is running.
 .SH AUTHOR
 Marcel Holtmann <marcel@holtmann.org>
 .SH LICENSE
diff -urpN gnome/properties/main.c gnome-new/properties/main.c
--- gnome/properties/main.c	2007-07-31 17:37:29.000000000 -0400
+++ gnome-new/properties/main.c	2007-12-17 19:20:43.000000000 -0500
@@ -40,6 +40,7 @@
 #include "general.h"
 #include "service.h"
 #include "adapter.h"
+#include "bluetooth-instance.h"
 
 static void delete_callback(GtkWidget *window, GdkEvent *event,
 						gpointer user_data)
@@ -58,7 +59,7 @@ static void close_callback(GtkWidget *bu
 	gtk_main_quit();
 }
 
-static void create_window(GtkWidget *notebook)
+static GtkWidget *create_window(GtkWidget *notebook)
 {
 	GtkWidget *window;
 	GtkWidget *widget;
@@ -108,6 +109,7 @@ static void create_window(GtkWidget *not
 						widget, _("General"));
 
 	gtk_widget_show_all(window);
+	return window;
 }
 
 static void name_owner_changed(DBusGProxy *object, const char *name,
@@ -139,18 +141,36 @@ static DBusGProxy *setup_manager(DBusGCo
 	return proxy;
 }
 
+static gboolean singleton = FALSE;
+static GOptionEntry options[] = {
+	{ "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+	  "Only allow one instance of this application", NULL },
+	{ NULL, 0, 0, 0, NULL, NULL, NULL }
+};
+
 int main(int argc, char *argv[])
 {
 	GtkWidget *notebook;
+	GtkWidget *window;
+	GError *error = NULL;
 	DBusGConnection *conn;
+	BluetoothInstance *app;
 	DBusGProxy *manager;
-	GError *error = NULL;
-
+	
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 	textdomain(GETTEXT_PACKAGE);
 
-	gtk_init(&argc, &argv);
+	if (gtk_init_with_args(&argc, &argv, "",
+				options, GETTEXT_PACKAGE, &error) == FALSE) {
+		if (error) {
+			g_print("%s\n", error->message);
+			g_error_free(error);
+		} else
+			g_print("An unknown error occurred\n");
+
+		gtk_exit(1);
+	}
 
 	conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
 	if (error != NULL) {
@@ -163,12 +183,18 @@ int main(int argc, char *argv[])
 	setup_general();
 
 	notebook = gtk_notebook_new();
-
+    
 	assign_adapter(notebook);
 
-	manager = setup_manager(conn);
+	window = create_window(notebook);
 
-	create_window(notebook);
+	app = bluetooth_instance_new();
+	bluetooth_instance_set_window(app, GTK_WINDOW(window));
+	if(!bluetooth_instance_register(app, singleton, 
+		"/org/bluez/properties", "org.bluez.properties"))
+		exit(EXIT_FAILURE);
+	
+	manager = setup_manager(conn);
 
 	gtk_main();
 
@@ -181,6 +207,8 @@ int main(int argc, char *argv[])
 	g_object_unref(manager);
 
 	dbus_g_connection_unref(conn);
+    
+	g_object_unref(app);
 
 	return 0;
 }
diff -urpN gnome/wizard/bluetooth-wizard.1 gnome-new/wizard/bluetooth-wizard.1
--- gnome/wizard/bluetooth-wizard.1	2007-07-22 11:33:12.000000000 -0400
+++ gnome-new/wizard/bluetooth-wizard.1	2007-12-16 18:31:09.000000000 -0500
@@ -9,8 +9,9 @@ will display a wizard for setting up Blu
 .I bluetooth-wizard
 is part of bluez-gnome, see also http://www.bluez.org
 .SH OPTIONS
-.I bluetooth-wizard
-takes no options
+.TP 
+.BI \-\-singleton
+Ensure that only one instance is running.
 .SH AUTHOR
 Marcel Holtmann <marcel@holtmann.org>
 .SH LICENSE
diff -urpN gnome/wizard/main.c gnome-new/wizard/main.c
--- gnome/wizard/main.c	2007-08-15 03:04:03.000000000 -0400
+++ gnome-new/wizard/main.c	2007-12-17 19:21:13.000000000 -0500
@@ -26,6 +26,7 @@
 #endif
 
 #include <string.h>
+#include <stdlib.h>
 
 #include <dbus/dbus-glib.h>
 
@@ -38,6 +39,7 @@
 #include "dbus-glue.h"
 
 #include "bluetooth-device-selection.h"
+#include "bluetooth-instance.h"
 
 static BluetoothClient *client;
 
@@ -387,7 +389,7 @@ static void create_summary(GtkWidget *as
 	page_summary = vbox;
 }
 
-static void create_wizard(void)
+static GtkWidget *create_wizard(void)
 {
 	GtkWidget *assistant;
 
@@ -430,23 +432,52 @@ static void create_wizard(void)
 	gtk_widget_show_all(assistant);
 
 	gtk_assistant_update_buttons_state(GTK_ASSISTANT(assistant));
+	return assistant;
 }
 
+static gboolean singleton = FALSE;
+static GOptionEntry options[] = {
+	{ "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+	  "Only allow one instance of this application", NULL },
+	{ NULL, 0, 0, 0, NULL, NULL, NULL }
+};
+
 int main(int argc, char *argv[])
 {
+	GtkWidget *window;
+	BluetoothInstance *app;
+	GError *error = NULL;
+	
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 	textdomain(GETTEXT_PACKAGE);
 
-	gtk_init(&argc, &argv);
+	if (gtk_init_with_args(&argc, &argv, "",
+				options, GETTEXT_PACKAGE, &error) == FALSE) {
+		if (error) {
+			g_print("%s\n", error->message);
+			g_error_free(error);
+		} else
+			g_print("An unknown error occurred\n");
 
+		gtk_exit(1);
+	}
+	
 	client = bluetooth_client_new();
 
-	create_wizard();
+	window = create_wizard();
+    
+	app = bluetooth_instance_new();
+	bluetooth_instance_set_window(app, GTK_WINDOW(window));
+	if(!bluetooth_instance_register(app, singleton, 
+		"/org/bluez/wizard", "org.bluez.wizard"))
+		exit(EXIT_FAILURE);
 
 	gtk_main();
 
 	g_object_unref(client);
 
+	g_object_unref(app);
+
 	return 0;
 }

[-- Attachment #3: Type: text/plain, Size: 308 bytes --]

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

[-- Attachment #4: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-18 18:37                       ` Chris Rivera
@ 2007-12-18 19:10                         ` Marcel Holtmann
  2007-12-18 19:51                           ` Chris Rivera
  0 siblings, 1 reply; 19+ messages in thread
From: Marcel Holtmann @ 2007-12-18 19:10 UTC (permalink / raw)
  To: BlueZ development

Hi Chris,

> Updated patch attached.

patch looks good to me. One question though, why do we use the extra
register function. Can't we include that in the _new function. This
would make the code a little simpler. We still have to check if the
object creation succeeded.

Regards

Marcel



-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-18 19:10                         ` Marcel Holtmann
@ 2007-12-18 19:51                           ` Chris Rivera
  2007-12-18 19:58                             ` Marcel Holtmann
  0 siblings, 1 reply; 19+ messages in thread
From: Chris Rivera @ 2007-12-18 19:51 UTC (permalink / raw)
  To: BlueZ development


[-- Attachment #1.1: Type: text/plain, Size: 690 bytes --]

On Dec 18, 2007 2:10 PM, Marcel Holtmann <marcel@holtmann.org> wrote:

> Hi Chris,
>
> > Updated patch attached.
>
> patch looks good to me. One question though, why do we use the extra
> register function. Can't we include that in the _new function. This
> would make the code a little simpler. We still have to check if the
> object creation succeeded.
>
>
This would require defining GObject properties and get and set operations.
Also, the register function is what actually initiates the connection to the
bus and requests the bus name.  This sort of operation might fail and
shouldn't be done in an object constructor.  The register function seemed
like the simplest solution.

Chris

[-- Attachment #1.2: Type: text/html, Size: 977 bytes --]

[-- Attachment #2: Type: text/plain, Size: 308 bytes --]

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

[-- Attachment #3: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-18 19:51                           ` Chris Rivera
@ 2007-12-18 19:58                             ` Marcel Holtmann
  2007-12-18 20:52                               ` Bastien Nocera
  0 siblings, 1 reply; 19+ messages in thread
From: Marcel Holtmann @ 2007-12-18 19:58 UTC (permalink / raw)
  To: BlueZ development

Hi Chris,

>         patch looks good to me. One question though, why do we use the
>         extra
>         register function. Can't we include that in the _new function.
>         This
>         would make the code a little simpler. We still have to check
>         if the 
>         object creation succeeded.
>
> This would require defining GObject properties and get and set
> operations.  Also, the register function is what actually initiates
> the connection to the bus and requests the bus name.  This sort of
> operation might fail and shouldn't be done in an object constructor.
> The register function seemed like the simplest solution. 

I did it the way I think it should be done to make it a lot simpler. It
works, but I am not sure if it is the best way. Feel free to improve it.
The stuff is in the CVS now.

Regards

Marcel



-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-18 19:58                             ` Marcel Holtmann
@ 2007-12-18 20:52                               ` Bastien Nocera
  2007-12-18 21:00                                 ` Marcel Holtmann
  0 siblings, 1 reply; 19+ messages in thread
From: Bastien Nocera @ 2007-12-18 20:52 UTC (permalink / raw)
  To: BlueZ development


On Tue, 2007-12-18 at 20:58 +0100, Marcel Holtmann wrote:
> Hi Chris,
> 
> >         patch looks good to me. One question though, why do we use the
> >         extra
> >         register function. Can't we include that in the _new function.
> >         This
> >         would make the code a little simpler. We still have to check
> >         if the 
> >         object creation succeeded.
> >
> > This would require defining GObject properties and get and set
> > operations.  Also, the register function is what actually initiates
> > the connection to the bus and requests the bus name.  This sort of
> > operation might fail and shouldn't be done in an object constructor.
> > The register function seemed like the simplest solution. 
> 
> I did it the way I think it should be done to make it a lot simpler. It
> works, but I am not sure if it is the best way. Feel free to improve it.
> The stuff is in the CVS now.

Chris is right, object creation should never fail.


-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons
  2007-12-18 20:52                               ` Bastien Nocera
@ 2007-12-18 21:00                                 ` Marcel Holtmann
  0 siblings, 0 replies; 19+ messages in thread
From: Marcel Holtmann @ 2007-12-18 21:00 UTC (permalink / raw)
  To: BlueZ development

Hi Bastien,

> > > This would require defining GObject properties and get and set
> > > operations.  Also, the register function is what actually initiates
> > > the connection to the bus and requests the bus name.  This sort of
> > > operation might fail and shouldn't be done in an object constructor.
> > > The register function seemed like the simplest solution. 
> > 
> > I did it the way I think it should be done to make it a lot simpler. It
> > works, but I am not sure if it is the best way. Feel free to improve it.
> > The stuff is in the CVS now.
> 
> Chris is right, object creation should never fail.

then we should not use an object for the singleton support. The overhead
for an application to get it right is too much. The singleton support
should be as less intrusive as possible.

So maybe something like bluetooth_instance_init(...) and a corresponding
bluetooth_instance_cleanup() would be better.

This is purely from the application standpoint. If it internally uses an
BluetoothInstance object, I don't really care.

Regards

Marcel



-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2007-12-18 21:00 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-03 15:33 [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons Chris Rivera
2007-12-03 16:25 ` Marcel Holtmann
2007-12-03 16:50   ` Chris Rivera
2007-12-03 16:59     ` Marcel Holtmann
2007-12-06 17:59       ` Chris Rivera
2007-12-17  3:08         ` Chris Rivera
2007-12-17  5:47         ` Marcel Holtmann
2007-12-17 15:54           ` Chris Rivera
2007-12-17 18:53             ` Marcel Holtmann
2007-12-17 19:29               ` Chris Rivera
2007-12-17 20:17                 ` Marcel Holtmann
2007-12-17 20:47                   ` Chris Rivera
2007-12-17 21:01                     ` Marcel Holtmann
2007-12-18 18:37                       ` Chris Rivera
2007-12-18 19:10                         ` Marcel Holtmann
2007-12-18 19:51                           ` Chris Rivera
2007-12-18 19:58                             ` Marcel Holtmann
2007-12-18 20:52                               ` Bastien Nocera
2007-12-18 21:00                                 ` Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox