Blame src/seq/seq_hw.c

Packit 4a16fb
/*
Packit 4a16fb
 *  Sequencer Interface - main file
Packit 4a16fb
 *  Copyright (c) 2000 by Jaroslav Kysela <perex@perex.cz>
Packit 4a16fb
 *                        Abramo Bagnara <abramo@alsa-project.org>
Packit 4a16fb
 *
Packit 4a16fb
 *
Packit 4a16fb
 *   This library is free software; you can redistribute it and/or modify
Packit 4a16fb
 *   it under the terms of the GNU Lesser General Public License as
Packit 4a16fb
 *   published by the Free Software Foundation; either version 2.1 of
Packit 4a16fb
 *   the License, or (at your option) any later version.
Packit 4a16fb
 *
Packit 4a16fb
 *   This program is distributed in the hope that it will be useful,
Packit 4a16fb
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 4a16fb
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 4a16fb
 *   GNU Lesser General Public License for more details.
Packit 4a16fb
 *
Packit 4a16fb
 *   You should have received a copy of the GNU Lesser General Public
Packit 4a16fb
 *   License along with this library; if not, write to the Free Software
Packit 4a16fb
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit 4a16fb
 *
Packit 4a16fb
 */
Packit 4a16fb
Packit 4a16fb
#include <fcntl.h>
Packit 4a16fb
#include <sys/ioctl.h>
Packit 4a16fb
#include "seq_local.h"
Packit 4a16fb
Packit 4a16fb
#ifndef PIC
Packit 4a16fb
/* entry for static linking */
Packit 4a16fb
const char *_snd_module_seq_hw = "";
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
#ifndef DOC_HIDDEN
Packit 4a16fb
#define SNDRV_FILE_SEQ		ALSA_DEVICE_DIRECTORY "seq"
Packit 4a16fb
#define SNDRV_FILE_ALOADSEQ	ALOAD_DEVICE_DIRECTORY "aloadSEQ"
Packit 4a16fb
#define SNDRV_SEQ_VERSION_MAX	SNDRV_PROTOCOL_VERSION(1, 0, 2)
Packit 4a16fb
Packit 4a16fb
typedef struct {
Packit 4a16fb
	int fd;
Packit 4a16fb
	int version;
Packit 4a16fb
} snd_seq_hw_t;
Packit 4a16fb
#endif /* DOC_HIDDEN */
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_close(snd_seq_t *seq)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	int err = 0;
Packit 4a16fb
Packit 4a16fb
	if (close(hw->fd)) {
Packit 4a16fb
		err = -errno;
Packit 4a16fb
		SYSERR("close failed\n");
Packit 4a16fb
	}
Packit 4a16fb
	free(hw);
Packit 4a16fb
	return err;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_nonblock(snd_seq_t *seq, int nonblock)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	long flags;
