Re: [PATCH BlueZ 1/4] android/AVRCP: Add bt_avrcp_connect

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Luiz,

On Wednesday 05 of February 2014 12:26:57 Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx>
> 
> This adds bt_avrcp_connect function which can be used to request AVRCP
> connections.
> ---
>  android/avrcp.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
>  android/avrcp.h |  2 ++
>  2 files changed, 57 insertions(+), 5 deletions(-)
> 
> diff --git a/android/avrcp.c b/android/avrcp.c
> index ef833df..8600d98 100644
> --- a/android/avrcp.c
> +++ b/android/avrcp.c
> @@ -54,6 +54,7 @@ static GIOChannel *server = NULL;
>  struct avrcp_device {
>  	bdaddr_t	dst;
>  	struct avctp	*session;
> +	GIOChannel	*io;
>  };
>  
>  static const struct ipc_handler cmd_handlers[] = {
> @@ -197,17 +198,20 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
>  	}
>  
>  	ba2str(&dst, address);
> -	DBG("Incoming connection from %s", address);
>  
>  	l = g_slist_find_custom(devices, &dst, device_cmp);
>  	if (l) {
> -		error("Unexpected connection");
> -		return;
> +		dev = l->data;
> +		if (dev->session) {
> +			error("Unexpected connection");
> +			return;
> +		}
> +	} else {
> +		DBG("Incoming connection from %s", address);
> +		dev = avrcp_device_new(&dst);
>  	}
>  
>  	fd = g_io_channel_unix_get_fd(chan);
> -
> -	dev = avrcp_device_new(&dst);
>  	dev->session = avctp_new(fd, imtu, omtu, 0x0100);
>  
>  	if (!dev->session) {
> @@ -222,6 +226,11 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
>  
>  	g_io_channel_set_close_on_unref(chan, FALSE);
>  
> +	if (dev->io) {
> +		g_io_channel_unref(dev->io);
> +		dev->io = NULL;
> +	}
> +
>  	DBG("%s connected", address);
>  }
>  
> @@ -288,3 +297,44 @@ void bt_avrcp_unregister(void)
>  		server = NULL;
>  	}
>  }
> +
> +static bool avrcp_device_connect(struct avrcp_device *dev, BtIOConnect cb)
> +{
> +	GError *err = NULL;
> +
> +	dev->io = bt_io_connect(cb, dev, NULL, &err,
> +					BT_IO_OPT_SOURCE_BDADDR, &adapter_addr,
> +					BT_IO_OPT_DEST_BDADDR, &dev->dst,
> +					BT_IO_OPT_PSM, L2CAP_PSM_AVCTP,
> +					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
> +					BT_IO_OPT_INVALID);
> +	if (err) {
> +		error("%s", err->message);
> +		g_error_free(err);
> +		return false;
> +	}
> +
> +	return true;
> +}
> +
> +void bt_avrcp_connect(const bdaddr_t *dst)
> +{
> +	struct avrcp_device *dev;
> +	char addr[18];
> +	GSList *l;
> +
> +	DBG("");
> +
> +	l = g_slist_find_custom(devices, dst, device_cmp);
> +	if (l)
> +		return;
> +
> +	dev = avrcp_device_new(dst);
> +	if (!avrcp_device_connect(dev, connect_cb)) {
> +		avrcp_device_free(dev);
> +		return;
> +	}
> +
> +	ba2str(&dev->dst, addr);
> +	DBG("connecting to %s", addr);
> +}
> diff --git a/android/avrcp.h b/android/avrcp.h
> index 6fe7fbf..7b0a5ed 100644
> --- a/android/avrcp.h
> +++ b/android/avrcp.h
> @@ -23,3 +23,5 @@
>  
>  bool bt_avrcp_register(const bdaddr_t *addr);
>  void bt_avrcp_unregister(void);
> +
> +void bt_avrcp_connect(const bdaddr_t *dst);
> 

All four patches applied, thanks.

-- 
Best regards, 
Szymon Janc
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux