2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu" -*- */
|
|
|
|
|
/* dbus-gmain.c GLib main loop integration
|
|
|
|
|
*
|
2003-01-24 23:51:59 +00:00
|
|
|
* Copyright (C) 2002, 2003 CodeFactory AB
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
*
|
|
|
|
|
* Licensed under the Academic Free License version 1.2
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2003-09-01 18:02:06 +00:00
|
|
|
#include <config.h>
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
#include "dbus-glib.h"
|
2003-09-01 18:02:06 +00:00
|
|
|
#include "dbus-gtest.h"
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
|
2003-09-17 03:52:07 +00:00
|
|
|
#include <libintl.h>
|
|
|
|
|
#define _(x) dgettext (GETTEXT_PACKAGE, x)
|
|
|
|
|
#define N_(x) x
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
|
2003-02-26 06:42:57 +00:00
|
|
|
/**
|
|
|
|
|
* @defgroup DBusGLib GLib bindings
|
|
|
|
|
* @ingroup DBus
|
|
|
|
|
* @brief API for using D-BUS with GLib
|
|
|
|
|
*
|
|
|
|
|
* Convenience functions are provided for using D-BUS
|
|
|
|
|
* with the GLib library (see http://www.gtk.org for GLib
|
|
|
|
|
* information).
|
|
|
|
|
*
|
|
|
|
|
*/
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2003-02-26 06:42:57 +00:00
|
|
|
/**
|
|
|
|
|
* @defgroup DBusGLibInternals GLib bindings implementation details
|
|
|
|
|
* @ingroup DBusInternals
|
|
|
|
|
* @brief Implementation details of GLib bindings
|
|
|
|
|
*
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** @typedef DBusGSource
|
|
|
|
|
* A GSource representing a #DBusConnection or #DBusServer
|
|
|
|
|
*/
|
|
|
|
|
typedef struct DBusGSource DBusGSource;
|
|
|
|
|
|
2003-09-07 23:04:54 +00:00
|
|
|
/**
|
|
|
|
|
* A GSource subclass for a DBusConnection.
|
|
|
|
|
*/
|
2003-02-26 06:42:57 +00:00
|
|
|
struct DBusGSource
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
{
|
2003-02-26 06:42:57 +00:00
|
|
|
GSource source; /**< the parent GSource */
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2003-08-05 13:57:20 +00:00
|
|
|
GList *watch_fds; /**< descriptors we're watching */
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
|
2003-04-24 02:22:49 +00:00
|
|
|
GMainContext *context; /**< the GMainContext to use, NULL for default */
|
|
|
|
|
|
2003-02-26 06:42:57 +00:00
|
|
|
void *connection_or_server; /**< DBusConnection or DBusServer */
|
2003-01-25 21:22:57 +00:00
|
|
|
};
|
|
|
|
|
|
2003-08-05 13:57:20 +00:00
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
int refcount;
|
|
|
|
|
|
|
|
|
|
GPollFD poll_fd;
|
|
|
|
|
DBusWatch *watch;
|
|
|
|
|
|
|
|
|
|
unsigned int removed : 1;
|
|
|
|
|
} WatchFD;
|
|
|
|
|
|
|
|
|
|
static WatchFD *
|
|
|
|
|
watch_fd_new (void)
|
|
|
|
|
{
|
|
|
|
|
WatchFD *watch_fd;
|
|
|
|
|
|
|
|
|
|
watch_fd = g_new0 (WatchFD, 1);
|
|
|
|
|
watch_fd->refcount = 1;
|
|
|
|
|
|
|
|
|
|
return watch_fd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
watch_fd_ref (WatchFD *watch_fd)
|
|
|
|
|
{
|
|
|
|
|
watch_fd->refcount += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
watch_fd_unref (WatchFD *watch_fd)
|
|
|
|
|
{
|
|
|
|
|
watch_fd->refcount -= 1;
|
|
|
|
|
|
|
|
|
|
if (watch_fd->refcount == 0)
|
|
|
|
|
{
|
|
|
|
|
g_assert (watch_fd->removed);
|
|
|
|
|
|
|
|
|
|
g_free (watch_fd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-22 19:39:47 +00:00
|
|
|
static dbus_int32_t connection_slot = -1;
|
|
|
|
|
static dbus_int32_t server_slot = -1;
|
2003-02-16 12:57:26 +00:00
|
|
|
|
2003-03-16 20:16:47 +00:00
|
|
|
static gboolean gsource_connection_prepare (GSource *source,
|
|
|
|
|
gint *timeout);
|
|
|
|
|
static gboolean gsource_connection_check (GSource *source);
|
|
|
|
|
static gboolean gsource_connection_dispatch (GSource *source,
|
|
|
|
|
GSourceFunc callback,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
static gboolean gsource_server_prepare (GSource *source,
|
|
|
|
|
gint *timeout);
|
|
|
|
|
static gboolean gsource_server_check (GSource *source);
|
|
|
|
|
static gboolean gsource_server_dispatch (GSource *source,
|
|
|
|
|
GSourceFunc callback,
|
|
|
|
|
gpointer user_data);
|
2003-02-26 06:42:57 +00:00
|
|
|
|
|
|
|
|
static GSourceFuncs dbus_connection_funcs = {
|
2003-03-16 20:16:47 +00:00
|
|
|
gsource_connection_prepare,
|
|
|
|
|
gsource_connection_check,
|
|
|
|
|
gsource_connection_dispatch,
|
2003-01-25 21:22:57 +00:00
|
|
|
NULL
|
|
|
|
|
};
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
|
2003-02-26 06:42:57 +00:00
|
|
|
static GSourceFuncs dbus_server_funcs = {
|
2003-03-16 20:16:47 +00:00
|
|
|
gsource_server_prepare,
|
|
|
|
|
gsource_server_check,
|
|
|
|
|
gsource_server_dispatch,
|
2003-02-26 06:42:57 +00:00
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
static gboolean
|
2003-03-16 20:16:47 +00:00
|
|
|
gsource_connection_prepare (GSource *source,
|
|
|
|
|
gint *timeout)
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
{
|
2003-02-26 06:42:57 +00:00
|
|
|
DBusConnection *connection = ((DBusGSource *)source)->connection_or_server;
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
|
2003-01-25 21:22:57 +00:00
|
|
|
*timeout = -1;
|
|
|
|
|
|
2003-03-16 20:16:47 +00:00
|
|
|
return (dbus_connection_get_dispatch_status (connection) == DBUS_DISPATCH_DATA_REMAINS);
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
2003-01-25 21:22:57 +00:00
|
|
|
static gboolean
|
2003-03-16 20:16:47 +00:00
|
|
|
gsource_server_prepare (GSource *source,
|
|
|
|
|
gint *timeout)
|
2003-02-26 06:42:57 +00:00
|
|
|
{
|
|
|
|
|
*timeout = -1;
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
dbus_gsource_check (GSource *source)
|
2003-01-25 21:22:57 +00:00
|
|
|
{
|
|
|
|
|
DBusGSource *dbus_source = (DBusGSource *)source;
|
|
|
|
|
GList *list;
|
|
|
|
|
|
2003-08-05 13:57:20 +00:00
|
|
|
list = dbus_source->watch_fds;
|
2003-01-25 21:22:57 +00:00
|
|
|
|
|
|
|
|
while (list)
|
|
|
|
|
{
|
2003-08-05 13:57:20 +00:00
|
|
|
WatchFD *watch_fd = list->data;
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2003-08-05 13:57:20 +00:00
|
|
|
if (watch_fd->poll_fd.revents != 0)
|
2003-01-25 21:22:57 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
list = list->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2003-03-16 20:16:47 +00:00
|
|
|
gsource_connection_check (GSource *source)
|
2003-02-26 06:42:57 +00:00
|
|
|
{
|
|
|
|
|
return dbus_gsource_check (source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2003-03-16 20:16:47 +00:00
|
|
|
gsource_server_check (GSource *source)
|
2003-02-26 06:42:57 +00:00
|
|
|
{
|
|
|
|
|
return dbus_gsource_check (source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
dbus_gsource_dispatch (GSource *source,
|
|
|
|
|
GSourceFunc callback,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
dbus_bool_t is_server)
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
{
|
2003-01-25 21:22:57 +00:00
|
|
|
DBusGSource *dbus_source = (DBusGSource *)source;
|
2003-01-26 00:06:30 +00:00
|
|
|
GList *copy, *list;
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2003-08-05 13:57:20 +00:00
|
|
|
/* Make a copy of the list and ref all WatchFDs */
|
|
|
|
|
copy = g_list_copy (dbus_source->watch_fds);
|
|
|
|
|
g_list_foreach (copy, (GFunc)watch_fd_ref, NULL);
|
|
|
|
|
|
2003-01-26 00:06:30 +00:00
|
|
|
list = copy;
|
2003-01-25 21:22:57 +00:00
|
|
|
while (list)
|
|
|
|
|
{
|
2003-08-05 13:57:20 +00:00
|
|
|
WatchFD *watch_fd = list->data;
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2003-08-05 13:57:20 +00:00
|
|
|
if (!watch_fd->removed && watch_fd->poll_fd.revents != 0)
|
2003-01-25 21:22:57 +00:00
|
|
|
{
|
|
|
|
|
guint condition = 0;
|
|
|
|
|
|
2003-08-05 13:57:20 +00:00
|
|
|
if (watch_fd->poll_fd.revents & G_IO_IN)
|
2003-01-25 21:22:57 +00:00
|
|
|
condition |= DBUS_WATCH_READABLE;
|
2003-08-05 13:57:20 +00:00
|
|
|
if (watch_fd->poll_fd.revents & G_IO_OUT)
|
2003-01-25 21:22:57 +00:00
|
|
|
condition |= DBUS_WATCH_WRITABLE;
|
2003-08-05 13:57:20 +00:00
|
|
|
if (watch_fd->poll_fd.revents & G_IO_ERR)
|
2003-01-25 21:22:57 +00:00
|
|
|
condition |= DBUS_WATCH_ERROR;
|
2003-08-05 13:57:20 +00:00
|
|
|
if (watch_fd->poll_fd.revents & G_IO_HUP)
|
2003-01-25 21:22:57 +00:00
|
|
|
condition |= DBUS_WATCH_HANGUP;
|
2003-02-26 06:42:57 +00:00
|
|
|
|
2003-08-05 13:57:20 +00:00
|
|
|
dbus_watch_handle (watch_fd->watch, condition);
|
2003-01-25 21:22:57 +00:00
|
|
|
}
|
2003-01-26 00:06:30 +00:00
|
|
|
|
2003-01-25 21:22:57 +00:00
|
|
|
list = list->next;
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-05 13:57:20 +00:00
|
|
|
g_list_foreach (copy, (GFunc)watch_fd_unref, NULL);
|
2003-02-26 06:42:57 +00:00
|
|
|
g_list_free (copy);
|
2003-01-25 21:22:57 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
2003-02-26 06:42:57 +00:00
|
|
|
static gboolean
|
2003-03-16 20:16:47 +00:00
|
|
|
gsource_connection_dispatch (GSource *source,
|
|
|
|
|
GSourceFunc callback,
|
|
|
|
|
gpointer user_data)
|
2003-02-26 06:42:57 +00:00
|
|
|
{
|
|
|
|
|
DBusGSource *dbus_source = (DBusGSource *)source;
|
|
|
|
|
DBusConnection *connection = dbus_source->connection_or_server;
|
|
|
|
|
|
|
|
|
|
dbus_connection_ref (connection);
|
|
|
|
|
|
|
|
|
|
dbus_gsource_dispatch (source, callback, user_data,
|
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
|
|
/* Dispatch messages */
|
2003-03-16 20:16:47 +00:00
|
|
|
while (dbus_connection_dispatch (connection) == DBUS_DISPATCH_DATA_REMAINS)
|
2003-02-26 06:42:57 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
dbus_connection_unref (connection);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2003-03-16 20:16:47 +00:00
|
|
|
gsource_server_dispatch (GSource *source,
|
|
|
|
|
GSourceFunc callback,
|
|
|
|
|
gpointer user_data)
|
2003-02-26 06:42:57 +00:00
|
|
|
{
|
|
|
|
|
DBusGSource *dbus_source = (DBusGSource *)source;
|
|
|
|
|
DBusServer *server = dbus_source->connection_or_server;
|
|
|
|
|
|
|
|
|
|
dbus_server_ref (server);
|
|
|
|
|
|
|
|
|
|
dbus_gsource_dispatch (source, callback, user_data,
|
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
|
|
dbus_server_unref (server);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-14 01:27:58 +00:00
|
|
|
static dbus_bool_t
|
2003-01-21 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-connection.c: (dbus_connection_send_message):
Add a new client_serial parameter.
(dbus_connection_send_message_with_reply):
Remove a @todo since we've implemented the blocking function.
(dbus_connection_send_message_with_reply_and_block):
New function that sends a message and waits for a reply and
then returns the reply.
* dbus/dbus-connection.h:
Add new functions.
* dbus/dbus-errors.c: (dbus_result_to_string):
* dbus/dbus-errors.h:
Add new DBUS_RESULT.
* dbus/dbus-message-internal.h:
* dbus/dbus-message.c: (_dbus_message_get_reply_serial),
(_dbus_message_set_sender), (dbus_message_write_header),
(dbus_message_new_reply), (decode_header_data),
(_dbus_message_loader_return_buffer), (_dbus_message_test):
* dbus/dbus-message.h:
Add new functions that set the reply serial and sender.
Also marshal and demarshal them correctly and add test.
* dbus/dbus-protocol.h:
Add new DBUS_MESSAGE_TYPE_SENDER.
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (watch_callback), (free_callback_data),
(add_watch), (remove_watch), (add_timeout), (remove_timeout),
(dbus_connection_hookup_with_g_main):
* glib/test-dbus-glib.c: (main):
Rewrite to use GIOChannel and remove the GSource crack.
* test/echo-client.c: (main):
* test/watch.c: (check_messages):
Update for changed APIs
2003-01-21 09:23:18 +00:00
|
|
|
add_watch (DBusWatch *watch,
|
|
|
|
|
gpointer data)
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
{
|
2003-08-05 13:57:20 +00:00
|
|
|
WatchFD *watch_fd;
|
2003-01-25 21:22:57 +00:00
|
|
|
DBusGSource *dbus_source;
|
|
|
|
|
guint flags;
|
2003-03-15 20:47:16 +00:00
|
|
|
|
|
|
|
|
if (!dbus_watch_get_enabled (watch))
|
|
|
|
|
return TRUE;
|
2003-01-25 21:22:57 +00:00
|
|
|
|
|
|
|
|
dbus_source = data;
|
2003-08-05 13:57:20 +00:00
|
|
|
|
|
|
|
|
watch_fd = watch_fd_new ();
|
|
|
|
|
watch_fd->poll_fd.fd = dbus_watch_get_fd (watch);
|
|
|
|
|
watch_fd->poll_fd.events = 0;
|
2003-01-25 21:22:57 +00:00
|
|
|
flags = dbus_watch_get_flags (watch);
|
2003-08-05 13:57:20 +00:00
|
|
|
dbus_watch_set_data (watch, watch_fd, (DBusFreeFunction)watch_fd_unref);
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
if (flags & DBUS_WATCH_READABLE)
|
2003-08-05 13:57:20 +00:00
|
|
|
watch_fd->poll_fd.events |= G_IO_IN;
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
if (flags & DBUS_WATCH_WRITABLE)
|
2003-08-05 13:57:20 +00:00
|
|
|
watch_fd->poll_fd.events |= G_IO_OUT;
|
|
|
|
|
watch_fd->poll_fd.events |= G_IO_ERR | G_IO_HUP;
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2003-08-05 13:57:20 +00:00
|
|
|
watch_fd->watch = watch;
|
|
|
|
|
|
|
|
|
|
g_source_add_poll ((GSource *)dbus_source, &watch_fd->poll_fd);
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2003-08-05 13:57:20 +00:00
|
|
|
dbus_source->watch_fds = g_list_prepend (dbus_source->watch_fds, watch_fd);
|
2003-03-14 01:27:58 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2003-01-21 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-connection.c: (dbus_connection_send_message):
Add a new client_serial parameter.
(dbus_connection_send_message_with_reply):
Remove a @todo since we've implemented the blocking function.
(dbus_connection_send_message_with_reply_and_block):
New function that sends a message and waits for a reply and
then returns the reply.
* dbus/dbus-connection.h:
Add new functions.
* dbus/dbus-errors.c: (dbus_result_to_string):
* dbus/dbus-errors.h:
Add new DBUS_RESULT.
* dbus/dbus-message-internal.h:
* dbus/dbus-message.c: (_dbus_message_get_reply_serial),
(_dbus_message_set_sender), (dbus_message_write_header),
(dbus_message_new_reply), (decode_header_data),
(_dbus_message_loader_return_buffer), (_dbus_message_test):
* dbus/dbus-message.h:
Add new functions that set the reply serial and sender.
Also marshal and demarshal them correctly and add test.
* dbus/dbus-protocol.h:
Add new DBUS_MESSAGE_TYPE_SENDER.
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (watch_callback), (free_callback_data),
(add_watch), (remove_watch), (add_timeout), (remove_timeout),
(dbus_connection_hookup_with_g_main):
* glib/test-dbus-glib.c: (main):
Rewrite to use GIOChannel and remove the GSource crack.
* test/echo-client.c: (main):
* test/watch.c: (check_messages):
Update for changed APIs
2003-01-21 09:23:18 +00:00
|
|
|
remove_watch (DBusWatch *watch,
|
|
|
|
|
gpointer data)
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
{
|
2003-01-25 21:22:57 +00:00
|
|
|
DBusGSource *dbus_source = data;
|
2003-08-05 13:57:20 +00:00
|
|
|
WatchFD *watch_fd;
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2003-08-05 13:57:20 +00:00
|
|
|
watch_fd = dbus_watch_get_data (watch);
|
|
|
|
|
if (watch_fd == NULL)
|
2003-03-15 20:47:16 +00:00
|
|
|
return; /* probably a not-enabled watch that was added */
|
2003-08-05 13:57:20 +00:00
|
|
|
|
|
|
|
|
watch_fd->removed = TRUE;
|
|
|
|
|
watch_fd->watch = NULL;
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
|
2003-08-05 13:57:20 +00:00
|
|
|
dbus_source->watch_fds = g_list_remove (dbus_source->watch_fds, watch_fd);
|
|
|
|
|
|
|
|
|
|
g_source_remove_poll ((GSource *)dbus_source, &watch_fd->poll_fd);
|
2003-04-25 20:41:49 +00:00
|
|
|
|
|
|
|
|
dbus_watch_set_data (watch, NULL, NULL); /* needed due to watch_toggled
|
|
|
|
|
* breaking add/remove symmetry
|
|
|
|
|
*/
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-15 20:47:16 +00:00
|
|
|
static void
|
|
|
|
|
watch_toggled (DBusWatch *watch,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
/* Because we just exit on OOM, enable/disable is
|
|
|
|
|
* no different from add/remove
|
|
|
|
|
*/
|
|
|
|
|
if (dbus_watch_get_enabled (watch))
|
|
|
|
|
add_watch (watch, data);
|
|
|
|
|
else
|
|
|
|
|
remove_watch (watch, data);
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-13 20:37:07 +00:00
|
|
|
static gboolean
|
|
|
|
|
timeout_handler (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
DBusTimeout *timeout = data;
|
|
|
|
|
|
|
|
|
|
dbus_timeout_handle (timeout);
|
|
|
|
|
|
2003-03-15 02:19:02 +00:00
|
|
|
return TRUE;
|
2003-02-13 20:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-14 01:27:58 +00:00
|
|
|
static dbus_bool_t
|
2003-01-21 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-connection.c: (dbus_connection_send_message):
Add a new client_serial parameter.
(dbus_connection_send_message_with_reply):
Remove a @todo since we've implemented the blocking function.
(dbus_connection_send_message_with_reply_and_block):
New function that sends a message and waits for a reply and
then returns the reply.
* dbus/dbus-connection.h:
Add new functions.
* dbus/dbus-errors.c: (dbus_result_to_string):
* dbus/dbus-errors.h:
Add new DBUS_RESULT.
* dbus/dbus-message-internal.h:
* dbus/dbus-message.c: (_dbus_message_get_reply_serial),
(_dbus_message_set_sender), (dbus_message_write_header),
(dbus_message_new_reply), (decode_header_data),
(_dbus_message_loader_return_buffer), (_dbus_message_test):
* dbus/dbus-message.h:
Add new functions that set the reply serial and sender.
Also marshal and demarshal them correctly and add test.
* dbus/dbus-protocol.h:
Add new DBUS_MESSAGE_TYPE_SENDER.
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (watch_callback), (free_callback_data),
(add_watch), (remove_watch), (add_timeout), (remove_timeout),
(dbus_connection_hookup_with_g_main):
* glib/test-dbus-glib.c: (main):
Rewrite to use GIOChannel and remove the GSource crack.
* test/echo-client.c: (main):
* test/watch.c: (check_messages):
Update for changed APIs
2003-01-21 09:23:18 +00:00
|
|
|
add_timeout (DBusTimeout *timeout,
|
|
|
|
|
void *data)
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
{
|
2003-04-24 02:22:49 +00:00
|
|
|
DBusGSource *dbus_source = data;
|
|
|
|
|
GSource *source;
|
2003-02-13 20:37:07 +00:00
|
|
|
|
2003-03-15 20:47:16 +00:00
|
|
|
if (!dbus_timeout_get_enabled (timeout))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
2003-04-24 02:22:49 +00:00
|
|
|
source = g_timeout_source_new (dbus_timeout_get_interval (timeout));
|
|
|
|
|
g_source_set_callback (source, timeout_handler, timeout, NULL);
|
|
|
|
|
g_source_attach (source, dbus_source->context);
|
2003-02-13 20:37:07 +00:00
|
|
|
|
2003-04-24 02:22:49 +00:00
|
|
|
dbus_timeout_set_data (timeout, GUINT_TO_POINTER (g_source_get_id (source)),
|
|
|
|
|
NULL);
|
2003-03-14 01:27:58 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
2003-01-21 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-connection.c: (dbus_connection_send_message):
Add a new client_serial parameter.
(dbus_connection_send_message_with_reply):
Remove a @todo since we've implemented the blocking function.
(dbus_connection_send_message_with_reply_and_block):
New function that sends a message and waits for a reply and
then returns the reply.
* dbus/dbus-connection.h:
Add new functions.
* dbus/dbus-errors.c: (dbus_result_to_string):
* dbus/dbus-errors.h:
Add new DBUS_RESULT.
* dbus/dbus-message-internal.h:
* dbus/dbus-message.c: (_dbus_message_get_reply_serial),
(_dbus_message_set_sender), (dbus_message_write_header),
(dbus_message_new_reply), (decode_header_data),
(_dbus_message_loader_return_buffer), (_dbus_message_test):
* dbus/dbus-message.h:
Add new functions that set the reply serial and sender.
Also marshal and demarshal them correctly and add test.
* dbus/dbus-protocol.h:
Add new DBUS_MESSAGE_TYPE_SENDER.
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (watch_callback), (free_callback_data),
(add_watch), (remove_watch), (add_timeout), (remove_timeout),
(dbus_connection_hookup_with_g_main):
* glib/test-dbus-glib.c: (main):
Rewrite to use GIOChannel and remove the GSource crack.
* test/echo-client.c: (main):
* test/watch.c: (check_messages):
Update for changed APIs
2003-01-21 09:23:18 +00:00
|
|
|
}
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
|
2003-01-21 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-connection.c: (dbus_connection_send_message):
Add a new client_serial parameter.
(dbus_connection_send_message_with_reply):
Remove a @todo since we've implemented the blocking function.
(dbus_connection_send_message_with_reply_and_block):
New function that sends a message and waits for a reply and
then returns the reply.
* dbus/dbus-connection.h:
Add new functions.
* dbus/dbus-errors.c: (dbus_result_to_string):
* dbus/dbus-errors.h:
Add new DBUS_RESULT.
* dbus/dbus-message-internal.h:
* dbus/dbus-message.c: (_dbus_message_get_reply_serial),
(_dbus_message_set_sender), (dbus_message_write_header),
(dbus_message_new_reply), (decode_header_data),
(_dbus_message_loader_return_buffer), (_dbus_message_test):
* dbus/dbus-message.h:
Add new functions that set the reply serial and sender.
Also marshal and demarshal them correctly and add test.
* dbus/dbus-protocol.h:
Add new DBUS_MESSAGE_TYPE_SENDER.
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (watch_callback), (free_callback_data),
(add_watch), (remove_watch), (add_timeout), (remove_timeout),
(dbus_connection_hookup_with_g_main):
* glib/test-dbus-glib.c: (main):
Rewrite to use GIOChannel and remove the GSource crack.
* test/echo-client.c: (main):
* test/watch.c: (check_messages):
Update for changed APIs
2003-01-21 09:23:18 +00:00
|
|
|
static void
|
|
|
|
|
remove_timeout (DBusTimeout *timeout,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
2003-02-13 20:37:07 +00:00
|
|
|
guint timeout_tag;
|
|
|
|
|
|
|
|
|
|
timeout_tag = GPOINTER_TO_UINT (dbus_timeout_get_data (timeout));
|
2003-03-15 20:47:16 +00:00
|
|
|
|
|
|
|
|
if (timeout_tag != 0) /* if 0, probably timeout was disabled */
|
|
|
|
|
g_source_remove (timeout_tag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
timeout_toggled (DBusTimeout *timeout,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
/* Because we just exit on OOM, enable/disable is
|
|
|
|
|
* no different from add/remove
|
|
|
|
|
*/
|
|
|
|
|
if (dbus_timeout_get_enabled (timeout))
|
|
|
|
|
add_timeout (timeout, data);
|
|
|
|
|
else
|
|
|
|
|
remove_timeout (timeout, data);
|
2003-01-21 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-connection.c: (dbus_connection_send_message):
Add a new client_serial parameter.
(dbus_connection_send_message_with_reply):
Remove a @todo since we've implemented the blocking function.
(dbus_connection_send_message_with_reply_and_block):
New function that sends a message and waits for a reply and
then returns the reply.
* dbus/dbus-connection.h:
Add new functions.
* dbus/dbus-errors.c: (dbus_result_to_string):
* dbus/dbus-errors.h:
Add new DBUS_RESULT.
* dbus/dbus-message-internal.h:
* dbus/dbus-message.c: (_dbus_message_get_reply_serial),
(_dbus_message_set_sender), (dbus_message_write_header),
(dbus_message_new_reply), (decode_header_data),
(_dbus_message_loader_return_buffer), (_dbus_message_test):
* dbus/dbus-message.h:
Add new functions that set the reply serial and sender.
Also marshal and demarshal them correctly and add test.
* dbus/dbus-protocol.h:
Add new DBUS_MESSAGE_TYPE_SENDER.
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (watch_callback), (free_callback_data),
(add_watch), (remove_watch), (add_timeout), (remove_timeout),
(dbus_connection_hookup_with_g_main):
* glib/test-dbus-glib.c: (main):
Rewrite to use GIOChannel and remove the GSource crack.
* test/echo-client.c: (main):
* test/watch.c: (check_messages):
Update for changed APIs
2003-01-21 09:23:18 +00:00
|
|
|
}
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
|
2003-03-15 20:47:16 +00:00
|
|
|
|
2003-02-16 12:57:26 +00:00
|
|
|
static void
|
|
|
|
|
free_source (GSource *source)
|
|
|
|
|
{
|
|
|
|
|
g_source_destroy (source);
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-26 15:52:25 +00:00
|
|
|
static void
|
|
|
|
|
wakeup_main (void *data)
|
|
|
|
|
{
|
2003-04-24 02:22:49 +00:00
|
|
|
DBusGSource *dbus_source = data;
|
|
|
|
|
|
|
|
|
|
g_main_context_wakeup (dbus_source->context);
|
2003-02-26 15:52:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-26 06:42:57 +00:00
|
|
|
/** @} */ /* End of GLib bindings internals */
|
|
|
|
|
|
|
|
|
|
/** @addtogroup DBusGLib
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static GSource*
|
|
|
|
|
create_source (void *connection_or_server,
|
2003-04-24 02:22:49 +00:00
|
|
|
GSourceFuncs *funcs,
|
|
|
|
|
GMainContext *context)
|
2003-01-21 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-connection.c: (dbus_connection_send_message):
Add a new client_serial parameter.
(dbus_connection_send_message_with_reply):
Remove a @todo since we've implemented the blocking function.
(dbus_connection_send_message_with_reply_and_block):
New function that sends a message and waits for a reply and
then returns the reply.
* dbus/dbus-connection.h:
Add new functions.
* dbus/dbus-errors.c: (dbus_result_to_string):
* dbus/dbus-errors.h:
Add new DBUS_RESULT.
* dbus/dbus-message-internal.h:
* dbus/dbus-message.c: (_dbus_message_get_reply_serial),
(_dbus_message_set_sender), (dbus_message_write_header),
(dbus_message_new_reply), (decode_header_data),
(_dbus_message_loader_return_buffer), (_dbus_message_test):
* dbus/dbus-message.h:
Add new functions that set the reply serial and sender.
Also marshal and demarshal them correctly and add test.
* dbus/dbus-protocol.h:
Add new DBUS_MESSAGE_TYPE_SENDER.
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (watch_callback), (free_callback_data),
(add_watch), (remove_watch), (add_timeout), (remove_timeout),
(dbus_connection_hookup_with_g_main):
* glib/test-dbus-glib.c: (main):
Rewrite to use GIOChannel and remove the GSource crack.
* test/echo-client.c: (main):
* test/watch.c: (check_messages):
Update for changed APIs
2003-01-21 09:23:18 +00:00
|
|
|
{
|
2003-01-25 21:22:57 +00:00
|
|
|
GSource *source;
|
|
|
|
|
DBusGSource *dbus_source;
|
|
|
|
|
|
2003-02-26 06:42:57 +00:00
|
|
|
source = g_source_new (funcs, sizeof (DBusGSource));
|
2003-01-25 21:22:57 +00:00
|
|
|
|
|
|
|
|
dbus_source = (DBusGSource *)source;
|
2003-02-26 06:42:57 +00:00
|
|
|
dbus_source->connection_or_server = connection_or_server;
|
2003-04-24 02:22:49 +00:00
|
|
|
dbus_source->context = context;
|
2003-02-26 06:42:57 +00:00
|
|
|
|
|
|
|
|
return source;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the watch and timeout functions of a #DBusConnection
|
|
|
|
|
* to integrate the connection with the GLib main loop.
|
2003-04-29 22:57:13 +00:00
|
|
|
* Pass in #NULL for the #GMainContext unless you're
|
|
|
|
|
* doing something specialized.
|
2003-02-26 06:42:57 +00:00
|
|
|
*
|
|
|
|
|
* @param connection the connection
|
2003-04-29 22:57:13 +00:00
|
|
|
* @param context the #GMainContext or #NULL for default context
|
2003-02-26 06:42:57 +00:00
|
|
|
*/
|
|
|
|
|
void
|
2003-04-24 02:22:49 +00:00
|
|
|
dbus_connection_setup_with_g_main (DBusConnection *connection,
|
|
|
|
|
GMainContext *context)
|
2003-02-26 06:42:57 +00:00
|
|
|
{
|
|
|
|
|
GSource *source;
|
|
|
|
|
|
2003-04-24 02:22:49 +00:00
|
|
|
source = create_source (connection, &dbus_connection_funcs, context);
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
|
2003-03-14 01:27:58 +00:00
|
|
|
if (!dbus_connection_set_watch_functions (connection,
|
|
|
|
|
add_watch,
|
|
|
|
|
remove_watch,
|
2003-03-15 20:47:16 +00:00
|
|
|
watch_toggled,
|
2003-03-14 01:27:58 +00:00
|
|
|
source, NULL))
|
|
|
|
|
goto nomem;
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2003-03-14 01:27:58 +00:00
|
|
|
if (!dbus_connection_set_timeout_functions (connection,
|
|
|
|
|
add_timeout,
|
|
|
|
|
remove_timeout,
|
2003-03-15 20:47:16 +00:00
|
|
|
timeout_toggled,
|
2003-03-14 01:27:58 +00:00
|
|
|
NULL, NULL))
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
2003-02-26 15:52:25 +00:00
|
|
|
dbus_connection_set_wakeup_main_function (connection,
|
|
|
|
|
wakeup_main,
|
2003-04-24 02:22:49 +00:00
|
|
|
source, NULL);
|
2003-02-26 15:52:25 +00:00
|
|
|
|
2003-04-24 02:22:49 +00:00
|
|
|
g_source_attach (source, context);
|
2003-02-16 12:57:26 +00:00
|
|
|
|
2003-06-22 19:39:47 +00:00
|
|
|
/* FIXME we never free the slot, so its refcount just keeps growing,
|
|
|
|
|
* which is kind of broken.
|
|
|
|
|
*/
|
|
|
|
|
dbus_connection_allocate_data_slot (&connection_slot);
|
2003-02-26 06:42:57 +00:00
|
|
|
if (connection_slot < 0)
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_set_data (connection, connection_slot, source,
|
|
|
|
|
(DBusFreeFunction)free_source))
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
nomem:
|
|
|
|
|
g_error ("Not enough memory to set up DBusConnection for use with GLib");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the watch and timeout functions of a #DBusServer
|
|
|
|
|
* to integrate the server with the GLib main loop.
|
2003-04-29 22:57:13 +00:00
|
|
|
* In most cases the context argument should be #NULL.
|
2003-02-26 06:42:57 +00:00
|
|
|
*
|
|
|
|
|
* @param server the server
|
2003-04-29 22:57:13 +00:00
|
|
|
* @param context the #GMainContext or #NULL for default
|
2003-02-26 06:42:57 +00:00
|
|
|
*/
|
|
|
|
|
void
|
2003-04-29 22:57:13 +00:00
|
|
|
dbus_server_setup_with_g_main (DBusServer *server,
|
|
|
|
|
GMainContext *context)
|
2003-02-26 06:42:57 +00:00
|
|
|
{
|
|
|
|
|
GSource *source;
|
|
|
|
|
|
2003-04-24 02:22:49 +00:00
|
|
|
source = create_source (server, &dbus_server_funcs, context);
|
2003-02-26 06:42:57 +00:00
|
|
|
|
|
|
|
|
dbus_server_set_watch_functions (server,
|
|
|
|
|
add_watch,
|
|
|
|
|
remove_watch,
|
2003-03-15 20:47:16 +00:00
|
|
|
watch_toggled,
|
2003-02-26 06:42:57 +00:00
|
|
|
source, NULL);
|
|
|
|
|
|
|
|
|
|
dbus_server_set_timeout_functions (server,
|
|
|
|
|
add_timeout,
|
|
|
|
|
remove_timeout,
|
2003-03-15 20:47:16 +00:00
|
|
|
timeout_toggled,
|
2003-02-26 06:42:57 +00:00
|
|
|
NULL, NULL);
|
2003-02-26 15:52:25 +00:00
|
|
|
|
2003-04-24 02:22:49 +00:00
|
|
|
g_source_attach (source, context);
|
2003-02-26 06:42:57 +00:00
|
|
|
|
2003-06-22 19:39:47 +00:00
|
|
|
/* FIXME we never free the slot, so its refcount just keeps growing,
|
|
|
|
|
* which is kind of broken.
|
|
|
|
|
*/
|
|
|
|
|
dbus_server_allocate_data_slot (&server_slot);
|
2003-02-26 06:42:57 +00:00
|
|
|
if (server_slot < 0)
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
if (!dbus_server_set_data (server, server_slot, source,
|
|
|
|
|
(DBusFreeFunction)free_source))
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
nomem:
|
|
|
|
|
g_error ("Not enough memory to set up DBusServer for use with GLib");
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
}
|
2003-02-26 06:42:57 +00:00
|
|
|
|
2003-09-17 03:52:07 +00:00
|
|
|
/**
|
|
|
|
|
* The implementation of DBUS_GERROR error domain. See documentation
|
|
|
|
|
* for GError in GLib reference manual.
|
|
|
|
|
*
|
|
|
|
|
* @returns the error domain quark for use with GError
|
|
|
|
|
*/
|
|
|
|
|
GQuark
|
|
|
|
|
dbus_g_error_quark (void)
|
|
|
|
|
{
|
|
|
|
|
static GQuark quark = 0;
|
|
|
|
|
if (quark == 0)
|
|
|
|
|
quark = g_quark_from_static_string ("g-exec-error-quark");
|
|
|
|
|
return quark;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a GError return location from a DBusError.
|
|
|
|
|
*
|
|
|
|
|
* @todo expand the DBUS_GERROR enum and take advantage of it here
|
|
|
|
|
*
|
|
|
|
|
* @param gerror location to store a GError, or #NULL
|
|
|
|
|
* @param derror the DBusError
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
dbus_set_g_error (GError **gerror,
|
|
|
|
|
DBusError *derror)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (derror != NULL);
|
|
|
|
|
g_return_if_fail (dbus_error_is_set (derror));
|
|
|
|
|
|
|
|
|
|
g_set_error (gerror, DBUS_GERROR,
|
|
|
|
|
DBUS_GERROR_FAILED,
|
|
|
|
|
_("D-BUS error %s: %s"),
|
|
|
|
|
derror->name, derror->message);
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-23 23:47:09 +00:00
|
|
|
/**
|
|
|
|
|
* Get the GLib type ID for a DBusConnection boxed type.
|
|
|
|
|
*
|
|
|
|
|
* @returns GLib type
|
|
|
|
|
*/
|
|
|
|
|
GType
|
|
|
|
|
dbus_connection_get_g_type (void)
|
|
|
|
|
{
|
|
|
|
|
static GType our_type = 0;
|
|
|
|
|
|
|
|
|
|
if (our_type == 0)
|
|
|
|
|
our_type = g_boxed_type_register_static ("DBusConnection",
|
|
|
|
|
(GBoxedCopyFunc) dbus_connection_ref,
|
|
|
|
|
(GBoxedFreeFunc) dbus_connection_unref);
|
|
|
|
|
|
|
|
|
|
return our_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the GLib type ID for a DBusMessage boxed type.
|
|
|
|
|
*
|
|
|
|
|
* @returns GLib type
|
|
|
|
|
*/
|
|
|
|
|
GType
|
|
|
|
|
dbus_message_get_g_type (void)
|
|
|
|
|
{
|
|
|
|
|
static GType our_type = 0;
|
|
|
|
|
|
|
|
|
|
if (our_type == 0)
|
|
|
|
|
our_type = g_boxed_type_register_static ("DBusMessage",
|
|
|
|
|
(GBoxedCopyFunc) dbus_message_ref,
|
|
|
|
|
(GBoxedFreeFunc) dbus_message_unref);
|
|
|
|
|
|
|
|
|
|
return our_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-26 06:42:57 +00:00
|
|
|
/** @} */ /* end of public API */
|
2003-09-01 18:02:06 +00:00
|
|
|
|
|
|
|
|
#ifdef DBUS_BUILD_TESTS
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ingroup DBusGLibInternals
|
|
|
|
|
* Unit test for GLib main loop integration
|
|
|
|
|
* @returns #TRUE on success.
|
|
|
|
|
*/
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
_dbus_gmain_test (const char *test_data_dir)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* DBUS_BUILD_TESTS */
|