summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@codefactory.se>2003-01-19 21:55:49 +0000
committerAnders Carlsson <andersca@codefactory.se>2003-01-19 21:55:49 +0000
commitf0dbc1bdd06e1cb4f32b7fe05ee1287ae5f9df85 (patch)
tree9d830da02f403ef3a111bd68b04bfa916413690c
parent037192972af12511ca1476b9604d1603f382d8f9 (diff)
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.
-rw-r--r--ChangeLog18
-rw-r--r--dbus/Makefile.am2
-rw-r--r--dbus/dbus-connection.c39
-rw-r--r--dbus/dbus-connection.h55
-rw-r--r--dbus/dbus-message.c12
-rw-r--r--dbus/dbus-message.h1
-rw-r--r--dbus/dbus-server.c2
7 files changed, 110 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 45530307..35a7dadf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,23 @@
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.
diff --git a/dbus/Makefile.am b/dbus/Makefile.am
index b9d97da4..5254010b 100644
--- a/dbus/Makefile.am
+++ b/dbus/Makefile.am
@@ -36,6 +36,8 @@ libdbus_1_la_SOURCES= \
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 \
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index 4b9d4caa..25114964 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -23,6 +23,7 @@
#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"
@@ -82,6 +83,7 @@ struct DBusConnection
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. */
@@ -291,6 +293,7 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
{
DBusConnection *connection;
DBusWatchList *watch_list;
+ DBusTimeoutList *timeout_list;
DBusHashTable *handler_table;
watch_list = NULL;
@@ -301,6 +304,10 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
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);
@@ -314,6 +321,7 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
connection->refcount = 1;
connection->transport = transport;
connection->watches = watch_list;
+ connection->timeouts = timeout_list;
connection->handler_table = handler_table;
connection->filter_list = NULL;
@@ -930,6 +938,37 @@ dbus_connection_set_watch_functions (DBusConnection *connection,
}
/**
+ * 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.
diff --git a/dbus/dbus-connection.h b/dbus/dbus-connection.h
index a973e5d4..2a888ec1 100644
--- a/dbus/dbus-connection.h
+++ b/dbus/dbus-connection.h
@@ -35,6 +35,7 @@ DBUS_BEGIN_DECLS;
typedef struct DBusConnection DBusConnection;
typedef struct DBusWatch DBusWatch;
+typedef struct DBusTimeout DBusTimeout;
typedef struct DBusMessageHandler DBusMessageHandler;
typedef enum
@@ -54,14 +55,19 @@ 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);
@@ -85,18 +91,24 @@ dbus_bool_t dbus_connection_send_message_with_reply (DBusConnection *connect
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);
@@ -106,6 +118,13 @@ void dbus_watch_set_data (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,
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index 6206815f..5767bda6 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -360,6 +360,18 @@ dbus_message_get_name (DBusMessage *message)
}
/**
+ * 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.
diff --git a/dbus/dbus-message.h b/dbus/dbus-message.h
index 5da95796..b8be6907 100644
--- a/dbus/dbus-message.h
+++ b/dbus/dbus-message.h
@@ -43,6 +43,7 @@ void dbus_message_ref (DBusMessage *message);
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,
diff --git a/dbus/dbus-server.c b/dbus/dbus-server.c
index 994a100a..83b1f578 100644
--- a/dbus/dbus-server.c
+++ b/dbus/dbus-server.c
@@ -363,7 +363,7 @@ dbus_server_get_max_connections (DBusServer *server)
* 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)