2004-06-18 00:22:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
#include "module.h"
|
|
|
|
|
#include "iochannel.h"
|
|
|
|
|
#include "cli.h"
|
|
|
|
|
|
|
|
|
|
int module_init(struct core *c, struct module*m) {
|
|
|
|
|
struct iochannel *io;
|
|
|
|
|
assert(c && m);
|
|
|
|
|
|
|
|
|
|
if (stdin_inuse || stdout_inuse) {
|
|
|
|
|
fprintf(stderr, "STDIN/STDUSE already used\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stdin_inuse = stdout_inuse = 1;
|
|
|
|
|
io = iochannel_new(c->mainloop, STDIN_FILENO, STDOUT_FILENO);
|
|
|
|
|
assert(io);
|
2004-06-19 19:27:47 +00:00
|
|
|
iochannel_set_noclose(io, 1);
|
2004-06-18 00:22:37 +00:00
|
|
|
|
|
|
|
|
m->userdata = cli_new(c, io);
|
|
|
|
|
assert(m->userdata);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void module_done(struct core *c, struct module*m) {
|
|
|
|
|
assert(c && m);
|
|
|
|
|
|
|
|
|
|
cli_free(m->userdata);
|
|
|
|
|
assert(stdin_inuse && stdout_inuse);
|
|
|
|
|
stdin_inuse = stdout_inuse = 0;
|
|
|
|
|
}
|