diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2006-03-09 17:57:09 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2006-03-09 17:57:09 +0000 |
commit | 4bac26fbcf785c3a438ac3b2c2edb1227a800023 (patch) | |
tree | def7373f622713fb89e30d96a3b3d6ab5dbbed55 /hcid | |
parent | 148aa53876853a637e5b94f3c6aae5fb2d788c90 (diff) |
Cleanup the error definitions and add some new ones
Diffstat (limited to 'hcid')
-rw-r--r-- | hcid/dbus-adapter.c | 38 | ||||
-rw-r--r-- | hcid/dbus-error.c | 28 | ||||
-rw-r--r-- | hcid/dbus-manager.c | 6 | ||||
-rw-r--r-- | hcid/dbus.h | 7 |
4 files changed, 50 insertions, 29 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c index e25d0252..51eed18a 100644 --- a/hcid/dbus-adapter.c +++ b/hcid/dbus-adapter.c @@ -72,7 +72,7 @@ static DBusMessage *handle_dev_get_address_req(DBusMessage *msg, void *data) err = get_device_address(dbus_data->dev_id, str, sizeof(str)); if (err < 0) - return error_generic(msg, -err); + return error_failed(msg, -err); reply = dbus_message_new_method_return(msg); if (!reply) @@ -93,7 +93,7 @@ static DBusMessage *handle_dev_get_version_req(DBusMessage *msg, void *data) err = get_device_version(dbus_data->dev_id, str, sizeof(str)); if (err < 0) - return error_generic(msg, -err); + return error_failed(msg, -err); reply = dbus_message_new_method_return(msg); if (!reply) @@ -114,7 +114,7 @@ static DBusMessage *handle_dev_get_revision_req(DBusMessage *msg, void *data) err = get_device_revision(dbus_data->dev_id, str, sizeof(str)); if (err < 0) - return error_generic(msg, -err); + return error_failed(msg, -err); reply = dbus_message_new_method_return(msg); if (!reply) @@ -135,7 +135,7 @@ static DBusMessage *handle_dev_get_manufacturer_req(DBusMessage *msg, void *data err = get_device_manufacturer(dbus_data->dev_id, str, sizeof(str)); if (err < 0) - return error_generic(msg, -err); + return error_failed(msg, -err); reply = dbus_message_new_method_return(msg); if (!reply) @@ -156,7 +156,7 @@ static DBusMessage *handle_dev_get_company_req(DBusMessage *msg, void *data) err = get_device_company(dbus_data->dev_id, str, sizeof(str)); if (err < 0) - return error_generic(msg, -err); + return error_failed(msg, -err); reply = dbus_message_new_method_return(msg); if (!reply) @@ -248,7 +248,7 @@ static DBusMessage *handle_dev_set_mode_req(DBusMessage *msg, void *data) dd = hci_open_dev(dbus_data->dev_id); if (dd < 0) - return error_no_such_device(msg); + return error_no_such_adapter(msg); /* Check if the new requested mode is different from the current */ if (current_mode != hci_mode) { @@ -387,13 +387,13 @@ static DBusMessage *handle_dev_get_minor_class_req(DBusMessage *msg, void *data) dd = hci_open_dev(dbus_data->dev_id); if (dd < 0) - return error_no_such_device(msg); + return error_no_such_adapter(msg); if (hci_read_class_of_dev(dd, cls, 1000) < 0) { syslog(LOG_ERR, "Can't read class of device on hci%d: %s(%d)", dbus_data->dev_id, strerror(errno), errno); hci_close_dev(dd); - return error_generic(msg, -errno); + return error_failed(msg, -errno); } hci_close_dev(dd); @@ -453,7 +453,7 @@ static DBusMessage *handle_dev_set_minor_class_req(DBusMessage *msg, void *data) dd = hci_open_dev(dbus_data->dev_id); if (dd < 0) - return error_no_such_device(msg); + return error_no_such_adapter(msg); if (hci_read_class_of_dev(dd, cls, 1000) < 0) { syslog(LOG_ERR, "Can't read class of device on hci%d: %s(%d)", @@ -508,7 +508,7 @@ static DBusMessage *handle_dev_get_service_classes_req(DBusMessage *msg, void *d dd = hci_open_dev(dbus_data->dev_id); if (dd < 0) - return error_no_such_device(msg); + return error_no_such_adapter(msg); if (hci_read_class_of_dev(dd, cls, 1000) < 0) { syslog(LOG_ERR, "Can't read class of device on hci%d: %s(%d)", @@ -548,7 +548,7 @@ static DBusMessage *handle_dev_get_name_req(DBusMessage *msg, void *data) err = get_device_name(dbus_data->dev_id, str, sizeof(str)); if (err < 0) - return error_generic(msg, -err); + return error_failed(msg, -err); reply = dbus_message_new_method_return(msg); if (!reply) @@ -583,7 +583,7 @@ static DBusMessage *handle_dev_set_name_req(DBusMessage *msg, void *data) err = set_device_name(dbus_data->dev_id, str_ptr); if (err < 0) - return error_generic(msg, -err); + return error_failed(msg, -err); reply = dbus_message_new_method_return(msg); if (!reply) @@ -686,7 +686,7 @@ static DBusMessage *handle_dev_get_remote_name_req(DBusMessage *msg, void *data) err = get_device_address(dbus_data->dev_id, addr, sizeof(addr)); if (err < 0) - return error_generic(msg, -err); + return error_failed(msg, -err); snprintf(filename, PATH_MAX, "%s/%s/names", STORAGEDIR, addr); @@ -727,7 +727,7 @@ static DBusMessage *handle_dev_get_remote_alias_req(DBusMessage *msg, void *data err = get_device_alias(dbus_data->dev_id, &bdaddr, str, sizeof(str)); if (err < 0) - return error_generic(msg, -err); + return error_failed(msg, -err); reply = dbus_message_new_method_return(msg); if (!reply) @@ -763,7 +763,7 @@ static DBusMessage *handle_dev_set_remote_alias_req(DBusMessage *msg, void *data err = set_device_alias(dbus_data->dev_id, &bdaddr, str_ptr); if (err < 0) - return error_generic(msg, -err); + return error_failed(msg, -err); signal = dev_signal_factory(dbus_data->dev_id, DEV_SIG_REMOTE_ALIAS_CHANGED, DBUS_TYPE_STRING, &addr_ptr, @@ -877,7 +877,7 @@ static DBusMessage *handle_dev_create_bonding_req(DBusMessage *msg, void *data) dd = hci_open_dev(dev_id); if (dd < 0) - return error_no_such_device(msg); + return error_no_such_adapter(msg); cr = malloc(sizeof(*cr) + sizeof(struct hci_conn_info)); if (!cr) { @@ -938,7 +938,7 @@ static DBusMessage *handle_dev_remove_bonding_req(DBusMessage *msg, void *data) dd = hci_open_dev(dbus_data->dev_id); if (dd < 0) - return error_no_such_device(msg); + return error_no_such_adapter(msg); get_device_address(dbus_data->dev_id, addr, sizeof(addr)); @@ -1139,7 +1139,7 @@ static DBusMessage *handle_dev_discover_req(DBusMessage *msg, void *data) dd = hci_open_dev(dbus_data->dev_id); if (dd < 0) - return error_no_such_device(msg); + return error_no_such_adapter(msg); memset(&cp, 0, sizeof(cp)); cp.lap[0] = lap & 0xff; @@ -1182,7 +1182,7 @@ static DBusMessage *handle_dev_discover_cancel_req(DBusMessage *msg, void *data) dd = hci_open_dev(dbus_data->dev_id); if (dd < 0) - return error_no_such_device(msg); + return error_no_such_adapter(msg); memset(&rq, 0, sizeof(rq)); rq.ogf = OGF_LINK_CTL; diff --git a/hcid/dbus-error.c b/hcid/dbus-error.c index 88e5bd7f..ae8af500 100644 --- a/hcid/dbus-error.c +++ b/hcid/dbus-error.c @@ -157,11 +157,23 @@ DBusMessage *bluez_new_failure_msg(DBusMessage *msg, const uint32_t ecode) return reply; } -DBusMessage *error_generic(DBusMessage *msg, int err) +DBusMessage *error_failed(DBusMessage *msg, int err) { const char *str = strerror(err); - return dbus_message_new_error(msg, ERROR_INTERFACE ".UnknownError", str); + return dbus_message_new_error(msg, ERROR_INTERFACE ".Failed", str); +} + +DBusMessage *error_invalid_arguments(DBusMessage *msg) +{ + return dbus_message_new_error(msg, ERROR_INTERFACE ".InvalidArguments", + "Invalid arguments"); +} + +DBusMessage *error_not_authorized(DBusMessage *msg) +{ + return dbus_message_new_error(msg, ERROR_INTERFACE ".NotAuthorized", + "Not authorized"); } DBusMessage *error_out_of_memory(DBusMessage *msg) @@ -170,8 +182,14 @@ DBusMessage *error_out_of_memory(DBusMessage *msg) "Out of memory"); } -DBusMessage *error_no_such_device(DBusMessage *msg) +DBusMessage *error_no_such_adapter(DBusMessage *msg) +{ + return dbus_message_new_error(msg, ERROR_INTERFACE ".NoSuchAdapter", + "No such adapter"); +} + +DBusMessage *error_unknown_address(DBusMessage *msg) { - return dbus_message_new_error(msg, ERROR_INTERFACE ".NoSuchDevice", - "No such device"); + return dbus_message_new_error(msg, ERROR_INTERFACE ".UnknownAddress", + "Device address is unknown"); } diff --git a/hcid/dbus-manager.c b/hcid/dbus-manager.c index 6981d9d2..784266fd 100644 --- a/hcid/dbus-manager.c +++ b/hcid/dbus-manager.c @@ -50,7 +50,7 @@ static DBusMessage *handle_mgr_list_devices_req(DBusMessage *msg, void *data) sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); if (sk < 0) - return error_generic(msg, errno); + return error_failed(msg, errno); dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl)); if (!dl) { @@ -62,7 +62,7 @@ static DBusMessage *handle_mgr_list_devices_req(DBusMessage *msg, void *data) dr = dl->dev_req; if (ioctl(sk, HCIGETDEVLIST, dl) < 0) { - reply = error_generic(msg, errno); + reply = error_failed(msg, errno); goto failed; } @@ -112,7 +112,7 @@ static DBusMessage *handle_mgr_default_device_req(DBusMessage *msg, void *data) int default_dev = get_default_dev_id(); if (default_dev < 0) - return error_no_such_device(msg); + return error_no_such_adapter(msg); reply = dbus_message_new_method_return(msg); if (!reply) diff --git a/hcid/dbus.h b/hcid/dbus.h index 5bcc0f65..99599210 100644 --- a/hcid/dbus.h +++ b/hcid/dbus.h @@ -87,9 +87,12 @@ DBusConnection *get_dbus_connection(void); int get_default_dev_id(void); -DBusMessage *error_generic(DBusMessage *msg, int err); +DBusMessage *error_failed(DBusMessage *msg, int err); +DBusMessage *error_invalid_arguments(DBusMessage *msg); +DBusMessage *error_not_authorized(DBusMessage *msg); DBusMessage *error_out_of_memory(DBusMessage *msg); -DBusMessage *error_no_such_device(DBusMessage *msg); +DBusMessage *error_no_such_adapter(DBusMessage *msg); +DBusMessage *error_unknown_address(DBusMessage *msg); /*======================================================================== BlueZ D-Bus Manager service definitions "/org/bluez/Manager" |