2004-06-18 00:22:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
|
#include "iochannel.h"
|
|
|
|
|
#include "cli.h"
|
2004-07-04 17:40:15 +00:00
|
|
|
#include "sioman.h"
|
|
|
|
|
|
|
|
|
|
static void eof_cb(struct pa_cli*c, void *userdata) {
|
|
|
|
|
struct pa_module *m = userdata;
|
|
|
|
|
assert(c && m);
|
|
|
|
|
|
|
|
|
|
pa_module_unload_request(m->core, m);
|
|
|
|
|
}
|
2004-06-18 00:22:37 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
int module_init(struct pa_core *c, struct pa_module*m) {
|
|
|
|
|
struct pa_iochannel *io;
|
2004-06-18 00:22:37 +00:00
|
|
|
assert(c && m);
|
|
|
|
|
|
2004-07-04 17:40:15 +00:00
|
|
|
if (pa_stdio_acquire() < 0) {
|
2004-06-18 00:22:37 +00:00
|
|
|
fprintf(stderr, "STDIN/STDUSE already used\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
io = pa_iochannel_new(c->mainloop, STDIN_FILENO, STDOUT_FILENO);
|
2004-06-18 00:22:37 +00:00
|
|
|
assert(io);
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_iochannel_set_noclose(io, 1);
|
2004-06-18 00:22:37 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
m->userdata = pa_cli_new(c, io);
|
2004-06-18 00:22:37 +00:00
|
|
|
assert(m->userdata);
|
2004-07-04 17:40:15 +00:00
|
|
|
|
|
|
|
|
pa_cli_set_eof_callback(m->userdata, eof_cb, m);
|
|
|
|
|
|
2004-06-18 00:22:37 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
void module_done(struct pa_core *c, struct pa_module*m) {
|
2004-06-18 00:22:37 +00:00
|
|
|
assert(c && m);
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_cli_free(m->userdata);
|
2004-07-04 17:40:15 +00:00
|
|
|
pa_stdio_release();
|
2004-06-18 00:22:37 +00:00
|
|
|
}
|