summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-timeout.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-03-15 20:47:16 +0000
committerHavoc Pennington <hp@redhat.com>2003-03-15 20:47:16 +0000
commitf587ce7845edb0eb01451368d01b5bc86b5904cd (patch)
treef3a549cd61df701882d818b5fc452b1438097f5b /dbus/dbus-timeout.c
parentf05f87a825ab8ed5273674a7f65521ffc526f0d2 (diff)
2003-03-15 Havoc Pennington <hp@pobox.com>
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
Diffstat (limited to 'dbus/dbus-timeout.c')
-rw-r--r--dbus/dbus-timeout.c50
1 files changed, 49 insertions, 1 deletions
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 */