Mercurial > pidgin
changeset 11055:df0241eb602c
[gaim-migrate @ 12996]
Added preliminary DBUS support to gaim, the details are described in
README.dbus.
committer: Tailor Script <tailor@pidgin.im>
author | Piotr Zielinski <zielaj> |
---|---|
date | Sun, 03 Jul 2005 21:48:56 +0000 |
parents | bc700cc98b82 |
children | 9be8ac00f27f |
files | README.dbus configure.ac src/Makefile.am src/dbus-client.c src/dbus-gaim.h src/dbus-gaim.service src/dbus-server.c src/dbus-server.h src/dbus-service.xml src/gtkmain.c |
diffstat | 10 files changed, 513 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.dbus Sun Jul 03 21:48:56 2005 +0000 @@ -0,0 +1,53 @@ +This file describes how to compile and run gaim with dbus support. +Hopefully, most of the steps from point 3 will soon be automated. + + +1. Make sure you have the latest version (0.34) of the dbus library + installed, including glib bindings. + + http://www.freedesktop.org/Software/dbus + + +2. Compile gaim + + ./configure --enable-dbus + make + make install + + +3. Configure your dbus instalation for gaim + + A. Find your dbus session configuration file, usually + + /etc/dbus-1/session.conf + + B. In that file, find the <servicedir> section. This section + contains the directory that stores files describing services, + usually + + /usr/share/dbus-1/services + + C. Copy src/dbus-gaim.service to that directory + + D. Edit the dbus-gaim.service file you've just copied, and replace + the path in the "Exec=" line with the path to your gaim + executable. + + +4. Start DBUS if you haven't done it already + + eval `dbus-launch --session` + export DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID + + These commands will set the two above shell variables. These + variables must be set before running any dbus-aware programs. + + +Now you can start gaim as usual. A new program, gaim-client can be +used to issue commands to a running gaim process + + gaim-client command1 command2 ... + +At the moment there are only three commands: ping, quit, and connect. +When you execute gaim-client, the dbus system will automatically start +a gaim process if one is not running already.
--- a/configure.ac Sun Jul 03 06:42:16 2005 +0000 +++ b/configure.ac Sun Jul 03 21:48:56 2005 +0000 @@ -306,6 +306,32 @@ fi dnl ####################################################################### +dnl # Check for DBUS libraries +dnl ####################################################################### + +AC_ARG_ENABLE(dbus, [ --enable-dbus enable DBUS support],,enable_dbus=no) + +if test "x$enable_dbus" = "xyes"; then + AC_CHECK_PROG(enable_dbus, dbus-binding-tool, yes, no) +fi + +if test "x$enable_dbus" = "xyes"; then + PKG_CHECK_MODULES(DBUS, [dbus-1 >= 0.34 dbus-glib-1 >= 0.34], + [ + AC_DEFINE(HAVE_DBUS, 1, [Define if we're using DBUS.]) + AC_SUBST(DBUS_CFLAGS) + AC_SUBST(DBUS_LIBS) + echo "Building with DBUS support" + ]) +else + echo "Building without DBUS support" + enable_dbus=no +fi + +AM_CONDITIONAL(ENABLE_DBUS, test "x$enable_dbus" = "xyes") + + +dnl ####################################################################### dnl # Check for startup notification dnl ####################################################################### AC_ARG_ENABLE(startup-notification, [ --disable-startup-notification compile without startup notification support],,enable_startup_notification=yes) @@ -1279,6 +1305,7 @@ echo Build with Audio support...... : $enable_audio echo Build with NAS support........ : $enable_nas echo Build with GtkSpell support... : $enable_gtkspell +echo Build with DBUS support....... : $enable_dbus echo Has you....................... : yes echo echo Use kerberos 4 with zephyr.... : $kerberos
--- a/src/Makefile.am Sun Jul 03 06:42:16 2005 +0000 +++ b/src/Makefile.am Sun Jul 03 21:48:56 2005 +0000 @@ -143,6 +143,28 @@ bin_PROGRAMS = gaim gaim-remote + +if ENABLE_DBUS + +gaim_coresources += dbus-server.c +gaim_coreheaders += dbus-server.h +bin_PROGRAMS += gaim-client + +dbus-client-bindings.c: dbus-service.xml + dbus-binding-tool --prefix=gaim_object --mode=glib-client --output=$@ $< + +dbus-server-bindings.c: dbus-service.xml + dbus-binding-tool --prefix=gaim_object --mode=glib-server --output=$@ $< + +dbus-client.$(OBJEXT): dbus-client-bindings.c +dbus-server.$(OBJEXT): dbus-server-bindings.c + +gaim_client_SOURCES = dbus-client.c +gaim_client_DEPENDENCIES = @LIBOBJS@ +gaim_client_LDADD = @LIBOBJS@ $(GLIB_LIBS) $(DBUS_LIBS) $(INTLLIBS) + +endif + gaim_SOURCES = \ $(gaim_coresources) \ gtkcombobox.c \ @@ -231,6 +253,7 @@ gaim_LDADD = \ @LIBOBJS@ \ $(GTK_LIBS) \ + $(DBUS_LIBS) \ $(SOUND_LIBS) \ $(STATIC_LINK_LIBS) \ $(XSS_LIBS) \ @@ -260,5 +283,6 @@ $(AO_CFLAGS) \ $(DEBUG_CFLAGS) \ $(GTK_CFLAGS) \ + $(DBUS_CFLAGS) \ $(GTKSPELL_CFLAGS) \ $(STARTUP_NOTIFICATION_CFLAGS)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dbus-client.c Sun Jul 03 21:48:56 2005 +0000 @@ -0,0 +1,135 @@ +/* + * gaim + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * 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 + * + */ + +#define DBUS_API_SUBJECT_TO_CHANGE + +#include <string.h> +#include <dbus/dbus-glib.h> +#include <dbus/dbus-glib-bindings.h> +#include <glib-object.h> + +#include "dbus-gaim.h" +#include "dbus-client-bindings.c" + +int +main (int argc, char **argv) +{ + DBusGConnection *connection; + DBusGProxy *driver; + DBusGProxy *proxy; + GError *error; + guint32 result; + int i; + + + g_type_init (); + + /* Connecting to dbus */ + + error = NULL; + connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + + if (connection == NULL) { + g_assert (error != NULL); + g_critical("Failed to open connection to dbuso %s.", + error->message); + g_error_free(error); + return 1; + } + + g_message("Connected to dbus"); + + /* Create a proxy object for the "bus driver" */ + + driver = dbus_g_proxy_new_for_name(connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS); + + + /* Activate gaim */ + + error = NULL; + org_freedesktop_DBus_start_service_by_name(driver, DBUS_SERVICE_GAIM, 0, + &result, &error); + + if (error) { + g_critical("Failed to activate the gaim object: %s.", + error->message); + g_clear_error(&error); + return 1; + } + + g_message("Gaim object activated"); + + + /* Create a proxy object for gaim */ + + error = NULL; + proxy = dbus_g_proxy_new_for_name_owner (connection, + DBUS_SERVICE_GAIM, + DBUS_PATH_GAIM, + DBUS_INTERFACE_GAIM, + &error); + + if (proxy == NULL) { + g_assert(error); + g_critical("Failed to create proxy for name owner: %s.\n", + error->message); + g_clear_error(&error); + return 1; + } + + g_message("Gaim proxy created"); + + /* Processing commands */ + + for(i=1; i<argc; i++) { + gboolean success = TRUE; + gchar *command = argv[i]; + + error = NULL; + g_print("Executing command: %s ...\n", command); + + if (!strcmp(command, "quit")) + success = org_gaim_GaimInterface_quit(proxy, &error); + else if (!strcmp(command, "ping")) + success = org_gaim_GaimInterface_ping (proxy, &error); + else if (!strcmp(command, "connect")) + success = org_gaim_GaimInterface_connect_all (proxy, &error); + else + g_print("Unknown command: %s.\n", command); + + if (!success) + g_print ("Command %s failed: %s.\n", command, + error->message); + + g_clear_error(&error); + } + + g_object_unref (G_OBJECT (proxy)); + g_object_unref (G_OBJECT (driver)); + g_print ("Successfully completed (%s).\n", argv[0]); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dbus-gaim.h Sun Jul 03 21:48:56 2005 +0000 @@ -0,0 +1,31 @@ +/* + * gaim + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * 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 + * + */ + +#ifndef _DBUS_GAIM_H_ +#define _DBUS_GAIM_H_ + +#define DBUS_SERVICE_GAIM "org.gaim.GaimService" +#define DBUS_PATH_GAIM "/org/gaim/GaimObject" +#define DBUS_INTERFACE_GAIM "org.gaim.GaimInterface" + +#endif /* _DBUS_GAIM_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dbus-gaim.service Sun Jul 03 21:48:56 2005 +0000 @@ -0,0 +1,5 @@ +[D-BUS Service] +Name=org.gaim.GaimService + +#replace this by the path to the gaim executable in your system +Exec=/usr/local/bin/gaim
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dbus-server.c Sun Jul 03 21:48:56 2005 +0000 @@ -0,0 +1,173 @@ +/* + * gaim + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * 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 + * + */ + +#include <dbus/dbus-glib.h> +#include <dbus/dbus-glib-bindings.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <glib/gi18n.h> +#include <glib-object.h> +#include <glib/gquark.h> + +#include "account.h" +#include "dbus-gaim.h" +#include "dbus-server.h" +#include "debug.h" +#include "core.h" + +/* GaimObject, basic definitions*/ + +typedef struct GaimObject GaimObject; +typedef struct GaimObjectClass GaimObjectClass; + +GType gaim_object_get_type(void); + +struct GaimObject { + GObject parent; +}; + +struct GaimObjectClass { + GObjectClass parent; +}; + +#define GAIM_TYPE_OBJECT (gaim_object_get_type ()) +#define GAIM_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GAIM_TYPE_OBJECT, GaimObject)) +#define GAIM_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAIM_TYPE_OBJECT, GaimObjectClass)) +#define GAIM_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GAIM_TYPE_OBJECT)) +#define GAIM_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAIM_TYPE_OBJECT)) +#define GAIM_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAIM_TYPE_OBJECT, GaimObjectClass)) + +G_DEFINE_TYPE(GaimObject, gaim_object, G_TYPE_OBJECT) + + +static void +gaim_object_init(GaimObject *obj) +{ +} + +static void +gaim_object_class_init(GaimObjectClass *mobject_class) +{ +} + +static GObject *gaim_object; + + +/* Implementations of remote DBUS calls */ + + +static gboolean +gaim_object_ping(GaimObject *obj, GError **error) +{ + return TRUE; +} + +static gboolean +gaim_object_quit(GaimObject *obj, GError **error) +{ + g_timeout_add(0, gaim_core_quit_cb, NULL); + return TRUE; +} + +static gboolean +gaim_object_connect_all(GaimObject *obj, GError **error) +{ + GList *cur; + + for (cur = gaim_accounts_get_all(); cur != NULL; cur = cur->next) + gaim_account_connect((GaimAccount*) cur->data); + + return TRUE; +} + +#include "dbus-server-bindings.c" + + +gboolean +dbus_server_init(void) +{ + DBusGConnection *connection; + GError *error; + DBusGProxy *driver_proxy; + guint32 request_name_ret; + + gaim_debug_misc("dbus", "launching dbus server\n"); + + /* Connect to the bus */ + + error = NULL; + connection = dbus_g_bus_get(DBUS_BUS_STARTER, &error); + + if (connection == NULL) { + g_assert(error); + gaim_debug_error("dbus", "Failed to open connection to bus: %s\n", + error->message); + g_error_free (error); + return FALSE; + } + + + /* Instantiate the gaim dbus object and register it */ + + gaim_object = g_object_new (GAIM_TYPE_OBJECT, NULL); + + dbus_g_object_type_install_info (GAIM_TYPE_OBJECT, + &dbus_glib_gaim_object_object_info); + + dbus_g_connection_register_g_object (connection, DBUS_PATH_GAIM, + gaim_object); + + + /* Obtain a proxy for the DBus object */ + + driver_proxy = dbus_g_proxy_new_for_name (connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS); + + + /* Test whether the registration was successful */ + + org_freedesktop_DBus_request_name(driver_proxy, DBUS_SERVICE_GAIM, + 0, &request_name_ret, &error); + + if (error) { + gaim_debug_error("dbus", "Failed to get name: %s\n", error->message); + g_error_free (error); + return FALSE; + } + + if (request_name_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) + { + gaim_debug_error ("dbus", "Got result code %u from requesting name\n", + request_name_ret); + return FALSE; + } + + gaim_debug_misc ("dbus", "GLib test service has name '%s'\n", + DBUS_SERVICE_GAIM); + gaim_debug_misc ("dbus", "GLib test service entering main loop\n"); + + return TRUE; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dbus-server.h Sun Jul 03 21:48:56 2005 +0000 @@ -0,0 +1,42 @@ +/** + * @file dbus-server.h Gaim DBUS Server + * @ingroup core + * + * gaim + * + * Gaim is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * 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 + * + */ + +#ifndef _GAIM_DBUS_SERVER_H_ +#define _GAIM_DBUS_SERVER_H_ + +G_BEGIN_DECLS + +/** + * Starts the gaim DBUS server. It is responsible for handling DBUS + * requests from other applications. + * + * @return TRUE if successful, FALSE otherwise. + */ +gboolean dbus_server_init(void); + +G_END_DECLS + +#endif /* _GAIM_DBUS_SERVER_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dbus-service.xml Sun Jul 03 21:48:56 2005 +0000 @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<node name="/org/gaim/GaimObject"> + <interface name="org.gaim.GaimInterface"> + <method name="Ping"> + </method> + <method name="Quit"> + </method> + <method name="ConnectAll"> + </method> + </interface> +</node> +
--- a/src/gtkmain.c Sun Jul 03 06:42:16 2005 +0000 +++ b/src/gtkmain.c Sun Jul 03 21:48:56 2005 +0000 @@ -71,6 +71,11 @@ # include <gdk/gdkx.h> #endif +#ifdef HAVE_DBUS +# include "dbus-server.h" +#endif + + #ifdef HAVE_STARTUP_NOTIFICATION static SnLauncheeContext *sn_context = NULL; static SnDisplay *sn_display = NULL; @@ -715,6 +720,11 @@ gaim_debug_register_category("server"); gaim_debug_register_category("stringref"); +#ifdef HAVE_DBUS + /* Starting DBUS */ + dbus_server_init(); +#endif + gtk_main(); #ifdef _WIN32