[glib/wip/gapplication] Don't use temporary connection objects
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/gapplication] Don't use temporary connection objects
- Date: Mon, 7 Jun 2010 11:57:32 +0000 (UTC)
commit 87cb4578a4252b92b986ed8a7d90079b9d0932c8
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jun 7 07:55:28 2010 -0400
Don't use temporary connection objects
That can lead to unexpected behaviour since we don't really know
if it is safe to unref the connection object.
gio/gapplication.c | 28 +++++++++++++++--------
gio/gdbusapplication.c | 56 +++++++++++++++-------------------------------
gio/gnullapplication.c | 8 +++---
gio/tests/application.c | 2 +-
gio/tests/testapps.c | 1 -
5 files changed, 41 insertions(+), 54 deletions(-)
---
diff --git a/gio/gapplication.c b/gio/gapplication.c
index 8c3ca77..d974ed9 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -23,12 +23,21 @@
#include "config.h"
+#include <string.h>
+#include <stdlib.h>
+
#include <gobject/gvaluecollector.h>
#include "gapplication.h"
#include "gio-marshal.h"
#include "glibintl.h"
+#include "gioerror.h"
+
+#include "gdbusconnection.h"
+#include "gdbusintrospection.h"
+#include "gdbusmethodinvocation.h"
+
#include "gioalias.h"
/**
@@ -185,14 +194,14 @@ static GApplication *primary_application = NULL;
static GHashTable *instances_for_appid = NULL;
static void _g_application_platform_init (GApplication *app);
-static gboolean _g_application_platform_acquire_single_instance (const char *appid,
+static gboolean _g_application_platform_acquire_single_instance (GApplication *app,
GError **error);
static void _g_application_platform_remote_invoke_action (GApplication *app,
const char *action,
guint timestamp);
static void _g_application_platform_remote_quit (GApplication *app,
guint timestamp);
-static void _g_application_platform_activate (const char *appid,
+static void _g_application_platform_activate (GApplication *app,
GVariant *data) G_GNUC_NORETURN;
static void _g_application_platform_on_actions_changed (GApplication *app);
@@ -264,10 +273,10 @@ g_application_default_run (GApplication *application)
}
static void
-_g_application_handle_activation (const char *appid,
- int argc,
- char **argv,
- GVariant *platform_data)
+_g_application_handle_activation (GApplication *app,
+ int argc,
+ char **argv,
+ GVariant *platform_data)
{
GVariantBuilder builder;
GVariant *message;
@@ -300,7 +309,7 @@ _g_application_handle_activation (const char *appid,
}
message = g_variant_builder_end (&builder);
- _g_application_platform_activate (appid, message);
+ _g_application_platform_activate (app, message);
g_variant_unref (message);
}
@@ -395,11 +404,10 @@ g_application_register_with_data (GApplication *application,
g_return_if_fail (platform_data == NULL
|| strcmp (g_variant_get_type_string (platform_data), "a{sv}") == 0);
- if (!_g_application_platform_acquire_single_instance (application->priv->appid, NULL))
+ if (!_g_application_platform_acquire_single_instance (application, NULL))
{
if (application->priv->default_quit)
- _g_application_handle_activation (application->priv->appid,
- argc, argv, platform_data);
+ _g_application_handle_activation (application, argc, argv, platform_data);
else
return;
}
diff --git a/gio/gdbusapplication.c b/gio/gdbusapplication.c
index 338ef65..0eae10f 100644
--- a/gio/gdbusapplication.c
+++ b/gio/gdbusapplication.c
@@ -20,15 +20,6 @@
* Authors: Colin Walters <walters verbum org>
*/
-#include <string.h>
-#include <stdlib.h>
-
-#include "gioerror.h"
-
-#include "gdbusconnection.h"
-#include "gdbusintrospection.h"
-#include "gdbusmethodinvocation.h"
-
#define G_APPLICATION_IFACE "org.gtk.Application"
static void
@@ -320,23 +311,22 @@ _g_application_platform_init (GApplication *app)
}
static gboolean
-_g_application_platform_acquire_single_instance (const char *appid,
- GError **error)
+_g_application_platform_acquire_single_instance (GApplication *app,
+ GError **error)
{
- GDBusConnection *connection;
GVariant *request_result;
guint32 request_status;
- connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
- if (connection == NULL)
+ ensure_bus (app);
+ if (app->priv->session_bus == NULL)
return FALSE;
- request_result = g_dbus_connection_call_sync (connection,
+ request_result = g_dbus_connection_call_sync (app->priv->session_bus,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
"RequestName",
- g_variant_new ("(su)", appid, 0x4),
+ g_variant_new ("(su)", app->priv->appid, 0x4),
NULL, 0, -1, NULL, error);
if (request_result == NULL)
@@ -352,7 +342,7 @@ _g_application_platform_acquire_single_instance (const char *appid,
if (request_status != 1 && request_status != 4)
{
if (request_status == 3)
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Another process has name \"%s\"", appid);
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Another process has name \"%s\"", app->priv->appid);
else
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unknown error");
@@ -414,29 +404,19 @@ _g_application_platform_remote_quit (GApplication *app,
}
static void
-_g_application_platform_activate (const char *appid,
- GVariant *data)
+_g_application_platform_activate (GApplication *app,
+ GVariant *data)
{
- GVariant *result;
- GDBusConnection *connection;
- char *dbus_path;
-
- connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
- if (connection == NULL)
- goto done;
+ ensure_bus (app);
- dbus_path = application_path_from_appid (appid);
- result = g_dbus_connection_call_sync (connection,
- appid,
- dbus_path,
- G_APPLICATION_IFACE,
- "Activate",
- data,
- NULL, 0, -1, NULL, NULL);
- g_free (dbus_path);
- if (result)
- g_variant_unref (result);
+ if (app->priv->session_bus)
+ g_dbus_connection_call_sync (app->priv->session_bus,
+ app->priv->appid,
+ app->priv->dbus_path,
+ G_APPLICATION_IFACE,
+ "Activate",
+ data,
+ NULL, 0, -1, NULL, NULL);
- done:
exit (0);
}
diff --git a/gio/gnullapplication.c b/gio/gnullapplication.c
index f340b7c..6d255e6 100644
--- a/gio/gnullapplication.c
+++ b/gio/gnullapplication.c
@@ -31,8 +31,8 @@ _g_application_platform_init (GApplication *app)
}
static gboolean
-_g_application_platform_acquire_single_instance (const char *appid,
- GError **error)
+_g_application_platform_acquire_single_instance (GApplication *app,
+ GError **error)
{
return TRUE;
}
@@ -62,8 +62,8 @@ _g_application_platform_default_quit (void)
}
static void
-_g_application_platform_activate (const char *appid,
- GVariant *data)
+_g_application_platform_activate (GApplication *app,
+ GVariant *data)
{
exit (0);
}
diff --git a/gio/tests/application.c b/gio/tests/application.c
index e44dbb0..5dba027 100644
--- a/gio/tests/application.c
+++ b/gio/tests/application.c
@@ -108,7 +108,7 @@ test_basic (void)
{
GApplication *app;
- app = g_application_new_and_register (0, NULL, "org.gtk.TestApplication");
+ app = g_application_new_and_register ("org.gtk.TestApplication", 0, NULL);
g_application_add_action (app, "About", "Print an about message");
g_signal_connect (app, "action::About", G_CALLBACK (on_app_action), NULL);
diff --git a/gio/tests/testapps.c b/gio/tests/testapps.c
index b8e46fb..a265974 100644
--- a/gio/tests/testapps.c
+++ b/gio/tests/testapps.c
@@ -140,7 +140,6 @@ quit_app (gpointer data)
NULL);
if (res)
g_variant_unref (res);
- g_object_unref (connection);
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]