summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@codefactory.se>2003-03-28 14:23:10 +0000
committerAnders Carlsson <andersca@codefactory.se>2003-03-28 14:23:10 +0000
commitd361874ef6a94a61fa3e0534d8352392edf9bbb9 (patch)
tree9696b9418e3b373dc3c5a2520e94cdfb03ac9601
parentbf99381351b802fb3348a24037898222aae631e2 (diff)
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.
-rw-r--r--ChangeLog9
-rw-r--r--dbus/dbus-bus.c95
-rw-r--r--dbus/dbus-bus.h32
-rw-r--r--dbus/dbus-memory.c2
4 files changed, 125 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 9f7ce5ad..276235cd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+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,
diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c
index 1b63d608..c3978db2 100644
--- a/dbus/dbus-bus.c
+++ b/dbus/dbus-bus.c
@@ -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.
diff --git a/dbus/dbus-bus.h b/dbus/dbus-bus.h
index 9f25eeb6..508dc5b1 100644
--- a/dbus/dbus-bus.h
+++ b/dbus/dbus-bus.h
@@ -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;
diff --git a/dbus/dbus-memory.c b/dbus/dbus-memory.c
index 11d52045..fbda7139 100644
--- a/dbus/dbus-memory.c
+++ b/dbus/dbus-memory.c
@@ -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)