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 struct pa_autoload_entry
* entry_new(struct pa_core
*c
, const char *name
) {
49 struct pa_autoload_entry
*e
= NULL
;
52 if (c
->autoload_hashmap
&& (e
= pa_hashmap_get(c
->autoload_hashmap
, name
)))
55 e
= pa_xmalloc(sizeof(struct pa_autoload_entry
));
57 e
->name
= pa_xstrdup(name
);
58 e
->module
= e
->argument
= NULL
;
61 if (!c
->autoload_hashmap
)
62 c
->autoload_hashmap
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
63 assert(c
->autoload_hashmap
);
65 pa_hashmap_put(c
->autoload_hashmap
, e
->name
, e
);
67 pa_subscription_post(c
, PA_SUBSCRIPTION_EVENT_AUTOLOAD
|PA_SUBSCRIPTION_EVENT_NEW
, PA_INVALID_INDEX
);
72 int pa_autoload_add(struct pa_core
*c
, const char*name
, enum pa_namereg_type type
, const char*module
, const char *argument
) {
73 struct pa_autoload_entry
*e
= NULL
;
74 assert(c
&& name
&& module
&& (type
== PA_NAMEREG_SINK
|| type
== PA_NAMEREG_SOURCE
));
76 if (!(e
= entry_new(c
, name
)))
79 e
->module
= pa_xstrdup(module
);
80 e
->argument
= pa_xstrdup(argument
);
85 int pa_autoload_remove(struct pa_core
*c
, const char*name
, enum pa_namereg_type type
) {
86 struct pa_autoload_entry
*e
;
87 assert(c
&& name
&& type
);
89 if (!c
->autoload_hashmap
|| !(e
= pa_hashmap_get(c
->autoload_hashmap
, name
)))
92 pa_hashmap_remove(c
->autoload_hashmap
, e
->name
);
97 void pa_autoload_request(struct pa_core
*c
, const char *name
, enum pa_namereg_type type
) {
98 struct pa_autoload_entry
*e
;
102 if (!c
->autoload_hashmap
|| !(e
= pa_hashmap_get(c
->autoload_hashmap
, name
)) || (e
->type
!= type
))
110 if (type
== PA_NAMEREG_SINK
|| type
== PA_NAMEREG_SOURCE
) {
111 if ((m
= pa_module_load(c
, e
->module
, e
->argument
)))
118 static void free_func(void *p
, void *userdata
) {
119 struct pa_autoload_entry
*e
= p
;
123 void pa_autoload_free(struct pa_core
*c
) {
124 if (!c
->autoload_hashmap
)
127 pa_hashmap_free(c
->autoload_hashmap
, free_func
, NULL
);