Commit df008ef9 authored by Havoc Pennington's avatar Havoc Pennington

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
parent 856361ff
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> 2003-04-06 Havoc Pennington <hp@pobox.com>
* dbus/dbus-sysdeps.c (_dbus_become_daemon): write the pidfile * dbus/dbus-sysdeps.c (_dbus_become_daemon): write the pidfile
......
...@@ -40,8 +40,6 @@ BUS_SOURCES= \ ...@@ -40,8 +40,6 @@ BUS_SOURCES= \
dispatch.h \ dispatch.h \
driver.c \ driver.c \
driver.h \ driver.h \
loop.c \
loop.h \
policy.c \ policy.c \
policy.h \ policy.h \
services.c \ services.c \
......
...@@ -90,7 +90,7 @@ handle_timeout_callback (DBusTimeout *timeout, ...@@ -90,7 +90,7 @@ handle_timeout_callback (DBusTimeout *timeout,
BusPendingActivation *pending_activation = data; BusPendingActivation *pending_activation = data;
while (!dbus_timeout_handle (pending_activation->timeout)) while (!dbus_timeout_handle (pending_activation->timeout))
bus_wait_for_memory (); _dbus_wait_for_memory ();
} }
static void static void
...@@ -103,9 +103,9 @@ bus_pending_activation_free (BusPendingActivation *pending_activation) ...@@ -103,9 +103,9 @@ bus_pending_activation_free (BusPendingActivation *pending_activation)
if (pending_activation->timeout_added) if (pending_activation->timeout_added)
{ {
bus_loop_remove_timeout (bus_context_get_loop (pending_activation->activation->context), _dbus_loop_remove_timeout (bus_context_get_loop (pending_activation->activation->context),
pending_activation->timeout, pending_activation->timeout,
handle_timeout_callback, pending_activation); handle_timeout_callback, pending_activation);
pending_activation->timeout_added = FALSE; pending_activation->timeout_added = FALSE;
} }
...@@ -604,7 +604,7 @@ pending_activation_failed (BusPendingActivation *pending_activation, ...@@ -604,7 +604,7 @@ pending_activation_failed (BusPendingActivation *pending_activation,
{ {
/* FIXME use preallocated OOM messages instead of bus_wait_for_memory() */ /* FIXME use preallocated OOM messages instead of bus_wait_for_memory() */
while (!try_send_activation_failure (pending_activation, how)) while (!try_send_activation_failure (pending_activation, how))
bus_wait_for_memory (); _dbus_wait_for_memory ();
/* Destroy this pending activation */ /* Destroy this pending activation */
_dbus_hash_table_remove_string (pending_activation->activation->pending_activations, _dbus_hash_table_remove_string (pending_activation->activation->pending_activations,
...@@ -650,9 +650,9 @@ add_babysitter_watch (DBusWatch *watch, ...@@ -650,9 +650,9 @@ add_babysitter_watch (DBusWatch *watch,
{ {
BusPendingActivation *pending_activation = data; BusPendingActivation *pending_activation = data;
return bus_loop_add_watch (bus_context_get_loop (pending_activation->activation->context), return _dbus_loop_add_watch (bus_context_get_loop (pending_activation->activation->context),
watch, babysitter_watch_callback, pending_activation, watch, babysitter_watch_callback, pending_activation,
NULL); NULL);
} }
static void static void
...@@ -661,8 +661,8 @@ remove_babysitter_watch (DBusWatch *watch, ...@@ -661,8 +661,8 @@ remove_babysitter_watch (DBusWatch *watch,
{ {
BusPendingActivation *pending_activation = data; BusPendingActivation *pending_activation = data;
bus_loop_remove_watch (bus_context_get_loop (pending_activation->activation->context), _dbus_loop_remove_watch (bus_context_get_loop (pending_activation->activation->context),
watch, babysitter_watch_callback, pending_activation); watch, babysitter_watch_callback, pending_activation);
} }
static dbus_bool_t static dbus_bool_t
...@@ -806,11 +806,11 @@ bus_activation_activate_service (BusActivation *activation, ...@@ -806,11 +806,11 @@ bus_activation_activate_service (BusActivation *activation,
return FALSE; return FALSE;
} }
if (!bus_loop_add_timeout (bus_context_get_loop (activation->context), if (!_dbus_loop_add_timeout (bus_context_get_loop (activation->context),
pending_activation->timeout, pending_activation->timeout,
handle_timeout_callback, handle_timeout_callback,
pending_activation, pending_activation,
NULL)) NULL))
{ {
BUS_SET_OOM (error); BUS_SET_OOM (error);
bus_pending_activation_free (pending_activation); bus_pending_activation_free (pending_activation);
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
*/ */
#include "bus.h" #include "bus.h"
#include "loop.h"
#include "activation.h" #include "activation.h"
#include "connection.h" #include "connection.h"
#include "services.h" #include "services.h"
...@@ -38,7 +37,7 @@ struct BusContext ...@@ -38,7 +37,7 @@ struct BusContext
int refcount; int refcount;
char *type; char *type;
char *address; char *address;
BusLoop *loop; DBusLoop *loop;
DBusList *servers; DBusList *servers;
BusConnections *connections; BusConnections *connections;
BusActivation *activation; BusActivation *activation;
...@@ -138,9 +137,9 @@ add_server_watch (DBusWatch *watch, ...@@ -138,9 +137,9 @@ add_server_watch (DBusWatch *watch,
context = server_get_context (server); context = server_get_context (server);
return bus_loop_add_watch (context->loop, return _dbus_loop_add_watch (context->loop,
watch, server_watch_callback, server, watch, server_watch_callback, server,
NULL); NULL);
} }
static void static void
...@@ -152,8 +151,8 @@ remove_server_watch (DBusWatch *watch, ...@@ -152,8 +151,8 @@ remove_server_watch (DBusWatch *watch,
context = server_get_context (server); context = server_get_context (server);
bus_loop_remove_watch (context->loop, _dbus_loop_remove_watch (context->loop,
watch, server_watch_callback, server); watch, server_watch_callback, server);
} }
...@@ -174,8 +173,8 @@ add_server_timeout (DBusTimeout *timeout, ...@@ -174,8 +173,8 @@ add_server_timeout (DBusTimeout *timeout,
context = server_get_context (server); context = server_get_context (server);
return bus_loop_add_timeout (context->loop, return _dbus_loop_add_timeout (context->loop,
timeout, server_timeout_callback, server, NULL); timeout, server_timeout_callback, server, NULL);
} }
static void static void
...@@ -187,8 +186,8 @@ remove_server_timeout (DBusTimeout *timeout, ...@@ -187,8 +186,8 @@ remove_server_timeout (DBusTimeout *timeout,
context = server_get_context (server); context = server_get_context (server);
bus_loop_remove_timeout (context->loop, _dbus_loop_remove_timeout (context->loop,
timeout, server_timeout_callback, server); timeout, server_timeout_callback, server);
} }
static void static void
...@@ -396,7 +395,7 @@ bus_context_new (const DBusString *config_file, ...@@ -396,7 +395,7 @@ bus_context_new (const DBusString *config_file,
*/ */
context->max_completed_connections = 1024; context->max_completed_connections = 1024;
context->loop = bus_loop_new (); context->loop = _dbus_loop_new ();
if (context->loop == NULL) if (context->loop == NULL)
{ {
BUS_SET_OOM (error); BUS_SET_OOM (error);
...@@ -755,7 +754,7 @@ bus_context_unref (BusContext *context) ...@@ -755,7 +754,7 @@ bus_context_unref (BusContext *context)
if (context->loop) if (context->loop)
{ {
bus_loop_unref (context->loop); _dbus_loop_unref (context->loop);
context->loop = NULL; context->loop = NULL;
} }
...@@ -798,7 +797,7 @@ bus_context_get_activation (BusContext *context) ...@@ -798,7 +797,7 @@ bus_context_get_activation (BusContext *context)
return context->activation; return context->activation;
} }
BusLoop* DBusLoop*
bus_context_get_loop (BusContext *context) bus_context_get_loop (BusContext *context)
{ {
return context->loop; return context->loop;
......
...@@ -28,8 +28,7 @@ ...@@ -28,8 +28,7 @@
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <dbus/dbus-string.h> #include <dbus/dbus-string.h>
#include <dbus/dbus-mainloop.h>
#include "loop.h"
typedef struct BusActivation BusActivation; typedef struct BusActivation BusActivation;
typedef struct BusConnections BusConnections; typedef struct BusConnections BusConnections;
...@@ -51,7 +50,7 @@ const char* bus_context_get_address (BusContext *context) ...@@ -51,7 +50,7 @@ const char* bus_context_get_address (BusContext *context)
BusRegistry* bus_context_get_registry (BusContext *context); BusRegistry* bus_context_get_registry (BusContext *context);
BusConnections* bus_context_get_connections (BusContext *context); BusConnections* bus_context_get_connections (BusContext *context);
BusActivation* bus_context_get_activation (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, dbus_bool_t bus_context_allow_user (BusContext *context,
unsigned long uid); unsigned long uid);
BusPolicy* bus_context_create_connection_policy (BusContext *context, BusPolicy* bus_context_create_connection_policy (BusContext *context,
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
*/ */
#include "connection.h" #include "connection.h"
#include "dispatch.h" #include "dispatch.h"
#include "loop.h"
#include "policy.h" #include "policy.h"
#include "services.h" #include "services.h"
#include "utils.h" #include "utils.h"
...@@ -89,7 +88,7 @@ connection_data_slot_unref (void) ...@@ -89,7 +88,7 @@ connection_data_slot_unref (void)
} }
} }
static BusLoop* static DBusLoop*
connection_get_loop (DBusConnection *connection) connection_get_loop (DBusConnection *connection)
{ {
BusConnectionData *d; BusConnectionData *d;
...@@ -134,7 +133,7 @@ bus_connection_disconnected (DBusConnection *connection) ...@@ -134,7 +133,7 @@ bus_connection_disconnected (DBusConnection *connection)
while (transaction == NULL) while (transaction == NULL)
{ {
transaction = bus_transaction_new (d->connections->context); transaction = bus_transaction_new (d->connections->context);
bus_wait_for_memory (); _dbus_wait_for_memory ();
} }
if (!bus_service_remove_owner (service, connection, if (!bus_service_remove_owner (service, connection,
...@@ -144,7 +143,7 @@ bus_connection_disconnected (DBusConnection *connection) ...@@ -144,7 +143,7 @@ bus_connection_disconnected (DBusConnection *connection)
{ {
dbus_error_free (&error); dbus_error_free (&error);
bus_transaction_cancel_and_free (transaction); bus_transaction_cancel_and_free (transaction);
bus_wait_for_memory (); _dbus_wait_for_memory ();
goto retry; goto retry;
} }
else else
...@@ -209,9 +208,9 @@ add_connection_watch (DBusWatch *watch, ...@@ -209,9 +208,9 @@ add_connection_watch (DBusWatch *watch,
{ {
DBusConnection *connection = data; DBusConnection *connection = data;
return bus_loop_add_watch (connection_get_loop (connection), return _dbus_loop_add_watch (connection_get_loop (connection),
watch, connection_watch_callback, connection, watch, connection_watch_callback, connection,
NULL); NULL);
} }
static void static void
...@@ -220,8 +219,8 @@ remove_connection_watch (DBusWatch *watch, ...@@ -220,8 +219,8 @@ remove_connection_watch (DBusWatch *watch,
{ {
DBusConnection *connection = data; DBusConnection *connection = data;
bus_loop_remove_watch (connection_get_loop (connection), _dbus_loop_remove_watch (connection_get_loop (connection),
watch, connection_watch_callback, connection); watch, connection_watch_callback, connection);
} }
static void static void
...@@ -246,8 +245,8 @@ add_connection_timeout (DBusTimeout *timeout, ...@@ -246,8 +245,8 @@ add_connection_timeout (DBusTimeout *timeout,
{ {
DBusConnection *connection = data; DBusConnection *connection = data;
return bus_loop_add_timeout (connection_get_loop (connection), return _dbus_loop_add_timeout (connection_get_loop (connection),
timeout, connection_timeout_callback, connection, NULL); timeout, connection_timeout_callback, connection, NULL);
} }
static void static void
...@@ -256,8 +255,8 @@ remove_connection_timeout (DBusTimeout *timeout, ...@@ -256,8 +255,8 @@ remove_connection_timeout (DBusTimeout *timeout,
{ {
DBusConnection *connection = data; DBusConnection *connection = data;
bus_loop_remove_timeout (connection_get_loop (connection), _dbus_loop_remove_timeout (connection_get_loop (connection),
timeout, connection_timeout_callback, connection); timeout, connection_timeout_callback, connection);
} }
static dbus_bool_t static dbus_bool_t
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "utils.h" #include "utils.h"
#include "bus.h" #include "bus.h"
#include "test.h" #include "test.h"
#include "loop.h"
#include <dbus/dbus-internals.h> #include <dbus/dbus-internals.h>
#include <string.h> #include <string.h>
...@@ -176,7 +175,7 @@ bus_dispatch (DBusConnection *connection, ...@@ -176,7 +175,7 @@ bus_dispatch (DBusConnection *connection,
* until we can. * until we can.
*/ */
while (!bus_connection_preallocate_oom_error (connection)) 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 */ /* Ref connection in case we disconnect it at some point in here */
dbus_connection_ref (connection); dbus_connection_ref (connection);
...@@ -537,7 +536,7 @@ kill_client_connection (BusContext *context, ...@@ -537,7 +536,7 @@ kill_client_connection (BusContext *context,
_dbus_assert (s != NULL); _dbus_assert (s != NULL);
while ((base_service = _dbus_strdup (s)) == NULL) while ((base_service = _dbus_strdup (s)) == NULL)
bus_wait_for_memory (); _dbus_wait_for_memory ();
dbus_connection_ref (connection); dbus_connection_ref (connection);
...@@ -805,7 +804,7 @@ check_hello_message (BusContext *context, ...@@ -805,7 +804,7 @@ check_hello_message (BusContext *context,
{ {
_dbus_verbose ("no memory to get service name arg from hello\n"); _dbus_verbose ("no memory to get service name arg from hello\n");
dbus_error_free (&error); dbus_error_free (&error);
bus_wait_for_memory (); _dbus_wait_for_memory ();
goto retry_get_hello_name; goto retry_get_hello_name;
} }
else else
...@@ -819,7 +818,7 @@ check_hello_message (BusContext *context, ...@@ -819,7 +818,7 @@ check_hello_message (BusContext *context,
_dbus_verbose ("Got hello name: %s\n", name); _dbus_verbose ("Got hello name: %s\n", name);
while (!dbus_bus_set_base_service (connection, name)) while (!dbus_bus_set_base_service (connection, name))
bus_wait_for_memory (); _dbus_wait_for_memory ();
scd.skip_connection = NULL; scd.skip_connection = NULL;
scd.failed = FALSE; scd.failed = FALSE;
...@@ -849,7 +848,7 @@ check_hello_message (BusContext *context, ...@@ -849,7 +848,7 @@ check_hello_message (BusContext *context,
{ {
_dbus_verbose ("no memory to get service name arg from acquired\n"); _dbus_verbose ("no memory to get service name arg from acquired\n");
dbus_error_free (&error); dbus_error_free (&error);
bus_wait_for_memory (); _dbus_wait_for_memory ();
goto retry_get_acquired_name; goto retry_get_acquired_name;
} }
else else
......
This diff is collapsed.
/* -*- 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 */
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
* *
*/ */
#include "bus.h" #include "bus.h"
#include "loop.h"
#include <dbus/dbus-internals.h> #include <dbus/dbus-internals.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -40,7 +39,7 @@ signal_handler (int sig) ...@@ -40,7 +39,7 @@ signal_handler (int sig)
case SIGHUP: case SIGHUP:
got_sighup = TRUE; got_sighup = TRUE;
case SIGTERM: case SIGTERM:
bus_loop_quit (bus_context_get_loop (context)); _dbus_loop_quit (bus_context_get_loop (context));
break; break;
} }
} }
...@@ -230,7 +229,7 @@ main (int argc, char **argv) ...@@ -230,7 +229,7 @@ main (int argc, char **argv)
_dbus_set_signal_handler (SIGTERM, signal_handler); _dbus_set_signal_handler (SIGTERM, signal_handler);
_dbus_verbose ("We are on D-Bus...\n"); _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_shutdown (context);
bus_context_unref (context); bus_context_unref (context);
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#ifdef DBUS_BUILD_TESTS #ifdef DBUS_BUILD_TESTS
#include "test.h" #include "test.h"
#include "loop.h"
#include <dbus/dbus-internals.h> #include <dbus/dbus-internals.h>
#include <dbus/dbus-list.h> #include <dbus/dbus-list.h>
...@@ -34,7 +33,7 @@ ...@@ -34,7 +33,7 @@
* are different from the real handlers in connection.c * are different from the real handlers in connection.c
*/ */
static DBusList *clients = NULL; static DBusList *clients = NULL;
static BusLoop *client_loop = NULL; static DBusLoop *client_loop = NULL;
static dbus_bool_t static dbus_bool_t
client_watch_callback (DBusWatch *watch, client_watch_callback (DBusWatch *watch,
...@@ -59,9 +58,9 @@ add_client_watch (DBusWatch *watch, ...@@ -59,9 +58,9 @@ add_client_watch (DBusWatch *watch,
{ {
DBusConnection *connection = data; DBusConnection *connection = data;
return bus_loop_add_watch (client_loop, return _dbus_loop_add_watch (client_loop,
watch, client_watch_callback, connection, watch, client_watch_callback, connection,
NULL); NULL);
} }
static void static void
...@@ -70,8 +69,8 @@ remove_client_watch (DBusWatch *watch, ...@@ -70,8 +69,8 @@ remove_client_watch (DBusWatch *watch,
{ {
DBusConnection *connection = data; DBusConnection *connection = data;
bus_loop_remove_watch (client_loop, _dbus_loop_remove_watch (client_loop,
watch, client_watch_callback, connection); watch, client_watch_callback, connection);
} }
static void static void
...@@ -94,7 +93,7 @@ add_client_timeout (DBusTimeout *timeout, ...@@ -94,7 +93,7 @@ add_client_timeout (DBusTimeout *timeout,
{ {
DBusConnection *connection = data; 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 static void
...@@ -103,7 +102,7 @@ remove_client_timeout (DBusTimeout *timeout, ...@@ -103,7 +102,7 @@ remove_client_timeout (DBusTimeout *timeout,
{ {
DBusConnection *connection = data; 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 static DBusHandlerResult
...@@ -121,7 +120,7 @@ client_disconnect_handler (DBusMessageHandler *handler, ...@@ -121,7 +120,7 @@ client_disconnect_handler (DBusMessageHandler *handler,
if (clients == NULL) if (clients == NULL)
{ {
bus_loop_unref (client_loop); _dbus_loop_unref (client_loop);
client_loop = NULL; client_loop = NULL;
} }
...@@ -199,7 +198,7 @@ bus_setup_debug_client (DBusConnection *connection) ...@@ -199,7 +198,7 @@ bus_setup_debug_client (DBusConnection *connection)
if (client_loop == NULL) if (client_loop == NULL)
{ {
client_loop = bus_loop_new (); client_loop = _dbus_loop_new ();
if (client_loop == NULL) if (client_loop == NULL)
goto out; goto out;
} }
...@@ -250,7 +249,7 @@ bus_setup_debug_client (DBusConnection *connection) ...@@ -250,7 +249,7 @@ bus_setup_debug_client (DBusConnection *connection)
if (clients == NULL) if (clients == NULL)
{ {
bus_loop_unref (client_loop); _dbus_loop_unref (client_loop);
client_loop = NULL; client_loop = NULL;
} }
} }
...@@ -304,10 +303,10 @@ bus_test_run_clients_loop (void) ...@@ -304,10 +303,10 @@ bus_test_run_clients_loop (void)
return; return;
/* Do one blocking wait, since we're expecting data */ /* 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 */ /* Then mop everything up */
while (bus_loop_iterate (client_loop, FALSE)) while (_dbus_loop_iterate (client_loop, FALSE))
; ;