4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
35 struct namereg_entry
{
36 enum pa_namereg_type type
;
41 void pa_namereg_free(struct pa_core
*c
) {
45 assert(pa_hashmap_ncontents(c
->namereg
) == 0);
46 pa_hashmap_free(c
->namereg
, NULL
, NULL
);
49 const char *pa_namereg_register(struct pa_core
*c
, const char *name
, enum pa_namereg_type type
, void *data
, int fail
) {
50 struct namereg_entry
*e
;
54 assert(c
&& name
&& data
);
57 c
->namereg
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
61 if ((e
= pa_hashmap_get(c
->namereg
, name
)) && fail
)
68 size_t l
= strlen(name
);
72 for (i
= 1; i
<= 99; i
++) {
73 snprintf(n
, l
+2, "%s%u", name
, i
);
75 if (!(e
= pa_hashmap_get(c
->namereg
, n
)))
86 e
= malloc(sizeof(struct namereg_entry
));
92 r
= pa_hashmap_put(c
->namereg
, e
->name
, e
);
99 void pa_namereg_unregister(struct pa_core
*c
, const char *name
) {
100 struct namereg_entry
*e
;
104 e
= pa_hashmap_get(c
->namereg
, name
);
107 r
= pa_hashmap_remove(c
->namereg
, name
);
114 void* pa_namereg_get(struct pa_core
*c
, const char *name
, enum pa_namereg_type type
) {
115 struct namereg_entry
*e
;
121 if ((e
= pa_hashmap_get(c
->namereg
, name
)))
122 if (e
->type
== e
->type
)
125 index
= (uint32_t) strtol(name
, &x
, 0);
130 if (type
== PA_NAMEREG_SINK
)
131 d
= pa_idxset_get_by_index(c
->sinks
, index
);
132 else if (type
== PA_NAMEREG_SOURCE
)
133 d
= pa_idxset_get_by_index(c
->sources
, index
);