From f587ce7845edb0eb01451368d01b5bc86b5904cd Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sat, 15 Mar 2003 20:47:16 +0000 Subject: 2003-03-15 Havoc Pennington Make it pass the Hello handling test including all OOM codepaths. Now to do other messages... * bus/services.c (bus_service_remove_owner): fix crash when removing owner from an empty list of owners (bus_registry_ensure): don't leave service in the list of a connection's owned services if we fail to put the service in the hash table. * bus/connection.c (bus_connection_preallocate_oom_error): set error flag on the OOM error. * dbus/dbus-connection.c (_dbus_connection_new_for_transport): handle _dbus_transport_set_connection failure * dbus/dbus-transport-unix.c (_dbus_transport_new_for_fd): modify to create watches up front and simply enable/disable them as needed. (unix_connection_set): this can now fail on OOM * dbus/dbus-timeout.c, dbus/dbus-watch.c: add concept of enabling/disabling a watch or timeout. * bus/loop.c (bus_loop_iterate): don't touch disabled watches/timeouts * glib/dbus-gmain.c: adapt to enable/disable watches and timeouts --- dbus/dbus-timeout.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'dbus/dbus-timeout.c') diff --git a/dbus/dbus-timeout.c b/dbus/dbus-timeout.c index 09e54b31..9825872e 100644 --- a/dbus/dbus-timeout.c +++ b/dbus/dbus-timeout.c @@ -44,6 +44,7 @@ struct DBusTimeout void *data; /**< Application data. */ DBusFreeFunction free_data_function; /**< Free the application data. */ + unsigned int enabled : 1; /**< True if timeout is active. */ }; /** @@ -69,6 +70,8 @@ _dbus_timeout_new (int interval, timeout->handler = handler; timeout->handler_data = data; timeout->free_handler_data_function = free_data_function; + + timeout->enabled = TRUE; return timeout; } @@ -130,6 +133,7 @@ struct DBusTimeoutList DBusAddTimeoutFunction add_timeout_function; /**< Callback for adding a timeout. */ DBusRemoveTimeoutFunction remove_timeout_function; /**< Callback for removing a timeout. */ + DBusTimeoutToggledFunction timeout_toggled_function; /**< Callback when timeout is enabled/disabled */ void *timeout_data; /**< Data for timeout callbacks */ DBusFreeFunction timeout_free_data_function; /**< Free function for timeout callback data */ }; @@ -162,7 +166,7 @@ _dbus_timeout_list_free (DBusTimeoutList *timeout_list) { /* free timeout_data and remove timeouts as a side effect */ _dbus_timeout_list_set_functions (timeout_list, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); _dbus_list_foreach (&timeout_list->timeouts, (DBusForeachFunction) _dbus_timeout_unref, @@ -179,6 +183,7 @@ _dbus_timeout_list_free (DBusTimeoutList *timeout_list) * @param timeout_list the timeout list * @param add_function the add timeout function. * @param remove_function the remove timeout function. + * @param toggled_function toggle notify function, or #NULL * @param data the data for those functions. * @param free_data_function the function to free the data. * @returns #FALSE if no memory @@ -188,6 +193,7 @@ dbus_bool_t _dbus_timeout_list_set_functions (DBusTimeoutList *timeout_list, DBusAddTimeoutFunction add_function, DBusRemoveTimeoutFunction remove_function, + DBusTimeoutToggledFunction toggled_function, void *data, DBusFreeFunction free_data_function) { @@ -239,6 +245,7 @@ _dbus_timeout_list_set_functions (DBusTimeoutList *timeout_list, timeout_list->add_timeout_function = add_function; timeout_list->remove_timeout_function = remove_function; + timeout_list->timeout_toggled_function = toggled_function; timeout_list->timeout_data = data; timeout_list->timeout_free_data_function = free_data_function; @@ -297,6 +304,31 @@ _dbus_timeout_list_remove_timeout (DBusTimeoutList *timeout_list, _dbus_timeout_unref (timeout); } +/** + * Sets a timeout to the given enabled state, invoking the + * application's DBusTimeoutToggledFunction if appropriate. + * + * @param timeout_list the timeout list. + * @param timeout the timeout to toggle. + * @param enabled #TRUE to enable + */ +void +_dbus_timeout_list_toggle_timeout (DBusTimeoutList *timeout_list, + DBusTimeout *timeout, + dbus_bool_t enabled) +{ + enabled = !!enabled; + + if (enabled == timeout->enabled) + return; + + timeout->enabled = enabled; + + if (timeout_list->timeout_toggled_function != NULL) + (* timeout_list->timeout_toggled_function) (timeout, + timeout_list->timeout_data); +} + /** @} */ /** @@ -380,3 +412,19 @@ dbus_timeout_handle (DBusTimeout *timeout) { (* timeout->handler) (timeout->handler_data); } + + +/** + * Returns whether a timeout is enabled or not. If not + * enabled, it should not be polled by the main loop. + * + * @param timeout the DBusTimeout object + * @returns #TRUE if the timeout is enabled + */ +dbus_bool_t +dbus_timeout_get_enabled (DBusTimeout *timeout) +{ + return timeout->enabled; +} + +/** @} end public API docs */ -- cgit