dbus-mainloop.c
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-mainloop.c Main loop utility
*
* Copyright © 2003, 2004 Red Hat, Inc.
* Copyright © 2011 Nokia Corporation
*
* SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <config.h>
#include "dbus-mainloop.h"
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#include <dbus/dbus-hash.h>
#include <dbus/dbus-list.h>
#include <dbus/dbus-pollable-set.h>
#include <dbus/dbus-timeout.h>
#include <dbus/dbus-watch.h>
#define MAINLOOP_SPEW 0
struct DBusLoop
{
int refcount;
DBusHashTable *watches;
DBusPollableSet *pollable_set;
DBusList *timeouts;
int callback_list_serial;
int watch_count;
int timeout_count;
int depth;
DBusList *need_dispatch;
unsigned oom_watch_pending : 1;
};
typedef struct
{
DBusTimeout *timeout;
dbus_int64_t last_tv_sec;
long last_tv_usec;
} TimeoutCallback;
#define TIMEOUT_CALLBACK(callback) ((TimeoutCallback*)callback)
static TimeoutCallback*
timeout_callback_new (DBusTimeout *timeout)
{
TimeoutCallback *cb;
cb = dbus_new (TimeoutCallback, 1);
if (cb == NULL)
return NULL;
cb->timeout = timeout;
_dbus_get_monotonic_time (&cb->last_tv_sec,
&cb->last_tv_usec);
return cb;
}
static void
timeout_callback_free (TimeoutCallback *cb)
{
dbus_free (cb);
}
static void
free_watch_table_entry (void *data)
{
DBusList **watches = data;
DBusWatch *watch;
/* DBusHashTable sometimes calls free_function(NULL) even if you never
* have NULL as a value */
if (watches == NULL)
return;
for (watch = _dbus_list_pop_first (watches);
watch != NULL;
watch = _dbus_list_pop_first (watches))
{
_dbus_watch_unref (watch);
}
_dbus_assert (*watches == NULL);
dbus_free (watches);
}
DBusLoop*
_dbus_loop_new (void)
{
DBusLoop *loop;
loop = dbus_new0 (DBusLoop, 1);
if (loop == NULL)
return NULL;
loop->watches = _dbus_hash_table_new (DBUS_HASH_POLLABLE, NULL,
free_watch_table_entry);
loop->pollable_set = _dbus_pollable_set_new (0);
if (loop->watches == NULL || loop->pollable_set == NULL)
{
if (loop->watches != NULL)
_dbus_hash_table_unref (loop->watches);
if (loop->pollable_set != NULL)
_dbus_pollable_set_free (loop->pollable_set);
dbus_free (loop);
return NULL;
}
loop->refcount = 1;
return loop;
}
DBusLoop *
_dbus_loop_ref (DBusLoop *loop)
{
_dbus_assert (loop != NULL);
_dbus_assert (loop->refcount > 0);
loop->refcount += 1;
return loop;
}
void
_dbus_loop_unref (DBusLoop *loop)
{
_dbus_assert (loop != NULL);
_dbus_assert (loop->refcount > 0);
loop->refcount -= 1;
if (loop->refcount == 0)
{
while (loop->need_dispatch)
{
DBusConnection *connection = _dbus_list_pop_first (&loop->need_dispatch);
dbus_connection_unref (connection);
}
_dbus_hash_table_unref (loop->watches);
_dbus_pollable_set_free (loop->pollable_set);
dbus_free (loop);
}
}
static DBusList **
ensure_watch_table_entry (DBusLoop *loop,
DBusPollable fd)
{
DBusList **watches;
watches = _dbus_hash_table_lookup_pollable (loop->watches, fd);
if (watches == NULL)
{
watches = dbus_new0 (DBusList *, 1);
if (watches == NULL)
return watches;
if (!_dbus_hash_table_insert_pollable (loop->watches, fd, watches))
{
dbus_free (watches);
watches = NULL;
}
}
return watches;
}
static void
cull_watches_for_invalid_fd (DBusLoop *loop,
DBusPollable fd)
{
DBusList *link;
DBusList **watches;
_dbus_warn ("invalid request, socket fd %" DBUS_POLLABLE_FORMAT " not open",
_dbus_pollable_printable (fd));
watches = _dbus_hash_table_lookup_pollable (loop->watches, fd);
if (watches != NULL)
{
for (link = _dbus_list_get_first_link (watches);
link != NULL;
link = _dbus_list_get_next_link (watches, link))
_dbus_watch_invalidate (link->data);
}
_dbus_hash_table_remove_pollable (loop->watches, fd);
}
static dbus_bool_t
gc_watch_table_entry (DBusLoop *loop,
DBusList **watches,
DBusPollable fd)
{
/* If watches is already NULL we have nothing to do */
if (watches == NULL)
return FALSE;
/* We can't GC hash table entries if they're non-empty lists */
if (*watches != NULL)
return FALSE;
_dbus_hash_table_remove_pollable (loop->watches, fd);
return TRUE;
}
static void
refresh_watches_for_fd (DBusLoop *loop,
DBusList **watches,
DBusPollable fd)
{
DBusList *link;
unsigned int flags = 0;
dbus_bool_t interested = FALSE;
_dbus_assert (_dbus_pollable_is_valid (fd));
if (watches == NULL)
watches = _dbus_hash_table_lookup_pollable (loop->watches, fd);
/* we allocated this in the first _dbus_loop_add_watch for the fd, and keep
* it until there are none left */
_dbus_assert (watches != NULL);
for (link = _dbus_list_get_first_link (watches);
link != NULL;
link = _dbus_list_get_next_link (watches, link))
{
if (dbus_watch_get_enabled (link->data) &&
!_dbus_watch_get_oom_last_time (link->data))
{
flags |= dbus_watch_get_flags (link->data);
interested = TRUE;
}
}
if (interested)
_dbus_pollable_set_enable (loop->pollable_set, fd, flags);
else
_dbus_pollable_set_disable (loop->pollable_set, fd);
}
dbus_bool_t
_dbus_loop_add_watch (DBusLoop *loop,
DBusWatch *watch)
{
DBusPollable fd;
DBusList **watches;
fd = _dbus_watch_get_pollable (watch);
_dbus_assert (_dbus_pollable_is_valid (fd));
watches = ensure_watch_table_entry (loop, fd);
if (watches == NULL)
return FALSE;
if (!_dbus_list_append (watches, _dbus_watch_ref (watch)))
{
_dbus_watch_unref (watch);
gc_watch_table_entry (loop, watches, fd);
return FALSE;
}
if (_dbus_list_length_is_one (watches))
{
if (!_dbus_pollable_set_add (loop->pollable_set, fd,
dbus_watch_get_flags (watch),
dbus_watch_get_enabled (watch)))
{
_dbus_hash_table_remove_pollable (loop->watches, fd);
return FALSE;
}
}
else
{
/* we're modifying, not adding, which can't fail with OOM */
refresh_watches_for_fd (loop, watches, fd);
}
loop->callback_list_serial += 1;
loop->watch_count += 1;
return TRUE;
}
void
_dbus_loop_toggle_watch (DBusLoop *loop,
DBusWatch *watch)
{
refresh_watches_for_fd (loop, NULL, _dbus_watch_get_pollable (watch));
}
void
_dbus_loop_remove_watch (DBusLoop *loop,
DBusWatch *watch)
{
DBusList **watches;
DBusList *link;
DBusPollable fd;
/* This relies on people removing watches before they invalidate them,
* which has been safe since fd.o #33336 was fixed. Assert about it
* so we don't regress. */
fd = _dbus_watch_get_pollable (watch);
_dbus_assert (_dbus_pollable_is_valid (fd));
watches = _dbus_hash_table_lookup_pollable (loop->watches, fd);
if (watches != NULL)
{
link = _dbus_list_get_first_link (watches);
while (link != NULL)
{
DBusList *next = _dbus_list_get_next_link (watches, link);
DBusWatch *this = link->data;
if (this == watch)
{
_dbus_list_remove_link (watches, link);
loop->callback_list_serial += 1;
loop->watch_count -= 1;
_dbus_watch_unref (this);
/* if that was the last watch for that fd, drop the hash table
* entry, and stop reserving space for it in the socket set */
if (gc_watch_table_entry (loop, watches, fd))
{
_dbus_pollable_set_remove (loop->pollable_set, fd);
}
return;
}
link = next;
}
}
_dbus_warn ("could not find watch %p to remove", watch);
}
dbus_bool_t
_dbus_loop_add_timeout (DBusLoop *loop,
DBusTimeout *timeout)
{
TimeoutCallback *tcb;
tcb = timeout_callback_new (timeout);
if (tcb == NULL)
return FALSE;
if (_dbus_list_append (&loop->timeouts, tcb))
{
loop->callback_list_serial += 1;
loop->timeout_count += 1;
}
else
{
timeout_callback_free (tcb);
return FALSE;
}
return TRUE;
}
void
_dbus_loop_remove_timeout (DBusLoop *loop,
DBusTimeout *timeout)
{
DBusList *link;
link = _dbus_list_get_first_link (&loop->timeouts);
while (link != NULL)
{
DBusList *next = _dbus_list_get_next_link (&loop->timeouts, link);
TimeoutCallback *this = link->data;
if (this->timeout == timeout)
{
_dbus_list_remove_link (&loop->timeouts, link);
loop->callback_list_serial += 1;
loop->timeout_count -= 1;
timeout_callback_free (this);
return;
}
link = next;
}
_dbus_warn ("could not find timeout %p to remove", timeout);
}
/* Convolutions from GLib, there really must be a better way
* to do this.
*/
static dbus_bool_t
check_timeout (dbus_int64_t tv_sec,
long tv_usec,
TimeoutCallback *tcb,
int *timeout)
{
dbus_int64_t sec_remaining;
long msec_remaining;
dbus_int64_t expiration_tv_sec;
long expiration_tv_usec;
dbus_int64_t interval_seconds;
long interval_milliseconds;
int interval;
/* I'm pretty sure this function could suck (a lot) less */
interval = dbus_timeout_get_interval (tcb->timeout);
interval_seconds = interval / 1000L;
interval_milliseconds = interval % 1000L;
expiration_tv_sec = tcb->last_tv_sec + interval_seconds;
expiration_tv_usec = tcb->last_tv_usec + interval_milliseconds * 1000;
if (expiration_tv_usec >= 1000000)
{
expiration_tv_usec -= 1000000;
expiration_tv_sec += 1;
}
sec_remaining = expiration_tv_sec - tv_sec;
msec_remaining = (expiration_tv_usec - tv_usec) / 1000L;
#if MAINLOOP_SPEW
_dbus_verbose ("Interval is %ld seconds %ld msecs\n",
interval_seconds,
interval_milliseconds);
_dbus_verbose ("Now is %lu seconds %lu usecs\n",
tv_sec, tv_usec);
_dbus_verbose ("Last is %lu seconds %lu usecs\n",
tcb->last_tv_sec, tcb->last_tv_usec);
_dbus_verbose ("Exp is %lu seconds %lu usecs\n",
expiration_tv_sec, expiration_tv_usec);
_dbus_verbose ("Pre-correction, sec_remaining %ld msec_remaining %ld\n",
sec_remaining, msec_remaining);
#endif
/* We do the following in a rather convoluted fashion to deal with
* the fact that we don't have an integral type big enough to hold
* the difference of two timevals in milliseconds.
*/
if (sec_remaining < 0 || (sec_remaining == 0 && msec_remaining < 0))
{
*timeout = 0;
}
else
{
if (msec_remaining < 0)
{
msec_remaining += 1000;
sec_remaining -= 1;
}
if (sec_remaining > (_DBUS_INT_MAX / 1000) ||
msec_remaining > _DBUS_INT_MAX)
*timeout = _DBUS_INT_MAX;
else
*timeout = sec_remaining * 1000 + msec_remaining;
}
if (*timeout > interval)
{
/* This indicates that the system clock probably moved backward */
_dbus_verbose ("System clock set backward! Resetting timeout.\n");
tcb->last_tv_sec = tv_sec;
tcb->last_tv_usec = tv_usec;
*timeout = interval;
}
#if MAINLOOP_SPEW
_dbus_verbose (" timeout expires in %d milliseconds\n", *timeout);
#endif
return *timeout == 0;
}
dbus_bool_t
_dbus_loop_dispatch (DBusLoop *loop)
{
#if MAINLOOP_SPEW
_dbus_verbose (" %d connections to dispatch\n", _dbus_list_get_length (&loop->need_dispatch));
#endif
if (loop->need_dispatch == NULL)
return FALSE;
next:
while (loop->need_dispatch != NULL)
{
DBusConnection *connection = _dbus_list_pop_first (&loop->need_dispatch);
while (TRUE)
{
DBusDispatchStatus status;
status = dbus_connection_dispatch (connection);
if (status == DBUS_DISPATCH_COMPLETE)
{
dbus_connection_unref (connection);
goto next;
}
else
{
if (status == DBUS_DISPATCH_NEED_MEMORY)
_dbus_wait_for_memory ();
}
}
}
return TRUE;
}
dbus_bool_t
_dbus_loop_queue_dispatch (DBusLoop *loop,
DBusConnection *connection)
{
if (_dbus_list_append (&loop->need_dispatch, connection))
{
dbus_connection_ref (connection);
return TRUE;
}
else
return FALSE;
}
/* Returns the smaller non-negative number of the two, or the larger negative
* number if both numbers are negative. Poll interprets negative timeout as
* infinity, which makes it longer than any actual timeout.
*/
static int
min_poll_timeout (int a,
int b)
{
if (a < b)
return a < 0 ? b : a;
else
return b < 0 ? a : b;
}
/* Returns TRUE if we invoked any timeouts or have ready file
* descriptors, which is just used in test code as a debug hack
*/
dbus_bool_t
_dbus_loop_iterate (DBusLoop *loop,
dbus_bool_t block)
{
#define N_STACK_DESCRIPTORS 64
dbus_bool_t retval;
DBusPollableEvent ready_fds[N_STACK_DESCRIPTORS];
int i;
DBusList *link;
int n_ready;
int initial_serial;
int timeout;
int orig_depth;
retval = FALSE;
orig_depth = loop->depth;
#if MAINLOOP_SPEW
_dbus_verbose ("Iteration block=%d depth=%d timeout_count=%d watch_count=%d\n",
block, loop->depth, loop->timeout_count, loop->watch_count);
#endif
if (_dbus_hash_table_get_n_entries (loop->watches) == 0 &&
loop->timeouts == NULL)
goto next_iteration;
timeout = -1;
if (loop->timeout_count > 0)
{
dbus_int64_t tv_sec;
long tv_usec;
_dbus_get_monotonic_time (&tv_sec, &tv_usec);
link = _dbus_list_get_first_link (&loop->timeouts);
while (link != NULL)
{
DBusList *next = _dbus_list_get_next_link (&loop->timeouts, link);
TimeoutCallback *tcb = link->data;
if (dbus_timeout_get_enabled (tcb->timeout))
{
int msecs_remaining;
if (_dbus_timeout_needs_restart (tcb->timeout))
{
tcb->last_tv_sec = tv_sec;
tcb->last_tv_usec = tv_usec;
_dbus_timeout_restarted (tcb->timeout);
}
check_timeout (tv_sec, tv_usec, tcb, &msecs_remaining);
timeout = min_poll_timeout (msecs_remaining, timeout);
#if MAINLOOP_SPEW
_dbus_verbose (" timeout added, %d remaining, aggregate timeout %ld\n",
msecs_remaining, timeout);
#endif
_dbus_assert (timeout >= 0);
}
#if MAINLOOP_SPEW
else
{
_dbus_verbose (" skipping disabled timeout\n");
}
#endif
link = next;
}
}
/* Never block if we have stuff to dispatch */
if (!block || loop->need_dispatch != NULL)
{
timeout = 0;
#if MAINLOOP_SPEW
_dbus_verbose (" timeout is 0 as we aren't blocking\n");
#endif
}
/* if a watch was OOM last time, don't wait longer than the OOM
* wait to re-enable it
*/
if (loop->oom_watch_pending)
timeout = min_poll_timeout (timeout, _dbus_get_oom_wait ());
#if MAINLOOP_SPEW
_dbus_verbose (" polling on %d descriptors timeout %ld\n", _DBUS_N_ELEMENTS (ready_fds), timeout);
#endif
n_ready = _dbus_pollable_set_poll (loop->pollable_set, ready_fds,
_DBUS_N_ELEMENTS (ready_fds), timeout);
/* re-enable any watches we skipped this time */
if (loop->oom_watch_pending)
{
DBusHashIter hash_iter;
loop->oom_watch_pending = FALSE;
_dbus_hash_iter_init (loop->watches, &hash_iter);
while (_dbus_hash_iter_next (&hash_iter))
{
DBusList **watches;
DBusPollable fd;
dbus_bool_t changed;
changed = FALSE;
fd = _dbus_hash_iter_get_pollable_key (&hash_iter);
watches = _dbus_hash_iter_get_value (&hash_iter);
for (link = _dbus_list_get_first_link (watches);
link != NULL;
link = _dbus_list_get_next_link (watches, link))
{
DBusWatch *watch = link->data;
if (_dbus_watch_get_oom_last_time (watch))
{
_dbus_watch_set_oom_last_time (watch, FALSE);
changed = TRUE;
}
}
if (changed)
refresh_watches_for_fd (loop, watches, fd);
}
retval = TRUE; /* return TRUE here to keep the loop going,
* since we don't know the watch was inactive */
}
initial_serial = loop->callback_list_serial;
if (loop->timeout_count > 0)
{
dbus_int64_t tv_sec;
long tv_usec;
_dbus_get_monotonic_time (&tv_sec, &tv_usec);
/* It'd be nice to avoid this O(n) thingy here */
link = _dbus_list_get_first_link (&loop->timeouts);
while (link != NULL)
{
DBusList *next = _dbus_list_get_next_link (&loop->timeouts, link);
TimeoutCallback *tcb = link->data;
if (initial_serial != loop->callback_list_serial)
goto next_iteration;
if (loop->depth != orig_depth)
goto next_iteration;
if (dbus_timeout_get_enabled (tcb->timeout))
{
int msecs_remaining;
if (check_timeout (tv_sec, tv_usec,
tcb, &msecs_remaining))
{
/* Save last callback time and fire this timeout */
tcb->last_tv_sec = tv_sec;
tcb->last_tv_usec = tv_usec;
#if MAINLOOP_SPEW
_dbus_verbose (" invoking timeout\n");
#endif
/* can theoretically return FALSE on OOM, but we just
* let it fire again later - in practice that's what
* every wrapper callback in dbus-daemon used to do */
dbus_timeout_handle (tcb->timeout);
retval = TRUE;
}
else
{
#if MAINLOOP_SPEW
_dbus_verbose (" timeout has not expired\n");
#endif
}
}
#if MAINLOOP_SPEW
else
{
_dbus_verbose (" skipping invocation of disabled timeout\n");
}
#endif
link = next;
}
}
if (n_ready > 0)
{
for (i = 0; i < n_ready; i++)
{
DBusList **watches;
DBusList *next;
unsigned int condition;
dbus_bool_t any_oom;
/* FIXME I think this "restart if we change the watches"
* approach could result in starving watches
* toward the end of the list.
*/
if (initial_serial != loop->callback_list_serial)
goto next_iteration;
if (loop->depth != orig_depth)
goto next_iteration;
_dbus_assert (ready_fds[i].flags != 0);
if (_DBUS_UNLIKELY (ready_fds[i].flags & _DBUS_WATCH_NVAL))
{
cull_watches_for_invalid_fd (loop, ready_fds[i].fd);
goto next_iteration;
}
condition = ready_fds[i].flags;
_dbus_assert ((condition & _DBUS_WATCH_NVAL) == 0);
/* condition may still be 0 if we got some
* weird POLLFOO thing like POLLWRBAND
*/
if (condition == 0)
continue;
watches = _dbus_hash_table_lookup_pollable (loop->watches,
ready_fds[i].fd);
if (watches == NULL)
continue;
any_oom = FALSE;
for (link = _dbus_list_get_first_link (watches);
link != NULL;
link = next)
{
DBusWatch *watch = link->data;
next = _dbus_list_get_next_link (watches, link);
if (dbus_watch_get_enabled (watch))
{
dbus_bool_t oom;
oom = !dbus_watch_handle (watch, condition);
if (oom)
{
_dbus_watch_set_oom_last_time (watch, TRUE);
loop->oom_watch_pending = TRUE;
any_oom = TRUE;
}
#if MAINLOOP_SPEW
_dbus_verbose (" Invoked watch, oom = %d\n", oom);
#endif
retval = TRUE;
/* We re-check this every time, in case the callback
* added/removed watches, which might make our position in
* the linked list invalid. See the FIXME above. */
if (initial_serial != loop->callback_list_serial ||
loop->depth != orig_depth)
{
if (any_oom)
refresh_watches_for_fd (loop, NULL, ready_fds[i].fd);
goto next_iteration;
}
}
}
if (any_oom)
refresh_watches_for_fd (loop, watches, ready_fds[i].fd);
}
}
next_iteration:
#if MAINLOOP_SPEW
_dbus_verbose (" moving to next iteration\n");
#endif
if (_dbus_loop_dispatch (loop))
retval = TRUE;
#if MAINLOOP_SPEW
_dbus_verbose ("Returning %d\n", retval);
#endif
return retval;
}
void
_dbus_loop_run (DBusLoop *loop)
{
int our_exit_depth;
_dbus_assert (loop->depth >= 0);
_dbus_loop_ref (loop);
our_exit_depth = loop->depth;
loop->depth += 1;
_dbus_verbose ("Running main loop, depth %d -> %d\n",
loop->depth - 1, loop->depth);
while (loop->depth != our_exit_depth)
_dbus_loop_iterate (loop, TRUE);
_dbus_loop_unref (loop);
}
void
_dbus_loop_quit (DBusLoop *loop)
{
_dbus_assert (loop->depth > 0);
loop->depth -= 1;
_dbus_verbose ("Quit main loop, depth %d -> %d\n",
loop->depth + 1, loop->depth);
}
int
_dbus_get_oom_wait (void)
{
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
/* make tests go fast */
return 0;
#else
return 500;
#endif
}
void
_dbus_wait_for_memory (void)
{
_dbus_verbose ("Waiting for more memory\n");
_dbus_sleep_milliseconds (_dbus_get_oom_wait ());
}
#endif /* !DOXYGEN_SHOULD_SKIP_THIS */
dbus_connection_unref
void dbus_connection_unref(DBusConnection *connection)
Decrements the reference count of a DBusConnection, and finalizes it if the count reaches zero.
Definition dbus-connection.c:2832
dbus_connection_dispatch
DBusDispatchStatus dbus_connection_dispatch(DBusConnection *connection)
Processes any incoming data.
Definition dbus-connection.c:4591
DBusDispatchStatus
DBusDispatchStatus
Indicates the status of incoming data on a DBusConnection.
Definition dbus-connection.h:83
dbus_connection_ref
DBusConnection * dbus_connection_ref(DBusConnection *connection)
Increments the reference count of a DBusConnection.
Definition dbus-connection.c:2700
DBUS_DISPATCH_NEED_MEMORY
@ DBUS_DISPATCH_NEED_MEMORY
More memory is needed to continue.
Definition dbus-connection.h:86
DBUS_DISPATCH_COMPLETE
@ DBUS_DISPATCH_COMPLETE
All currently available data has been processed.
Definition dbus-connection.h:85
_dbus_hash_table_get_n_entries
int _dbus_hash_table_get_n_entries(DBusHashTable *table)
Gets the number of hash entries in a hash table.
Definition dbus-hash.c:1461
_dbus_hash_iter_get_value
void * _dbus_hash_iter_get_value(DBusHashIter *iter)
Gets the value of the current entry.
Definition dbus-hash.c:620
_dbus_hash_table_unref
void _dbus_hash_table_unref(DBusHashTable *table)
Decrements the reference count for a hash table, freeing the hash table if the count reaches zero.
Definition dbus-hash.c:368
_dbus_hash_iter_next
dbus_bool_t _dbus_hash_iter_next(DBusHashIter *iter)
Move the hash iterator forward one step, to the next hash entry.
Definition dbus-hash.c:550
_dbus_hash_iter_init
void _dbus_hash_iter_init(DBusHashTable *table, DBusHashIter *iter)
Initializes a hash table iterator.
Definition dbus-hash.c:524
_dbus_hash_table_new
DBusHashTable * _dbus_hash_table_new(DBusHashType type, DBusFreeFunction key_free_function, DBusFreeFunction value_free_function)
Constructs a new hash table.
Definition dbus-hash.c:292
DBusHashTable
struct DBusHashTable DBusHashTable
Public opaque hash table object.
Definition dbus-hash.h:59
_dbus_assert
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
Definition dbus-internals.h:153
_DBUS_INT_MAX
#define _DBUS_INT_MAX
Maximum value of type "int".
Definition dbus-internals.h:327
_dbus_warn
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
Definition dbus-internals.c:278
_DBUS_N_ELEMENTS
#define _DBUS_N_ELEMENTS(array)
Computes the number of elements in a fixed-size array using sizeof().
Definition dbus-internals.h:189
_dbus_list_get_first_link
DBusList * _dbus_list_get_first_link(DBusList **list)
Gets the first link in the list.
Definition dbus-list.c:597
_dbus_list_length_is_one
dbus_bool_t _dbus_list_length_is_one(DBusList **list)
Check whether length is exactly one.
Definition dbus-list.c:813
_dbus_list_remove_link
void _dbus_list_remove_link(DBusList **list, DBusList *link)
Removes a link from the list.
Definition dbus-list.c:530
_dbus_list_pop_first
void * _dbus_list_pop_first(DBusList **list)
Removes the first value in the list and returns it.
Definition dbus-list.c:679
_dbus_list_get_length
int _dbus_list_get_length(DBusList **list)
Gets the length of a list.
Definition dbus-list.c:760
_dbus_list_append
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
Definition dbus-list.c:273
_dbus_list_get_next_link
#define _dbus_list_get_next_link(list, link)
Gets the next link in the list, or NULL if there are no more links.
Definition dbus-list.h:121
NULL
#define NULL
A null pointer, defined appropriately for C or C++.
Definition dbus-macros.h:51
TRUE
#define TRUE
Expands to "1".
Definition dbus-macros.h:41
FALSE
#define FALSE
Expands to "0".
Definition dbus-macros.h:44
dbus_free
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
Definition dbus-memory.c:710
dbus_new
#define dbus_new(type, count)
Safe macro for using dbus_malloc().
Definition dbus-memory.h:59
dbus_new0
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
Definition dbus-memory.h:60
_dbus_get_monotonic_time
void _dbus_get_monotonic_time(dbus_int64_t *tv_sec, long *tv_usec)
Get current time, as in gettimeofday().
Definition dbus-sysdeps-unix.c:3381
_dbus_sleep_milliseconds
void _dbus_sleep_milliseconds(int milliseconds)
Sleeps the given number of milliseconds.
Definition dbus-sysdeps-unix.c:3542
_dbus_timeout_restarted
void _dbus_timeout_restarted(DBusTimeout *timeout)
Mark timeout as restarted (setting timestamps is responsibility of the event loop).
Definition dbus-timeout.c:401
_dbus_timeout_needs_restart
dbus_bool_t _dbus_timeout_needs_restart(DBusTimeout *timeout)
Returns whether a timeout needs restart time counting in the event loop.
Definition dbus-timeout.c:389
dbus_timeout_handle
DBUS_EXPORT dbus_bool_t dbus_timeout_handle(DBusTimeout *timeout)
Calls the timeout handler for this timeout.
Definition dbus-timeout.c:500
dbus_timeout_get_enabled
DBUS_EXPORT dbus_bool_t dbus_timeout_get_enabled(DBusTimeout *timeout)
Returns whether a timeout is enabled or not.
Definition dbus-timeout.c:514
dbus_timeout_get_interval
DBUS_EXPORT int dbus_timeout_get_interval(DBusTimeout *timeout)
Gets the timeout interval.
Definition dbus-timeout.c:444
dbus_int64_t
_DBUS_GNUC_EXTENSION typedef long dbus_int64_t
A 64-bit signed integer.
Definition dbus-arch-deps.h:37
dbus_bool_t
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition dbus-types.h:37
_dbus_watch_ref
DBusWatch * _dbus_watch_ref(DBusWatch *watch)
Increments the reference count of a DBusWatch object.
Definition dbus-watch.c:126
_dbus_watch_unref
void _dbus_watch_unref(DBusWatch *watch)
Decrements the reference count of a DBusWatch object and finalizes the object if the count reaches ze...
Definition dbus-watch.c:140
_dbus_watch_invalidate
void _dbus_watch_invalidate(DBusWatch *watch)
Clears the file descriptor from a now-invalid watch object so that no one tries to use it.
Definition dbus-watch.c:171
dbus_watch_handle
DBUS_EXPORT dbus_bool_t dbus_watch_handle(DBusWatch *watch, unsigned int flags)
Called to notify the D-Bus library when a previously-added watch is ready for reading or writing,...
Definition dbus-watch.c:735
dbus_watch_get_enabled
DBUS_EXPORT dbus_bool_t dbus_watch_get_enabled(DBusWatch *watch)
Returns whether a watch is enabled or not.
Definition dbus-watch.c:704
dbus_watch_get_flags
DBUS_EXPORT unsigned int dbus_watch_get_flags(DBusWatch *watch)
Gets flags from DBusWatchFlags indicating what conditions should be monitored on the file descriptor.
Definition dbus-watch.c:644
DBusConnection
Implementation details of DBusConnection.
Definition dbus-connection.c:259
DBusHashIter
Hash iterator object.
Definition dbus-hash.h:50
DBusList
A node in a linked list.
Definition dbus-list.h:37
DBusList::data
void * data
Data stored at this element.
Definition dbus-list.h:40
DBusTimeout
Internals of DBusTimeout.
Definition dbus-timeout.c:43
DBusWatch
Implementation of DBusWatch.
Definition dbus-watch.c:43