10 struct pa_module
* pa_module_load(struct pa_core
*c
, const char *name
, const char *argument
) {
11 struct pa_module
*m
= NULL
;
16 m
= malloc(sizeof(struct pa_module
));
19 m
->name
= strdup(name
);
20 m
->argument
= argument
? strdup(argument
) : NULL
;
22 if (!(m
->dl
= lt_dlopenext(name
)))
25 if (!(m
->init
= lt_dlsym(m
->dl
, "pa_module_init")))
28 if (!(m
->done
= lt_dlsym(m
->dl
, "pa_module_done")))
35 if (m
->init(c
, m
) < 0)
39 c
->modules
= pa_idxset_new(NULL
, NULL
);
42 r
= pa_idxset_put(c
->modules
, m
, &m
->index
);
43 assert(r
>= 0 && m
->index
!= PA_IDXSET_INVALID
);
45 fprintf(stderr
, "module: loaded %u \"%s\" with argument \"%s\".\n", m
->index
, m
->name
, m
->argument
);
63 static void pa_module_free(struct pa_module
*m
) {
64 assert(m
&& m
->done
&& m
->core
);
69 fprintf(stderr
, "module: unloaded %u \"%s\".\n", m
->index
, m
->name
);
77 void pa_module_unload(struct pa_core
*c
, struct pa_module
*m
) {
81 if (!(m
= pa_idxset_remove_by_data(c
->modules
, m
, NULL
)))
87 void pa_module_unload_by_index(struct pa_core
*c
, uint32_t index
) {
89 assert(c
&& index
!= PA_IDXSET_INVALID
);
92 if (!(m
= pa_idxset_remove_by_index(c
->modules
, index
)))
98 static void free_callback(void *p
, void *userdata
) {
99 struct pa_module
*m
= p
;
104 void pa_module_unload_all(struct pa_core
*c
) {
110 pa_idxset_free(c
->modules
, free_callback
, NULL
);
115 struct pa_core
*core
;
120 static void module_unload_once_callback(void *userdata
) {
121 struct once_info
*i
= userdata
;
123 pa_module_unload_by_index(i
->core
, i
->index
);
127 void pa_module_unload_request(struct pa_core
*c
, struct pa_module
*m
) {
131 i
= malloc(sizeof(struct once_info
));
135 pa_mainloop_api_once(c
->mainloop
, module_unload_once_callback
, i
);