summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'dbus/dbus-bus.c')
-rw-r--r--dbus/dbus-bus.c124
1 files changed, 68 insertions, 56 deletions
diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c
index 99ef5ade..cc612a78 100644
--- a/dbus/dbus-bus.c
+++ b/dbus/dbus-bus.c
@@ -2,6 +2,7 @@
/* dbus-bus.c Convenience functions for communicating with the bus.
*
* Copyright (C) 2003 CodeFactory AB
+ * Copyright (C) 2003 Red Hat, Inc.
*
* Licensed under the Academic Free License version 1.2
*
@@ -23,29 +24,32 @@
#include "dbus-bus.h"
#include "dbus-protocol.h"
+#include "dbus-internals.h"
/**
- * @defgroup DBusBus Convenience functinos for communicating with the bus.
+ * @defgroup DBusBus Message bus APIs
* @ingroup DBus
- * @brief Convenience functinos for communicating with the bus.
+ * @brief Functions for communicating with the message bus
*
* @{
*/
/**
- * Registers a connection with the bus. This is needed to send messages
- * to other clients.
+ * Registers a connection with the bus. This must be the first
+ * thing an application does when connecting to the message bus.
*
- * @param connection The connection
- * @param result address where a result code can be returned.
- * @returns the service name of which the client is known as.
+ * @todo if we get an error reply, it has to be converted into
+ * DBusError and returned
+ *
+ * @param connection the connection
+ * @param error place to store errors
+ * @returns the client's unique service name, #NULL on error
*/
-char *
+char*
dbus_bus_register_client (DBusConnection *connection,
- DBusResultCode *result)
+ DBusError *error)
{
DBusMessage *message, *reply;
- DBusResultCode code;
char *name;
message = dbus_message_new (DBUS_SERVICE_DBUS,
@@ -53,56 +57,61 @@ dbus_bus_register_client (DBusConnection *connection,
if (!message)
{
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ _DBUS_SET_OOM (error);
return NULL;
}
- reply = dbus_connection_send_message_with_reply_and_block (connection, message, -1, result);
+ reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
dbus_message_unref (message);
- if (!reply)
- return NULL;
-
- code = dbus_message_get_args (reply,
- DBUS_TYPE_STRING, &name,
- 0);
- if (code != DBUS_RESULT_SUCCESS)
+ if (reply == NULL)
{
- dbus_set_result (result, code);
+ _DBUS_ASSERT_ERROR_IS_SET (error);
return NULL;
}
- dbus_set_result (result, DBUS_RESULT_SUCCESS);
-
+ if (!dbus_message_get_args (reply, error,
+ DBUS_TYPE_STRING, &name,
+ 0))
+ {
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ return NULL;
+ }
+
return name;
}
/**
* Asks the bus to try to acquire a certain service.
*
+ * @todo these docs are not complete, need to document the
+ * return value and flags
+ *
+ * @todo if we get an error reply, it has to be converted into
+ * DBusError and returned
+ *
* @param connection the connection
* @param service_name the service name
* @param flags flags
- * @param result address where a result code can be returned.
- * @returns a result code.
+ * @param error location to store the error
+ * @returns a result code, -1 if error is set
*/
int
dbus_bus_acquire_service (DBusConnection *connection,
const char *service_name,
unsigned int flags,
- DBusResultCode *result)
+ DBusError *error)
{
DBusMessage *message, *reply;
int service_result;
- DBusResultCode code;
message = dbus_message_new (DBUS_SERVICE_DBUS,
DBUS_MESSAGE_ACQUIRE_SERVICE);
- if (!message)
+ if (message == NULL)
{
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ _DBUS_SET_OOM (error);
return -1;
}
@@ -112,26 +121,28 @@ dbus_bus_acquire_service (DBusConnection *connection,
0))
{
dbus_message_unref (message);
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ _DBUS_SET_OOM (error);
return -1;
}
- reply = dbus_connection_send_message_with_reply_and_block (connection, message, -1, result);
+ reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
+ error);
+
dbus_message_unref (message);
- if (!reply)
- return -1;
-
- code = dbus_message_get_args (reply,
- DBUS_TYPE_UINT32, &service_result,
- 0);
- if (code != DBUS_RESULT_SUCCESS)
+ if (reply == NULL)
{
- dbus_set_result (result, code);
+ _DBUS_ASSERT_ERROR_IS_SET (error);
return -1;
}
- dbus_set_result (result, DBUS_RESULT_SUCCESS);
+ if (!dbus_message_get_args (reply, error,
+ DBUS_TYPE_UINT32, &service_result,
+ 0))
+ {
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ return -1;
+ }
return service_result;
}
@@ -139,25 +150,26 @@ dbus_bus_acquire_service (DBusConnection *connection,
/**
* Checks whether a certain service exists.
*
+ * @todo the SERVICE_EXISTS message should use BOOLEAN not UINT32
+ *
* @param connection the connection
* @param service_name the service name
- * @param result address where a result code can be returned.
- * @returns #TRUE if the service exists, #FALSE otherwise.
+ * @param error location to store any errors
+ * @returns #TRUE if the service exists, #FALSE if not or on error
*/
dbus_bool_t
dbus_bus_service_exists (DBusConnection *connection,
const char *service_name,
- DBusResultCode *result)
+ DBusError *error)
{
DBusMessage *message, *reply;
unsigned int exists;
- DBusResultCode code;
message = dbus_message_new (DBUS_SERVICE_DBUS,
DBUS_MESSAGE_SERVICE_EXISTS);
- if (!message)
+ if (message == NULL)
{
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ _DBUS_SET_OOM (error);
return FALSE;
}
@@ -166,27 +178,27 @@ dbus_bus_service_exists (DBusConnection *connection,
0))
{
dbus_message_unref (message);
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ _DBUS_SET_OOM (error);
return FALSE;
}
- reply = dbus_connection_send_message_with_reply_and_block (connection, message, -1, result);
+ reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
dbus_message_unref (message);
- if (!reply)
- return FALSE;
+ if (reply == NULL)
+ {
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ return FALSE;
+ }
- code = dbus_message_get_args (reply,
- DBUS_TYPE_UINT32, &exists,
- 0);
- if (code != DBUS_RESULT_SUCCESS)
+ if (!dbus_message_get_args (reply, error,
+ DBUS_TYPE_UINT32, &exists,
+ 0))
{
- dbus_set_result (result, code);
+ _DBUS_ASSERT_ERROR_IS_SET (error);
return FALSE;
}
- dbus_set_result (result, DBUS_RESULT_SUCCESS);
-
return (exists != FALSE);
}