New async notification API. Removed obsolete surround. Cleaning

This commit is contained in:
Abramo Bagnara 2001-06-20 20:52:12 +00:00
parent 57469ec597
commit 157f47aedd
35 changed files with 436 additions and 1581 deletions

View file

@ -74,12 +74,16 @@ snd_ctl_type_t snd_ctl_type(snd_ctl_t *ctl)
*/
int snd_ctl_close(snd_ctl_t *ctl)
{
int res;
res = ctl->ops->close(ctl);
int err;
while (!list_empty(&ctl->async_handlers)) {
snd_async_handler_t *h = list_entry(&ctl->async_handlers.next, snd_async_handler_t, hlist);
snd_async_del_handler(h);
}
err = ctl->ops->close(ctl);
if (ctl->name)
free(ctl->name);
free(ctl);
return res;
return err;
}
/**
@ -99,6 +103,22 @@ int snd_ctl_nonblock(snd_ctl_t *ctl, int nonblock)
return 0;
}
#ifndef DOC_HIDDEN
int snd_ctl_new(snd_ctl_t **ctlp, snd_ctl_type_t type, const char *name)
{
snd_ctl_t *ctl;
ctl = calloc(1, sizeof(*ctl));
if (!ctl)
return -ENOMEM;
ctl->type = type;
if (name)
ctl->name = strdup(name);
INIT_LIST_HEAD(&ctl->async_handlers);
*ctlp = ctl;
return 0;
}
/**
* \brief set async mode
* \param ctl CTL handle
@ -110,21 +130,10 @@ int snd_ctl_nonblock(snd_ctl_t *ctl, int nonblock)
*/
int snd_ctl_async(snd_ctl_t *ctl, int sig, pid_t pid)
{
int err;
assert(ctl);
err = ctl->ops->async(ctl, sig, pid);
if (err < 0)
return err;
if (sig)
ctl->async_sig = sig;
else
ctl->async_sig = SIGIO;
if (pid)
ctl->async_pid = pid;
else
ctl->async_pid = getpid();
return 0;
return ctl->ops->async(ctl, sig, pid);
}
#endif
/**
* \brief get count of poll descriptors for CTL handle
@ -148,7 +157,7 @@ int snd_ctl_poll_descriptors(snd_ctl_t *ctl, struct pollfd *pfds, unsigned int s
{
assert(ctl);
if (space > 0) {
pfds->fd = ctl->ops->poll_descriptor(ctl);
pfds->fd = ctl->poll_fd;
pfds->events = POLLIN;
return 1;
}
@ -380,6 +389,50 @@ int snd_ctl_wait(snd_ctl_t *ctl, int timeout)
return 0;
}
/**
* \brief Add an async handler for a CTL
* \param handler Returned handler handle
* \param ctl CTL handle
* \param callback Callback function
* \param private_data Callback private data
* \return 0 otherwise a negative error code on failure
*/
int snd_async_add_ctl_handler(snd_async_handler_t **handler, snd_ctl_t *ctl,
snd_async_callback_t callback, void *private_data)
{
int err;
int was_empty;
snd_async_handler_t *h;
err = snd_async_add_handler(&h, _snd_ctl_async_descriptor(ctl),
callback, private_data);
if (err < 0)
return err;
h->type = SND_ASYNC_HANDLER_CTL;
h->u.ctl = ctl;
was_empty = list_empty(&ctl->async_handlers);
list_add_tail(&h->hlist, &ctl->async_handlers);
if (was_empty) {
err = snd_ctl_async(ctl, getpid(), SIGIO);
if (err < 0) {
snd_async_del_handler(h);
return err;
}
}
*handler = h;
return 0;
}
/**
* \brief Return CTL handle related to an async handler
* \param handler Async handler handle
* \return CTL handle
*/
snd_ctl_t *snd_async_handler_get_ctl(snd_async_handler_t *handler)
{
assert(handler->type = SND_ASYNC_HANDLER_CTL);
return handler->u.ctl;
}
int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
snd_config_t *ctl_root, snd_config_t *ctl_conf, int mode)
{
@ -701,7 +754,7 @@ unsigned int snd_ctl_event_elem_get_index(const snd_ctl_event_t *obj)
int _snd_ctl_poll_descriptor(snd_ctl_t *ctl)
{
assert(ctl);
return ctl->ops->poll_descriptor(ctl);
return ctl->poll_fd;
}
#endif

View file

@ -105,12 +105,6 @@ static int snd_ctl_hw_async(snd_ctl_t *ctl, int sig, pid_t pid)
return 0;
}
static int snd_ctl_hw_poll_descriptor(snd_ctl_t *handle)
{
snd_ctl_hw_t *hw = handle->private_data;
return hw->fd;
}
static int snd_ctl_hw_subscribe_events(snd_ctl_t *handle, int subscribe)
{
snd_ctl_hw_t *hw = handle->private_data;
@ -257,7 +251,6 @@ snd_ctl_ops_t snd_ctl_hw_ops = {
close: snd_ctl_hw_close,
nonblock: snd_ctl_hw_nonblock,
async: snd_ctl_hw_async,
poll_descriptor: snd_ctl_hw_poll_descriptor,
subscribe_events: snd_ctl_hw_subscribe_events,
card_info: snd_ctl_hw_card_info,
element_list: snd_ctl_hw_elem_list,
@ -284,6 +277,7 @@ int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card, int mode)
int fmode;
snd_ctl_t *ctl;
snd_ctl_hw_t *hw;
int err;
*handle = NULL;
@ -308,24 +302,22 @@ int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card, int mode)
close(fd);
return -SND_ERROR_INCOMPATIBLE_VERSION;
}
ctl = calloc(1, sizeof(snd_ctl_t));
if (ctl == NULL) {
close(fd);
return -ENOMEM;
}
hw = calloc(1, sizeof(snd_ctl_hw_t));
if (hw == NULL) {
close(fd);
free(ctl);
return -ENOMEM;
}
hw->card = card;
hw->fd = fd;
if (name)
ctl->name = strdup(name);
ctl->type = SND_CTL_TYPE_HW;
err = snd_ctl_new(&ctl, SND_CTL_TYPE_HW, name);
if (err < 0) {
close(fd);
free(hw);
}
ctl->ops = &snd_ctl_hw_ops;
ctl->private_data = hw;
ctl->poll_fd = fd;
*handle = ctl;
return 0;
}

View file

@ -20,13 +20,11 @@
*/
#include "local.h"
#include "list.h"
typedef struct _snd_ctl_ops {
int (*close)(snd_ctl_t *handle);
int (*nonblock)(snd_ctl_t *handle, int nonblock);
int (*async)(snd_ctl_t *handle, int sig, pid_t pid);
int (*poll_descriptor)(snd_ctl_t *handle);
int (*subscribe_events)(snd_ctl_t *handle, int subscribe);
int (*card_info)(snd_ctl_t *handle, snd_ctl_card_info_t *info);
int (*element_list)(snd_ctl_t *handle, snd_ctl_elem_list_t *list);
@ -53,8 +51,8 @@ struct _snd_ctl {
snd_ctl_ops_t *ops;
void *private_data;
int nonblock;
int async_sig;
pid_t async_pid;
int poll_fd;
struct list_head async_handlers;
};
struct _snd_hctl_elem {
@ -80,6 +78,9 @@ struct _snd_hctl {
};
int snd_ctl_new(snd_ctl_t **ctlp, snd_ctl_type_t type, const char *name);
int _snd_ctl_poll_descriptor(snd_ctl_t *ctl);
#define _snd_ctl_async_descriptor _snd_ctl_poll_descriptor
int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card, int mode);
int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *sockname, const char *sname, int mode);
int snd_ctl_async(snd_ctl_t *ctl, int sig, pid_t pid);

View file

@ -124,7 +124,7 @@ static int snd_ctl_shm_subscribe_events(snd_ctl_t *ctl, int subscribe)
{
snd_ctl_shm_t *shm = ctl->private_data;
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
ctrl->cmd = SND_CTL_IOCTL_POLL_DESCRIPTOR;
ctrl->cmd = SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS;
ctrl->u.subscribe_events = subscribe;
return snd_ctl_shm_action(ctl);
}
@ -368,7 +368,6 @@ snd_ctl_ops_t snd_ctl_shm_ops = {
close: snd_ctl_shm_close,
nonblock: snd_ctl_shm_nonblock,
async: snd_ctl_shm_async,
poll_descriptor: snd_ctl_shm_poll_descriptor,
subscribe_events: snd_ctl_shm_subscribe_events,
card_info: snd_ctl_shm_card_info,
element_list: snd_ctl_shm_elem_list,
@ -492,14 +491,8 @@ int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *sockname
goto _err;
}
ctl = calloc(1, sizeof(snd_ctl_t));
if (!ctl) {
result = -ENOMEM;
goto _err;
}
shm = calloc(1, sizeof(snd_ctl_shm_t));
if (!shm) {
free(ctl);
result = -ENOMEM;
goto _err;
}
@ -507,11 +500,19 @@ int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *sockname
shm->socket = sock;
shm->ctrl = ctrl;
if (name)
ctl->name = strdup(name);
ctl->type = SND_CTL_TYPE_SHM;
err = snd_ctl_new(&ctl, SND_CTL_TYPE_SHM, name);
if (err < 0) {
result = err;
goto _err;
}
ctl->ops = &snd_ctl_shm_ops;
ctl->private_data = shm;
err = snd_ctl_shm_poll_descriptor(ctl);
if (err < 0) {
snd_ctl_close(ctl);
return err;
}
ctl->poll_fd = err;
*handlep = ctl;
return 0;

View file

@ -34,7 +34,6 @@
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include "list.h"
#include "local.h"
typedef struct {