Commit d361874e authored by Anders Carlsson's avatar Anders Carlsson

2003-03-28 Anders Carlsson <andersca@codefactory.se>

	* dbus/dbus-bus.c: (bus_data_free), (dbus_bus_get):
	* dbus/dbus-bus.h:
	Add dbus_bus_get.

	* dbus/dbus-memory.c:
	Fix a doc comment.
parent bf993813
2003-03-28 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-bus.c: (bus_data_free), (dbus_bus_get):
* dbus/dbus-bus.h:
Add dbus_bus_get.
* dbus/dbus-memory.c:
Fix a doc comment.
2003-03-28 Havoc Pennington <hp@pobox.com>
* bus/test.c (bus_test_flush_bus): remove the sleep from here,
......
......@@ -51,6 +51,7 @@ typedef struct
{
char *base_service; /**< Base service name of this connection */
DBusConnection **connection; /**< Pointer to bus_connections entry */
} BusData;
/** The slot we have reserved to store BusData
......@@ -65,6 +66,7 @@ static int bus_data_slot_refcount = 0;
*/
_DBUS_DEFINE_GLOBAL_LOCK (bus);
static dbus_bool_t
data_slot_ref (void)
{
......@@ -114,6 +116,9 @@ bus_data_free (void *data)
{
BusData *bd = data;
if (bd->connection)
*bd->connection = NULL;
dbus_free (bd->base_service);
dbus_free (bd);
......@@ -163,6 +168,96 @@ ensure_bus_data (DBusConnection *connection)
* @{
*/
/** Number of bus types */
#define BUS_TYPES 2
static DBusConnection *bus_connections[BUS_TYPES];
/**
* Connects to a bus daemon and registers the client with it.
* If a connection to the bus already exists, then that connection is returned.
*
* @todo alex thinks we should nullify the connection when we get a disconnect-message.
*
* @param type bus type
* @param error address where an error can be returned.
* @returns a DBusConnection
*/
DBusConnection *
dbus_bus_get (DBusBusType type,
DBusError *error)
{
const char *name, *value;
DBusConnection *connection;
BusData *bd;
if (type <= 0 || type >= BUS_TYPES)
{
_dbus_assert_not_reached ("Invalid bus type specified.");
return NULL;
}
_DBUS_LOCK (bus);
if (bus_connections[type] != NULL)
{
connection = bus_connections[type];
dbus_connection_ref (connection);
_DBUS_UNLOCK (bus);
return connection;
}
switch (type)
{
case DBUS_BUS_SESSION:
name = "DBUS_SESSION_BUS_ADDRESS";
break;
case DBUS_BUS_SYSTEM:
name = "DBUS_SYSTEM_BUS_ADDRESS";
break;
}
value = _dbus_getenv (name);
if (!value)
{
dbus_set_error (error, DBUS_ERROR_FAILED,
"Could not get bus daemon address.");
_DBUS_UNLOCK (bus);
return NULL;
}
connection = dbus_connection_open (value, error);
if (!connection)
{
_DBUS_UNLOCK (bus);
return NULL;
}
if (!dbus_bus_register (connection, error))
{
dbus_connection_disconnect (connection);
dbus_connection_unref (connection);
_DBUS_UNLOCK (bus);
return NULL;
}
bus_connections[type] = connection;
bd = ensure_bus_data (connection);
_dbus_assert (bd != NULL);
bd->connection = &bus_connections[type];
_DBUS_UNLOCK (bus);
return connection;
}
/**
* Registers a connection with the bus. This must be the first
* thing an application does when connecting to the message bus.
......
......@@ -31,18 +31,26 @@
DBUS_BEGIN_DECLS;
dbus_bool_t dbus_bus_register (DBusConnection *connection,
DBusError *error);
dbus_bool_t dbus_bus_set_base_service (DBusConnection *connection,
const char *base_service);
const char* dbus_bus_get_base_service (DBusConnection *connection);
int dbus_bus_acquire_service (DBusConnection *connection,
const char *service_name,
unsigned int flags,
DBusError *error);
dbus_bool_t dbus_bus_service_exists (DBusConnection *connection,
const char *service_name,
DBusError *error);
typedef enum
{
DBUS_BUS_SESSION, /**< The login session bus */
DBUS_BUS_SYSTEM /**< The system bus */
} DBusBusType;
DBusConnection *dbus_bus_get (DBusBusType type,
DBusError *error);
dbus_bool_t dbus_bus_register (DBusConnection *connection,
DBusError *error);
dbus_bool_t dbus_bus_set_base_service (DBusConnection *connection,
const char *base_service);
const char* dbus_bus_get_base_service (DBusConnection *connection);
int dbus_bus_acquire_service (DBusConnection *connection,
const char *service_name,
unsigned int flags,
DBusError *error);
dbus_bool_t dbus_bus_service_exists (DBusConnection *connection,
const char *service_name,
DBusError *error);
DBUS_END_DECLS;
......
......@@ -190,7 +190,7 @@ _dbus_get_fail_alloc_counter (void)
* Sets how many mallocs to fail when the fail alloc counter reaches
* 0.
*
* @param number to fail
* @param failures_per_failure number to fail
*/
void
_dbus_set_fail_alloc_failures (int failures_per_failure)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment