From: "Chris Rivera" <chrismrivera@gmail.com>
To: "BlueZ development" <bluez-devel@lists.sourceforge.net>
Subject: Re: [Bluez-devel] [PATCH] make bluez GNOME UIs singletons
Date: Wed, 24 Oct 2007 15:54:49 -0400 [thread overview]
Message-ID: <5f84803c0710241254g413df936h3dc073ed8630354c@mail.gmail.com> (raw)
In-Reply-To: <1192633908.10179.2.camel@snoogens.fab.redhat.com>
[-- Attachment #1.1: Type: text/plain, Size: 522 bytes --]
Here's an updated patch that will ignore the singleton behavior if the
BLUEZ_IGNORE_SINGLETON environment variable is set. Marcel, is this
acceptable?
Chris
On 10/17/07, Bastien Nocera <hadess@hadess.net> wrote:
>
>
> Both of you are right. Developers should be able to launch another
> applet or prefs for testing, but users should only ever see one applet
> and prefs dialogue.
>
> Maybe a command-line flag or envvar to disable the singleton behaviour
> in Chris' patch would be acceptable for Marcel?
>
> Cheers
>
[-- Attachment #1.2: Type: text/html, Size: 830 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: 10244 bytes --]
Index: applet/main.c
===================================================================
RCS file: /cvsroot/bluez/gnome/applet/main.c,v
retrieving revision 1.87
diff -u -r1.87 main.c
--- applet/main.c 29 Aug 2007 20:42:18 -0000 1.87
+++ applet/main.c 24 Oct 2007 19:47:25 -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
@@ -1783,11 +1779,62 @@
auto_authorize = gconf_value_get_bool(value);
}
+static DBusGConnection *check_for_instance (int *retval)
+{
+ 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 (!g_getenv("BLUEZ_IGNORE_SINGLETON")) {
+ g_print("Another instance is already running.\n");
+ dbus_g_connection_unref(sc);
+ return NULL;
+ }
+ }
+
+ return sc;
+}
+
int main(int argc, char *argv[])
{
GtkWidget *menu;
GError *error = NULL;
char *str;
+ DBusGConnection *session_conn = NULL;
+ int retval = 0;
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
@@ -1806,6 +1853,10 @@
g_error_free(error);
exit(EXIT_FAILURE);
}
+
+ session_conn = check_for_instance(&retval);
+ if (!session_conn)
+ exit(retval);
gconf = gconf_client_get_default();
@@ -1863,6 +1914,7 @@
g_list_foreach(adapter_list, adapter_free, NULL);
dbus_g_connection_unref(conn);
+ dbus_g_connection_unref(session_conn);
return 0;
}
Index: properties/main.c
===================================================================
RCS file: /cvsroot/bluez/gnome/properties/main.c,v
retrieving revision 1.48
diff -u -r1.48 main.c
--- properties/main.c 31 Jul 2007 21:37:29 -0000 1.48
+++ properties/main.c 24 Oct 2007 19:47:25 -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 @@
gtk_main_quit();
}
-static void create_window(GtkWidget *notebook)
+static GtkWidget *create_window(GtkWidget *notebook)
{
GtkWidget *window;
GtkWidget *widget;
@@ -108,6 +112,7 @@
widget, _("General"));
gtk_widget_show_all(window);
+ return window;
}
static void name_owner_changed(DBusGProxy *object, const char *name,
@@ -139,12 +144,82 @@
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 *check_for_instance (int *retval)
+{
+ 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 &&
+ !g_getenv("BLUEZ_IGNORE_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[])
{
GtkWidget *notebook;
- DBusGConnection *conn;
- DBusGProxy *manager;
+ GtkWidget *window;
GError *error = NULL;
+ DBusGConnection *conn, *session_conn = NULL;
+ DBusGProxy *manager;
+ DBusObjectPathVTable vtable;
+ int retval = 0;
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
@@ -160,15 +235,24 @@
exit(EXIT_FAILURE);
}
+ session_conn = check_for_instance(&retval);
+ 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 +265,7 @@
g_object_unref(manager);
dbus_g_connection_unref(conn);
+ dbus_g_connection_unref(session_conn);
return 0;
}
Index: wizard/main.c
===================================================================
RCS file: /cvsroot/bluez/gnome/wizard/main.c,v
retrieving revision 1.23
diff -u -r1.23 main.c
--- wizard/main.c 15 Aug 2007 07:04:03 -0000 1.23
+++ wizard/main.c 24 Oct 2007 19:47:25 -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 @@
page_summary = vbox;
}
-static void create_wizard(void)
+static GtkWidget *create_wizard(void)
{
GtkWidget *assistant;
@@ -430,23 +435,107 @@
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 *check_for_instance (int *retval)
+{
+ 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 &&
+ !g_getenv("BLUEZ_IGNORE_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[])
{
+ GtkWidget *window;
+ DBusGConnection *session_conn = NULL;
+ DBusObjectPathVTable vtable;
+ int retval = 0;
+
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
gtk_init(&argc, &argv);
+ session_conn = check_for_instance(&retval);
+ 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);
+
return 0;
}
[-- Attachment #3: Type: text/plain, Size: 314 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
[-- 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
prev parent reply other threads:[~2007-10-24 19:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-16 18:38 [Bluez-devel] [PATCH] make bluez GNOME UIs singletons Chris Rivera
2007-10-17 14:24 ` Marcel Holtmann
2007-10-17 14:48 ` Chris Rivera
2007-10-17 15:11 ` Bastien Nocera
2007-10-18 10:15 ` Fabien Chevalier
2007-10-31 16:14 ` Marcel Holtmann
2007-10-31 16:24 ` Bastien Nocera
2007-10-31 16:36 ` Marcel Holtmann
2007-11-13 16:24 ` Chris Rivera
2007-11-13 16:30 ` Bastien Nocera
2007-11-13 17:06 ` Chris Rivera
2007-11-27 15:45 ` Chris Rivera
2007-10-24 19:54 ` Chris Rivera [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5f84803c0710241254g413df936h3dc073ed8630354c@mail.gmail.com \
--to=chrismrivera@gmail.com \
--cc=bluez-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox