summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-04-06 23:53:27 +0000
committerHavoc Pennington <hp@redhat.com>2003-04-06 23:53:27 +0000
commitdf008ef97deacd5bb00ac335e5d8671798fa09dd (patch)
tree806477f545a05128aa17f6981d4f6185cf7587fe
parent856361ff5b8ce701cdb447085931d3076ee52008 (diff)
2003-04-06 Havoc Pennington <hp@pobox.com>
* dbus/Makefile.am: split lists of sources into stuff that goes in the library, util functions that go in the lib and are also used elsewhere, and util functions that are used in tests/daemon but don't go in the lib. * dbus/dbus-mainloop.h, dbus/dbus-mainloop.c: move bus/loop.[hc] here so it can be used in test binaries also
-rw-r--r--ChangeLog10
-rw-r--r--bus/Makefile.am2
-rw-r--r--bus/activation.c30
-rw-r--r--bus/bus.c27
-rw-r--r--bus/bus.h5
-rw-r--r--bus/connection.c25
-rw-r--r--bus/dispatch.c11
-rw-r--r--bus/loop.c698
-rw-r--r--bus/loop.h65
-rw-r--r--bus/main.c5
-rw-r--r--bus/test.c35
-rw-r--r--bus/utils.c20
-rw-r--r--bus/utils.h3
-rw-r--r--dbus/Makefile.am28
14 files changed, 100 insertions, 864 deletions
diff --git a/ChangeLog b/ChangeLog
index 75eed1b4..0b17ac82 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2003-04-06 Havoc Pennington <hp@pobox.com>
+ * dbus/Makefile.am: split lists of sources into stuff that goes in
+ the library, util functions that go in the lib and are also used
+ elsewhere, and util functions that are used in tests/daemon but
+ don't go in the lib.
+
+ * dbus/dbus-mainloop.h, dbus/dbus-mainloop.c: move bus/loop.[hc]
+ here so it can be used in test binaries also
+
+2003-04-06 Havoc Pennington <hp@pobox.com>
+
* dbus/dbus-sysdeps.c (_dbus_become_daemon): write the pidfile
here in the parent process, so we can return an error if it
fails. Also, move some of the code into the child so the parent
diff --git a/bus/Makefile.am b/bus/Makefile.am
index adbebaeb..85f47ddc 100644
--- a/bus/Makefile.am
+++ b/bus/Makefile.am
@@ -40,8 +40,6 @@ BUS_SOURCES= \
dispatch.h \
driver.c \
driver.h \
- loop.c \
- loop.h \
policy.c \
policy.h \
services.c \
diff --git a/bus/activation.c b/bus/activation.c
index 54ddd948..425d9c19 100644
--- a/bus/activation.c
+++ b/bus/activation.c
@@ -90,7 +90,7 @@ handle_timeout_callback (DBusTimeout *timeout,
BusPendingActivation *pending_activation = data;
while (!dbus_timeout_handle (pending_activation->timeout))
- bus_wait_for_memory ();
+ _dbus_wait_for_memory ();
}
static void
@@ -103,9 +103,9 @@ bus_pending_activation_free (BusPendingActivation *pending_activation)
if (pending_activation->timeout_added)
{
- bus_loop_remove_timeout (bus_context_get_loop (pending_activation->activation->context),
- pending_activation->timeout,
- handle_timeout_callback, pending_activation);
+ _dbus_loop_remove_timeout (bus_context_get_loop (pending_activation->activation->context),
+ pending_activation->timeout,
+ handle_timeout_callback, pending_activation);
pending_activation->timeout_added = FALSE;
}
@@ -604,7 +604,7 @@ pending_activation_failed (BusPendingActivation *pending_activation,
{
/* FIXME use preallocated OOM messages instead of bus_wait_for_memory() */
while (!try_send_activation_failure (pending_activation, how))
- bus_wait_for_memory ();
+ _dbus_wait_for_memory ();
/* Destroy this pending activation */
_dbus_hash_table_remove_string (pending_activation->activation->pending_activations,
@@ -650,9 +650,9 @@ add_babysitter_watch (DBusWatch *watch,
{
BusPendingActivation *pending_activation = data;
- return bus_loop_add_watch (bus_context_get_loop (pending_activation->activation->context),
- watch, babysitter_watch_callback, pending_activation,
- NULL);
+ return _dbus_loop_add_watch (bus_context_get_loop (pending_activation->activation->context),
+ watch, babysitter_watch_callback, pending_activation,
+ NULL);
}
static void
@@ -661,8 +661,8 @@ remove_babysitter_watch (DBusWatch *watch,
{
BusPendingActivation *pending_activation = data;
- bus_loop_remove_watch (bus_context_get_loop (pending_activation->activation->context),
- watch, babysitter_watch_callback, pending_activation);
+ _dbus_loop_remove_watch (bus_context_get_loop (pending_activation->activation->context),
+ watch, babysitter_watch_callback, pending_activation);
}
static dbus_bool_t
@@ -806,11 +806,11 @@ bus_activation_activate_service (BusActivation *activation,
return FALSE;
}
- if (!bus_loop_add_timeout (bus_context_get_loop (activation->context),
- pending_activation->timeout,
- handle_timeout_callback,
- pending_activation,
- NULL))
+ if (!_dbus_loop_add_timeout (bus_context_get_loop (activation->context),
+ pending_activation->timeout,
+ handle_timeout_callback,
+ pending_activation,
+ NULL))
{
BUS_SET_OOM (error);
bus_pending_activation_free (pending_activation);
diff --git a/bus/bus.c b/bus/bus.c
index 09a0b5bb..ee40e539 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -22,7 +22,6 @@
*/
#include "bus.h"
-#include "loop.h"
#include "activation.h"
#include "connection.h"
#include "services.h"
@@ -38,7 +37,7 @@ struct BusContext
int refcount;
char *type;
char *address;
- BusLoop *loop;
+ DBusLoop *loop;
DBusList *servers;
BusConnections *connections;
BusActivation *activation;
@@ -138,9 +137,9 @@ add_server_watch (DBusWatch *watch,
context = server_get_context (server);
- return bus_loop_add_watch (context->loop,
- watch, server_watch_callback, server,
- NULL);
+ return _dbus_loop_add_watch (context->loop,
+ watch, server_watch_callback, server,
+ NULL);
}
static void
@@ -152,8 +151,8 @@ remove_server_watch (DBusWatch *watch,
context = server_get_context (server);
- bus_loop_remove_watch (context->loop,
- watch, server_watch_callback, server);
+ _dbus_loop_remove_watch (context->loop,
+ watch, server_watch_callback, server);
}
@@ -174,8 +173,8 @@ add_server_timeout (DBusTimeout *timeout,
context = server_get_context (server);
- return bus_loop_add_timeout (context->loop,
- timeout, server_timeout_callback, server, NULL);
+ return _dbus_loop_add_timeout (context->loop,
+ timeout, server_timeout_callback, server, NULL);
}
static void
@@ -187,8 +186,8 @@ remove_server_timeout (DBusTimeout *timeout,
context = server_get_context (server);
- bus_loop_remove_timeout (context->loop,
- timeout, server_timeout_callback, server);
+ _dbus_loop_remove_timeout (context->loop,
+ timeout, server_timeout_callback, server);
}
static void
@@ -396,7 +395,7 @@ bus_context_new (const DBusString *config_file,
*/
context->max_completed_connections = 1024;
- context->loop = bus_loop_new ();
+ context->loop = _dbus_loop_new ();
if (context->loop == NULL)
{
BUS_SET_OOM (error);
@@ -755,7 +754,7 @@ bus_context_unref (BusContext *context)
if (context->loop)
{
- bus_loop_unref (context->loop);
+ _dbus_loop_unref (context->loop);
context->loop = NULL;
}
@@ -798,7 +797,7 @@ bus_context_get_activation (BusContext *context)
return context->activation;
}
-BusLoop*
+DBusLoop*
bus_context_get_loop (BusContext *context)
{
return context->loop;
diff --git a/bus/bus.h b/bus/bus.h
index bbb0d481..60290c04 100644
--- a/bus/bus.h
+++ b/bus/bus.h
@@ -28,8 +28,7 @@
#include <dbus/dbus.h>
#include <dbus/dbus-string.h>
-
-#include "loop.h"
+#include <dbus/dbus-mainloop.h>
typedef struct BusActivation BusActivation;
typedef struct BusConnections BusConnections;
@@ -51,7 +50,7 @@ const char* bus_context_get_address (BusContext *context)
BusRegistry* bus_context_get_registry (BusContext *context);
BusConnections* bus_context_get_connections (BusContext *context);
BusActivation* bus_context_get_activation (BusContext *context);
-BusLoop* bus_context_get_loop (BusContext *context);
+DBusLoop* bus_context_get_loop (BusContext *context);
dbus_bool_t bus_context_allow_user (BusContext *context,
unsigned long uid);
BusPolicy* bus_context_create_connection_policy (BusContext *context,
diff --git a/bus/connection.c b/bus/connection.c
index aa8d65ca..f5a0ac16 100644
--- a/bus/connection.c
+++ b/bus/connection.c
@@ -22,7 +22,6 @@
*/
#include "connection.h"
#include "dispatch.h"
-#include "loop.h"
#include "policy.h"
#include "services.h"
#include "utils.h"
@@ -89,7 +88,7 @@ connection_data_slot_unref (void)
}
}
-static BusLoop*
+static DBusLoop*
connection_get_loop (DBusConnection *connection)
{
BusConnectionData *d;
@@ -134,7 +133,7 @@ bus_connection_disconnected (DBusConnection *connection)
while (transaction == NULL)
{
transaction = bus_transaction_new (d->connections->context);
- bus_wait_for_memory ();
+ _dbus_wait_for_memory ();
}
if (!bus_service_remove_owner (service, connection,
@@ -144,7 +143,7 @@ bus_connection_disconnected (DBusConnection *connection)
{
dbus_error_free (&error);
bus_transaction_cancel_and_free (transaction);
- bus_wait_for_memory ();
+ _dbus_wait_for_memory ();
goto retry;
}
else
@@ -209,9 +208,9 @@ add_connection_watch (DBusWatch *watch,
{
DBusConnection *connection = data;
- return bus_loop_add_watch (connection_get_loop (connection),
- watch, connection_watch_callback, connection,
- NULL);
+ return _dbus_loop_add_watch (connection_get_loop (connection),
+ watch, connection_watch_callback, connection,
+ NULL);
}
static void
@@ -220,8 +219,8 @@ remove_connection_watch (DBusWatch *watch,
{
DBusConnection *connection = data;
- bus_loop_remove_watch (connection_get_loop (connection),
- watch, connection_watch_callback, connection);
+ _dbus_loop_remove_watch (connection_get_loop (connection),
+ watch, connection_watch_callback, connection);
}
static void
@@ -246,8 +245,8 @@ add_connection_timeout (DBusTimeout *timeout,
{
DBusConnection *connection = data;
- return bus_loop_add_timeout (connection_get_loop (connection),
- timeout, connection_timeout_callback, connection, NULL);
+ return _dbus_loop_add_timeout (connection_get_loop (connection),
+ timeout, connection_timeout_callback, connection, NULL);
}
static void
@@ -256,8 +255,8 @@ remove_connection_timeout (DBusTimeout *timeout,
{
DBusConnection *connection = data;
- bus_loop_remove_timeout (connection_get_loop (connection),
- timeout, connection_timeout_callback, connection);
+ _dbus_loop_remove_timeout (connection_get_loop (connection),
+ timeout, connection_timeout_callback, connection);
}
static dbus_bool_t
diff --git a/bus/dispatch.c b/bus/dispatch.c
index 2e0fa9d2..ce0d71c6 100644
--- a/bus/dispatch.c
+++ b/bus/dispatch.c
@@ -29,7 +29,6 @@
#include "utils.h"
#include "bus.h"
#include "test.h"
-#include "loop.h"
#include <dbus/dbus-internals.h>
#include <string.h>
@@ -176,7 +175,7 @@ bus_dispatch (DBusConnection *connection,
* until we can.
*/
while (!bus_connection_preallocate_oom_error (connection))
- bus_wait_for_memory ();
+ _dbus_wait_for_memory ();
/* Ref connection in case we disconnect it at some point in here */
dbus_connection_ref (connection);
@@ -537,7 +536,7 @@ kill_client_connection (BusContext *context,
_dbus_assert (s != NULL);
while ((base_service = _dbus_strdup (s)) == NULL)
- bus_wait_for_memory ();
+ _dbus_wait_for_memory ();
dbus_connection_ref (connection);
@@ -805,7 +804,7 @@ check_hello_message (BusContext *context,
{
_dbus_verbose ("no memory to get service name arg from hello\n");
dbus_error_free (&error);
- bus_wait_for_memory ();
+ _dbus_wait_for_memory ();
goto retry_get_hello_name;
}
else
@@ -819,7 +818,7 @@ check_hello_message (BusContext *context,
_dbus_verbose ("Got hello name: %s\n", name);
while (!dbus_bus_set_base_service (connection, name))
- bus_wait_for_memory ();
+ _dbus_wait_for_memory ();
scd.skip_connection = NULL;
scd.failed = FALSE;
@@ -849,7 +848,7 @@ check_hello_message (BusContext *context,
{
_dbus_verbose ("no memory to get service name arg from acquired\n");
dbus_error_free (&error);
- bus_wait_for_memory ();
+ _dbus_wait_for_memory ();
goto retry_get_acquired_name;
}
else
diff --git a/bus/loop.c b/bus/loop.c
deleted file mode 100644
index e2e129eb..00000000
--- a/bus/loop.c
+++ /dev/null
@@ -1,698 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu" -*- */
-/* loop.c Main loop for daemon
- *
- * Copyright (C) 2003 Red Hat, Inc.
- *
- * Licensed under the Academic Free License version 1.2
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-#include "loop.h"
-#include "utils.h"
-#include <dbus/dbus-list.h>
-#include <dbus/dbus-sysdeps.h>
-
-struct BusLoop
-{
- int refcount;
- DBusList *callbacks;
- int callback_list_serial;
- int watch_count;
- int timeout_count;
- int depth; /**< number of recursive runs */
-};
-
-typedef enum
-{
- CALLBACK_WATCH,
- CALLBACK_TIMEOUT
-} CallbackType;
-
-typedef struct
-{
- CallbackType type;
- void *data;
- DBusFreeFunction free_data_func;
-} Callback;
-
-typedef struct
-{
- Callback callback;
- BusWatchFunction function;
- DBusWatch *watch;
- /* last watch handle failed due to OOM */
- unsigned int last_iteration_oom : 1;
-} WatchCallback;
-
-typedef struct
-{
- Callback callback;
- DBusTimeout *timeout;
- BusTimeoutFunction function;
- unsigned long last_tv_sec;
- unsigned long last_tv_usec;
-} TimeoutCallback;
-
-#define WATCH_CALLBACK(callback) ((WatchCallback*)callback)
-#define TIMEOUT_CALLBACK(callback) ((TimeoutCallback*)callback)
-
-static WatchCallback*
-watch_callback_new (DBusWatch *watch,
- BusWatchFunction function,
- void *data,
- DBusFreeFunction free_data_func)
-{
- WatchCallback *cb;
-
- cb = dbus_new (WatchCallback, 1);
- if (cb == NULL)
- return NULL;
-
- cb->watch = watch;
- cb->function = function;
- cb->last_iteration_oom = FALSE;
- cb->callback.type = CALLBACK_WATCH;
- cb->callback.data = data;
- cb->callback.free_data_func = free_data_func;
-
- return cb;
-}
-
-static TimeoutCallback*
-timeout_callback_new (DBusTimeout *timeout,
- BusTimeoutFunction function,
- void *data,
- DBusFreeFunction free_data_func)
-{
- TimeoutCallback *cb;
-
- cb = dbus_new (TimeoutCallback, 1);
- if (cb == NULL)
- return NULL;
-
- cb->timeout = timeout;
- cb->function = function;
- _dbus_get_current_time (&cb->last_tv_sec,
- &cb->last_tv_usec);
- cb->callback.type = CALLBACK_TIMEOUT;
- cb->callback.data = data;
- cb->callback.free_data_func = free_data_func;
-
- return cb;
-}
-
-static void
-callback_free (Callback *cb)
-{
- if (cb->free_data_func)
- (* cb->free_data_func) (cb->data);
-
- dbus_free (cb);
-}
-
-static dbus_bool_t
-add_callback (BusLoop *loop,
- Callback *cb)
-{
- if (!_dbus_list_append (&loop->callbacks, cb))
- return FALSE;
-
- loop->callback_list_serial += 1;
-
- switch (cb->type)
- {
- case CALLBACK_WATCH:
- loop->watch_count += 1;
- break;
- case CALLBACK_TIMEOUT:
- loop->timeout_count += 1;
- break;
- }
-
- return TRUE;
-}
-
-static void
-remove_callback (BusLoop *loop,
- DBusList *link)
-{
- Callback *cb = link->data;
-
- switch (cb->type)
- {
- case CALLBACK_WATCH:
- loop->watch_count -= 1;
- break;
- case CALLBACK_TIMEOUT:
- loop->timeout_count -= 1;
- break;
- }
-
- callback_free (cb);
- _dbus_list_remove_link (&loop->callbacks, link);
- loop->callback_list_serial += 1;
-}
-
-BusLoop*
-bus_loop_new (void)
-{
- BusLoop *loop;
-
- loop = dbus_new0 (BusLoop, 1);
- if (loop == NULL)
- return NULL;
-
- loop->refcount = 1;
-
- return loop;
-}
-
-void
-bus_loop_ref (BusLoop *loop)
-{
- _dbus_assert (loop != NULL);
- _dbus_assert (loop->refcount > 0);
-
- loop->refcount += 1;
-}
-
-void
-bus_loop_unref (BusLoop *loop)
-{
- _dbus_assert (loop != NULL);
- _dbus_assert (loop->refcount > 0);
-
- loop->refcount -= 1;
- if (loop->refcount == 0)
- {
-
- dbus_free (loop);
- }
-}
-
-dbus_bool_t
-bus_loop_add_watch (BusLoop *loop,
- DBusWatch *watch,
- BusWatchFunction function,
- void *data,
- DBusFreeFunction free_data_func)
-{
- WatchCallback *wcb;
-
- wcb = watch_callback_new (watch, function, data, free_data_func);
- if (wcb == NULL)
- return FALSE;
-
- if (!add_callback (loop, (Callback*) wcb))
- {
- wcb->callback.free_data_func = NULL; /* don't want to have this side effect */
- callback_free ((Callback*) wcb);
- return FALSE;
- }
-
- return TRUE;
-}
-
-void
-bus_loop_remove_watch (BusLoop *loop,
- DBusWatch *watch,
- BusWatchFunction function,
- void *data)
-{
- DBusList *link;
-
- link = _dbus_list_get_first_link (&loop->callbacks);
- while (link != NULL)
- {
- DBusList *next = _dbus_list_get_next_link (&loop->callbacks, link);
- Callback *this = link->data;
-
- if (this->type == CALLBACK_WATCH &&
- WATCH_CALLBACK (this)->watch == watch &&
- this->data == data &&
- WATCH_CALLBACK (this)->function == function)
- {
- remove_callback (loop, link);
-
- return;
- }
-
- link = next;
- }
-
- _dbus_warn ("could not find watch %p function %p data %p to remove\n",
- watch, function, data);
-}
-
-dbus_bool_t
-bus_loop_add_timeout (BusLoop *loop,
- DBusTimeout *timeout,
- BusTimeoutFunction function,
- void *data,
- DBusFreeFunction free_data_func)
-{
- TimeoutCallback *tcb;
-
- tcb = timeout_callback_new (timeout, function, data, free_data_func);
- if (tcb == NULL)
- return FALSE;
-
- if (!add_callback (loop, (Callback*) tcb))
- {
- tcb->callback.free_data_func = NULL; /* don't want to have this side effect */
- callback_free ((Callback*) tcb);
- return FALSE;
- }
-
- return TRUE;
-}
-
-void
-bus_loop_remove_timeout (BusLoop *loop,
- DBusTimeout *timeout,
- BusTimeoutFunction function,
- void *data)
-{
- DBusList *link;
-
- link = _dbus_list_get_first_link (&loop->callbacks);
- while (link != NULL)
- {
- DBusList *next = _dbus_list_get_next_link (&loop->callbacks, link);
- Callback *this = link->data;
-
- if (this->type == CALLBACK_TIMEOUT &&
- TIMEOUT_CALLBACK (this)->timeout == timeout &&
- this->data == data &&
- TIMEOUT_CALLBACK (this)->function == function)
- {
- remove_callback (loop, link);
-
- return;
- }
-
- link = next;
- }
-
- _dbus_warn ("could not find timeout %p function %p data %p to remove\n",
- timeout, function, data);
-}
-
-/* Convolutions from GLib, there really must be a better way
- * to do this.
- */
-static dbus_bool_t
-check_timeout (unsigned long tv_sec,
- unsigned long tv_usec,
- TimeoutCallback *tcb,
- int *timeout)
-{
- long sec;
- long msec;
- unsigned long expiration_tv_sec;
- unsigned long expiration_tv_usec;
- long interval_seconds;
- long interval_milliseconds;
- int interval;
-
- interval = dbus_timeout_get_interval (tcb->timeout);
-
- interval_seconds = interval / 1000;
- interval_milliseconds = interval - interval_seconds * 1000;
-
- 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 = expiration_tv_sec - tv_sec;
- msec = (expiration_tv_usec - tv_usec) / 1000;
-
-#if 0
- printf ("Interval is %ld seconds %ld msecs\n",
- interval_seconds,
- interval_milliseconds);
- printf ("Now is %lu seconds %lu usecs\n",
- tv_sec, tv_usec);
- printf ("Exp is %lu seconds %lu usecs\n",
- expiration_tv_sec, expiration_tv_usec);
- printf ("Pre-correction, remaining sec %ld msec %ld\n", sec, msec);
-#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 millseconds.
- */
- if (sec < 0 || (sec == 0 && msec < 0))
- msec = 0;
- else
- {
- if (msec < 0)
- {
- msec += 1000;
- sec -= 1;
- }
-
- if (sec > interval_seconds ||
- (sec == interval_seconds && msec > interval_milliseconds))
- {
- /* The system time has been set backwards, reset the timeout */
- tcb->last_tv_sec = tv_sec;
- tcb->last_tv_usec = tv_usec;
-
- msec = MIN (_DBUS_INT_MAX, interval);
-
- _dbus_verbose ("System clock went backward\n");
- }
- else
- {
- msec = MIN (_DBUS_INT_MAX, (unsigned int)msec + 1000 * (unsigned int)sec);
- }
- }
-
- *timeout = msec;
-
-#if 0
- printf ("Timeout expires in %d milliseconds\n", *timeout);
-#endif
-
- return msec == 0;
-}
-
-/* Returns TRUE if we have any timeouts or ready file descriptors,
- * which is just used in test code as a debug hack
- */
-
-dbus_bool_t
-bus_loop_iterate (BusLoop *loop,
- dbus_bool_t block)
-{
- dbus_bool_t retval;
- DBusPollFD *fds;
- int n_fds;
- WatchCallback **watches_for_fds;
- int i;
- DBusList *link;
- int n_ready;
- int initial_serial;
- long timeout;
- dbus_bool_t oom_watch_pending;
- int orig_depth;
-
- retval = FALSE;
-
- fds = NULL;
- watches_for_fds = NULL;
- oom_watch_pending = FALSE;
- orig_depth = loop->depth;
-
-#if 0
- _dbus_verbose (" iterate %d timeouts %d watches\n",
- loop->timeout_count, loop->watch_count);
-#endif
-
- if (loop->callbacks == NULL)
- {
- bus_loop_quit (loop);
- goto next_iteration;
- }
-
- /* count enabled watches */
- n_fds = 0;
- link = _dbus_list_get_first_link (&loop->callbacks);
- while (link != NULL)
- {
- DBusList *next = _dbus_list_get_next_link (&loop->callbacks, link);
- Callback *cb = link->data;
- if (cb->type == CALLBACK_WATCH)
- {
- WatchCallback *wcb = WATCH_CALLBACK (cb);
-
- if (!wcb->last_iteration_oom &&
- dbus_watch_get_enabled (wcb->watch))
- ++n_fds;
- }
-
- link = next;
- }
-
- /* fill our array of fds and watches */
- if (n_fds > 0)
- {
- fds = dbus_new0 (DBusPollFD, n_fds);
- while (fds == NULL)
- {
- bus_wait_for_memory ();
- fds = dbus_new0 (DBusPollFD, n_fds);
- }
-
- watches_for_fds = dbus_new (WatchCallback*, n_fds);
- while (watches_for_fds == NULL)
- {
- bus_wait_for_memory ();
- watches_for_fds = dbus_new (WatchCallback*, n_fds);
- }
-
- i = 0;
- link = _dbus_list_get_first_link (&loop->callbacks);
- while (link != NULL)
- {
- DBusList *next = _dbus_list_get_next_link (&loop->callbacks, link);
- Callback *cb = link->data;
- if (cb->type == CALLBACK_WATCH)
- {
- unsigned int flags;
- WatchCallback *wcb = WATCH_CALLBACK (cb);
-
- if (wcb->last_iteration_oom)
- {
- /* we skip this one this time, but reenable it next time,
- * and have a timeout on this iteration
- */
- wcb->last_iteration_oom = FALSE;
- oom_watch_pending = TRUE;
- }
- else if (dbus_watch_get_enabled (wcb->watch))
- {
- watches_for_fds[i] = wcb;
-
- flags = dbus_watch_get_flags (wcb->watch);
-
- fds[i].fd = dbus_watch_get_fd (wcb->watch);
- if (flags & DBUS_WATCH_READABLE)
- fds[i].events |= _DBUS_POLLIN;
- if (flags & DBUS_WATCH_WRITABLE)
- fds[i].events |= _DBUS_POLLOUT;
-
- ++i;
- }
- }
-
- link = next;
- }
-
- _dbus_assert (i == n_fds);
- }
-
- timeout = -1;
- if (loop->timeout_count > 0)
- {
- unsigned long tv_sec;
- unsigned long tv_usec;
-
- retval = TRUE;
-
- _dbus_get_current_time (&tv_sec, &tv_usec);
-
- link = _dbus_list_get_first_link (&loop->callbacks);
- while (link != NULL)
- {
- DBusList *next = _dbus_list_get_next_link (&loop->callbacks, link);
- Callback *cb = link->data;
-
- if (cb->type == CALLBACK_TIMEOUT &&
- dbus_timeout_get_enabled (TIMEOUT_CALLBACK (cb)->timeout))
- {
- TimeoutCallback *tcb = TIMEOUT_CALLBACK (cb);
- int msecs_remaining;
-
- check_timeout (tv_sec, tv_usec, tcb, &msecs_remaining);
-
- if (timeout < 0)
- timeout = msecs_remaining;
- else
- timeout = MIN (msecs_remaining, timeout);
-
- _dbus_assert (timeout >= 0);
-
- if (timeout == 0)
- break; /* it's not going to get shorter... */
- }
-
- link = next;
- }
- }
-
- if (!block)
- {
- timeout = 0;
-#if 0
- printf ("timeout is 0 as we aren't blocking\n");
-#endif
- }
-
- /* if a watch is OOM, don't wait longer than the OOM
- * wait to re-enable it
- */
- if (oom_watch_pending)
- timeout = MIN (timeout, bus_get_oom_wait ());
-
- n_ready = _dbus_poll (fds, n_fds, timeout);
-
- initial_serial = loop->callback_list_serial;
-
- if (loop->timeout_count > 0)
- {
- unsigned long tv_sec;
- unsigned long tv_usec;
-
- _dbus_get_current_time (&tv_sec, &tv_usec);
-
- /* It'd be nice to avoid this O(n) thingy here */
- link = _dbus_list_get_first_link (&loop->callbacks);
- while (link != NULL)
- {
- DBusList *next = _dbus_list_get_next_link (&loop->callbacks, link);
- Callback *cb = link->data;
-
- if (initial_serial != loop->callback_list_serial)
- goto next_iteration;
-
- if (loop->depth != orig_depth)
- goto next_iteration;
-
- if (cb->type == CALLBACK_TIMEOUT &&
- dbus_timeout_get_enabled (TIMEOUT_CALLBACK (cb)->timeout))
- {
- TimeoutCallback *tcb = TIMEOUT_CALLBACK (cb);
- 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 0
- printf (" invoking timeout\n");
-#endif
-
- (* tcb->function) (tcb->timeout,
- cb->data);
- }
- }
-
- link = next;
- }
- }
-
- if (n_ready > 0)
- {
- i = 0;
- while (i < n_fds)
- {
- /* 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;
-
- if (fds[i].revents != 0)
- {
- WatchCallback *wcb;
- unsigned int condition;
-
- wcb = watches_for_fds[i];
-
- condition = 0;
- if (fds[i].revents & _DBUS_POLLIN)
- condition |= DBUS_WATCH_READABLE;
- if (fds[i].revents & _DBUS_POLLOUT)
- condition |= DBUS_WATCH_WRITABLE;
- if (fds[i].revents & _DBUS_POLLHUP)
- condition |= DBUS_WATCH_HANGUP;
- if (fds[i].revents & _DBUS_POLLERR)
- condition |= DBUS_WATCH_ERROR;
-
- /* condition may still be 0 if we got some
- * weird POLLFOO thing like POLLWRBAND
- */
-
- if (condition != 0 &&
- dbus_watch_get_enabled (wcb->watch))
- {
- if (!(* wcb->function) (wcb->watch,
- condition,
- ((Callback*)wcb)->data))
- wcb->last_iteration_oom = TRUE;
-
- retval = TRUE;
- }
- }
-
- ++i;
- }
- }
-
- next_iteration:
- dbus_free (fds);
- dbus_free (watches_for_fds);
-
- return retval;
-}
-
-void
-bus_loop_run (BusLoop *loop)
-{
- int our_exit_depth;
-
- bus_loop_ref (loop);
-
- our_exit_depth = loop->depth;
- loop->depth += 1;
-
- while (loop->depth != our_exit_depth)
- bus_loop_iterate (loop, TRUE);
-
- bus_loop_unref (loop);
-}
-
-void
-bus_loop_quit (BusLoop *loop)
-{
- _dbus_assert (loop->depth > 0);
-
- loop->depth -= 1;
-}
diff --git a/bus/loop.h b/bus/loop.h
deleted file mode 100644
index 19b3bcd4..00000000
--- a/bus/loop.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu" -*- */
-/* loop.h Main loop for daemon
- *
- * Copyright (C) 2003 Red Hat, Inc.
- *
- * Licensed under the Academic Free License version 1.2
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-#ifndef BUS_LOOP_H
-#define BUS_LOOP_H
-
-#include <dbus/dbus.h>
-
-typedef struct BusLoop BusLoop;
-
-typedef dbus_bool_t (* BusWatchFunction) (DBusWatch *watch,
- unsigned int condition,
- void *data);
-typedef void (* BusTimeoutFunction) (DBusTimeout *timeout,
- void *data);
-
-
-BusLoop* bus_loop_new (void);
-void bus_loop_ref (BusLoop *loop);
-void bus_loop_unref (BusLoop *loop);
-dbus_bool_t bus_loop_add_watch (BusLoop *loop,
- DBusWatch *watch,
- BusWatchFunction function,
- void *data,
- DBusFreeFunction free_data_func);
-void bus_loop_remove_watch (BusLoop *loop,
- DBusWatch *watch,
- BusWatchFunction function,
- void *data);
-dbus_bool_t bus_loop_add_timeout (BusLoop *loop,
- DBusTimeout *timeout,
- BusTimeoutFunction function,
- void *data,
- DBusFreeFunction free_data_func);
-void bus_loop_remove_timeout (BusLoop *loop,
- DBusTimeout *timeout,
- BusTimeoutFunction function,
- void *data);
-void bus_loop_run (BusLoop *loop);
-void bus_loop_quit (BusLoop *loop);
-dbus_bool_t bus_loop_iterate (BusLoop *loop,
- dbus_bool_t block);
-
-
-#endif /* BUS_LOOP_H */
diff --git a/bus/main.c b/bus/main.c
index d18d61ac..ef3f013c 100644
--- a/bus/main.c
+++ b/bus/main.c
@@ -21,7 +21,6 @@
*
*/
#include "bus.h"
-#include "loop.h"
#include <dbus/dbus-internals.h>
#include <stdio.h>
#include <stdlib.h>
@@ -40,7 +39,7 @@ signal_handler (int sig)
case SIGHUP:
got_sighup = TRUE;
case SIGTERM:
- bus_loop_quit (bus_context_get_loop (context));
+ _dbus_loop_quit (bus_context_get_loop (context));
break;
}
}
@@ -230,7 +229,7 @@ main (int argc, char **argv)
_dbus_set_signal_handler (SIGTERM, signal_handler);
_dbus_verbose ("We are on D-Bus...\n");
- bus_loop_run (bus_context_get_loop (context));
+ _dbus_loop_run (bus_context_get_loop (context));
bus_context_shutdown (context);
bus_context_unref (context);
diff --git a/bus/test.c b/bus/test.c
index cf3ef8e8..31c279f9 100644
--- a/bus/test.c
+++ b/bus/test.c
@@ -25,7 +25,6 @@
#ifdef DBUS_BUILD_TESTS
#include "test.h"
-#include "loop.h"
#include <dbus/dbus-internals.h>
#include <dbus/dbus-list.h>
@@ -34,7 +33,7 @@
* are different from the real handlers in connection.c
*/
static DBusList *clients = NULL;
-static BusLoop *client_loop = NULL;
+static DBusLoop *client_loop = NULL;
static dbus_bool_t
client_watch_callback (DBusWatch *watch,
@@ -59,9 +58,9 @@ add_client_watch (DBusWatch *watch,
{
DBusConnection *connection = data;
- return bus_loop_add_watch (client_loop,
- watch, client_watch_callback, connection,
- NULL);
+ return _dbus_loop_add_watch (client_loop,
+ watch, client_watch_callback, connection,
+ NULL);
}
static void
@@ -70,8 +69,8 @@ remove_client_watch (DBusWatch *watch,
{
DBusConnection *connection = data;
- bus_loop_remove_watch (client_loop,
- watch, client_watch_callback, connection);
+ _dbus_loop_remove_watch (client_loop,
+ watch, client_watch_callback, connection);
}
static void
@@ -94,7 +93,7 @@ add_client_timeout (DBusTimeout *timeout,
{
DBusConnection *connection = data;
- return bus_loop_add_timeout (client_loop, timeout, client_timeout_callback, connection, NULL);
+ return _dbus_loop_add_timeout (client_loop, timeout, client_timeout_callback, connection, NULL);
}
static void
@@ -103,7 +102,7 @@ remove_client_timeout (DBusTimeout *timeout,
{
DBusConnection *connection = data;
- bus_loop_remove_timeout (client_loop, timeout, client_timeout_callback, connection);
+ _dbus_loop_remove_timeout (client_loop, timeout, client_timeout_callback, connection);
}
static DBusHandlerResult
@@ -121,7 +120,7 @@ client_disconnect_handler (DBusMessageHandler *handler,
if (clients == NULL)
{
- bus_loop_unref (client_loop);
+ _dbus_loop_unref (client_loop);
client_loop = NULL;
}
@@ -199,7 +198,7 @@ bus_setup_debug_client (DBusConnection *connection)
if (client_loop == NULL)
{
- client_loop = bus_loop_new ();
+ client_loop = _dbus_loop_new ();
if (client_loop == NULL)
goto out;
}
@@ -250,7 +249,7 @@ bus_setup_debug_client (DBusConnection *connection)
if (clients == NULL)
{
- bus_loop_unref (client_loop);
+ _dbus_loop_unref (client_loop);
client_loop = NULL;
}
}
@@ -304,10 +303,10 @@ bus_test_run_clients_loop (void)
return;
/* Do one blocking wait, since we're expecting data */
- bus_loop_iterate (client_loop, TRUE);
+ _dbus_loop_iterate (client_loop, TRUE);
/* Then mop everything up */
- while (bus_loop_iterate (client_loop, FALSE))
+ while (_dbus_loop_iterate (client_loop, FALSE))
;
}
@@ -315,10 +314,10 @@ void
bus_test_run_bus_loop (BusContext *context)
{
/* Do one blocking wait, since we're expecting data */
- bus_loop_iterate (bus_context_get_loop (context), TRUE);
+ _dbus_loop_iterate (bus_context_get_loop (context), TRUE);
/* Then mop everything up */
- while (bus_loop_iterate (bus_context_get_loop (context), FALSE))
+ while (_dbus_loop_iterate (bus_context_get_loop (context), FALSE))
;
}
@@ -330,8 +329,8 @@ bus_test_run_everything (BusContext *context)
i = 0;
while (i < 2)
{
- while (bus_loop_iterate (bus_context_get_loop (context), FALSE) ||
- (client_loop == NULL || bus_loop_iterate (client_loop, FALSE)))
+ while (_dbus_loop_iterate (bus_context_get_loop (context), FALSE) ||
+ (client_loop == NULL || _dbus_loop_iterate (client_loop, FALSE)))
;
++i;
}
diff --git a/bus/utils.c b/bus/utils.c
index df061165..65873b59 100644
--- a/bus/utils.c
+++ b/bus/utils.c
@@ -25,26 +25,10 @@
#include <config.h>
#include "utils.h"
#include <dbus/dbus-sysdeps.h>
+#include <dbus/dbus-mainloop.h>
const char bus_no_memory_message[] = "Memory allocation failure in message bus";
-int
-bus_get_oom_wait (void)
-{
-#ifdef DBUS_BUILD_TESTS
- /* make tests go fast */
- return 0;
-#else
- return 500;
-#endif
-}
-
-void
-bus_wait_for_memory (void)
-{
- _dbus_sleep_milliseconds (bus_get_oom_wait ());
-}
-
void
bus_connection_dispatch_all_messages (DBusConnection *connection)
{
@@ -58,7 +42,7 @@ bus_connection_dispatch_one_message (DBusConnection *connection)
DBusDispatchStatus status;
while ((status = dbus_connection_dispatch (connection)) == DBUS_DISPATCH_NEED_MEMORY)
- bus_wait_for_memory ();
+ _dbus_wait_for_memory ();
return status == DBUS_DISPATCH_DATA_REMAINS;
}
diff --git a/bus/utils.h b/bus/utils.h
index 5b30de60..15f05088 100644
--- a/bus/utils.h
+++ b/bus/utils.h
@@ -27,9 +27,6 @@
#include <dbus/dbus.h>
-int bus_get_oom_wait (void);
-void bus_wait_for_memory (void);
-
extern const char bus_no_memory_message[];
#define BUS_SET_OOM(error) dbus_set_error ((error), DBUS_ERROR_NO_MEMORY, bus_no_memory_message)
diff --git a/dbus/Makefile.am b/dbus/Makefile.am
index 7d5ed501..957227e8 100644
--- a/dbus/Makefile.am
+++ b/dbus/Makefile.am
@@ -22,7 +22,9 @@ dbusinclude_HEADERS= \
dbus-threads.h \
dbus-types.h
-DBUS_SOURCES= \
+### source code that goes in the installed client library
+### and is specific to library functionality
+DBUS_LIB_SOURCES= \
dbus-address.c \
dbus-auth.c \
dbus-auth.h \
@@ -68,7 +70,11 @@ DBUS_SOURCES= \
## dbus-md5.c \
## dbus-md5.h \
-UTIL_SOURCES= \
+### source code that goes in the installed client library
+### AND is generic utility functionality used by the
+### daemon or test programs (all symbols in here should
+### be underscore-prefixed)
+DBUS_SHARED_SOURCES= \
dbus-dataslot.c \
dbus-dataslot.h \
dbus-hash.c \
@@ -92,13 +98,23 @@ UTIL_SOURCES= \
dbus-sysdeps.c \
dbus-sysdeps.h
+### source code that is generic utility functionality used
+### by the bus daemon or test apps, but is NOT included
+### in the D-BUS client library (all symbols in here
+### should be underscore-prefixed but don't really need
+### to be unless they move to DBUS_SHARED_SOURCES later)
+DBUS_UTIL_SOURCES= \
+ dbus-mainloop.c \
+ dbus-mainloop.h
+
libdbus_1_la_SOURCES= \
- $(DBUS_SOURCES) \
- $(UTIL_SOURCES)
+ $(DBUS_LIB_SOURCES) \
+ $(DBUS_SHARED_SOURCES)
libdbus_convenience_la_SOURCES= \
- $(DBUS_SOURCES) \
- $(UTIL_SOURCES)
+ $(DBUS_LIB_SOURCES) \
+ $(DBUS_SHARED_SOURCES) \
+ $(DBUS_UTIL_SOURCES)
## this library is the same as libdbus, but exports all the symbols
## and is only used for static linking within the dbus package.