[Xfce4-commits] <terminal:master> Use GDBus for dbus communication.
Nick Schermer
noreply at xfce.org
Thu Dec 20 21:02:01 CET 2012
Updating branch refs/heads/master
to 42f061bd1c62e832d2d0974ca4c4d2e5336e1197 (commit)
from c0d2ad500ea9c1381d8250534a5250896bd56e22 (commit)
commit 42f061bd1c62e832d2d0974ca4c4d2e5336e1197
Author: Nick Schermer <nick at xfce.org>
Date: Thu Dec 20 21:01:29 2012 +0100
Use GDBus for dbus communication.
configure.ac.in | 17 +--
terminal/Makefile.am | 19 +--
terminal/main.c | 37 ++--
terminal/terminal-config.h.in | 4 -
terminal/terminal-dbus.c | 317 ------------------------
terminal/terminal-gdbus.c | 216 ++++++++++++++++
terminal/{terminal-dbus.h => terminal-gdbus.h} | 10 +-
7 files changed, 245 insertions(+), 375 deletions(-)
diff --git a/configure.ac.in b/configure.ac.in
index 74ac2b0..08f1f29 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -66,7 +66,7 @@ AC_PROG_LIBTOOL()
dnl **********************************
dnl *** Check for standard headers ***
dnl **********************************
-AC_CHECK_HEADERS([ctype.h errno.h limits.h pwd.h signal.h time.h])
+AC_CHECK_HEADERS([ctype.h errno.h limits.h pwd.h signal.h time.h unistd.h])
dnl ******************************
dnl *** Check for i18n support ***
@@ -87,21 +87,6 @@ XDT_CHECK_PACKAGE([VTE], [vte], [0.28])
XDT_CHECK_PACKAGE([GIO], [gio-2.0], [2.26.0])
XDT_CHECK_PACKAGE([LIBXFCE4UI], [libxfce4ui-1], [4.10.0])
-dnl **********************************
-dnl *** Optional support for D-BUS ***
-dnl **********************************
-XDT_CHECK_OPTIONAL_PACKAGE([DBUS], [dbus-glib-1], [0.22],
- [dbus], [D-BUS GLib bindings])
-if test x"$DBUS_FOUND" = x"yes"; then
- AC_MSG_CHECKING([whether to use new D-BUS API])
- if $PKG_CONFIG --atleast-version 0.31 dbus-1 >/dev/null 2>&1; then
- AC_DEFINE([DBUS_USE_NEW_API], [1], [Define to use new D-BUS API])
- AC_MSG_RESULT([yes])
- else
- AC_MSG_RESULT([no])
- fi
-fi
-
dnl ***************************************************
dnl *** Check if we need to build the documentation ***
dnl ***************************************************
diff --git a/terminal/Makefile.am b/terminal/Makefile.am
index 2e53093..aa06fe2 100644
--- a/terminal/Makefile.am
+++ b/terminal/Makefile.am
@@ -1,11 +1,10 @@
INCLUDES = \
+ -I$(top_srcdir) \
-DDATADIR=\"$(datadir)\" \
-DHELPDIR=\"$(docdir)\" \
-DEXO_DISABLE_DEPRECATED\
-DG_LOG_DOMAIN=\"Terminal\" \
-DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
- -DSN_API_NOT_YET_FROZEN \
- -I$(top_srcdir) \
$(PLATFORM_CPPFLAGS)
bin_PROGRAMS = \
@@ -17,15 +16,12 @@ Terminal_built_sources = \
terminal-marshal.c \
terminal-marshal.h
-Terminal_dbus_sources = \
- terminal-dbus.c \
- terminal-dbus.h
-
Terminal_headers = \
terminal-accel-map.h \
terminal-app.h \
terminal-dialogs.h \
terminal-encoding-action.h \
+ terminal-gdbus.h \
terminal-image-loader.h \
terminal-options.h \
terminal-preferences.h \
@@ -47,6 +43,7 @@ Terminal_SOURCES = \
terminal-app.c \
terminal-dialogs.c \
terminal-encoding-action.c \
+ terminal-gdbus.c \
terminal-image-loader.c \
terminal-options.c \
terminal-preferences.c \
@@ -59,7 +56,6 @@ Terminal_SOURCES = \
terminal-window.c
Terminal_CFLAGS = \
- $(DBUS_CFLAGS) \
$(EXO_CFLAGS) \
$(GTK_CFLAGS) \
$(GIO_CFLAGS) \
@@ -73,7 +69,6 @@ Terminal_LDFLAGS = \
$(PLATFORM_LDFLAGS)
Terminal_LDADD = \
- $(DBUS_LIBS) \
$(EXO_LIBS) \
$(GTK_LIBS) \
$(GIO_LIBS) \
@@ -88,14 +83,6 @@ install-exec-hook:
$(mkinstalldirs) $(DESTDIR)$(bindir)
-( cd $(DESTDIR)$(bindir) ; test -x terminal || test -x Terminal && ln -sf Terminal terminal )
-if HAVE_DBUS
-Terminal_CFLAGS += \
- -DDBUS_API_SUBJECT_TO_CHANGE
-
-Terminal_SOURCES += \
- $(Terminal_dbus_sources)
-endif
-
##
## Rules to auto-generate built sources
diff --git a/terminal/main.c b/terminal/main.c
index 4e77699..1c86410 100644
--- a/terminal/main.c
+++ b/terminal/main.c
@@ -32,9 +32,7 @@
#include <terminal/terminal-app.h>
#include <terminal/terminal-private.h>
-#ifdef HAVE_DBUS
-#include <terminal/terminal-dbus.h>
-#endif
+#include <terminal/terminal-gdbus.h>
@@ -116,6 +114,7 @@ main (int argc, char **argv)
gint nargc;
gint n;
gchar *name;
+ const gchar *msg;
/* install required signal handlers */
signal (SIGPIPE, SIG_IGN);
@@ -179,19 +178,20 @@ main (int argc, char **argv)
nargv[nargc++] = g_strdup (argv[n]);
nargv[nargc] = NULL;
-#ifdef HAVE_DBUS
+ /* for GDBus */
+ g_type_init ();
+
if (!disable_server)
{
/* try to connect to an existing Terminal service */
- if (terminal_dbus_invoke_launch (nargc, nargv, &error))
+ if (terminal_gdbus_invoke_launch (nargc, nargv, &error))
{
return EXIT_SUCCESS;
}
else
{
- if (error->domain == TERMINAL_ERROR
- && (error->code == TERMINAL_ERROR_USER_MISMATCH
- || error->code == TERMINAL_ERROR_DISPLAY_MISMATCH))
+ if (g_error_matches (error, TERMINAL_ERROR, TERMINAL_ERROR_USER_MISMATCH)
+ || g_error_matches (error, TERMINAL_ERROR, TERMINAL_ERROR_DISPLAY_MISMATCH))
{
/* don't try to establish another service here */
disable_server = TRUE;
@@ -202,17 +202,23 @@ main (int argc, char **argv)
error->message);
#endif
}
- else if (error->domain == TERMINAL_ERROR
- && error->code == TERMINAL_ERROR_OPTIONS)
+ else if (g_error_matches (error, TERMINAL_ERROR, TERMINAL_ERROR_OPTIONS))
{
+ /* skip the GDBus prefix */
+ msg = strchr (error->message, ' ');
+ if (G_LIKELY (msg != NULL))
+ msg++;
+ else
+ msg = error->message;
+
/* options were not parsed succesfully, don't try that again below */
- g_printerr ("%s\n", error->message);
+ g_printerr ("%s: %s\n", g_get_prgname (), msg);
g_error_free (error);
g_strfreev (nargv);
return EXIT_FAILURE;
}
#ifndef NDEBUG
- else
+ else if (error != NULL)
{
g_debug ("D-Bus reply error: %s (%s: %d)", error->message,
g_quark_to_string (error->domain), error->code);
@@ -222,7 +228,6 @@ main (int argc, char **argv)
g_clear_error (&error);
}
}
-#endif /* !HAVE_DBUS */
/* initialize Gtk+ */
gtk_init (&argc, &argv);
@@ -236,21 +241,19 @@ main (int argc, char **argv)
app = g_object_new (TERMINAL_TYPE_APP, NULL);
-#ifdef HAVE_DBUS
if (!disable_server)
{
- if (!terminal_dbus_register_service (app, &error))
+ if (!terminal_gdbus_register_service (app, &error))
{
g_printerr (_("Unable to register terminal service: %s\n"), error->message);
g_clear_error (&error);
}
}
-#endif /* !HAVE_DBUS */
if (!terminal_app_process (app, nargv, nargc, &error))
{
/* parsing one of the arguments failed */
- g_printerr ("%s\n", error->message);
+ g_printerr ("%s: %s\n", g_get_prgname (), error->message);
g_error_free (error);
g_object_unref (G_OBJECT (app));
g_strfreev (nargv);
diff --git a/terminal/terminal-config.h.in b/terminal/terminal-config.h.in
index 28fade4..a12d397 100644
--- a/terminal/terminal-config.h.in
+++ b/terminal/terminal-config.h.in
@@ -28,10 +28,6 @@ G_BEGIN_DECLS
#define TERMINAL_DBUS_METHOD_LAUNCH "Launch"
#define TERMINAL_DBUS_INTERFACE "org.xfce.Terminal at TERMINAL_VERSION_DBUS@"
#define TERMINAL_DBUS_SERVICE "org.xfce.Terminal at TERMINAL_VERSION_DBUS@"
-#define TERMINAL_DBUS_ERROR_USER "org.xfce.Terminal at TERMINAL_VERSION_DBUS@.ErrorUser"
-#define TERMINAL_DBUS_ERROR_DISPLAY "org.xfce.Terminal at TERMINAL_VERSION_DBUS@.ErrorDisplay"
-#define TERMINAL_DBUS_ERROR_GENERAL "org.xfce.Terminal at TERMINAL_VERSION_DBUS@.ErrorGeneral"
-#define TERMINAL_DBUS_ERROR_OPTIONS "org.xfce.Terminal at TERMINAL_VERSION_DBUS@.ErrorOptions"
#define TERMINAL_DBUS_PATH "/org/xfce/Terminal"
G_END_DECLS
diff --git a/terminal/terminal-dbus.c b/terminal/terminal-dbus.c
deleted file mode 100644
index 7bd203e..0000000
--- a/terminal/terminal-dbus.c
+++ /dev/null
@@ -1,317 +0,0 @@
-/*-
- * Copyright (c) 2004-2005 os-cillation e.K.
- *
- * Written by Benedikt Meurer <benny at xfce.org>.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program 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 General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include <gmodule.h>
-
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
-#include <terminal/terminal-config.h>
-#include <terminal/terminal-dbus.h>
-#include <terminal/terminal-private.h>
-
-
-
-/* Yay for D-BUS breakage... */
-#ifndef DBUS_USE_NEW_API
-#define dbus_bus_request_name(c, n, f, e) dbus_bus_acquire_service((c), (n), (f), (e))
-#define dbus_message_set_auto_start(m, v) dbus_message_set_auto_activation ((m), (v))
-#endif
-
-
-
-static DBusHandlerResult
-handle_message (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
-{
- TerminalApp *app = TERMINAL_APP (user_data);
- DBusMessage *reply;
- DBusError derror;
- GError *error = NULL;
- dbus_int64_t user_id;
- gchar **argv;
- gint argc;
- gchar *display_name;
-
- /* The D-BUS interface currently looks like this:
- *
- * The Terminal service offers a method "Launch", with
- * the following parameters:
- *
- * - UserId:int64
- * This is the real user id of the calling process.
- *
- * - DisplayName:string
- * Name of the display the service is running on, this to prevent
- * craching terminals if a display is disconnected.
- *
- * - Arguments:string array
- * The argument array as passed to main(), with some
- * additions.
- *
- * "Launch" returns an empty reply message if everything
- * worked, and an error message if anything failed. The
- * error can be TERMINAL_DBUS_ERROR_USER if the user ids
- * doesn't match, where the caller is expected to spawn
- * a new terminal of its own and do _NOT_ establish a
- * D-BUS service, a TERMINAL_DBUS_ERROR_OPTIONS when
- * parsing the options failed or TERMINAL_DBUS_ERROR_GENERAL,
- * which indicates a general problem.
- */
-
- if (dbus_message_is_method_call (message,
- TERMINAL_DBUS_INTERFACE,
- TERMINAL_DBUS_METHOD_LAUNCH))
- {
- dbus_error_init (&derror);
-
- /* query the list of arguments to this call */
- if (!dbus_message_get_args (message, &derror,
- DBUS_TYPE_INT64, &user_id,
- DBUS_TYPE_STRING, &display_name,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &argv, &argc,
- DBUS_TYPE_INVALID))
- {
- reply = dbus_message_new_error (message,
- TERMINAL_DBUS_ERROR_GENERAL,
- derror.message);
- }
- else if (user_id != getuid ())
- {
- reply = dbus_message_new_error (message,
- TERMINAL_DBUS_ERROR_USER,
- _("User id mismatch"));
- }
- else if (!exo_str_is_equal (display_name, g_getenv ("DISPLAY")))
- {
- reply = dbus_message_new_error (message,
- TERMINAL_DBUS_ERROR_DISPLAY,
- _("Display mismatch"));
- }
- else if (!terminal_app_process (app, argv, argc, &error))
- {
- reply = dbus_message_new_error (message,
- TERMINAL_DBUS_ERROR_OPTIONS,
- error->message);
- g_error_free (error);
- }
- else
- {
- reply = dbus_message_new_method_return (message);
- }
-
- dbus_connection_send (connection, reply, NULL);
- dbus_free_string_array (argv);
- dbus_message_unref (reply);
- }
- else if (dbus_message_is_signal (message,
-#ifdef DBUS_USE_NEW_API
- DBUS_INTERFACE_LOCAL,
-#else
- DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
-#endif
- "Disconnected"))
- {
- g_printerr (_("D-BUS message bus disconnected, exiting...\n"));
- gtk_main_quit ();
- }
- else
- {
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
-
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-
-
-/**
- * terminal_dbus_register_service:
- * @app : A #TerminalApp.
- * @error :
- *
- * Return value:
- **/
-gboolean
-terminal_dbus_register_service (TerminalApp *app,
- GError **error)
-{
- static const struct DBusObjectPathVTable vtable = { NULL, handle_message, NULL, NULL, NULL, NULL };
-
- DBusConnection *connection;
- DBusError derror;
-
- terminal_return_val_if_fail (TERMINAL_IS_APP (app), FALSE);
-
- /* check if the application object is already registered */
- connection = g_object_get_data (G_OBJECT (app), "terminal-dbus-connection");
- if (G_UNLIKELY (connection != NULL))
- return TRUE;
-
- dbus_error_init (&derror);
-
- /* try to connect to the session bus */
- connection = dbus_bus_get (DBUS_BUS_SESSION, &derror);
- if (G_UNLIKELY (connection == NULL))
- {
- dbus_set_g_error (error, &derror);
- dbus_error_free (&derror);
- return FALSE;
- }
-
- /* register DBus connection with GLib main loop */
- dbus_connection_setup_with_g_main (connection, NULL);
- dbus_connection_set_exit_on_disconnect (connection, FALSE);
-
- if (dbus_bus_request_name (connection, TERMINAL_DBUS_SERVICE, 0, &derror) < 0)
- {
- dbus_set_g_error (error, &derror);
- dbus_error_free (&derror);
- return FALSE;
- }
-
- /* register the application object */
- if (!dbus_connection_register_object_path (connection, TERMINAL_DBUS_PATH, &vtable, app))
- {
- g_set_error (error, DBUS_GERROR, DBUS_GERROR_FAILED,
- _("Unable to register object %s"),
- TERMINAL_DBUS_PATH);
- return FALSE;
- }
-
- g_object_set_data_full (G_OBJECT (app), I_("terminal-dbus-connection"),
- connection, (GDestroyNotify) dbus_connection_unref);
-
- return TRUE;
-}
-
-
-
-/**
- * terminal_dbus_invoke_launch:
- * @argc :
- * @argv :
- * @error :
- *
- * Return value:
- **/
-gboolean
-terminal_dbus_invoke_launch (gint argc,
- gchar **argv,
- GError **error)
-{
- DBusConnection *connection;
- dbus_int64_t uid;
- DBusMessage *message;
- DBusMessage *result;
- DBusError derror;
- gint code;
- gboolean retval = TRUE;
- const gchar *display_name;
-
- terminal_return_val_if_fail (argc > 0, FALSE);
- terminal_return_val_if_fail (argv != NULL, FALSE);
-
- dbus_error_init (&derror);
-
- /* try to connect to the session bus */
- connection = dbus_bus_get (DBUS_BUS_SESSION, &derror);
- if (G_UNLIKELY (connection == NULL))
- {
- dbus_set_g_error (error, &derror);
- dbus_error_free (&derror);
- return FALSE;
- }
-
- /* generate the message */
- message = dbus_message_new_method_call (TERMINAL_DBUS_SERVICE,
- TERMINAL_DBUS_PATH,
- TERMINAL_DBUS_INTERFACE,
- TERMINAL_DBUS_METHOD_LAUNCH);
- dbus_message_set_auto_start (message, FALSE);
-
- uid = getuid ();
-
- display_name = g_getenv ("DISPLAY");
- if (G_UNLIKELY (display_name == NULL))
- display_name = "";
-
- dbus_message_append_args (message,
-#ifdef DBUS_USE_NEW_API
- DBUS_TYPE_INT64, &uid,
- DBUS_TYPE_STRING, &display_name,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &argv, argc,
-#else
- DBUS_TYPE_INT64, uid,
- DBUS_TYPE_STRING, display_name,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, argv, argc,
-#endif
- DBUS_TYPE_INVALID);
-
- /* send the message */
- result = dbus_connection_send_with_reply_and_block (connection, message, 2000, &derror);
- dbus_message_unref (message);
-
- /* when we reply with an error, the error is put in the derror
- * and the result is %NULL */
- if (result == NULL)
- {
-set_error:
- if (dbus_error_has_name (&derror, TERMINAL_DBUS_ERROR_USER))
- code = TERMINAL_ERROR_USER_MISMATCH;
- if (dbus_error_has_name (&derror, TERMINAL_DBUS_ERROR_DISPLAY))
- code = TERMINAL_ERROR_DISPLAY_MISMATCH;
- else if (dbus_error_has_name (&derror, TERMINAL_DBUS_ERROR_OPTIONS))
- code = TERMINAL_ERROR_OPTIONS;
- else
- code = TERMINAL_ERROR_FAILED;
-
- g_set_error (error, TERMINAL_ERROR, code, "%s", derror.message);
- dbus_error_free (&derror);
-
- return FALSE;
- }
-
- /* handle other types of errors */
- if (dbus_message_get_type (result) == DBUS_MESSAGE_TYPE_ERROR)
- {
- dbus_set_error_from_message (&derror, result);
- dbus_message_unref (result);
- goto set_error;
- }
-
- dbus_message_unref (result);
-
- return retval;
-}
-
diff --git a/terminal/terminal-gdbus.c b/terminal/terminal-gdbus.c
new file mode 100644
index 0000000..3f8f6e4
--- /dev/null
+++ b/terminal/terminal-gdbus.c
@@ -0,0 +1,216 @@
+/*-
+ * Copyright (c) 2012 Nick Schermer <nick at xfce.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program 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 General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include <gio/gio.h>
+
+#include <terminal/terminal-config.h>
+#include <terminal/terminal-gdbus.h>
+#include <terminal/terminal-private.h>
+
+
+
+static const gchar terminal_gdbus_introspection_xml[] =
+ "<node>"
+ "<interface name='" TERMINAL_DBUS_INTERFACE "'>"
+ "<method name='" TERMINAL_DBUS_METHOD_LAUNCH "'>"
+ "<arg type='x' name='uid' direction='in'/>"
+ "<arg type='s' name='display-name' direction='in'/>"
+ "<arg type='as' name='argv' direction='in'/>"
+ "</method>"
+ "</interface>"
+ "</node>";
+
+
+
+static void
+terminal_gdbus_method_call (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ TerminalApp *app = TERMINAL_APP (user_data);
+ gint64 uid = -1;
+ const gchar *display_name = NULL;
+ gchar **argv = NULL;
+ GError *error = NULL;
+
+ terminal_return_if_fail (TERMINAL_IS_APP (app));
+ terminal_return_if_fail (!g_strcmp0 (object_path, TERMINAL_DBUS_PATH));
+ terminal_return_if_fail (!g_strcmp0 (interface_name, TERMINAL_DBUS_INTERFACE));
+
+ if (g_strcmp0 (method_name, TERMINAL_DBUS_METHOD_LAUNCH) == 0)
+ {
+ /* get paramenters */
+ g_variant_get (parameters, "(xs^as)", &uid, &display_name, &argv);
+
+ if (uid != getuid ())
+ {
+ g_dbus_method_invocation_return_error (invocation,
+ TERMINAL_ERROR, TERMINAL_ERROR_USER_MISMATCH,
+ _("User id mismatch"));
+ }
+ else if (g_strcmp0 (display_name, g_getenv ("DISPLAY")) != 0)
+ {
+ g_dbus_method_invocation_return_error (invocation,
+ TERMINAL_ERROR, TERMINAL_ERROR_DISPLAY_MISMATCH,
+ _("Display mismatch"));
+ }
+ else if (!terminal_app_process (app, argv, g_strv_length (argv), &error))
+ {
+ g_dbus_method_invocation_return_error (invocation,
+ TERMINAL_ERROR, TERMINAL_ERROR_OPTIONS,
+ error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ /* everything went fine */
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ }
+ }
+ else
+ {
+ g_dbus_method_invocation_return_error (invocation,
+ G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD,
+ "Unknown method for DBus service " TERMINAL_DBUS_SERVICE);
+ }
+}
+
+
+
+static const GDBusInterfaceVTable terminal_gdbus_vtable =
+{
+ terminal_gdbus_method_call,
+ NULL, /* get property */
+ NULL /* set property */
+};
+
+
+
+static void
+terminal_gdbus_bus_acquired (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ guint register_id;
+ GDBusNodeInfo *info;
+ GError *error = NULL;
+
+ info = g_dbus_node_info_new_for_xml (terminal_gdbus_introspection_xml, NULL);
+ terminal_assert (info != NULL);
+ terminal_assert (*info->interfaces != NULL);
+
+ register_id = g_dbus_connection_register_object (connection,
+ TERMINAL_DBUS_PATH,
+ *info->interfaces, /* first iface */
+ &terminal_gdbus_vtable,
+ user_data,
+ NULL,
+ &error);
+
+ if (register_id == 0)
+ {
+ g_message ("Failed to register object: %s", error->message);
+ g_error_free (error);
+ }
+
+ g_dbus_node_info_unref (info);
+}
+
+
+
+gboolean
+terminal_gdbus_register_service (TerminalApp *app,
+ GError **error)
+{
+ guint owner_id;
+
+ terminal_return_val_if_fail (TERMINAL_IS_APP (app), FALSE);
+
+ owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
+ TERMINAL_DBUS_SERVICE,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ terminal_gdbus_bus_acquired,
+ NULL,
+ NULL,
+ app,
+ NULL);
+
+ return (owner_id != 0);
+}
+
+
+
+gboolean
+terminal_gdbus_invoke_launch (gint argc,
+ gchar **argv,
+ GError **error)
+{
+ GVariant *reply;
+ GDBusConnection *connection;
+ GError *err = NULL;
+ gboolean result;
+
+ terminal_return_val_if_fail (argc == (gint) g_strv_length (argv), FALSE);
+
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
+ if (G_UNLIKELY (connection == NULL))
+ return FALSE;
+
+ reply = g_dbus_connection_call_sync (connection,
+ TERMINAL_DBUS_SERVICE,
+ TERMINAL_DBUS_PATH,
+ TERMINAL_DBUS_INTERFACE,
+ TERMINAL_DBUS_METHOD_LAUNCH,
+ g_variant_new ("(xs^as)",
+ getuid (),
+ g_getenv ("DISPLAY"),
+ argv),
+ NULL,
+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
+ 2000,
+ NULL,
+ &err);
+
+ g_object_unref (connection);
+
+ result = (reply != NULL);
+ if (G_LIKELY (result))
+ g_variant_unref (reply);
+ else
+ g_propagate_error (error, err);
+
+ return result;
+}
+
diff --git a/terminal/terminal-dbus.h b/terminal/terminal-gdbus.h
similarity index 75%
rename from terminal/terminal-dbus.h
rename to terminal/terminal-gdbus.h
index 6e1fc2f..9a7cdcf 100644
--- a/terminal/terminal-dbus.h
+++ b/terminal/terminal-gdbus.h
@@ -25,11 +25,11 @@
G_BEGIN_DECLS
-gboolean terminal_dbus_register_service (TerminalApp *app,
- GError **error);
-gboolean terminal_dbus_invoke_launch (gint argc,
- gchar **argv,
- GError **error);
+gboolean terminal_gdbus_register_service (TerminalApp *app,
+ GError **error);
+gboolean terminal_gdbus_invoke_launch (gint argc,
+ gchar **argv,
+ GError **error);
G_END_DECLS
More information about the Xfce4-commits
mailing list