[glib/wip/gapplication] Make remote invokation working
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/gapplication] Make remote invokation working
- Date: Sat, 5 Jun 2010 05:57:10 +0000 (UTC)
commit ef9c2773c1bb0d6a07e1ea71f23672f3f7867100
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jun 5 01:54:42 2010 -0400
Make remote invokation working
We need to make sure that session_bus and dbus_path are set
in those cases.
gio/gdbusapplication.c | 80 ++++++++++++++++++++++++++++++-----------------
1 files changed, 51 insertions(+), 29 deletions(-)
---
diff --git a/gio/gdbusapplication.c b/gio/gdbusapplication.c
index dfef635..5fc5eaa 100644
--- a/gio/gdbusapplication.c
+++ b/gio/gdbusapplication.c
@@ -275,30 +275,48 @@ application_path_from_appid (const char *appid)
for (iter = appid_path; *iter; iter++)
{
if (*iter == '.')
- *iter = '/';
+ *iter = '/';
}
return appid_path;
}
static void
+ensure_bus (GApplication *app)
+{
+ GError *error = NULL;
+
+ if (app->priv->session_bus == NULL)
+ app->priv->session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (app->priv->session_bus == NULL)
+ {
+ g_error ("%s", error->message);
+ g_error_free (error);
+ }
+
+ if (app->priv->dbus_path == NULL)
+ app->priv->dbus_path = application_path_from_appid (app->priv->appid);
+}
+
+static void
_g_application_platform_init (GApplication *app)
{
GError *error = NULL;
guint registration_id;
- app->priv->session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
- if (app->priv->session_bus == NULL)
- g_error ("%s", error->message);
-
- app->priv->dbus_path = application_path_from_appid (app->priv->appid);
- registration_id = g_dbus_connection_register_object (app->priv->session_bus, app->priv->dbus_path,
- &application_dbus_interface_info,
- &application_dbus_vtable,
- app, NULL,
- &error);
+ ensure_bus (app);
+
+ registration_id = g_dbus_connection_register_object (app->priv->session_bus,
+ app->priv->dbus_path,
+ &application_dbus_interface_info,
+ &application_dbus_vtable,
+ app, NULL,
+ &error);
if (registration_id == 0)
- g_error ("%s", error->message);
+ {
+ g_error ("%s", error->message);
+ g_error_free (error);
+ }
}
static gboolean
@@ -306,7 +324,6 @@ _g_application_platform_acquire_single_instance (const char *appid,
GError **error)
{
GDBusConnection *connection;
- gboolean ret = FALSE;
GVariant *request_result;
guint32 request_status;
@@ -320,34 +337,36 @@ _g_application_platform_acquire_single_instance (const char *appid,
"org.freedesktop.DBus",
"RequestName",
g_variant_new ("(su)", appid, 0x4),
- NULL, 0, -1, NULL, error);
+ NULL, 0, -1, NULL, error);
+
if (request_result == NULL)
return FALSE;
- if (strcmp (g_variant_get_type_string (request_result), "(u)") != 0)
- return FALSE;
- g_variant_get (request_result, "(u)", &request_status);
- if (request_status == 1 || request_status == 4)
- {
- ret = TRUE;
- }
+ if (strcmp (g_variant_get_type_string (request_result), "(u)") == 0)
+ g_variant_get (request_result, "(u)", &request_status);
else
+ request_status = 0;
+
+ g_variant_unref (request_result);
+
+ if (request_status != 1 && request_status != 4)
{
- char *errmsg = g_strdup ("Unknown error");
if (request_status == 3)
- errmsg = g_strdup_printf ("Another process has name \"%s\"", appid);
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s", errmsg);
- g_free (errmsg);
- }
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Another process has name \"%s\"", appid);
+ else
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unknown error");
+
+ return FALSE;
+ }
- return ret;
+ return TRUE;
}
static void
_g_application_platform_on_actions_changed (GApplication *app)
{
g_dbus_connection_emit_signal (app->priv->session_bus, NULL,
- app->priv->dbus_path,
+ app->priv->dbus_path,
G_APPLICATION_IFACE,
"ActionsChanged", NULL, NULL);
}
@@ -358,6 +377,9 @@ _g_application_platform_remote_invoke_action (GApplication *app,
guint timestamp)
{
GVariant *result;
+
+ ensure_bus (app);
+
result = g_dbus_connection_call_sync (app->priv->session_bus,
app->priv->appid,
app->priv->dbus_path,
@@ -366,7 +388,7 @@ _g_application_platform_remote_invoke_action (GApplication *app,
g_variant_new ("(su)",
action,
timestamp),
- NULL, 0, -1, NULL, NULL);
+ NULL, 0, -1, NULL, NULL);
if (result)
g_variant_unref (result);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]