2003-01-19 Anders Carlsson <andersca@codefactory.se>
+ * dbus/Makefile.am: Add dbus-timeout.[cħ]
+
+ * dbus/dbus-connection.c: (_dbus_connection_new_for_transport):
+ Create a DBusTimeoutList.
+ (dbus_connection_set_timeout_functions): Add new function to
+ set timeout callbacks
+
+ * dbus/dbus-connection.h: Add public DBusTimeout API.
+
+ * dbus/dbus-message.c: (dbus_message_get_service):
+ * dbus/dbus-message.h: New function.
+
+ * dbus/dbus-server.c: Fix small doc typo.
+
+ * dbus/dbus-timeout.[ch]: New files for mainloop timeouts.
+
+2003-01-19 Anders Carlsson <andersca@codefactory.se>
+
* dbus/dbus-string.c (_dbus_string_move_len): Don't delete all
of the string, just as long as specified.
dbus-server-unix.h \
dbus-test.c \
dbus-test.h \
+ dbus-timeout.c \
+ dbus-timeout.h \
dbus-threads.c \
dbus-transport.c \
dbus-transport.h \
#include "dbus-connection.h"
#include "dbus-list.h"
+#include "dbus-timeout.h"
#include "dbus-transport.h"
#include "dbus-watch.h"
#include "dbus-connection-internal.h"
DBusTransport *transport; /**< Object that sends/receives messages over network. */
DBusWatchList *watches; /**< Stores active watches. */
+ DBusTimeoutList *timeouts; /**< Stores active timeouts. */
DBusDisconnectFunction disconnect_function; /**< Callback on disconnect. */
void *disconnect_data; /**< Data for disconnect callback. */
{
DBusConnection *connection;
DBusWatchList *watch_list;
+ DBusTimeoutList *timeout_list;
DBusHashTable *handler_table;
watch_list = NULL;
if (watch_list == NULL)
goto error;
+ timeout_list = _dbus_timeout_list_new ();
+ if (timeout_list == NULL)
+ goto error;
+
handler_table =
_dbus_hash_table_new (DBUS_HASH_STRING,
dbus_free, NULL);
connection->refcount = 1;
connection->transport = transport;
connection->watches = watch_list;
+ connection->timeouts = timeout_list;
connection->handler_table = handler_table;
connection->filter_list = NULL;
}
/**
+ * Sets the timeout functions for the connection. These functions are
+ * responsible for making the application's main loop aware of timeouts.
+ * When using Qt, typically the DBusAddTimeoutFunction would create a
+ * QTimer. When using GLib, the DBusAddTimeoutFunction would call
+ * g_timeout_add.
+ *
+ * The DBusTimeout can be queried for the timer interval using
+ * dbus_timeout_get_interval.
+ *
+ * Once a timeout occurs, dbus_timeout_handle should be call to invoke
+ * the timeout's callback.
+ */
+void
+dbus_connection_set_timeout_functions (DBusConnection *connection,
+ DBusAddTimeoutFunction add_function,
+ DBusRemoveTimeoutFunction remove_function,
+ void *data,
+ DBusFreeFunction free_data_function)
+{
+ /* ref connection for slightly better reentrancy */
+ dbus_connection_ref (connection);
+
+ _dbus_timeout_list_set_functions (connection->timeouts,
+ add_function, remove_function,
+ data, free_data_function);
+
+ /* drop our paranoid refcount */
+ dbus_connection_unref (connection);
+}
+
+/**
* Called to notify the connection when a previously-added watch
* is ready for reading or writing, or has an exception such
* as a hangup.
typedef struct DBusConnection DBusConnection;
typedef struct DBusWatch DBusWatch;
+typedef struct DBusTimeout DBusTimeout;
typedef struct DBusMessageHandler DBusMessageHandler;
typedef enum
* can be present in current state). */
} DBusWatchFlags;
-typedef void (* DBusAddWatchFunction) (DBusWatch *watch,
- void *data);
+typedef void (* DBusAddWatchFunction) (DBusWatch *watch,
+ void *data);
-typedef void (* DBusRemoveWatchFunction) (DBusWatch *watch,
- void *data);
+typedef void (* DBusRemoveWatchFunction) (DBusWatch *watch,
+ void *data);
-typedef void (* DBusDisconnectFunction) (DBusConnection *connection,
- void *data);
+typedef void (* DBusAddTimeoutFunction) (DBusTimeout *timeout,
+ void *data);
+typedef void (* DBusRemoveTimeoutFunction) (DBusTimeout *timeout,
+ void *data);
+
+typedef void (* DBusDisconnectFunction) (DBusConnection *connection,
+ void *data);
DBusConnection* dbus_connection_open (const char *address,
DBusResultCode *result);
int timeout_milliseconds,
DBusResultCode *result);
-void dbus_connection_set_disconnect_function (DBusConnection *connection,
- DBusDisconnectFunction function,
- void *data,
- DBusFreeFunction free_data_function);
-void dbus_connection_set_watch_functions (DBusConnection *connection,
- DBusAddWatchFunction add_function,
- DBusRemoveWatchFunction remove_function,
- void *data,
- DBusFreeFunction free_data_function);
-void dbus_connection_handle_watch (DBusConnection *connection,
- DBusWatch *watch,
- unsigned int condition);
+void dbus_connection_set_disconnect_function (DBusConnection *connection,
+ DBusDisconnectFunction function,
+ void *data,
+ DBusFreeFunction free_data_function);
+void dbus_connection_set_watch_functions (DBusConnection *connection,
+ DBusAddWatchFunction add_function,
+ DBusRemoveWatchFunction remove_function,
+ void *data,
+ DBusFreeFunction free_data_function);
+void dbus_connection_set_timeout_functions (DBusConnection *connection,
+ DBusAddTimeoutFunction add_function,
+ DBusRemoveTimeoutFunction remove_function,
+ void *data,
+ DBusFreeFunction free_data_function);
+void dbus_connection_handle_watch (DBusConnection *connection,
+ DBusWatch *watch,
+ unsigned int condition);
+
int dbus_watch_get_fd (DBusWatch *watch);
void *data,
DBusFreeFunction free_data_function);
+int dbus_timeout_get_interval (DBusTimeout *timeout);
+void* dbus_timeout_get_data (DBusTimeout *timeout);
+void dbus_timeout_set_data (DBusTimeout *timeout,
+ void *data,
+ DBusFreeFunction free_data_function);
+void dbus_timeout_handle (DBusTimeout *timeout);
+
/* Handlers */
dbus_bool_t dbus_connection_add_filter (DBusConnection *connection,
}
/**
+ * Gets the destination service of a message.
+ *
+ * @param message the message
+ * @returns the message destination service (should not be freed)
+ */
+const char*
+dbus_message_get_service (DBusMessage *message)
+{
+ return message->service;
+}
+
+/**
* Appends fields to a message given a variable argument
* list. The variable argument list should contain the type
* of the field followed by the value to add.
void dbus_message_unref (DBusMessage *message);
const char* dbus_message_get_name (DBusMessage *message);
+const char* dbus_message_get_service (DBusMessage *message);
dbus_bool_t dbus_message_append_fields (DBusMessage *message,
* finalized will count in this total.
*
* @param server the server
- * @param returns the number of connections
+ * @returns the number of connections
*/
int
dbus_server_get_n_connections (DBusServer *server)