Packit 4a16fb
Packit 4a16fb
	if ((flags = fcntl(hw->fd, F_GETFL)) < 0) {
Packit 4a16fb
		SYSERR("F_GETFL failed");
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	if (nonblock)
Packit 4a16fb
		flags |= O_NONBLOCK;
Packit 4a16fb
	else
Packit 4a16fb
		flags &= ~O_NONBLOCK;
Packit 4a16fb
	if (fcntl(hw->fd, F_SETFL, flags) < 0) {
Packit 4a16fb
		SYSERR("F_SETFL for O_NONBLOCK failed");
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_client_id(snd_seq_t *seq)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	int client;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_CLIENT_ID, &client) < 0) {
Packit 4a16fb
		SYSERR("SNDRV_SEQ_IOCTL_CLIENT_ID failed");
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return client;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_system_info(snd_seq_t *seq, snd_seq_system_info_t * info)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_SYSTEM_INFO, info) < 0) {
Packit 4a16fb
		SYSERR("SNDRV_SEQ_IOCTL_SYSTEM_INFO failed");
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_get_client_info(snd_seq_t *seq, snd_seq_client_info_t * info)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_GET_CLIENT_INFO, info) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_GET_CLIENT_INFO failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	if (hw->version < SNDRV_PROTOCOL_VERSION(1, 0, 2)) {
Packit 4a16fb
		info->card = -1;
Packit 4a16fb
		info->pid = -1;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_set_client_info(snd_seq_t *seq, snd_seq_client_info_t * info)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, info) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_SET_CLIENT_INFO failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_create_port(snd_seq_t *seq, snd_seq_port_info_t * port)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_CREATE_PORT, port) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_CREATE_PORT failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_delete_port(snd_seq_t *seq, snd_seq_port_info_t * port)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_DELETE_PORT, port) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_DELETE_PORT failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_get_port_info(snd_seq_t *seq, snd_seq_port_info_t * info)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_GET_PORT_INFO, info) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_GET_PORT_INFO failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_set_port_info(snd_seq_t *seq, snd_seq_port_info_t * info)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_SET_PORT_INFO, info) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_SET_PORT_INFO failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_get_port_subscription(snd_seq_t *seq, snd_seq_port_subscribe_t * sub)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_GET_SUBSCRIPTION, sub) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_GET_SUBSCRIPTION failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_subscribe_port(snd_seq_t *seq, snd_seq_port_subscribe_t * sub)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT, sub) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_unsubscribe_port(snd_seq_t *seq, snd_seq_port_subscribe_t * sub)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT, sub) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_query_port_subscribers(snd_seq_t *seq, snd_seq_query_subscribe_t * subs)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_QUERY_SUBS, subs) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_QUERY_SUBS failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_get_queue_status(snd_seq_t *seq, snd_seq_queue_status_t * status)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_GET_QUEUE_STATUS, status) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_GET_QUEUE_STATUS failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_get_queue_tempo(snd_seq_t *seq, snd_seq_queue_tempo_t * tempo)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_GET_QUEUE_TEMPO, tempo) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_GET_QUEUE_TEMPO failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_set_queue_tempo(snd_seq_t *seq, snd_seq_queue_tempo_t * tempo)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_SET_QUEUE_TEMPO, tempo) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_SET_QUEUE_TEMPO failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_get_queue_timer(snd_seq_t *seq, snd_seq_queue_timer_t * timer)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_GET_QUEUE_TIMER, timer) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_GET_QUEUE_TIMER failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_set_queue_timer(snd_seq_t *seq, snd_seq_queue_timer_t * timer)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_SET_QUEUE_TIMER, timer) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_SET_QUEUE_TIMER failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_get_queue_client(snd_seq_t *seq, snd_seq_queue_client_t * info)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_GET_QUEUE_CLIENT, info) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_GET_QUEUE_CLIENT failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_set_queue_client(snd_seq_t *seq, snd_seq_queue_client_t * info)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_SET_QUEUE_CLIENT, info) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_SET_QUEUE_CLIENT failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_create_queue(snd_seq_t *seq, snd_seq_queue_info_t *info)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_CREATE_QUEUE, info) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_CREATE_QUEUE failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_delete_queue(snd_seq_t *seq, snd_seq_queue_info_t *info)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_DELETE_QUEUE, info) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_DELETE_QUEUE failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_get_queue_info(snd_seq_t *seq, snd_seq_queue_info_t *info)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_GET_QUEUE_INFO, info) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_GET_QUEUE_INFO failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_set_queue_info(snd_seq_t *seq, snd_seq_queue_info_t *info)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_SET_QUEUE_INFO, info) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_SET_QUEUE_INFO failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_get_named_queue(snd_seq_t *seq, snd_seq_queue_info_t *info)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_GET_NAMED_QUEUE, info) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_GET_NAMED_QUEUE failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static ssize_t snd_seq_hw_write(snd_seq_t *seq, void *buf, size_t len)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	ssize_t result = write(hw->fd, buf, len);
Packit 4a16fb
	if (result < 0)
Packit 4a16fb
		return -errno;
