|
Packit |
4a16fb |
/*
|
|
Packit |
4a16fb |
* Timer Interface - main file
|
|
Packit |
4a16fb |
* Copyright (c) 1998-2001 by Jaroslav Kysela <perex@perex.cz>
|
|
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 "timer_local.h"
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
#ifndef PIC
|
|
Packit |
4a16fb |
/* entry for static linking */
|
|
Packit |
4a16fb |
const char *_snd_module_timer_query_hw = "";
|
|
Packit |
4a16fb |
#endif
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
#define SNDRV_FILE_TIMER ALSA_DEVICE_DIRECTORY "timer"
|
|
Packit |
4a16fb |
#define SNDRV_TIMER_VERSION_MAX SNDRV_PROTOCOL_VERSION(2, 0, 0)
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
static int snd_timer_query_hw_close(snd_timer_query_t *handle)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
int res;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
if (!handle)
|
|
Packit |
4a16fb |
return -EINVAL;
|
|
Packit |
4a16fb |
res = close(handle->poll_fd) < 0 ? -errno : 0;
|
|
Packit |
4a16fb |
return res;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
static int snd_timer_query_hw_next_device(snd_timer_query_t *handle, snd_timer_id_t * tid)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
if (!handle || !tid)
|
|
Packit |
4a16fb |
return -EINVAL;
|
|
Packit |
4a16fb |
if (ioctl(handle->poll_fd, SNDRV_TIMER_IOCTL_NEXT_DEVICE, tid) < 0)
|
|
Packit |
4a16fb |
return -errno;
|
|
Packit |
4a16fb |
return 0;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
static int snd_timer_query_hw_info(snd_timer_query_t *handle, snd_timer_ginfo_t *info)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
if (!handle || !info)
|
|
Packit |
4a16fb |
return -EINVAL;
|
|
Packit |
4a16fb |
if (ioctl(handle->poll_fd, SNDRV_TIMER_IOCTL_GINFO, info) < 0)
|
|
Packit |
4a16fb |
return -errno;
|
|
Packit |
4a16fb |
return 0;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
static int snd_timer_query_hw_params(snd_timer_query_t *handle, snd_timer_gparams_t *params)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
if (!handle || !params)
|
|
Packit |
4a16fb |
return -EINVAL;
|
|
Packit |
4a16fb |
if (ioctl(handle->poll_fd, SNDRV_TIMER_IOCTL_GPARAMS, params) < 0)
|
|
Packit |
4a16fb |
return -errno;
|
|
Packit |
4a16fb |
return 0;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
static int snd_timer_query_hw_status(snd_timer_query_t *handle, snd_timer_gstatus_t *status)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
if (!handle || !status)
|
|
Packit |
4a16fb |
return -EINVAL;
|
|
Packit |
4a16fb |
if (ioctl(handle->poll_fd, SNDRV_TIMER_IOCTL_GSTATUS, status) < 0)
|
|
Packit |
4a16fb |
return -errno;
|
|
Packit |
4a16fb |
return 0;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
static const snd_timer_query_ops_t snd_timer_query_hw_ops = {
|
|
Packit |
4a16fb |
.close = snd_timer_query_hw_close,
|
|
Packit |
4a16fb |
.next_device = snd_timer_query_hw_next_device,
|
|
Packit |
4a16fb |
.info = snd_timer_query_hw_info,
|
|
Packit |
4a16fb |
.params = snd_timer_query_hw_params,
|
|
Packit |
4a16fb |
.status = snd_timer_query_hw_status
|
|
Packit |
4a16fb |
};
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
int snd_timer_query_hw_open(snd_timer_query_t **handle, const char *name, int mode)
|
|
Packit |
4a16fb |
{
|
|
Packit |
4a16fb |
int fd, ver, tmode;
|
|
Packit |
4a16fb |
snd_timer_query_t *tmr;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
*handle = NULL;
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
tmode = O_RDONLY;
|
|
Packit |
4a16fb |
if (mode & SND_TIMER_OPEN_NONBLOCK)
|
|
Packit |
4a16fb |
tmode |= O_NONBLOCK;
|
|
Packit |
4a16fb |
fd = snd_open_device(SNDRV_FILE_TIMER, tmode);
|
|
Packit |
4a16fb |
if (fd < 0)
|
|
Packit |
4a16fb |
return -errno;
|
|
Packit |
4a16fb |
if (ioctl(fd, SNDRV_TIMER_IOCTL_PVERSION, &ver) < 0) {
|
|
Packit |
4a16fb |
close(fd);
|
|
Packit |
4a16fb |
return -errno;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_TIMER_VERSION_MAX)) {
|
|
Packit |
4a16fb |
close(fd);
|
|
Packit |
4a16fb |
return -SND_ERROR_INCOMPATIBLE_VERSION;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
tmr = (snd_timer_query_t *) calloc(1, sizeof(snd_timer_t));
|
|
Packit |
4a16fb |
if (tmr == NULL) {
|
|
Packit |
4a16fb |
close(fd);
|
|
Packit |
4a16fb |
return -ENOMEM;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
tmr->type = SND_TIMER_TYPE_HW;
|
|
Packit |
4a16fb |
tmr->mode = tmode;
|
|
Packit |
4a16fb |
tmr->name = strdup(name);
|
|
Packit |
4a16fb |
tmr->poll_fd = fd;
|
|
Packit |
4a16fb |
tmr->ops = &snd_timer_query_hw_ops;
|
|
Packit |
4a16fb |
*handle = tmr;
|
|
Packit |
4a16fb |
return 0;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
|
|
Packit |
4a16fb |
int _snd_timer_query_hw_open(snd_timer_query_t **timer, char *name,
|
|
Packit |
4a16fb |
snd_config_t *root ATTRIBUTE_UNUSED,
|
|
Packit |
4a16fb |
snd_config_t *conf, 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 |
SNDERR("Unexpected field %s", id);
|
|
Packit |
4a16fb |
return -EINVAL;
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
return snd_timer_query_hw_open(timer, name, mode);
|
|
Packit |
4a16fb |
}
|
|
Packit |
4a16fb |
SND_DLSYM_BUILD_VERSION(_snd_timer_query_hw_open, SND_TIMER_QUERY_DLSYM_VERSION);
|