diff options
-rw-r--r-- | hcid/dbus-adapter.c | 24 | ||||
-rw-r--r-- | hcid/dbus.c | 78 |
2 files changed, 20 insertions, 82 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c index ac5b07b1..fbb913d3 100644 --- a/hcid/dbus-adapter.c +++ b/hcid/dbus-adapter.c @@ -882,11 +882,7 @@ static DBusHandlerResult handle_dev_set_minor_class_req(DBusConnection *conn, DB signal = dev_signal_factory(dbus_data->dev_id, "MinorClassChanged", DBUS_TYPE_STRING, &minor, DBUS_TYPE_INVALID); - if (signal) { - dbus_connection_send(conn, signal, NULL); - dbus_connection_flush(conn); - dbus_message_unref(signal); - } + send_reply_and_unref(conn, signal); reply = dbus_message_new_method_return(msg); @@ -1512,11 +1508,7 @@ static DBusHandlerResult handle_dev_set_remote_alias_req(DBusConnection *conn, D DBUS_TYPE_STRING, &addr, DBUS_TYPE_STRING, &alias, DBUS_TYPE_INVALID); - if (signal) { - dbus_connection_send(conn, signal, NULL); - dbus_connection_flush(conn); - dbus_message_unref(signal); - } + send_reply_and_unref(conn, signal); return send_reply_and_unref(conn, reply); } @@ -1564,11 +1556,7 @@ static DBusHandlerResult handle_dev_clear_remote_alias_req(DBusConnection *conn, signal = dev_signal_factory(dbus_data->dev_id, "RemoteAliasCleared", DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID); - if (signal) { - dbus_connection_send(conn, signal, NULL); - dbus_connection_flush(conn); - dbus_message_unref(signal); - } + send_reply_and_unref(conn, signal); } return send_reply_and_unref(conn, reply); @@ -2065,11 +2053,7 @@ static DBusHandlerResult handle_dev_remove_bonding_req(DBusConnection *conn, DBu signal = dev_signal_factory(dbus_data->dev_id, "BondingRemoved", DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID); - if (signal) { - dbus_connection_send(conn, signal, NULL); - dbus_connection_flush(conn); - dbus_message_unref(signal); - } + send_reply_and_unref(conn, signal); reply = dbus_message_new_method_return(msg); diff --git a/hcid/dbus.c b/hcid/dbus.c index c3731bde..5e05ae50 100644 --- a/hcid/dbus.c +++ b/hcid/dbus.c @@ -553,17 +553,9 @@ int hcid_dbus_unregister_device(uint16_t id) DBUS_TYPE_STRING, &pptr, DBUS_TYPE_INVALID); - if (!dbus_connection_send(connection, message, NULL)) { - error("Can't send D-Bus added device message"); - goto failed; - } - - dbus_connection_flush(connection); + send_reply_and_unref(connection, message); failed: - if (message) - dbus_message_unref(message); - ret = unregister_dbus_path(path); if (ret == 0 && default_dev == id) @@ -669,7 +661,7 @@ failed: default_dev = id; if (dd >= 0) - close(dd); + hci_close_dev(dd); if (cl) free(cl); @@ -881,7 +873,7 @@ failed: void hcid_dbus_inquiry_start(bdaddr_t *local) { struct hci_dbus_data *pdata; - DBusMessage *message = NULL; + DBusMessage *message; char path[MAX_PATH_LENGTH]; char *local_addr; bdaddr_t tmp; @@ -911,24 +903,12 @@ void hcid_dbus_inquiry_start(bdaddr_t *local) pdata->discover_type &= ~RESOLVE_NAME; } - message = dbus_message_new_signal(path, ADAPTER_INTERFACE, - "DiscoveryStarted"); - if (message == NULL) { - error("Can't allocate D-Bus message"); - goto failed; - } - - if (dbus_connection_send(connection, message, NULL) == FALSE) { - error("Can't send D-Bus inquiry start message"); - goto failed; - } + message = dev_signal_factory(pdata->dev_id, "DiscoveryStarted", + DBUS_TYPE_INVALID); - dbus_connection_flush(connection); + send_reply_and_unref(connection, message); failed: - if (message) - dbus_message_unref(message); - bt_free(local_addr); } @@ -1561,10 +1541,8 @@ void hcid_dbus_conn_complete(bdaddr_t *local, uint8_t status, uint16_t handle, b pdata->bonding->hci_status = status; } else { /* Sent the remote device connected signal */ - message = dbus_message_new_signal(path, ADAPTER_INTERFACE, "RemoteDeviceConnected"); - - dbus_message_append_args(message, - DBUS_TYPE_STRING, &peer_addr, + message = dev_signal_factory(pdata->dev_id, "RemoteDeviceConnected", + DBUS_TYPE_STRING, &peer_addr, DBUS_TYPE_INVALID); send_reply_and_unref(connection, message); @@ -1943,7 +1921,7 @@ gboolean discoverable_timeout_handler(void *data) failed: if (dd >= 0) - close(dd); + hci_close_dev(dd); return retval; } @@ -2039,7 +2017,7 @@ static DBusHandlerResult hci_dbus_signal_filter(DBusConnection *conn, DBusMessag *****************************************************************/ void hcid_dbus_setname_complete(bdaddr_t *local) { - DBusMessage *signal = NULL; + DBusMessage *signal; char *local_addr; bdaddr_t tmp; int id; @@ -2087,26 +2065,18 @@ void hcid_dbus_setname_complete(bdaddr_t *local) signal = dev_signal_factory(id, "NameChanged", DBUS_TYPE_STRING, &pname, DBUS_TYPE_INVALID); - if (dbus_connection_send(connection, signal, NULL) == FALSE) { - error("Can't send D-Bus name changed signal"); - goto failed; - } - - dbus_connection_flush(connection); + send_reply_and_unref(connection, signal); failed: - if (signal) - dbus_message_unref(signal); - if (dd >= 0) - close(dd); + hci_close_dev(dd); bt_free(local_addr); } void hcid_dbus_setscan_enable_complete(bdaddr_t *local) { - DBusMessage *message = NULL; + DBusMessage *message; struct hci_dbus_data *pdata; char *local_addr; char path[MAX_PATH_LENGTH]; @@ -2189,30 +2159,14 @@ void hcid_dbus_setscan_enable_complete(bdaddr_t *local) write_device_mode(local, scan_mode); - message = dbus_message_new_signal(path, ADAPTER_INTERFACE, - "ModeChanged"); - if (message == NULL) { - error("Can't allocate D-Bus message"); - goto failed; - } - - dbus_message_append_args(message, + message = dev_signal_factory(pdata->dev_id, "ModeChanged", DBUS_TYPE_STRING, &scan_mode, DBUS_TYPE_INVALID); - - if (dbus_connection_send(connection, message, NULL) == FALSE) { - error("Can't send D-Bus mode changed signal"); - goto failed; - } - - dbus_connection_flush(connection); + send_reply_and_unref(connection, message); failed: - if (message) - dbus_message_unref(message); - if (dd >= 0) - close(dd); + hci_close_dev(dd); bt_free(local_addr); } |