Commit e5b0bc44 authored by pbrook's avatar pbrook

Rearrange char event handlers to fix CHR_EVENT_RESET.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2361 c046a42c-6fe2-441c-8c8c-71466251a162
parent dff5efc8
......@@ -132,10 +132,7 @@ struct TextConsole {
int esc_params[MAX_ESC_PARAMS];
int nb_esc_params;
/* kbd read handler */
IOCanRWHandler *fd_can_read;
IOReadHandler *fd_read;
void *fd_opaque;
CharDriverState *chr;
/* fifo for key pressed */
QEMUFIFO out_fifo;
uint8_t out_fifo_buf[16];
......@@ -1021,16 +1018,6 @@ static int console_puts(CharDriverState *chr, const uint8_t *buf, int len)
return len;
}
static void console_chr_add_read_handler(CharDriverState *chr,
IOCanRWHandler *fd_can_read,
IOReadHandler *fd_read, void *opaque)
{
TextConsole *s = chr->opaque;
s->fd_can_read = fd_can_read;
s->fd_read = fd_read;
s->fd_opaque = opaque;
}
static void console_send_event(CharDriverState *chr, int event)
{
TextConsole *s = chr->opaque;
......@@ -1052,14 +1039,14 @@ static void kbd_send_chars(void *opaque)
int len;
uint8_t buf[16];
len = s->fd_can_read(s->fd_opaque);
len = qemu_chr_can_read(s->chr);
if (len > s->out_fifo.count)
len = s->out_fifo.count;
if (len > 0) {
if (len > sizeof(buf))
len = sizeof(buf);
qemu_fifo_read(&s->out_fifo, buf, len);
s->fd_read(s->fd_opaque, buf, len);
qemu_chr_read(s->chr, buf, len);
}
/* characters are pending: we send them a bit later (XXX:
horrible, should change char device API) */
......@@ -1110,7 +1097,7 @@ void kbd_put_keysym(int keysym)
} else {
*q++ = keysym;
}
if (s->fd_read) {
if (s->chr->chr_read) {
qemu_fifo_write(&s->out_fifo, buf, q - buf);
kbd_send_chars(s);
}
......@@ -1186,9 +1173,9 @@ CharDriverState *text_console_init(DisplayState *ds)
}
chr->opaque = s;
chr->chr_write = console_puts;
chr->chr_add_read_handler = console_chr_add_read_handler;
chr->chr_send_event = console_send_event;
s->chr = chr;
s->out_fifo.buf = s->out_fifo_buf;
s->out_fifo.buf_size = sizeof(s->out_fifo_buf);
s->kbd_timer = qemu_new_timer(rt_clock, kbd_send_chars, s);
......
......@@ -243,8 +243,8 @@ void pl011_init(uint32_t base, void *pic, int irq,
s->cr = 0x300;
s->flags = 0x90;
if (chr){
qemu_chr_add_read_handler(chr, pl011_can_recieve, pl011_recieve, s);
qemu_chr_add_event_handler(chr, pl011_event);
qemu_chr_add_handlers(chr, pl011_can_recieve, pl011_recieve,
pl011_event, s);
}
/* ??? Save/restore. */
}
......
......@@ -365,8 +365,8 @@ SerialState *serial_init(SetIRQFunc *set_irq, void *opaque,
register_ioport_write(base, 8, 1, serial_ioport_write, s);
register_ioport_read(base, 8, 1, serial_ioport_read, s);
s->chr = chr;
qemu_chr_add_read_handler(chr, serial_can_receive1, serial_receive1, s);
qemu_chr_add_event_handler(chr, serial_event);
qemu_chr_add_handlers(chr, serial_can_receive1, serial_receive1,
serial_event, s);
return s;
}
......@@ -453,7 +453,7 @@ SerialState *serial_mm_init (SetIRQFunc *set_irq, void *opaque,
serial_mm_write, s);
cpu_register_physical_memory(base, 8 << it_shift, s_io_memory);
s->chr = chr;
qemu_chr_add_read_handler(chr, serial_can_receive1, serial_receive1, s);
qemu_chr_add_event_handler(chr, serial_event);
qemu_chr_add_handlers(chr, serial_can_receive1, serial_receive1,
serial_event, s);
return s;
}
......@@ -299,9 +299,8 @@ static void init_serial1(SH7750State * s, int serial_nb)
}
s->serial1 = chr;
qemu_chr_add_read_handler(chr, serial1_can_receive,
serial1_receive, s);
qemu_chr_add_event_handler(chr, serial1_event);
qemu_chr_add_handlers(chr, serial1_can_receive,
serial1_receive, serial1_event, s);
}
/**********************************************************************
......@@ -415,9 +414,8 @@ static void init_serial2(SH7750State * s, int serial_nb)
}
s->serial2 = chr;
qemu_chr_add_read_handler(chr, serial2_can_receive,
serial2_receive, s);
qemu_chr_add_event_handler(chr, serial2_event);
qemu_chr_add_handlers(chr, serial2_can_receive,
serial2_receive, serial1_event, s);
}
static void init_serial_ports(SH7750State * s)
......
......@@ -565,8 +565,8 @@ SerialState *slavio_serial_init(int base, int irq, CharDriverState *chr1, CharDr
s->chn[i].chn = 1 - i;
s->chn[i].type = ser;
if (s->chn[i].chr) {
qemu_chr_add_read_handler(s->chn[i].chr, serial_can_receive, serial_receive1, &s->chn[i]);
qemu_chr_add_event_handler(s->chn[i].chr, serial_event);
qemu_chr_add_handlers(s->chn[i].chr, serial_can_receive,
serial_receive1, serial_event, &s->chn[i]);
}
}
s->chn[0].otherchn = &s->chn[1];
......
......@@ -2455,8 +2455,7 @@ void monitor_init(CharDriverState *hd, int show_banner)
monitor_hd = hd;
hide_banner = !show_banner;
qemu_chr_add_read_handler(hd, term_can_read, term_read, NULL);
qemu_chr_add_event_handler(hd, term_event);
qemu_chr_add_handlers(hd, term_can_read, term_read, term_event, NULL);
}
/* XXX: use threads ? */
......
......@@ -1119,11 +1119,17 @@ void quit_timers(void)
/***********************************************************/
/* character device */
static void qemu_chr_event(CharDriverState *s, int event)
{
if (!s->chr_event)
return;
s->chr_event(s->handler_opaque, event);
}
static void qemu_chr_reset_bh(void *opaque)
{
CharDriverState *s = opaque;
if (s->chr_event)
s->chr_event(s, CHR_EVENT_RESET);
qemu_chr_event(s, CHR_EVENT_RESET);
qemu_bh_delete(s->bh);
s->bh = NULL;
}
......@@ -1148,6 +1154,19 @@ int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg)
return s->chr_ioctl(s, cmd, arg);
}
int qemu_chr_can_read(CharDriverState *s)
{
if (!s->chr_can_read)
return 0;
return s->chr_can_read(s->handler_opaque);
}
void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len)
{
s->chr_read(s->handler_opaque, buf, len);
}
void qemu_chr_printf(CharDriverState *s, const char *fmt, ...)
{
char buf[4096];
......@@ -1164,29 +1183,25 @@ void qemu_chr_send_event(CharDriverState *s, int event)
s->chr_send_event(s, event);
}
void qemu_chr_add_read_handler(CharDriverState *s,
IOCanRWHandler *fd_can_read,
IOReadHandler *fd_read, void *opaque)
void qemu_chr_add_handlers(CharDriverState *s,
IOCanRWHandler *fd_can_read,
IOReadHandler *fd_read,
IOEventHandler *fd_event,
void *opaque)
{
s->chr_add_read_handler(s, fd_can_read, fd_read, opaque);
s->chr_can_read = fd_can_read;
s->chr_read = fd_read;
s->chr_event = fd_event;
s->handler_opaque = opaque;
if (s->chr_update_read_handler)
s->chr_update_read_handler(s);
}
void qemu_chr_add_event_handler(CharDriverState *s, IOEventHandler *chr_event)
{
s->chr_event = chr_event;
}
static int null_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
{
return len;
}
static void null_chr_add_read_handler(CharDriverState *chr,
IOCanRWHandler *fd_can_read,
IOReadHandler *fd_read, void *opaque)
{
}
static CharDriverState *qemu_chr_open_null(void)
{
CharDriverState *chr;
......@@ -1195,7 +1210,6 @@ static CharDriverState *qemu_chr_open_null(void)
if (!chr)
return NULL;
chr->chr_write = null_chr_write;
chr->chr_add_read_handler = null_chr_add_read_handler;
return chr;
}
......@@ -1287,9 +1301,6 @@ void socket_set_nonblock(int fd)
typedef struct {
int fd_in, fd_out;
IOCanRWHandler *fd_can_read;
IOReadHandler *fd_read;
void *fd_opaque;
int max_size;
} FDCharDriver;
......@@ -1309,7 +1320,7 @@ static int fd_chr_read_poll(void *opaque)
CharDriverState *chr = opaque;
FDCharDriver *s = chr->opaque;
s->max_size = s->fd_can_read(s->fd_opaque);
s->max_size = qemu_chr_can_read(chr);
return s->max_size;
}
......@@ -1332,20 +1343,15 @@ static void fd_chr_read(void *opaque)
return;
}
if (size > 0) {
s->fd_read(s->fd_opaque, buf, size);
qemu_chr_read(chr, buf, size);
}
}
static void fd_chr_add_read_handler(CharDriverState *chr,
IOCanRWHandler *fd_can_read,
IOReadHandler *fd_read, void *opaque)
static void fd_chr_update_read_handler(CharDriverState *chr)
{
FDCharDriver *s = chr->opaque;
if (s->fd_in >= 0) {
s->fd_can_read = fd_can_read;
s->fd_read = fd_read;
s->fd_opaque = opaque;
if (nographic && s->fd_in == 0) {
} else {
qemu_set_fd_handler2(s->fd_in, fd_chr_read_poll,
......@@ -1372,7 +1378,7 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out)
s->fd_out = fd_out;
chr->opaque = s;
chr->chr_write = fd_chr_write;
chr->chr_add_read_handler = fd_chr_add_read_handler;
chr->chr_update_read_handler = fd_chr_update_read_handler;
qemu_chr_reset(chr);
......@@ -1465,7 +1471,7 @@ static void stdio_received_byte(int ch)
chr = stdio_clients[client_index];
s = chr->opaque;
chr->chr_event(s->fd_opaque, CHR_EVENT_BREAK);
qemu_chr_event(chr, CHR_EVENT_BREAK);
}
break;
case 'c':
......@@ -1492,13 +1498,11 @@ static void stdio_received_byte(int ch)
if (client_index < stdio_nb_clients) {
uint8_t buf[1];
CharDriverState *chr;
FDCharDriver *s;
chr = stdio_clients[client_index];
s = chr->opaque;
if (s->fd_can_read(s->fd_opaque) > 0) {
if (qemu_chr_can_read(chr) > 0) {
buf[0] = ch;
s->fd_read(s->fd_opaque, buf, 1);
qemu_chr_read(chr, buf, 1);
} else if (term_fifo_size == 0) {
term_fifo[term_fifo_size++] = ch;
}
......@@ -1509,14 +1513,12 @@ static void stdio_received_byte(int ch)
static int stdio_read_poll(void *opaque)
{
CharDriverState *chr;
FDCharDriver *s;
if (client_index < stdio_nb_clients) {
chr = stdio_clients[client_index];
s = chr->opaque;
/* try to flush the queue if needed */
if (term_fifo_size != 0 && s->fd_can_read(s->fd_opaque) > 0) {
s->fd_read(s->fd_opaque, term_fifo, 1);
if (term_fifo_size != 0 && qemu_chr_can_read(chr) > 0) {
qemu_chr_read(chr, term_fifo, 1);
term_fifo_size = 0;
}
/* see if we can absorb more chars */
......@@ -1855,7 +1857,6 @@ static CharDriverState *qemu_chr_open_pp(const char *filename)
}
chr->opaque = (void *)fd;
chr->chr_write = null_chr_write;
chr->chr_add_read_handler = null_chr_add_read_handler;
chr->chr_ioctl = pp_ioctl;
qemu_chr_reset(chr);
......@@ -1874,9 +1875,6 @@ static CharDriverState *qemu_chr_open_pty(void)
#ifdef _WIN32
typedef struct {
IOCanRWHandler *fd_can_read;
IOReadHandler *fd_read;
void *win_opaque;
int max_size;
HANDLE hcom, hrecv, hsend;
OVERLAPPED orecv, osend;
......@@ -2020,10 +2018,10 @@ static int win_chr_write(CharDriverState *chr, const uint8_t *buf, int len1)
static int win_chr_read_poll(WinCharState *s)
{
s->max_size = s->fd_can_read(s->win_opaque);
s->max_size = qemu_chr_can_read(s->chr);
return s->max_size;
}
static void win_chr_readfile(WinCharState *s)
{
int ret, err;
......@@ -2041,7 +2039,7 @@ static void win_chr_readfile(WinCharState *s)
}
if (size > 0) {
s->fd_read(s->win_opaque, buf, size);
qemu_chr_read(s->chr, buf, size);
}
}
......@@ -2071,17 +2069,6 @@ static int win_chr_poll(void *opaque)
return 0;
}
static void win_chr_add_read_handler(CharDriverState *chr,
IOCanRWHandler *fd_can_read,
IOReadHandler *fd_read, void *opaque)
{
WinCharState *s = chr->opaque;
s->fd_can_read = fd_can_read;
s->fd_read = fd_read;
s->win_opaque = opaque;
}
static CharDriverState *qemu_chr_open_win(const char *filename)
{
CharDriverState *chr;
......@@ -2097,7 +2084,6 @@ static CharDriverState *qemu_chr_open_win(const char *filename)
}
chr->opaque = s;
chr->chr_write = win_chr_write;
chr->chr_add_read_handler = win_chr_add_read_handler;
chr->chr_close = win_chr_close;
if (win_chr_init(s, filename) < 0) {
......@@ -2201,7 +2187,6 @@ static CharDriverState *qemu_chr_open_win_pipe(const char *filename)
}
chr->opaque = s;
chr->chr_write = win_chr_write;
chr->chr_add_read_handler = win_chr_add_read_handler;
chr->chr_close = win_chr_close;
if (win_chr_pipe_init(s, filename) < 0) {
......@@ -2229,7 +2214,6 @@ static CharDriverState *qemu_chr_open_win_file(HANDLE fd_out)
s->hcom = fd_out;
chr->opaque = s;
chr->chr_write = win_chr_write;
chr->chr_add_read_handler = win_chr_add_read_handler;
qemu_chr_reset(chr);
return chr;
}
......@@ -2251,9 +2235,6 @@ static CharDriverState *qemu_chr_open_win_file_out(const char *file_out)
/* UDP Net console */
typedef struct {
IOCanRWHandler *fd_can_read;
IOReadHandler *fd_read;
void *fd_opaque;
int fd;
struct sockaddr_in daddr;
char buf[1024];
......@@ -2275,15 +2256,15 @@ static int udp_chr_read_poll(void *opaque)
CharDriverState *chr = opaque;
NetCharDriver *s = chr->opaque;
s->max_size = s->fd_can_read(s->fd_opaque);
s->max_size = qemu_chr_can_read(chr);
/* If there were any stray characters in the queue process them
* first
*/
while (s->max_size > 0 && s->bufptr < s->bufcnt) {
s->fd_read(s->fd_opaque, &s->buf[s->bufptr], 1);
qemu_chr_read(chr, &s->buf[s->bufptr], 1);
s->bufptr++;
s->max_size = s->fd_can_read(s->fd_opaque);
s->max_size = qemu_chr_can_read(chr);
}
return s->max_size;
}
......@@ -2302,22 +2283,17 @@ static void udp_chr_read(void *opaque)
s->bufptr = 0;
while (s->max_size > 0 && s->bufptr < s->bufcnt) {
s->fd_read(s->fd_opaque, &s->buf[s->bufptr], 1);
qemu_chr_read(chr, &s->buf[s->bufptr], 1);
s->bufptr++;
s->max_size = s->fd_can_read(s->fd_opaque);
s->max_size = qemu_chr_can_read(chr);
}
}
static void udp_chr_add_read_handler(CharDriverState *chr,
IOCanRWHandler *fd_can_read,
IOReadHandler *fd_read, void *opaque)
static void udp_chr_update_read_handler(CharDriverState *chr)
{
NetCharDriver *s = chr->opaque;
if (s->fd >= 0) {
s->fd_can_read = fd_can_read;
s->fd_read = fd_read;
s->fd_opaque = opaque;
qemu_set_fd_handler2(s->fd, udp_chr_read_poll,
udp_chr_read, NULL, chr);
}
......@@ -2367,7 +2343,7 @@ static CharDriverState *qemu_chr_open_udp(const char *def)
s->bufptr = 0;
chr->opaque = s;
chr->chr_write = udp_chr_write;
chr->chr_add_read_handler = udp_chr_add_read_handler;
chr->chr_update_read_handler = udp_chr_update_read_handler;
return chr;
return_err:
......@@ -2384,13 +2360,11 @@ return_err:
/* TCP Net console */
typedef struct {
IOCanRWHandler *fd_can_read;
IOReadHandler *fd_read;
void *fd_opaque;
int fd, listen_fd;
int connected;
int max_size;
int do_telnetopt;
int do_nodelay;
int is_unix;
} TCPCharDriver;
......@@ -2413,9 +2387,7 @@ static int tcp_chr_read_poll(void *opaque)
TCPCharDriver *s = chr->opaque;
if (!s->connected)
return 0;
if (!s->fd_can_read)
return 0;
s->max_size = s->fd_can_read(s->fd_opaque);
s->max_size = qemu_chr_can_read(chr);
return s->max_size;
}
......@@ -2448,7 +2420,7 @@ static void tcp_chr_process_IAC_bytes(CharDriverState *chr,
} else {
if ((unsigned char)buf[i] == IAC_BREAK && s->do_telnetopt == 2) {
/* Handle IAC break commands by sending a serial break */
chr->chr_event(s->fd_opaque, CHR_EVENT_BREAK);
qemu_chr_event(chr, CHR_EVENT_BREAK);
s->do_telnetopt++;
}
s->do_telnetopt++;
......@@ -2495,21 +2467,10 @@ static void tcp_chr_read(void *opaque)
if (s->do_telnetopt)
tcp_chr_process_IAC_bytes(chr, s, buf, &size);
if (size > 0)
s->fd_read(s->fd_opaque, buf, size);
qemu_chr_read(chr, buf, size);
}
}
static void tcp_chr_add_read_handler(CharDriverState *chr,
IOCanRWHandler *fd_can_read,
IOReadHandler *fd_read, void *opaque)
{
TCPCharDriver *s = chr->opaque;
s->fd_can_read = fd_can_read;
s->fd_read = fd_read;
s->fd_opaque = opaque;
}
static void tcp_chr_connect(void *opaque)
{
CharDriverState *chr = opaque;
......@@ -2658,7 +2619,6 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str,
chr->opaque = s;
chr->chr_write = tcp_chr_write;
chr->chr_add_read_handler = tcp_chr_add_read_handler;
chr->chr_close = tcp_chr_close;
if (is_listen) {
......
......@@ -293,11 +293,12 @@ typedef void IOEventHandler(void *opaque, int event);
typedef struct CharDriverState {
int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len);
void (*chr_add_read_handler)(struct CharDriverState *s,
IOCanRWHandler *fd_can_read,
IOReadHandler *fd_read, void *opaque);
void (*chr_update_read_handler)(struct CharDriverState *s);
int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg);
IOEventHandler *chr_event;
IOCanRWHandler *chr_can_read;
IOReadHandler *chr_read;
void *handler_opaque;
void (*chr_send_event)(struct CharDriverState *chr, int event);
void (*chr_close)(struct CharDriverState *chr);
void *opaque;
......@@ -308,12 +309,15 @@ CharDriverState *qemu_chr_open(const char *filename);
void qemu_chr_printf(CharDriverState *s, const char *fmt, ...);
int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len);
void qemu_chr_send_event(CharDriverState *s, int event);
void qemu_chr_add_read_handler(CharDriverState *s,
IOCanRWHandler *fd_can_read,
IOReadHandler *fd_read, void *opaque);
void qemu_chr_add_event_handler(CharDriverState *s, IOEventHandler *chr_event);
void qemu_chr_add_handlers(CharDriverState *s,
IOCanRWHandler *fd_can_read,
IOReadHandler *fd_read,
IOEventHandler *fd_event,
void *opaque);
int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg);
void qemu_chr_reset(CharDriverState *s);
int qemu_chr_can_read(CharDriverState *s);
void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len);
/* consoles */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment