Lines Matching refs:client

154 typedef struct client client_t;
157 int (*open)(client_t *client, int *cookie);
158 int (*cmd)(client_t *client);
159 int (*close)(client_t *client);
162 struct client {
223 client_t *client = waiter->private_data;
227 n = write(client->poll_fd, buf, 1);
233 n = read(client->poll_fd, buf, 1);
240 client->polling = 0;
247 client_t *client = pcm->hw.private_data;
248 volatile snd_pcm_shm_ctrl_t *ctrl = client->transport.shm.ctrl;
266 client_t *client = pcm->appl.private_data;
267 volatile snd_pcm_shm_ctrl_t *ctrl = client->transport.shm.ctrl;
283 static int pcm_shm_open(client_t *client, int *cookie)
289 err = snd_pcm_open(&pcm, client->name, client->stream, SND_PCM_NONBLOCK);
292 client->device.pcm.handle = pcm;
293 client->device.pcm.fd = _snd_pcm_poll_descriptor(pcm);
294 pcm->hw.private_data = client;
296 pcm->appl.private_data = client;
305 client->transport.shm.ctrl_id = shmid;
306 client->transport.shm.ctrl = shmat(shmid, 0, 0);
307 if (client->transport.shm.ctrl == (void*) -1) {
322 static int pcm_shm_close(client_t *client)
325 snd_pcm_shm_ctrl_t *ctrl = client->transport.shm.ctrl;
326 if (client->polling) {
327 del_waiter(client->device.pcm.fd);
328 client->polling = 0;
330 err = snd_pcm_close(client->device.pcm.handle);
334 if (client->transport.shm.ctrl) {
335 err = shmdt((void *)client->transport.shm.ctrl);
338 err = shmctl(client->transport.shm.ctrl_id, IPC_RMID, 0);
341 client->transport.shm.ctrl = 0;
343 client->open = 0;
347 static int shm_ack(client_t *client)
352 pfd.fd = client->ctrl_fd;
356 err = write(client->ctrl_fd, buf, 1);
362 static int shm_ack_fd(client_t *client, int fd)
367 pfd.fd = client->ctrl_fd;
371 err = snd_send_fd(client->ctrl_fd, buf, 1, fd);
377 static int shm_rbptr_fd(client_t *client, snd_pcm_rbptr_t *rbptr)
381 return shm_ack_fd(client, rbptr->fd);
386 client_t *client = snd_async_handler_get_callback_private(handler);
388 kill(client->async_pid, client->async_sig);
391 static int pcm_shm_cmd(client_t *client)
393 volatile snd_pcm_shm_ctrl_t *ctrl = client->transport.shm.ctrl;
398 err = read(client->ctrl_fd, buf, 1);
403 pcm = client->device.pcm.handle;
410 assert(client->async_sig < 0);
411 ctrl->result = snd_async_add_pcm_handler(&client->async_handler, pcm, async_handler, client);
415 assert(client->async_sig >= 0);
416 snd_async_del_handler(client->async_handler);
418 client->async_sig = ctrl->u.async.sig;
419 client->async_pid = ctrl->u.async.pid;
473 return shm_ack_fd(client, ctrl->u.channel_info.u.mmap.fd);
510 return shm_ack_fd(client, _snd_pcm_poll_descriptor(pcm));
512 client->ops->close(client);
515 return shm_rbptr_fd(client, &pcm->hw);
517 return shm_rbptr_fd(client, &pcm->appl);
522 return shm_ack(client);
533 client_t *client = waiter->private_data;
537 n = write(client->poll_fd, buf, 1);
544 client->polling = 0;
548 static int ctl_shm_open(client_t *client, int *cookie)
554 err = snd_ctl_open(&ctl, client->name, SND_CTL_NONBLOCK);
557 client->device.ctl.handle = ctl;
558 client->device.ctl.fd = _snd_ctl_poll_descriptor(ctl);
566 client->transport.shm.ctrl_id = shmid;
567 client->transport.shm.ctrl = shmat(shmid, 0, 0);
568 if (!client->transport.shm.ctrl) {
575 add_waiter(client->device.ctl.fd, POLLIN, ctl_handler, client);
576 client->polling = 1;
585 static int ctl_shm_close(client_t *client)
588 snd_ctl_shm_ctrl_t *ctrl = client->transport.shm.ctrl;
589 if (client->polling) {
590 del_waiter(client->device.ctl.fd);
591 client->polling = 0;
593 err = snd_ctl_close(client->device.ctl.handle);
597 if (client->transport.shm.ctrl) {
598 err = shmdt((void *)client->transport.shm.ctrl);
601 err = shmctl(client->transport.shm.ctrl_id, IPC_RMID, 0);
604 client->transport.shm.ctrl = 0;
606 client->open = 0;
610 static int ctl_shm_cmd(client_t *client)
612 snd_ctl_shm_ctrl_t *ctrl = client->transport.shm.ctrl;
617 err = read(client->ctrl_fd, buf, 1);
622 ctl = client->device.ctl.handle;
629 assert(client->async_sig < 0);
630 ctrl->result = snd_async_add_ctl_handler(&client->async_handler, ctl, async_handler, client);
634 assert(client->async_sig >= 0);
635 snd_async_del_handler(client->async_handler);
637 client->async_sig = ctrl->u.async.sig;
638 client->async_pid = ctrl->u.async.pid;
707 client->ops->close(client);
711 return shm_ack_fd(client, _snd_ctl_poll_descriptor(ctl));
716 return shm_ack(client);
725 static int snd_client_open(client_t *client)
732 err = read(client->ctrl_fd, &req, sizeof(req));
742 err = read(client->ctrl_fd, name, req.namelen);
754 if (!client->local) {
760 client->ops = &pcm_shm_ops;
763 client->ops = &ctl_shm_ops;
777 client->transport_type = req.transport_type;
778 if (sizeof(client->name) < (size_t)(req.namelen + 1)) {
782 strcpy(client->name, name);
783 client->stream = req.stream;
784 client->mode = req.mode;
786 err = client->ops->open(client, &ans.cookie);
790 client->open = 1;
795 err = write(client->ctrl_fd, &ans, sizeof(ans));
805 client_t *client = waiter->private_data;
806 if (client->open)
807 client->ops->close(client);
808 close(client->poll_fd);
809 close(client->ctrl_fd);
810 del_waiter(client->poll_fd);
811 del_waiter(client->ctrl_fd);
812 list_del(&client->list);
813 free(client);
819 client_t *client = waiter->private_data;
821 if (client->open)
822 client->ops->close(client);
823 close(client->ctrl_fd);
824 del_waiter(client->ctrl_fd);
825 list_del(&client->list);
826 free(client);
829 if (client->open)
830 return client->ops->cmd(client);
832 return snd_client_open(client);
839 client_t *client;
872 client = calloc(1, sizeof(*client));
873 client->local = 0;
874 client->poll_fd = pdata->fd;
875 client->ctrl_fd = waiter->fd;
876 add_waiter(client->ctrl_fd, POLLIN | POLLHUP, client_ctrl_handler, client);
877 add_waiter(client->poll_fd, POLLHUP, client_poll_handler, client);
878 client->open = 0;
879 list_add_tail(&client->list, &clients);
896 client_t *client = calloc(1, sizeof(*client));
897 client->ctrl_fd = sock;
898 client->local = 1;
899 client->open = 0;
900 add_waiter(sock, POLLIN | POLLHUP, client_ctrl_handler, client);
901 list_add_tail(&client->list, &clients);