11 struct pa_module
* pa_module_load(struct pa_core
*c
, const char *name
, const char *argument
) {
12 struct pa_module
*m
= NULL
;
17 m
= malloc(sizeof(struct pa_module
));
20 m
->name
= strdup(name
);
21 m
->argument
= argument
? strdup(argument
) : NULL
;
23 if (!(m
->dl
= lt_dlopenext(name
)))
26 if (!(m
->init
= lt_dlsym(m
->dl
, "pa_module_init")))
29 if (!(m
->done
= lt_dlsym(m
->dl
, "pa_module_done")))
36 if (m
->init(c
, m
) < 0)
40 c
->modules
= pa_idxset_new(NULL
, NULL
);
43 r
= pa_idxset_put(c
->modules
, m
, &m
->index
);
44 assert(r
>= 0 && m
->index
!= PA_IDXSET_INVALID
);
46 fprintf(stderr
, "module: loaded %u \"%s\" with argument \"%s\".\n", m
->index
, m
->name
, m
->argument
);
64 static void pa_module_free(struct pa_module
*m
) {
65 assert(m
&& m
->done
&& m
->core
);
70 fprintf(stderr
, "module: unloaded %u \"%s\".\n", m
->index
, m
->name
);
78 void pa_module_unload(struct pa_core
*c
, struct pa_module
*m
) {
82 if (!(m
= pa_idxset_remove_by_data(c
->modules
, m
, NULL
)))
88 void pa_module_unload_by_index(struct pa_core
*c
, uint32_t index
) {
90 assert(c
&& index
!= PA_IDXSET_INVALID
);
93 if (!(m
= pa_idxset_remove_by_index(c
->modules
, index
)))
99 static void free_callback(void *p
, void *userdata
) {
100 struct pa_module
*m
= p
;
105 void pa_module_unload_all(struct pa_core
*c
) {
111 pa_idxset_free(c
->modules
, free_callback
, NULL
);
115 char *pa_module_list_to_string(struct pa_core
*c
) {
118 uint32_t index
= PA_IDXSET_INVALID
;
124 pa_strbuf_printf(s
, "%u module(s) loaded.\n", pa_idxset_ncontents(c
->modules
));
126 for (m
= pa_idxset_first(c
->modules
, &index
); m
; m
= pa_idxset_next(c
->modules
, &index
))
127 pa_strbuf_printf(s
, " index: %u\n\tname: <%s>\n\targument: <%s>\n", m
->index
, m
->name
, m
->argument
);
129 return pa_strbuf_tostring_free(s
);
134 struct pa_core
*core
;
139 static void module_unload_once_callback(void *userdata
) {
140 struct once_info
*i
= userdata
;
142 pa_module_unload_by_index(i
->core
, i
->index
);
146 void pa_module_unload_request(struct pa_core
*c
, struct pa_module
*m
) {
150 i
= malloc(sizeof(struct once_info
));
154 pa_mainloop_api_once(c
->mainloop
, module_unload_once_callback
, i
);