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
34 #include "sound-file.h"
37 #include "subscribe.h"
39 static void entry_free(struct pa_autoload_entry
*e
) {
41 pa_subscription_post(e
->core
, PA_SUBSCRIPTION_EVENT_AUTOLOAD
|PA_SUBSCRIPTION_EVENT_REMOVE
, PA_INVALID_INDEX
);
44 pa_xfree(e
->argument
);
48 static void entry_remove_and_free(struct pa_autoload_entry
*e
) {
51 pa_idxset_remove_by_data(e
->core
->autoload_idxset
, e
, NULL
);
52 pa_hashmap_remove(e
->core
->autoload_hashmap
, e
->name
);
56 static struct pa_autoload_entry
* entry_new(struct pa_core
*c
, const char *name
) {
57 struct pa_autoload_entry
*e
= NULL
;
60 if (c
->autoload_hashmap
&& (e
= pa_hashmap_get(c
->autoload_hashmap
, name
)))
63 e
= pa_xmalloc(sizeof(struct pa_autoload_entry
));
65 e
->name
= pa_xstrdup(name
);
66 e
->module
= e
->argument
= NULL
;
69 if (!c
->autoload_hashmap
)
70 c
->autoload_hashmap
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
71 assert(c
->autoload_hashmap
);
73 pa_hashmap_put(c
->autoload_hashmap
, e
->name
, e
);
75 if (!c
->autoload_idxset
)
76 c
->autoload_idxset
= pa_idxset_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
77 pa_idxset_put(c
->autoload_idxset
, e
, &e
->index
);
79 pa_subscription_post(c
, PA_SUBSCRIPTION_EVENT_AUTOLOAD
|PA_SUBSCRIPTION_EVENT_NEW
, e
->index
);
84 int pa_autoload_add(struct pa_core
*c
, const char*name
, enum pa_namereg_type type
, const char*module
, const char *argument
, uint32_t *index
) {
85 struct pa_autoload_entry
*e
= NULL
;
86 assert(c
&& name
&& module
&& (type
== PA_NAMEREG_SINK
|| type
== PA_NAMEREG_SOURCE
));
88 if (!(e
= entry_new(c
, name
)))
91 e
->module
= pa_xstrdup(module
);
92 e
->argument
= pa_xstrdup(argument
);
101 int pa_autoload_remove_by_name(struct pa_core
*c
, const char*name
, enum pa_namereg_type type
) {
102 struct pa_autoload_entry
*e
;
103 assert(c
&& name
&& type
);
105 if (!c
->autoload_hashmap
|| !(e
= pa_hashmap_get(c
->autoload_hashmap
, name
)) || e
->type
!= type
)
108 entry_remove_and_free(e
);
112 int pa_autoload_remove_by_index(struct pa_core
*c
, uint32_t index
) {
113 struct pa_autoload_entry
*e
;
114 assert(c
&& index
!= PA_IDXSET_INVALID
);
116 if (!c
->autoload_idxset
|| !(e
= pa_idxset_get_by_index(c
->autoload_idxset
, index
)))
119 entry_remove_and_free(e
);
123 void pa_autoload_request(struct pa_core
*c
, const char *name
, enum pa_namereg_type type
) {
124 struct pa_autoload_entry
*e
;
128 if (!c
->autoload_hashmap
|| !(e
= pa_hashmap_get(c
->autoload_hashmap
, name
)) || (e
->type
!= type
))
136 if (type
== PA_NAMEREG_SINK
|| type
== PA_NAMEREG_SOURCE
) {
137 if ((m
= pa_module_load(c
, e
->module
, e
->argument
)))
144 static void free_func(void *p
, void *userdata
) {
145 struct pa_autoload_entry
*e
= p
;
146 pa_idxset_remove_by_data(e
->core
->autoload_idxset
, e
, NULL
);
150 void pa_autoload_free(struct pa_core
*c
) {
151 if (c
->autoload_hashmap
) {
152 pa_hashmap_free(c
->autoload_hashmap
, free_func
, NULL
);
153 c
->autoload_hashmap
= NULL
;
156 if (c
->autoload_idxset
) {
157 pa_idxset_free(c
->autoload_idxset
, NULL
, NULL
);
158 c
->autoload_idxset
= NULL
;
162 const struct pa_autoload_entry
* pa_autoload_get_by_name(struct pa_core
*c
, const char*name
, enum pa_namereg_type type
) {
163 struct pa_autoload_entry
*e
;
166 if (!c
->autoload_hashmap
|| !(e
= pa_hashmap_get(c
->autoload_hashmap
, name
)) || e
->type
!= type
)
172 const struct pa_autoload_entry
* pa_autoload_get_by_index(struct pa_core
*c
, uint32_t index
) {
173 struct pa_autoload_entry
*e
;
174 assert(c
&& index
!= PA_IDXSET_INVALID
);
176 if (!c
->autoload_idxset
|| !(e
= pa_idxset_get_by_index(c
->autoload_idxset
, index
)))