Commit 3df260c0 authored by Havoc Pennington's avatar Havoc Pennington

2003-04-18 Havoc Pennington <hp@pobox.com>

	* glib/dbus-gmain.c: adapt to watch changes

	* bus/bus.c, bus/activation.c, etc.: adjust to watch changes

	* dbus/dbus-server.h: remove dbus_server_handle_watch

	* dbus/dbus-connection.h: remove dbus_connection_handle_watch

	* dbus/dbus-watch.c (dbus_watch_handle): change DBusWatch to work
	like DBusTimeout, so we don't need dbus_connection_handle_watch
	etc.
parent 88cd5da3
2003-04-18 Havoc Pennington <hp@pobox.com>
* glib/dbus-gmain.c: adapt to watch changes
* bus/bus.c, bus/activation.c, etc.: adjust to watch changes
* dbus/dbus-server.h: remove dbus_server_handle_watch
* dbus/dbus-connection.h: remove dbus_connection_handle_watch
* dbus/dbus-watch.c (dbus_watch_handle): change DBusWatch to work
like DBusTimeout, so we don't need dbus_connection_handle_watch
etc.
2003-04-17 Havoc Pennington <hp@redhat.com> 2003-04-17 Havoc Pennington <hp@redhat.com>
* dbus/dbus-userdb.c, dbus/dbus-sysdeps.c: redo all the passwd * dbus/dbus-userdb.c, dbus/dbus-sysdeps.c: redo all the passwd
......
...@@ -706,8 +706,18 @@ babysitter_watch_callback (DBusWatch *watch, ...@@ -706,8 +706,18 @@ babysitter_watch_callback (DBusWatch *watch,
_dbus_babysitter_ref (babysitter); _dbus_babysitter_ref (babysitter);
retval = _dbus_babysitter_handle_watch (babysitter, watch, condition); retval = dbus_watch_handle (watch, condition);
/* FIXME this is broken in the same way that
* connection watches used to be; there should be
* a separate callback for status change, instead
* of doing "if we handled a watch status might
* have changed"
*
* Fixing this lets us move dbus_watch_handle
* calls into dbus-mainloop.c
*/
if (_dbus_babysitter_get_child_exited (babysitter)) if (_dbus_babysitter_get_child_exited (babysitter))
{ {
DBusError error; DBusError error;
......
...@@ -122,9 +122,12 @@ server_watch_callback (DBusWatch *watch, ...@@ -122,9 +122,12 @@ server_watch_callback (DBusWatch *watch,
unsigned int condition, unsigned int condition,
void *data) void *data)
{ {
DBusServer *server = data; /* FIXME this can be done in dbus-mainloop.c
* if the code in activation.c for the babysitter
return dbus_server_handle_watch (server, watch, condition); * watch handler is fixed.
*/
return dbus_watch_handle (watch, condition);
} }
static dbus_bool_t static dbus_bool_t
......
...@@ -195,15 +195,15 @@ connection_watch_callback (DBusWatch *watch, ...@@ -195,15 +195,15 @@ connection_watch_callback (DBusWatch *watch,
unsigned int condition, unsigned int condition,
void *data) void *data)
{ {
DBusConnection *connection = data; /* FIXME this can be done in dbus-mainloop.c
dbus_bool_t retval; * if the code in activation.c for the babysitter
* watch handler is fixed.
*/
#if 0 #if 0
_dbus_verbose ("Calling handle_watch\n"); _dbus_verbose ("Calling handle_watch\n");
#endif #endif
retval = dbus_connection_handle_watch (connection, watch, condition); return dbus_watch_handle (watch, condition);
return retval;
} }
static dbus_bool_t static dbus_bool_t
...@@ -231,7 +231,7 @@ static void ...@@ -231,7 +231,7 @@ static void
connection_timeout_callback (DBusTimeout *timeout, connection_timeout_callback (DBusTimeout *timeout,
void *data) void *data)
{ {
DBusConnection *connection = data; /* DBusConnection *connection = data; */
/* can return FALSE on OOM but we just let it fire again later */ /* can return FALSE on OOM but we just let it fire again later */
dbus_timeout_handle (timeout); dbus_timeout_handle (timeout);
...@@ -815,7 +815,7 @@ bus_connection_get_name (DBusConnection *connection) ...@@ -815,7 +815,7 @@ bus_connection_get_name (DBusConnection *connection)
return d->name; return d->name;
} }
/** /*
* Transactions * Transactions
* *
* Note that this is fairly fragile; in particular, don't try to use * Note that this is fairly fragile; in particular, don't try to use
......
...@@ -40,16 +40,12 @@ client_watch_callback (DBusWatch *watch, ...@@ -40,16 +40,12 @@ client_watch_callback (DBusWatch *watch,
unsigned int condition, unsigned int condition,
void *data) void *data)
{ {
DBusConnection *connection = data; /* FIXME this can be done in dbus-mainloop.c
dbus_bool_t retval; * if the code in activation.c for the babysitter
* watch handler is fixed.
dbus_connection_ref (connection); */
retval = dbus_connection_handle_watch (connection, watch, condition); return dbus_watch_handle (watch, condition);
dbus_connection_unref (connection);
return retval;
} }
static dbus_bool_t static dbus_bool_t
......
...@@ -38,6 +38,7 @@ typedef enum ...@@ -38,6 +38,7 @@ typedef enum
DBUS_ITERATION_DO_READING = 1 << 1, /**< Read messages in. */ DBUS_ITERATION_DO_READING = 1 << 1, /**< Read messages in. */
DBUS_ITERATION_BLOCK = 1 << 2 /**< Block if nothing to do. */ DBUS_ITERATION_BLOCK = 1 << 2 /**< Block if nothing to do. */
} DBusIterationFlags; } DBusIterationFlags;
void _dbus_connection_lock (DBusConnection *connection); void _dbus_connection_lock (DBusConnection *connection);
void _dbus_connection_unlock (DBusConnection *connection); void _dbus_connection_unlock (DBusConnection *connection);
void _dbus_connection_ref_unlocked (DBusConnection *connection); void _dbus_connection_ref_unlocked (DBusConnection *connection);
...@@ -56,6 +57,9 @@ void _dbus_connection_remove_watch (DBusConnection ...@@ -56,6 +57,9 @@ void _dbus_connection_remove_watch (DBusConnection
void _dbus_connection_toggle_watch (DBusConnection *connection, void _dbus_connection_toggle_watch (DBusConnection *connection,
DBusWatch *watch, DBusWatch *watch,
dbus_bool_t enabled); dbus_bool_t enabled);
dbus_bool_t _dbus_connection_handle_watch (DBusWatch *watch,
unsigned int condition,
void *data);
dbus_bool_t _dbus_connection_add_timeout (DBusConnection *connection, dbus_bool_t _dbus_connection_add_timeout (DBusConnection *connection,
DBusTimeout *timeout); DBusTimeout *timeout);
void _dbus_connection_remove_timeout (DBusConnection *connection, void _dbus_connection_remove_timeout (DBusConnection *connection,
...@@ -78,9 +82,6 @@ DBusHandlerResult _dbus_message_handler_handle_message (DBusMessageHandl ...@@ -78,9 +82,6 @@ DBusHandlerResult _dbus_message_handler_handle_message (DBusMessageHandl
DBusConnection *connection, DBusConnection *connection,
DBusMessage *message); DBusMessage *message);
DBUS_END_DECLS; DBUS_END_DECLS;
#endif /* DBUS_CONNECTION_INTERNAL_H */ #endif /* DBUS_CONNECTION_INTERNAL_H */
...@@ -115,7 +115,7 @@ struct DBusConnection ...@@ -115,7 +115,7 @@ struct DBusConnection
void *dispatch_status_data; /**< Application data for dispatch_status_function */ void *dispatch_status_data; /**< Application data for dispatch_status_function */
DBusFreeFunction free_dispatch_status_data; /**< free dispatch_status_data */ DBusFreeFunction free_dispatch_status_data; /**< free dispatch_status_data */
DBusDispatchStatus last_dispatch_status; DBusDispatchStatus last_dispatch_status; /**< The last dispatch status we reported to the application. */
}; };
typedef struct typedef struct
...@@ -2171,10 +2171,10 @@ dbus_connection_dispatch (DBusConnection *connection) ...@@ -2171,10 +2171,10 @@ dbus_connection_dispatch (DBusConnection *connection)
* other exceptional conditions. * other exceptional conditions.
* *
* Once a file descriptor becomes readable or writable, or an exception * Once a file descriptor becomes readable or writable, or an exception
* occurs, dbus_connection_handle_watch() should be called to * occurs, dbus_watch_handle() should be called to
* notify the connection of the file descriptor's condition. * notify the connection of the file descriptor's condition.
* *
* dbus_connection_handle_watch() cannot be called during the * dbus_watch_handle() cannot be called during the
* DBusAddWatchFunction, as the connection will not be ready to handle * DBusAddWatchFunction, as the connection will not be ready to handle
* that watch yet. * that watch yet.
* *
...@@ -2366,29 +2366,28 @@ dbus_connection_set_dispatch_status_function (DBusConnection *connec ...@@ -2366,29 +2366,28 @@ dbus_connection_set_dispatch_status_function (DBusConnection *connec
} }
/** /**
* Called to notify the connection when a previously-added watch * A callback for use with dbus_watch_new() to create a DBusWatch.
* is ready for reading or writing, or has an exception such *
* as a hangup. * @todo This is basically a hack - we could delete _dbus_transport_handle_watch()
* * and the virtual handle_watch in DBusTransport if we got rid of it.
* If this function returns #FALSE, then the file descriptor may still * The reason this is some work is threading, see the _dbus_connection_handle_watch()
* be ready for reading or writing, but more memory is needed in order * implementation.
* to do the reading or writing. If you ignore the #FALSE return, your
* application may spin in a busy loop on the file descriptor until
* memory becomes available, but nothing more catastrophic should
* happen.
* *
* @param connection the connection.
* @param watch the watch. * @param watch the watch.
* @param condition the current condition of the file descriptors being watched. * @param condition the current condition of the file descriptors being watched.
* @param data must be a pointer to a #DBusConnection
* @returns #FALSE if the IO condition may not have been fully handled due to lack of memory * @returns #FALSE if the IO condition may not have been fully handled due to lack of memory
*/ */
dbus_bool_t dbus_bool_t
dbus_connection_handle_watch (DBusConnection *connection, _dbus_connection_handle_watch (DBusWatch *watch,
DBusWatch *watch, unsigned int condition,
unsigned int condition) void *data)
{ {
DBusConnection *connection;
dbus_bool_t retval; dbus_bool_t retval;
DBusDispatchStatus status; DBusDispatchStatus status;
connection = data;
dbus_mutex_lock (connection->mutex); dbus_mutex_lock (connection->mutex);
_dbus_connection_acquire_io_path (connection, -1); _dbus_connection_acquire_io_path (connection, -1);
......
...@@ -50,7 +50,7 @@ typedef enum ...@@ -50,7 +50,7 @@ typedef enum
DBUS_WATCH_READABLE = 1 << 0, /**< As in POLLIN */ DBUS_WATCH_READABLE = 1 << 0, /**< As in POLLIN */
DBUS_WATCH_WRITABLE = 1 << 1, /**< As in POLLOUT */ DBUS_WATCH_WRITABLE = 1 << 1, /**< As in POLLOUT */
DBUS_WATCH_ERROR = 1 << 2, /**< As in POLLERR (can't watch for this, but DBUS_WATCH_ERROR = 1 << 2, /**< As in POLLERR (can't watch for this, but
* the flag can be passed to dbus_connection_handle_watch()). * the flag can be passed to dbus_watch_handle()).
*/ */
DBUS_WATCH_HANGUP = 1 << 3 /**< As in POLLHUP (can't watch for it, but DBUS_WATCH_HANGUP = 1 << 3 /**< As in POLLHUP (can't watch for it, but
* can be present in current state). */ * can be present in current state). */
...@@ -130,9 +130,6 @@ void dbus_connection_set_dispatch_status_function (DBusConnection ...@@ -130,9 +130,6 @@ void dbus_connection_set_dispatch_status_function (DBusConnection
DBusDispatchStatusFunction function, DBusDispatchStatusFunction function,
void *data, void *data,
DBusFreeFunction free_data_function); DBusFreeFunction free_data_function);
dbus_bool_t dbus_connection_handle_watch (DBusConnection *connection,
DBusWatch *watch,
unsigned int condition);
dbus_bool_t dbus_connection_get_unix_user (DBusConnection *connection, dbus_bool_t dbus_connection_get_unix_user (DBusConnection *connection,
unsigned long *uid); unsigned long *uid);
void dbus_connection_set_unix_user_function (DBusConnection *connection, void dbus_connection_set_unix_user_function (DBusConnection *connection,
...@@ -147,6 +144,8 @@ void* dbus_watch_get_data (DBusWatch *watch); ...@@ -147,6 +144,8 @@ void* dbus_watch_get_data (DBusWatch *watch);
void dbus_watch_set_data (DBusWatch *watch, void dbus_watch_set_data (DBusWatch *watch,
void *data, void *data,
DBusFreeFunction free_data_function); DBusFreeFunction free_data_function);
dbus_bool_t dbus_watch_handle (DBusWatch *watch,
unsigned int flags);
dbus_bool_t dbus_watch_get_enabled (DBusWatch *watch); dbus_bool_t dbus_watch_get_enabled (DBusWatch *watch);
int dbus_timeout_get_interval (DBusTimeout *timeout); int dbus_timeout_get_interval (DBusTimeout *timeout);
......
...@@ -104,7 +104,7 @@ struct DBusMessage ...@@ -104,7 +104,7 @@ struct DBusMessage
DBusList *size_counters; /**< 0-N DBusCounter used to track message size. */ DBusList *size_counters; /**< 0-N DBusCounter used to track message size. */
long size_counter_delta; /**< Size we incremented the size counters by. */ long size_counter_delta; /**< Size we incremented the size counters by. */
dbus_uint32_t changed_stamp; dbus_uint32_t changed_stamp; /**< Incremented when iterators are invalidated. */
unsigned int locked : 1; /**< Message being sent, no modifications allowed. */ unsigned int locked : 1; /**< Message being sent, no modifications allowed. */
}; };
...@@ -115,6 +115,7 @@ enum { ...@@ -115,6 +115,7 @@ enum {
DBUS_MESSAGE_ITER_TYPE_DICT DBUS_MESSAGE_ITER_TYPE_DICT
}; };
/** typedef for internals of message iterator */
typedef struct DBusMessageRealIter DBusMessageRealIter; typedef struct DBusMessageRealIter DBusMessageRealIter;
/** /**
...@@ -1689,7 +1690,7 @@ dbus_message_iter_get_args_valist (DBusMessageIter *iter, ...@@ -1689,7 +1690,7 @@ dbus_message_iter_get_args_valist (DBusMessageIter *iter,
* message passed in. * message passed in.
* *
* @param message the message * @param message the message
* @param _iter pointer to an iterator to initialize * @param iter pointer to an iterator to initialize
*/ */
void void
dbus_message_iter_init (DBusMessage *message, dbus_message_iter_init (DBusMessage *message,
...@@ -1825,7 +1826,7 @@ dbus_message_iter_has_next (DBusMessageIter *iter) ...@@ -1825,7 +1826,7 @@ dbus_message_iter_has_next (DBusMessageIter *iter)
/** /**
* Moves the iterator to the next field. * Moves the iterator to the next field.
* *
* @param _iter The message iter * @param iter The message iter
* @returns #TRUE if the iterator was moved to the next field * @returns #TRUE if the iterator was moved to the next field
*/ */
dbus_bool_t dbus_bool_t
...@@ -2486,7 +2487,7 @@ dbus_message_iter_get_dict_key (DBusMessageIter *iter) ...@@ -2486,7 +2487,7 @@ dbus_message_iter_get_dict_key (DBusMessageIter *iter)
* message. * message.
* *
* @param message the message * @param message the message
* @param _iter pointer to an iterator to initialize * @param iter pointer to an iterator to initialize
*/ */
void void
dbus_message_append_iter_init (DBusMessage *message, dbus_message_append_iter_init (DBusMessage *message,
...@@ -2789,11 +2790,15 @@ dbus_message_iter_append_string (DBusMessageIter *iter, ...@@ -2789,11 +2790,15 @@ dbus_message_iter_append_string (DBusMessageIter *iter,
} }
/** /**
* Appends a named type data chunk to the message. * Appends a named type data chunk to the message. A named
* type is simply an arbitrary UTF-8 string used as a type
* tag, plus an array of arbitrary bytes to be interpreted
* according to the type tag.
* *
* @param iter an iterator pointing to the end of the message * @param iter an iterator pointing to the end of the message
* @param name the name of the type * @param name the name of the type
* @parame * @param data the binary data used to store the value
* @param len the length of the binary data in bytes
* @returns #TRUE on success * @returns #TRUE on success
*/ */
dbus_bool_t dbus_bool_t
...@@ -3003,8 +3008,7 @@ dbus_message_iter_append_array (DBusMessageIter *iter, ...@@ -3003,8 +3008,7 @@ dbus_message_iter_append_array (DBusMessageIter *iter,
* can be used to append to the dict. * can be used to append to the dict.
* *
* @param iter an iterator pointing to the end of the message * @param iter an iterator pointing to the end of the message
* @param array_iter pointer to an iter that will be initialized * @param dict_iter pointer to an iter that will be initialized
* @param element_type the type of the array elements
* @returns #TRUE on success * @returns #TRUE on success
*/ */
dbus_bool_t dbus_bool_t
......
...@@ -108,15 +108,6 @@ debug_finalize (DBusServer *server) ...@@ -108,15 +108,6 @@ debug_finalize (DBusServer *server)
dbus_free (server); dbus_free (server);
} }
static dbus_bool_t
debug_handle_watch (DBusServer *server,
DBusWatch *watch,
unsigned int flags)
{
return TRUE;
}
static void static void
debug_disconnect (DBusServer *server) debug_disconnect (DBusServer *server)
{ {
...@@ -125,7 +116,6 @@ debug_disconnect (DBusServer *server) ...@@ -125,7 +116,6 @@ debug_disconnect (DBusServer *server)
static DBusServerVTable debug_vtable = { static DBusServerVTable debug_vtable = {
debug_finalize, debug_finalize,
debug_handle_watch,
debug_disconnect debug_disconnect
}; };
......
...@@ -71,14 +71,6 @@ debug_finalize (DBusServer *server) ...@@ -71,14 +71,6 @@ debug_finalize (DBusServer *server)
{ {
} }
static dbus_bool_t
debug_handle_watch (DBusServer *server,
DBusWatch *watch,
unsigned int flags)
{
return TRUE;
}
static void static void
debug_disconnect (DBusServer *server) debug_disconnect (DBusServer *server)
{ {
...@@ -86,7 +78,6 @@ debug_disconnect (DBusServer *server) ...@@ -86,7 +78,6 @@ debug_disconnect (DBusServer *server)
static DBusServerVTable debug_vtable = { static DBusServerVTable debug_vtable = {
debug_finalize, debug_finalize,
debug_handle_watch,
debug_disconnect debug_disconnect
}; };
......
...@@ -38,13 +38,6 @@ struct DBusServerVTable ...@@ -38,13 +38,6 @@ struct DBusServerVTable
{ {
void (* finalize) (DBusServer *server); void (* finalize) (DBusServer *server);
/**< The finalize method must free the server. */ /**< The finalize method must free the server. */
dbus_bool_t (* handle_watch) (DBusServer *server,
DBusWatch *watch,
unsigned int flags);
/**< The handle_watch method handles reading/writing
* data as indicated by the flags.
*/
void (* disconnect) (DBusServer *server); void (* disconnect) (DBusServer *server);
/**< Disconnect this server. */ /**< Disconnect this server. */
......
/* -*- mode: C; c-file-style: "gnu" -*- */ /* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-server-unix.c Server implementation for Unix network protocols. /* dbus-server-unix.c Server implementation for Unix network protocols.
* *
* Copyright (C) 2002 Red Hat Inc. * Copyright (C) 2002, 2003 Red Hat Inc.
* *
* Licensed under the Academic Free License version 1.2 * Licensed under the Academic Free License version 1.2
* *
...@@ -129,11 +129,12 @@ handle_new_client_fd (DBusServer *server, ...@@ -129,11 +129,12 @@ handle_new_client_fd (DBusServer *server,
} }
static dbus_bool_t static dbus_bool_t
unix_handle_watch (DBusServer *server, unix_handle_watch (DBusWatch *watch,
DBusWatch *watch, unsigned int flags,
unsigned int flags) void *data)
{ {
DBusServerUnix *unix_server = (DBusServerUnix*) server; DBusServer *server = data;
DBusServerUnix *unix_server = data;
_dbus_assert (watch == unix_server->watch); _dbus_assert (watch == unix_server->watch);
...@@ -202,7 +203,6 @@ unix_disconnect (DBusServer *server) ...@@ -202,7 +203,6 @@ unix_disconnect (DBusServer *server)
static DBusServerVTable unix_vtable = { static DBusServerVTable unix_vtable = {
unix_finalize, unix_finalize,
unix_handle_watch,
unix_disconnect unix_disconnect
}; };
...@@ -225,17 +225,19 @@ _dbus_server_new_for_fd (int fd, ...@@ -225,17 +225,19 @@ _dbus_server_new_for_fd (int fd,
{ {
DBusServerUnix *unix_server; DBusServerUnix *unix_server;
DBusWatch *watch; DBusWatch *watch;
unix_server = dbus_new0 (DBusServerUnix, 1);
if (unix_server == NULL)
return NULL;
watch = _dbus_watch_new (fd, watch = _dbus_watch_new (fd,
DBUS_WATCH_READABLE, DBUS_WATCH_READABLE,
TRUE); TRUE,
unix_handle_watch, unix_server,
NULL);
if (watch == NULL) if (watch == NULL)
return NULL;
unix_server = dbus_new0 (DBusServerUnix, 1);
if (unix_server == NULL)
{ {
_dbus_watch_unref (watch); dbus_free (unix_server);
return NULL; return NULL;
} }
......
...@@ -609,34 +609,6 @@ dbus_server_set_timeout_functions (DBusServer *server, ...@@ -609,34 +609,6 @@ dbus_server_set_timeout_functions (DBusServer *server,
data, free_data_function); data, free_data_function);
} }
/**
* Called to notify the server when a previously-added watch
* is ready for reading or writing, or has an exception such
* as a hangup.
*
* If this function returns #FALSE, then the file descriptor may still
* be ready for reading or writing, but more memory is needed in order
* to do the reading or writing. If you ignore the #FALSE return, your
* application may spin in a busy loop on the file descriptor until
* memory becomes available, but nothing more catastrophic should
* happen.
*
* @param server the server.
* @param watch the watch.
* @param condition the current condition of the file descriptors being watched.
*/
dbus_bool_t
dbus_server_handle_watch (DBusServer *server,
DBusWatch *watch,
unsigned int condition)
{
_dbus_assert (server->vtable->handle_watch != NULL);
_dbus_watch_sanitize_condition (watch, &condition);
return (* server->vtable->handle_watch) (server, watch, condition);
}
/** /**
* Sets the authentication mechanisms that this server offers * Sets the authentication mechanisms that this server offers