mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2025-12-25 00:00:17 +01:00
* 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
145 lines
3.3 KiB
C
145 lines
3.3 KiB
C
/* -*- mode: C; c-file-style: "gnu" -*- */
|
|
/* dbus-gmain.c GLib main loop integration
|
|
*
|
|
* Copyright (C) 2002 CodeFactory AB
|
|
*
|
|
* 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
|
|
*
|
|
*/
|
|
|
|
#include "dbus-glib.h"
|
|
#include <glib.h>
|
|
|
|
typedef struct
|
|
{
|
|
DBusWatch *watch;
|
|
DBusConnection *connection;
|
|
|
|
guint tag;
|
|
} WatchCallback;
|
|
|
|
static gboolean
|
|
watch_callback (GIOChannel *source,
|
|
GIOCondition condition,
|
|
gpointer data)
|
|
{
|
|
WatchCallback *cb = data;
|
|
unsigned int flags = 0;
|
|
|
|
if (condition & G_IO_IN)
|
|
flags |= DBUS_WATCH_READABLE;
|
|
if (condition & G_IO_OUT)
|
|
flags |= DBUS_WATCH_WRITABLE;
|
|
if (condition & G_IO_ERR)
|
|
flags |= DBUS_WATCH_ERROR;
|
|
if (condition & G_IO_HUP)
|
|
flags |= DBUS_WATCH_HANGUP;
|
|
|
|
dbus_connection_handle_watch (cb->connection,
|
|
cb->watch,
|
|
flags);
|
|
|
|
/* Dispatch messages */
|
|
while (dbus_connection_dispatch_message (cb->connection));
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
static void
|
|
free_callback_data (WatchCallback *cb)
|
|
{
|
|
dbus_connection_unref (cb->connection);
|
|
g_free (cb);
|
|
}
|
|
|
|
static void
|
|
add_watch (DBusWatch *watch,
|
|
gpointer data)
|
|
{
|
|
GIOChannel *channel;
|
|
DBusConnection *connection = data;
|
|
GIOCondition condition = 0;
|
|
WatchCallback *cb;
|
|
guint tag;
|
|
gint flags;
|
|
|
|
flags = dbus_watch_get_flags (watch);
|
|
condition = 0;
|
|
|
|
if (flags & DBUS_WATCH_READABLE)
|
|
condition |= G_IO_IN;
|
|
if (flags & DBUS_WATCH_WRITABLE)
|
|
condition |= G_IO_OUT;
|
|
if (flags & DBUS_WATCH_ERROR)
|
|
condition |= G_IO_ERR;
|
|
if (flags & DBUS_WATCH_HANGUP)
|
|
condition |= G_IO_HUP;
|
|
|
|
channel = g_io_channel_unix_new (dbus_watch_get_fd (watch));
|
|
g_io_channel_set_encoding (channel, NULL, NULL);
|
|
g_io_channel_set_buffered (channel, FALSE);
|
|
|
|
cb = g_new0 (WatchCallback, 1);
|
|
cb->watch = watch;
|
|
cb->connection = connection;
|
|
dbus_connection_ref (connection);
|
|
|
|
dbus_watch_set_data (watch, cb, (DBusFreeFunction)free_callback_data);
|
|
|
|
tag = g_io_add_watch (channel, condition, watch_callback, cb);
|
|
cb->tag = tag;
|
|
}
|
|
|
|
static void
|
|
remove_watch (DBusWatch *watch,
|
|
gpointer data)
|
|
{
|
|
WatchCallback *cb;
|
|
|
|
cb = dbus_watch_get_data (watch);
|
|
|
|
g_source_remove (cb->tag);
|
|
|
|
dbus_watch_set_data (watch, NULL, NULL);
|
|
}
|
|
|
|
static void
|
|
add_timeout (DBusTimeout *timeout,
|
|
void *data)
|
|
{
|
|
}
|
|
|
|
static void
|
|
remove_timeout (DBusTimeout *timeout,
|
|
void *data)
|
|
{
|
|
}
|
|
|
|
void
|
|
dbus_connection_hookup_with_g_main (DBusConnection *connection)
|
|
{
|
|
|
|
dbus_connection_set_watch_functions (connection,
|
|
add_watch,
|
|
remove_watch,
|
|
connection, NULL);
|
|
dbus_connection_set_timeout_functions (connection,
|
|
add_timeout,
|
|
remove_timeout,
|
|
NULL, NULL);
|
|
|
|
}
|