diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-08-24 17:44:08 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-09-22 12:00:33 +0100 |
commit | 99559f249043b8416594f327e3526ff724046cfa (patch) | |
tree | 2d52d52ddd875605f4e563e2d5f2d4fdfdfcfb58 | |
parent | 1df10ad35badac54e07e473d4ff731ecb026ac85 (diff) |
Turn dbus-gmain into a separate librarydbus-gmain
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | configure.ac | 8 | ||||
-rw-r--r-- | dbus-gmain/Makefile.am | 23 | ||||
-rw-r--r-- | dbus-gmain/dbus-gmain.c (renamed from dbus/dbus-gmain.c) | 41 | ||||
-rw-r--r-- | dbus-gmain/dbus-gmain.h | 44 | ||||
-rw-r--r-- | dbus/Makefile.am | 2 | ||||
-rw-r--r-- | dbus/dbus-glib.c | 53 |
7 files changed, 155 insertions, 20 deletions
diff --git a/Makefile.am b/Makefile.am index 296203f..b7cca9f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,8 +1,8 @@ ACLOCAL_AMFLAGS = -I m4 GLIB_PC=dbus-glib-1.pc -SUBDIRS=dbus tools test doc -DIST_SUBDIRS=dbus tools test doc m4 +SUBDIRS=dbus-gmain dbus tools test doc +DIST_SUBDIRS=dbus-gmain dbus tools test doc m4 pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = $(GLIB_PC) diff --git a/configure.ac b/configure.ac index 7e6e11d..50d60bf 100644 --- a/configure.ac +++ b/configure.ac @@ -40,6 +40,13 @@ AC_SUBST(LT_CURRENT) AC_SUBST(LT_REVISION) AC_SUBST(LT_AGE) +# As above but for dbus-gmain-1 +DGMAIN_LT_CUR=0 +DGMAIN_LT_REV=0 +DGMAIN_LT_AGE=0 +AC_SUBST([DGMAIN_LT_CUR]) +AC_SUBST([DGMAIN_LT_REV]) +AC_SUBST([DGMAIN_LT_AGE]) AC_PROG_CC AC_ISC_POSIX @@ -295,6 +302,7 @@ m4/Makefile doc/Makefile doc/reference/Makefile doc/reference/version.xml +dbus-gmain/Makefile dbus/Makefile dbus/examples/Makefile dbus/examples/statemachine/Makefile diff --git a/dbus-gmain/Makefile.am b/dbus-gmain/Makefile.am new file mode 100644 index 0000000..ebdd688 --- /dev/null +++ b/dbus-gmain/Makefile.am @@ -0,0 +1,23 @@ +AM_CPPFLAGS = \ + -I$(top_srcdir) \ + -I$(top_builddir) \ + $(DBUS_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(NULL) + +dbus_gmain_includedir = $(includedir)/dbus-gmain-1/dbus-gmain +dbus_gmain_include_HEADERS = dbus-gmain.h + +lib_LTLIBRARIES = libdbus-gmain-1.la + +libdbus_gmain_1_la_SOURCES = dbus-gmain.c +libdbus_gmain_1_la_LIBADD = \ + $(DBUS_LIBS) \ + $(GLIB_LIBS) \ + $(NULL) +libdbus_gmain_1_la_LDFLAGS = \ + -export-symbols-regex "^dbus.*" \ + -version-info \ + $(DGMAIN_LT_CUR):$(DGMAIN_LT_REV):$(DGMAIN_LT_AGE) \ + -no-undefined \ + $(NULL) diff --git a/dbus/dbus-gmain.c b/dbus-gmain/dbus-gmain.c index 3cf743a..be3fff1 100644 --- a/dbus/dbus-gmain.c +++ b/dbus-gmain/dbus-gmain.c @@ -25,7 +25,7 @@ */ #include <config.h> -#include <dbus/dbus-gmain.h> +#include <dbus-gmain/dbus-gmain.h> /* * DBusGMessageQueue: @@ -112,7 +112,7 @@ typedef struct DBusTimeout *timeout; } TimeoutHandler; -dbus_int32_t _dbus_gmain_connection_slot = -1; +static dbus_int32_t connection_slot = -1; static dbus_int32_t server_slot = -1; static ConnectionSetup* @@ -508,7 +508,7 @@ connection_setup_new_from_old (GMainContext *context, } /** - * dbus_connection_setup_with_g_main: + * dbus_gmain_connection_setup: * @connection: the connection * @context: the #GMainContext or #NULL for default context * @@ -523,8 +523,8 @@ connection_setup_new_from_old (GMainContext *context, * connection. */ void -dbus_connection_setup_with_g_main (DBusConnection *connection, - GMainContext *context) +dbus_gmain_connection_setup (DBusConnection *connection, + GMainContext *context) { ConnectionSetup *old_setup; ConnectionSetup *cs; @@ -532,8 +532,8 @@ dbus_connection_setup_with_g_main (DBusConnection *connection, /* FIXME we never free the slot, so its refcount just keeps growing, * which is kind of broken. */ - dbus_connection_allocate_data_slot (&_dbus_gmain_connection_slot); - if (_dbus_gmain_connection_slot < 0) + dbus_connection_allocate_data_slot (&connection_slot); + if (connection_slot < 0) goto nomem; if (context == NULL) @@ -541,7 +541,7 @@ dbus_connection_setup_with_g_main (DBusConnection *connection, cs = NULL; - old_setup = dbus_connection_get_data (connection, _dbus_gmain_connection_slot); + old_setup = dbus_connection_get_data (connection, connection_slot); if (old_setup != NULL) { if (old_setup->context == context) @@ -550,14 +550,14 @@ dbus_connection_setup_with_g_main (DBusConnection *connection, cs = connection_setup_new_from_old (context, old_setup); /* Nuke the old setup */ - dbus_connection_set_data (connection, _dbus_gmain_connection_slot, NULL, NULL); + dbus_connection_set_data (connection, connection_slot, NULL, NULL); old_setup = NULL; } if (cs == NULL) cs = connection_setup_new (context, connection); - if (!dbus_connection_set_data (connection, _dbus_gmain_connection_slot, cs, + if (!dbus_connection_set_data (connection, connection_slot, cs, (DBusFreeFunction)connection_setup_free)) goto nomem; @@ -586,7 +586,22 @@ dbus_connection_setup_with_g_main (DBusConnection *connection, } /** - * dbus_server_setup_with_g_main: + * dbus_gmain_connection_was_set_up: + * @connection: a connection + * + * Return %TRUE if @connection has been set up with the GLib main loop. + * + * Returns: whether @connection has been set up with the GLib main loop + */ +gboolean +dbus_gmain_connection_was_set_up (DBusConnection *connection) +{ + g_return_val_if_fail (connection != NULL, FALSE); + return (dbus_connection_get_data (connection, connection_slot) != NULL); +} + +/** + * dbus_gmain_server_setup: * @server: the server * @context: the #GMainContext or #NULL for default * @@ -600,8 +615,8 @@ dbus_connection_setup_with_g_main (DBusConnection *connection, * connection. */ void -dbus_server_setup_with_g_main (DBusServer *server, - GMainContext *context) +dbus_gmain_server_setup (DBusServer *server, + GMainContext *context) { ConnectionSetup *old_setup; ConnectionSetup *cs; diff --git a/dbus-gmain/dbus-gmain.h b/dbus-gmain/dbus-gmain.h new file mode 100644 index 0000000..ae08b27 --- /dev/null +++ b/dbus-gmain/dbus-gmain.h @@ -0,0 +1,44 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-gmain.h - GLib main loop integration for dbus-1 + * + * Copyright © 2002-2003 CodeFactory AB + * Copyright © 2003-2004 Red Hat, Inc. + * Copyright © 2011 Nokia Corporation + * + * Licensed under the Academic Free License version 2.1 + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#ifndef DBUS_GMAIN_H +#define DBUS_GMAIN_H + +#include <glib.h> + +#include <dbus/dbus.h> + +G_BEGIN_DECLS + +void dbus_gmain_connection_setup (DBusConnection *connection, + GMainContext *context); +gboolean dbus_gmain_connection_was_set_up (DBusConnection *connection); + +void dbus_gmain_server_setup (DBusServer *server, + GMainContext *context); + +G_END_DECLS + +#endif diff --git a/dbus/Makefile.am b/dbus/Makefile.am index b06e8a9..9beed90 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -27,7 +27,6 @@ DBUS_GLIB_INTERNALS = \ libdbus_glib_1_la_SOURCES = \ dbus-glib.c \ - dbus-gmain.c \ dbus-gmarshal.c \ dbus-gmarshal.h \ dbus-gobject.c \ @@ -50,6 +49,7 @@ libdbus_glib_HEADERS = \ libdbus_glibdir = $(includedir)/dbus-1.0/dbus libdbus_glib_1_la_LIBADD = \ + $(top_builddir)/dbus-gmain/libdbus-gmain-1.la \ $(DBUS_LIBS) \ $(GLIB_LIBS) \ $(GOBJECT_LIBS) \ diff --git a/dbus/dbus-glib.c b/dbus/dbus-glib.c index e4f9af8..3b68aa5 100644 --- a/dbus/dbus-glib.c +++ b/dbus/dbus-glib.c @@ -26,11 +26,15 @@ #include <config.h> #include "dbus-glib.h" #include "dbus-glib-lowlevel.h" + +#include <string.h> + +#include <dbus-gmain/dbus-gmain.h> + #include "dbus-gtest.h" #include "dbus-gutils.h" #include "dbus-gobject.h" #include "dbus-gvalue.h" -#include <string.h> /** * SECTION:dbus-gconnection @@ -307,8 +311,6 @@ dbus_g_connection_get_connection (DBusGConnection *gconnection) return DBUS_CONNECTION_FROM_G_CONNECTION (gconnection); } -extern dbus_int32_t _dbus_gmain_connection_slot; - /** * dbus_connection_get_g_connection: * @connection: a #DBusConnection @@ -324,7 +326,7 @@ DBusGConnection* dbus_connection_get_g_connection (DBusConnection *connection) { g_return_val_if_fail (connection, NULL); - g_return_val_if_fail (dbus_connection_get_data (connection, _dbus_gmain_connection_slot), NULL); + g_return_val_if_fail (dbus_gmain_connection_was_set_up (connection), NULL); return DBUS_G_CONNECTION_FROM_CONNECTION (connection); } @@ -466,3 +468,46 @@ dbus_g_bus_get_private (DBusBusType type, return DBUS_G_CONNECTION_FROM_CONNECTION (connection); } + +/** + * dbus_connection_setup_with_g_main: + * @connection: the connection + * @context: the #GMainContext or #NULL for default context + * + * Sets the watch and timeout functions of a #DBusConnection + * to integrate the connection with the GLib main loop. + * Pass in #NULL for the #GMainContext unless you're + * doing something specialized. + * + * If called twice for the same context, does nothing the second + * time. If called once with context A and once with context B, + * context B replaces context A as the context monitoring the + * connection. + */ +void +dbus_connection_setup_with_g_main (DBusConnection *connection, + GMainContext *context) +{ + dbus_gmain_connection_setup (connection, context); +} + +/** + * dbus_server_setup_with_g_main: + * @server: the server + * @context: the #GMainContext or #NULL for default + * + * Sets the watch and timeout functions of a #DBusServer + * to integrate the server with the GLib main loop. + * In most cases the context argument should be #NULL. + * + * If called twice for the same context, does nothing the second + * time. If called once with context A and once with context B, + * context B replaces context A as the context monitoring the + * connection. + */ +void +dbus_server_setup_with_g_main (DBusServer *server, + GMainContext *context) +{ + dbus_gmain_server_setup (server, context); +} |