2001-07-16 11:15:28 +00:00
|
|
|
/*
|
|
|
|
|
* Timer Interface - main file
|
2007-10-15 10:24:55 +02:00
|
|
|
* Copyright (c) 1998-2001 by Jaroslav Kysela <perex@perex.cz>
|
2001-07-16 11:15:28 +00:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or modify
|
2001-12-30 09:22:54 +00:00
|
|
|
* it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of
|
2001-07-16 11:15:28 +00:00
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2001-12-30 09:22:54 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2001-07-16 11:15:28 +00:00
|
|
|
*
|
2001-12-30 09:22:54 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2001-07-16 11:15:28 +00:00
|
|
|
* License along with this library; if not, write to the Free Software
|
2001-12-30 09:22:54 +00:00
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-07-16 11:15:28 +00:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
#include "timer_local.h"
|
|
|
|
|
|
2001-10-24 14:14:11 +00:00
|
|
|
#ifndef PIC
|
|
|
|
|
/* entry for static linking */
|
|
|
|
|
const char *_snd_module_timer_query_hw = "";
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-02-27 10:03:19 +00:00
|
|
|
#define SNDRV_FILE_TIMER ALSA_DEVICE_DIRECTORY "timer"
|
2001-07-16 11:15:28 +00:00
|
|
|
#define SNDRV_TIMER_VERSION_MAX SNDRV_PROTOCOL_VERSION(2, 0, 0)
|
|
|
|
|
|
|
|
|
|
static int snd_timer_query_hw_close(snd_timer_query_t *handle)
|
|
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
|
|
|
|
|
if (!handle)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
res = close(handle->poll_fd) < 0 ? -errno : 0;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_timer_query_hw_next_device(snd_timer_query_t *handle, snd_timer_id_t * tid)
|
|
|
|
|
{
|
|
|
|
|
if (!handle || !tid)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (ioctl(handle->poll_fd, SNDRV_TIMER_IOCTL_NEXT_DEVICE, tid) < 0)
|
|
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-04 20:01:06 +00:00
|
|
|
static int snd_timer_query_hw_info(snd_timer_query_t *handle, snd_timer_ginfo_t *info)
|
|
|
|
|
{
|
|
|
|
|
if (!handle || !info)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (ioctl(handle->poll_fd, SNDRV_TIMER_IOCTL_GINFO, info) < 0)
|
|
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_timer_query_hw_params(snd_timer_query_t *handle, snd_timer_gparams_t *params)
|
|
|
|
|
{
|
|
|
|
|
if (!handle || !params)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (ioctl(handle->poll_fd, SNDRV_TIMER_IOCTL_GPARAMS, params) < 0)
|
|
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_timer_query_hw_status(snd_timer_query_t *handle, snd_timer_gstatus_t *status)
|
|
|
|
|
{
|
|
|
|
|
if (!handle || !status)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (ioctl(handle->poll_fd, SNDRV_TIMER_IOCTL_GSTATUS, status) < 0)
|
|
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-21 19:43:33 +01:00
|
|
|
static const snd_timer_query_ops_t snd_timer_query_hw_ops = {
|
2003-07-25 17:02:00 +00:00
|
|
|
.close = snd_timer_query_hw_close,
|
|
|
|
|
.next_device = snd_timer_query_hw_next_device,
|
|
|
|
|
.info = snd_timer_query_hw_info,
|
|
|
|
|
.params = snd_timer_query_hw_params,
|
|
|
|
|
.status = snd_timer_query_hw_status
|
2001-07-16 11:15:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int snd_timer_query_hw_open(snd_timer_query_t **handle, const char *name, int mode)
|
|
|
|
|
{
|
|
|
|
|
int fd, ver, tmode;
|
|
|
|
|
snd_timer_query_t *tmr;
|
|
|
|
|
|
|
|
|
|
*handle = NULL;
|
|
|
|
|
|
|
|
|
|
tmode = O_RDONLY;
|
|
|
|
|
if (mode & SND_TIMER_OPEN_NONBLOCK)
|
|
|
|
|
tmode |= O_NONBLOCK;
|
2005-02-11 16:35:24 +00:00
|
|
|
fd = snd_open_device(SNDRV_FILE_TIMER, tmode);
|
2005-01-26 10:50:28 +00:00
|
|
|
if (fd < 0)
|
2001-07-16 11:15:28 +00:00
|
|
|
return -errno;
|
|
|
|
|
if (ioctl(fd, SNDRV_TIMER_IOCTL_PVERSION, &ver) < 0) {
|
|
|
|
|
close(fd);
|
|
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_TIMER_VERSION_MAX)) {
|
|
|
|
|
close(fd);
|
|
|
|
|
return -SND_ERROR_INCOMPATIBLE_VERSION;
|
|
|
|
|
}
|
|
|
|
|
tmr = (snd_timer_query_t *) calloc(1, sizeof(snd_timer_t));
|
|
|
|
|
if (tmr == NULL) {
|
|
|
|
|
close(fd);
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
}
|
|
|
|
|
tmr->type = SND_TIMER_TYPE_HW;
|
|
|
|
|
tmr->mode = tmode;
|
|
|
|
|
tmr->name = strdup(name);
|
|
|
|
|
tmr->poll_fd = fd;
|
|
|
|
|
tmr->ops = &snd_timer_query_hw_ops;
|
|
|
|
|
*handle = tmr;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int _snd_timer_query_hw_open(snd_timer_query_t **timer, char *name,
|
|
|
|
|
snd_config_t *root ATTRIBUTE_UNUSED,
|
|
|
|
|
snd_config_t *conf, int mode)
|
|
|
|
|
{
|
|
|
|
|
snd_config_iterator_t i, next;
|
|
|
|
|
snd_config_for_each(i, next, conf) {
|
|
|
|
|
snd_config_t *n = snd_config_iterator_entry(i);
|
2001-11-19 08:14:21 +00:00
|
|
|
const char *id;
|
|
|
|
|
if (snd_config_get_id(n, &id) < 0)
|
|
|
|
|
continue;
|
2001-07-16 11:15:28 +00:00
|
|
|
if (strcmp(id, "comment") == 0)
|
|
|
|
|
continue;
|
|
|
|
|
if (strcmp(id, "type") == 0)
|
|
|
|
|
continue;
|
|
|
|
|
SNDERR("Unexpected field %s", id);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
return snd_timer_query_hw_open(timer, name, mode);
|
|
|
|
|
}
|
2001-10-24 14:14:11 +00:00
|
|
|
SND_DLSYM_BUILD_VERSION(_snd_timer_query_hw_open, SND_TIMER_QUERY_DLSYM_VERSION);
|