Packit 4a16fb
	return result;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static ssize_t snd_seq_hw_read(snd_seq_t *seq, void *buf, size_t len)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	ssize_t result = read(hw->fd, buf, len);
Packit 4a16fb
	if (result < 0)
Packit 4a16fb
		return -errno;
Packit 4a16fb
	return result;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_remove_events(snd_seq_t *seq, snd_seq_remove_events_t *rmp)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_REMOVE_EVENTS, rmp) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_REMOVE_EVENTS failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_get_client_pool(snd_seq_t *seq, snd_seq_client_pool_t *info)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_GET_CLIENT_POOL, info) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_GET_CLIENT_POOL failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_set_client_pool(snd_seq_t *seq, snd_seq_client_pool_t *info)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_SET_CLIENT_POOL, info) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_SET_CLIENT_POOL failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_query_next_client(snd_seq_t *seq, snd_seq_client_info_t *info)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT, info) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	if (hw->version < SNDRV_PROTOCOL_VERSION(1, 0, 2)) {
Packit 4a16fb
		info->card = -1;
Packit 4a16fb
		info->pid = -1;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static int snd_seq_hw_query_next_port(snd_seq_t *seq, snd_seq_port_info_t *info)
Packit 4a16fb
{
Packit 4a16fb
	snd_seq_hw_t *hw = seq->private_data;
Packit 4a16fb
	if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT, info) < 0) {
Packit 4a16fb
		/*SYSERR("SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT failed");*/
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static const snd_seq_ops_t snd_seq_hw_ops = {
Packit 4a16fb
	.close = snd_seq_hw_close,
Packit 4a16fb
	.nonblock = snd_seq_hw_nonblock,
Packit 4a16fb
	.system_info = snd_seq_hw_system_info,
Packit 4a16fb
	.get_client_info = snd_seq_hw_get_client_info,
Packit 4a16fb
	.set_client_info = snd_seq_hw_set_client_info,
Packit 4a16fb
	.create_port = snd_seq_hw_create_port,
Packit 4a16fb
	.delete_port = snd_seq_hw_delete_port,
Packit 4a16fb
	.get_port_info = snd_seq_hw_get_port_info,
Packit 4a16fb
	.set_port_info = snd_seq_hw_set_port_info,
Packit 4a16fb
	.get_port_subscription = snd_seq_hw_get_port_subscription,
Packit 4a16fb
	.subscribe_port = snd_seq_hw_subscribe_port,
Packit 4a16fb
	.unsubscribe_port = snd_seq_hw_unsubscribe_port,
Packit 4a16fb
	.query_port_subscribers = snd_seq_hw_query_port_subscribers,
Packit 4a16fb
	.get_queue_status = snd_seq_hw_get_queue_status,
Packit 4a16fb
	.get_queue_tempo = snd_seq_hw_get_queue_tempo,
Packit 4a16fb
	.set_queue_tempo = snd_seq_hw_set_queue_tempo,
Packit 4a16fb
	.get_queue_timer = snd_seq_hw_get_queue_timer,
Packit 4a16fb
	.set_queue_timer = snd_seq_hw_set_queue_timer,
Packit 4a16fb
	.get_queue_client = snd_seq_hw_get_queue_client,
Packit 4a16fb
	.set_queue_client = snd_seq_hw_set_queue_client,
Packit 4a16fb
	.create_queue = snd_seq_hw_create_queue,
Packit 4a16fb
	.delete_queue = snd_seq_hw_delete_queue,
Packit 4a16fb
	.get_queue_info = snd_seq_hw_get_queue_info,
Packit 4a16fb
	.set_queue_info = snd_seq_hw_set_queue_info,
Packit 4a16fb
	.get_named_queue = snd_seq_hw_get_named_queue,
Packit 4a16fb
	.write = snd_seq_hw_write,
Packit 4a16fb
	.read = snd_seq_hw_read,
Packit 4a16fb
	.remove_events = snd_seq_hw_remove_events,
Packit 4a16fb
	.get_client_pool = snd_seq_hw_get_client_pool,
Packit 4a16fb
	.set_client_pool = snd_seq_hw_set_client_pool,
Packit 4a16fb
	.query_next_client = snd_seq_hw_query_next_client,
Packit 4a16fb
	.query_next_port = snd_seq_hw_query_next_port,
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
int snd_seq_hw_open(snd_seq_t **handle, const char *name, int streams, int mode)
Packit 4a16fb
{
Packit 4a16fb
	int fd, ver, client, fmode, ret;
Packit 4a16fb
	const char *filename;
Packit 4a16fb
	snd_seq_t *seq;
Packit 4a16fb
	snd_seq_hw_t *hw;
Packit 4a16fb
Packit 4a16fb
	*handle = NULL;
Packit 4a16fb
Packit 4a16fb
	switch (streams) {
Packit 4a16fb
	case SND_SEQ_OPEN_OUTPUT:
Packit 4a16fb
		fmode = O_WRONLY;
Packit 4a16fb
		break;
Packit 4a16fb
	case SND_SEQ_OPEN_INPUT:
Packit 4a16fb
		fmode = O_RDONLY;
Packit 4a16fb
		break;
Packit 4a16fb
	case SND_SEQ_OPEN_DUPLEX:
Packit 4a16fb
		fmode = O_RDWR;
Packit 4a16fb
		break;
Packit 4a16fb
	default:
Packit 4a16fb
		assert(0);
Packit 4a16fb
		return -EINVAL;
Packit 4a16fb
	}
Packit 4a16fb
	
Packit 4a16fb
	if (mode & SND_SEQ_NONBLOCK)
Packit 4a16fb
		fmode |= O_NONBLOCK;
Packit 4a16fb
Packit 4a16fb
	filename = SNDRV_FILE_SEQ;
Packit 4a16fb
	fd = snd_open_device(filename, fmode);
Packit 4a16fb
#ifdef SUPPORT_ALOAD
Packit 4a16fb
	if (fd < 0) {
Packit 4a16fb
		fd = snd_open_device(SNDRV_FILE_ALOADSEQ, fmode);
Packit 4a16fb
		if (fd >= 0)
Packit 4a16fb
			close(fd);
Packit 4a16fb
		fd = snd_open_device(filename, fmode);
Packit 4a16fb
	}
Packit 4a16fb
#endif
Packit 4a16fb
	if (fd < 0) {
Packit 4a16fb
		SYSERR("open %s failed", filename);
Packit 4a16fb
		return -errno;
Packit 4a16fb
	}
Packit 4a16fb
	if (ioctl(fd, SNDRV_SEQ_IOCTL_PVERSION, &ver) < 0) {
Packit 4a16fb
		SYSERR("SNDRV_SEQ_IOCTL_PVERSION failed");
Packit 4a16fb
		ret = -errno;
Packit 4a16fb
		close(fd);
Packit 4a16fb
		return ret;
Packit 4a16fb
	}
Packit 4a16fb
	if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_SEQ_VERSION_MAX)) {
Packit 4a16fb
		close(fd);
Packit 4a16fb
		return -SND_ERROR_INCOMPATIBLE_VERSION;
Packit 4a16fb
	}
Packit 4a16fb
	hw = calloc(1, sizeof(snd_seq_hw_t));
Packit 4a16fb
	if (hw == NULL) {
Packit 4a16fb
		close(fd);
Packit 4a16fb
		return -ENOMEM;
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	seq = calloc(1, sizeof(snd_seq_t));
Packit 4a16fb
	if (seq == NULL) {
Packit 4a16fb
		free(hw);
Packit 4a16fb
		close(fd);
Packit 4a16fb
		return -ENOMEM;
Packit 4a16fb
	}
Packit 4a16fb
	hw->fd = fd;
Packit 4a16fb
	hw->version = ver;
Packit 4a16fb
	if (streams & SND_SEQ_OPEN_OUTPUT) {
Packit 4a16fb
		seq->obuf = (char *) malloc(seq->obufsize = SND_SEQ_OBUF_SIZE);
Packit 4a16fb
		if (!seq->obuf) {
Packit 4a16fb
			free(hw);
Packit 4a16fb
			free(seq);
Packit 4a16fb
			close(fd);
Packit 4a16fb
			return -ENOMEM;
Packit 4a16fb
		}
Packit 4a16fb
	}
Packit 4a16fb
	if (streams & SND_SEQ_OPEN_INPUT) {
Packit 4a16fb
		seq->ibuf = (snd_seq_event_t *) calloc(sizeof(snd_seq_event_t), seq->ibufsize = SND_SEQ_IBUF_SIZE);
Packit 4a16fb
		if (!seq->ibuf) {
Packit 4a16fb
			free(seq->obuf);
Packit 4a16fb
			free(hw);
Packit 4a16fb
			free(seq);
Packit 4a16fb
			close(fd);
Packit 4a16fb
			return -ENOMEM;
Packit 4a16fb
		}
Packit 4a16fb
	}
Packit 4a16fb
	if (name)
Packit 4a16fb
		seq->name = strdup(name);
Packit 4a16fb
	seq->type = SND_SEQ_TYPE_HW;
Packit 4a16fb
	seq->streams = streams;
Packit 4a16fb
	seq->mode = mode;
Packit 4a16fb
	seq->tmpbuf = NULL;
Packit 4a16fb
	seq->tmpbufsize = 0;
Packit 4a16fb
	seq->poll_fd = fd;
Packit 4a16fb
	seq->ops = &snd_seq_hw_ops;
Packit 4a16fb
	seq->private_data = hw;
Packit 4a16fb
	client = snd_seq_hw_client_id(seq);
Packit 4a16fb
	if (client < 0) {
Packit 4a16fb
		snd_seq_close(seq);
Packit 4a16fb
		return client;
Packit 4a16fb
	} else
Packit 4a16fb
		seq->client = client;
Packit 4a16fb
Packit 4a16fb
#ifdef SNDRV_SEQ_IOCTL_RUNNING_MODE
Packit 4a16fb
	{
Packit 4a16fb
		struct snd_seq_running_info run_mode;
Packit 4a16fb
		/* check running mode */
Packit 4a16fb
		memset(&run_mode, 0, sizeof(run_mode));
Packit 4a16fb
		run_mode.client = client;
Packit 4a16fb
#ifdef SNDRV_BIG_ENDIAN
Packit 4a16fb
		run_mode.big_endian = 1;
Packit 4a16fb
#else
Packit 4a16fb
		run_mode.big_endian = 0;
Packit 4a16fb
#endif
Packit 4a16fb
		run_mode.cpu_mode = sizeof(long);
Packit 4a16fb
		ioctl(fd, SNDRV_SEQ_IOCTL_RUNNING_MODE, &run_mode);
Packit 4a16fb
	}
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
	*handle = seq;
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int _snd_seq_hw_open(snd_seq_t **handlep, char *name,
Packit 4a16fb
		     snd_config_t *root ATTRIBUTE_UNUSED, snd_config_t *conf,
Packit 4a16fb
		     int streams, int mode)
Packit 4a16fb
{
Packit 4a16fb
	snd_config_iterator_t i, next;
Packit 4a16fb
	snd_config_for_each(i, next, conf) {
Packit 4a16fb
		snd_config_t *n = snd_config_iterator_entry(i);
Packit 4a16fb
		const char *id;
Packit 4a16fb
		if (snd_config_get_id(n, &id) < 0)
Packit 4a16fb
			continue;
Packit 4a16fb
		if (_snd_conf_generic_id(id))
Packit 4a16fb
			continue;
Packit 4a16fb
		return -EINVAL;
Packit 4a16fb
	}
Packit 4a16fb
	return snd_seq_hw_open(handlep, name, streams, mode);
Packit 4a16fb
}
Packit 4a16fb
SND_DLSYM_BUILD_VERSION(_snd_seq_hw_open, SND_SEQ_DLSYM_VERSION);