• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/iserver/alsa-lib-1.0.26/src/timer/

Lines Matching defs:*

2  *  Timer Interface - main file
3 * Copyright (c) 1998-2001 by Jaroslav Kysela <perex@perex.cz>
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <string.h>
26 #include <fcntl.h>
27 #include <sys/ioctl.h>
28 #include "timer_local.h"
30 #ifndef PIC
31 /* entry for static linking */
32 const char *_snd_module_timer_query_hw = "";
33 #endif
35 #define SNDRV_FILE_TIMER ALSA_DEVICE_DIRECTORY "timer"
36 #define SNDRV_TIMER_VERSION_MAX SNDRV_PROTOCOL_VERSION(2, 0, 0)
38 static int snd_timer_query_hw_close(snd_timer_query_t *handle)
40 int res;
42 if (!handle)
43 return -EINVAL;
44 res = close(handle->poll_fd) < 0 ? -errno : 0;
45 return res;
48 static int snd_timer_query_hw_next_device(snd_timer_query_t *handle, snd_timer_id_t * tid)
50 if (!handle || !tid)
51 return -EINVAL;
52 if (ioctl(handle->poll_fd, SNDRV_TIMER_IOCTL_NEXT_DEVICE, tid) < 0)
53 return -errno;
54 return 0;
57 static int snd_timer_query_hw_info(snd_timer_query_t *handle, snd_timer_ginfo_t *info)
59 if (!handle || !info)
60 return -EINVAL;
61 if (ioctl(handle->poll_fd, SNDRV_TIMER_IOCTL_GINFO, info) < 0)
62 return -errno;
63 return 0;
66 static int snd_timer_query_hw_params(snd_timer_query_t *handle, snd_timer_gparams_t *params)
68 if (!handle || !params)
69 return -EINVAL;
70 if (ioctl(handle->poll_fd, SNDRV_TIMER_IOCTL_GPARAMS, params) < 0)
71 return -errno;
72 return 0;
75 static int snd_timer_query_hw_status(snd_timer_query_t *handle, snd_timer_gstatus_t *status)
77 if (!handle || !status)
78 return -EINVAL;
79 if (ioctl(handle->poll_fd, SNDRV_TIMER_IOCTL_GSTATUS, status) < 0)
80 return -errno;
81 return 0;
84 static const snd_timer_query_ops_t snd_timer_query_hw_ops = {
85 .close = snd_timer_query_hw_close,
86 .next_device = snd_timer_query_hw_next_device,
87 .info = snd_timer_query_hw_info,
88 .params = snd_timer_query_hw_params,
89 .status = snd_timer_query_hw_status
92 int snd_timer_query_hw_open(snd_timer_query_t **handle, const char *name, int mode)
94 int fd, ver, tmode;
95 snd_timer_query_t *tmr;
97 *handle = NULL;
99 tmode = O_RDONLY;
100 if (mode & SND_TIMER_OPEN_NONBLOCK)
101 tmode |= O_NONBLOCK;
102 fd = snd_open_device(SNDRV_FILE_TIMER, tmode);
103 if (fd < 0)
104 return -errno;
105 if (ioctl(fd, SNDRV_TIMER_IOCTL_PVERSION, &ver) < 0) {
106 close(fd);
107 return -errno;
109 if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_TIMER_VERSION_MAX)) {
110 close(fd);
111 return -SND_ERROR_INCOMPATIBLE_VERSION;
113 tmr = (snd_timer_query_t *) calloc(1, sizeof(snd_timer_t));
114 if (tmr == NULL) {
115 close(fd);
116 return -ENOMEM;
118 tmr->type = SND_TIMER_TYPE_HW;
119 tmr->mode = tmode;
120 tmr->name = strdup(name);
121 tmr->poll_fd = fd;
122 tmr->ops = &snd_timer_query_hw_ops;
123 *handle = tmr;
124 return 0;
127 int _snd_timer_query_hw_open(snd_timer_query_t **timer, char *name,
128 snd_config_t *root ATTRIBUTE_UNUSED,
129 snd_config_t *conf, int mode)
131 snd_config_iterator_t i, next;
132 snd_config_for_each(i, next, conf) {
133 snd_config_t *n = snd_config_iterator_entry(i);
134 const char *id;
135 if (snd_config_get_id(n, &id) < 0)
136 continue;
137 if (strcmp(id, "comment") == 0)
138 continue;
139 if (strcmp(id, "type") == 0)
140 continue;
141 SNDERR("Unexpected field %s", id);
142 return -EINVAL;
144 return snd_timer_query_hw_open(timer, name, mode);
146 SND_DLSYM_BUILD_VERSION(_snd_timer_query_hw_open, SND_TIMER_QUERY_DLSYM_VERSION);