summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-05-27 11:43:25 +0000
committerMarcel Holtmann <marcel@holtmann.org>2008-05-27 11:43:25 +0000
commit40b5cf346c985b629c927c5b2a6d188ccd0966dd (patch)
treeaffbcf4c5baed5178e8e9b06e582273c559355d9
parentd0b06ea8fd1a8642c99d6b2c7661d562acf3c43e (diff)
Restore error handling for the new manager interface
-rw-r--r--common/error.c6
-rw-r--r--common/error.h2
-rw-r--r--hcid/manager.c36
3 files changed, 23 insertions, 21 deletions
diff --git a/common/error.c b/common/error.c
index 656c7299..51f4f4bc 100644
--- a/common/error.c
+++ b/common/error.c
@@ -35,6 +35,12 @@
#include "error.h"
+DBusMessage *create_errno_message(DBusMessage *msg, int err)
+{
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
+ strerror(err));
+}
+
/**
org.bluez.Error.DeviceUnreachable:
diff --git a/common/error.h b/common/error.h
index 44b6f417..a2492601 100644
--- a/common/error.h
+++ b/common/error.h
@@ -27,6 +27,8 @@
#define ERROR_INTERFACE "org.bluez.Error"
+DBusMessage *create_errno_message(DBusMessage *msg, int err);
+
DBusHandlerResult error_device_unreachable(DBusConnection *conn,
DBusMessage *msg);
diff --git a/hcid/manager.c b/hcid/manager.c
index 6d84d4b5..43019b2a 100644
--- a/hcid/manager.c
+++ b/hcid/manager.c
@@ -356,19 +356,20 @@ static DBusSignalVTable old_manager_signals[] = {
{ NULL, NULL }
};
+static inline DBusMessage *no_such_adapter(DBusMessage *msg)
+{
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".NoSuchAdapter",
+ "No such adapter");
+}
+
static DBusMessage *default_adapter(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
char path[MAX_PATH_LENGTH], *path_ptr = path;
- if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING))
- // FIXME return error_invalid_arguments(conn, msg, NULL);
- return NULL;
-
if (default_adapter_id < 0)
- // FIXME return error_no_such_adapter(conn, msg);
- return NULL;
+ return no_such_adapter(msg);
reply = dbus_message_new_method_return(msg);
if (!reply)
@@ -391,10 +392,8 @@ static DBusMessage *find_adapter(DBusConnection *conn,
const char *pattern;
int dev_id;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_STRING, &pattern,
- DBUS_TYPE_INVALID))
- // FIXME return error_invalid_arguments(conn, msg, NULL);
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern,
+ DBUS_TYPE_INVALID))
return NULL;
/* hci_devid() would make sense to use here, except it
@@ -405,16 +404,13 @@ static DBusMessage *find_adapter(DBusConnection *conn,
dev_id = find_by_address(pattern);
if (dev_id < 0)
- // FIXME return error_no_such_adapter(conn, msg);
- return NULL;
+ return no_such_adapter(msg);
if (hci_devinfo(dev_id, &di) < 0)
- // FIXME return error_no_such_adapter(conn, msg);
- return NULL;
+ return no_such_adapter(msg);
if (hci_test_bit(HCI_RAW, &di.flags))
- // FIXME return error_no_such_adapter(conn, msg);
- return NULL;
+ return no_such_adapter(msg);
reply = dbus_message_new_method_return(msg);
if (!reply)
@@ -440,8 +436,7 @@ static DBusMessage *list_adapters(DBusConnection *conn,
sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (sk < 0)
- // FIXME return error_failed_errno(conn, msg, errno);
- return NULL;
+ return create_errno_message(msg, errno);
dl = g_malloc0(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
@@ -449,11 +444,10 @@ static DBusMessage *list_adapters(DBusConnection *conn,
dr = dl->dev_req;
if (ioctl(sk, HCIGETDEVLIST, dl) < 0) {
- //int err = errno;
+ int err = errno;
close(sk);
g_free(dl);
- // FIXME return error_failed_errno(conn, msg, err);
- return NULL;
+ return create_errno_message(msg, err);
}
dr = dl->dev_req;