-/* -*- mode: C; c-file-style: "gnu" -*- */
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-timeout.c DBusTimeout implementation
*
* Copyright (C) 2003 CodeFactory AB
*
- * Licensed under the Academic Free License version 1.2
+ * Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
+#include <config.h>
#include "dbus-internals.h"
#include "dbus-timeout.h"
#include "dbus-list.h"
* @{
*/
+/**
+ * Internals of DBusTimeout
+ */
struct DBusTimeout
{
int refcount; /**< Reference count */
};
/**
- * Creates a new DBusTimeout.
+ * Creates a new DBusTimeout, enabled by default.
* @param interval the timeout interval in milliseconds.
* @param handler function to call when the timeout occurs.
* @param data data to pass to the handler
DBusTimeout *timeout;
timeout = dbus_new0 (DBusTimeout, 1);
+ if (timeout == NULL)
+ return NULL;
+
timeout->refcount = 1;
timeout->interval = interval;
* Increments the reference count of a DBusTimeout object.
*
* @param timeout the timeout object.
+ * @returns the timeout object.
*/
-void
+DBusTimeout *
_dbus_timeout_ref (DBusTimeout *timeout)
{
timeout->refcount += 1;
+
+ return timeout;
}
/**
}
/**
+ * Changes the timeout interval. Note that you have to disable and
+ * re-enable the timeout using the timeout toggle function
+ * (_dbus_connection_toggle_timeout_unlocked() etc.) to notify the
+ * application of this change.
+ *
+ * @param timeout the timeout
+ * @param interval the new interval
+ */
+void
+_dbus_timeout_set_interval (DBusTimeout *timeout,
+ int interval)
+{
+ _dbus_assert (interval >= 0);
+
+ timeout->interval = interval;
+}
+
+/**
+ * Changes the timeout's enabled-ness. Note that you should use
+ * _dbus_connection_toggle_timeout_unlocked() etc. instead, if
+ * the timeout is passed out to an application main loop.
+ * i.e. you can't use this function in the D-Bus library, it's
+ * only used in the message bus daemon implementation.
+ *
+ * @param timeout the timeout
+ * @param enabled #TRUE if timeout should be enabled.
+ */
+void
+_dbus_timeout_set_enabled (DBusTimeout *timeout,
+ dbus_bool_t enabled)
+{
+ timeout->enabled = enabled != FALSE;
+}
+
+
+/**
* @typedef DBusTimeoutList
*
* Opaque data type representing a list of timeouts
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 */
+ DBusTimeoutToggledFunction timeout_toggled_function; /**< Callback when timeout is enabled/disabled or changes interval */
void *timeout_data; /**< Data for timeout callbacks */
DBusFreeFunction timeout_free_data_function; /**< Free function for timeout callback data */
};
* Types and functions related to DBusTimeout. A timeout
* represents a timeout that the main loop needs to monitor,
* as in Qt's QTimer or GLib's g_timeout_add().
+ *
+ * Use dbus_connection_set_timeout_functions() or dbus_server_set_timeout_functions()
+ * to be notified when libdbus needs to add or remove timeouts.
*
* @{
*/
* should be called each time this interval elapses,
* starting after it elapses once.
*
+ * The interval may change during the life of the
+ * timeout; if so, the timeout will be disabled and
+ * re-enabled (calling the "timeout toggled function")
+ * to notify you of the change.
+ *
* @param timeout the DBusTimeout object.
* @returns the interval in milliseconds.
*/
* This function should be called when the timeout
* occurs.
*
+ * If this function returns #FALSE, then there wasn't
+ * enough memory to handle the timeout. Typically just
+ * letting the timeout fire again next time it naturally
+ * times out is an adequate response to that problem,
+ * but you could try to do more if you wanted.
+ *
* @param timeout the DBusTimeout object.
+ * @returns #FALSE if there wasn't enough memory
*/
-void
+dbus_bool_t
dbus_timeout_handle (DBusTimeout *timeout)
{
- (* timeout->handler) (timeout->handler_data);
+ return (* timeout->handler) (timeout->handler_data);
}