bt_a2dp_notify_state(dev, HAL_A2DP_STATE_CONNECTED);
}
-static uint8_t bt_a2dp_connect(struct hal_cmd_a2dp_connect *cmd, uint16_t len)
+static void bt_a2dp_connect(const void *buf, uint16_t len)
{
+ const struct hal_cmd_a2dp_connect *cmd = buf;
struct a2dp_device *dev;
+ uint8_t status;
char addr[18];
bdaddr_t dst;
GSList *l;
DBG("");
- if (len < sizeof(*cmd))
- return HAL_STATUS_INVALID;
-
android2bdaddr(&cmd->bdaddr, &dst);
l = g_slist_find_custom(devices, &dst, device_cmp);
- if (l)
- return HAL_STATUS_FAILED;
+ if (l) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
dev = a2dp_device_new(&dst);
dev->io = bt_io_connect(signaling_connect_cb, dev, NULL, &err,
error("%s", err->message);
g_error_free(err);
a2dp_device_free(dev);
- return HAL_STATUS_FAILED;
+ status = HAL_STATUS_FAILED;
+ goto failed;
}
ba2str(&dev->dst, addr);
bt_a2dp_notify_state(dev, HAL_A2DP_STATE_CONNECTING);
- return HAL_STATUS_SUCCESS;
+ status = HAL_STATUS_SUCCESS;
+
+failed:
+ ipc_send_rsp(HAL_SERVICE_ID_A2DP, HAL_OP_A2DP_CONNECT, status);
}
-static uint8_t bt_a2dp_disconnect(struct hal_cmd_a2dp_connect *cmd,
- uint16_t len)
+static void bt_a2dp_disconnect(const void *buf, uint16_t len)
{
+ const struct hal_cmd_a2dp_connect *cmd = buf;
+ uint8_t status;
struct a2dp_device *dev;
GSList *l;
bdaddr_t dst;
DBG("");
- if (len < sizeof(*cmd))
- return HAL_STATUS_INVALID;
-
android2bdaddr(&cmd->bdaddr, &dst);
l = g_slist_find_custom(devices, &dst, device_cmp);
- if (!l)
- return HAL_STATUS_FAILED;
+ if (!l) {
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
dev = l->data;
bt_a2dp_notify_state(dev, HAL_A2DP_STATE_DISCONNECTING);
- return HAL_STATUS_SUCCESS;
-}
-
-void bt_a2dp_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
-{
- uint8_t status = HAL_STATUS_FAILED;
-
- switch (opcode) {
- case HAL_OP_A2DP_CONNECT:
- status = bt_a2dp_connect(buf, len);
- break;
- case HAL_OP_A2DP_DISCONNECT:
- status = bt_a2dp_disconnect(buf, len);
- break;
- default:
- DBG("Unhandled command, opcode 0x%x", opcode);
- break;
- }
+ status = HAL_STATUS_SUCCESS;
- ipc_send_rsp(HAL_SERVICE_ID_A2DP, opcode, status);
+failed:
+ ipc_send_rsp(HAL_SERVICE_ID_A2DP, HAL_OP_A2DP_DISCONNECT, status);
}
+static const struct ipc_handler cmd_handlers[] = {
+ /* HAL_OP_A2DP_CONNECT */
+ { bt_a2dp_connect, false, sizeof(struct hal_cmd_a2dp_connect) },
+ /* HAL_OP_A2DP_DISCONNECT */
+ { bt_a2dp_disconnect, false, sizeof(struct hal_cmd_a2dp_disconnect) },
+};
+
static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
{
struct a2dp_device *dev;
}
record_id = rec->handle;
+ ipc_register(HAL_SERVICE_ID_A2DP, cmd_handlers,
+ sizeof(cmd_handlers)/sizeof(cmd_handlers[0]));
+
return true;
}
g_slist_foreach(devices, a2dp_device_disconnected, NULL);
devices = NULL;
+
+ ipc_unregister(HAL_SERVICE_ID_A2DP);
bt_adapter_remove_record(record_id);
record_id = 0;