Commit e5b0bc445ed7edb1738aabb982a387ee38da1655
1 parent
dff5efc8
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
Showing
8 changed files
with
84 additions
and
136 deletions
console.c
| @@ -132,10 +132,7 @@ struct TextConsole { | @@ -132,10 +132,7 @@ struct TextConsole { | ||
| 132 | int esc_params[MAX_ESC_PARAMS]; | 132 | int esc_params[MAX_ESC_PARAMS]; |
| 133 | int nb_esc_params; | 133 | int nb_esc_params; |
| 134 | 134 | ||
| 135 | - /* kbd read handler */ | ||
| 136 | - IOCanRWHandler *fd_can_read; | ||
| 137 | - IOReadHandler *fd_read; | ||
| 138 | - void *fd_opaque; | 135 | + CharDriverState *chr; |
| 139 | /* fifo for key pressed */ | 136 | /* fifo for key pressed */ |
| 140 | QEMUFIFO out_fifo; | 137 | QEMUFIFO out_fifo; |
| 141 | uint8_t out_fifo_buf[16]; | 138 | uint8_t out_fifo_buf[16]; |
| @@ -1021,16 +1018,6 @@ static int console_puts(CharDriverState *chr, const uint8_t *buf, int len) | @@ -1021,16 +1018,6 @@ static int console_puts(CharDriverState *chr, const uint8_t *buf, int len) | ||
| 1021 | return len; | 1018 | return len; |
| 1022 | } | 1019 | } |
| 1023 | 1020 | ||
| 1024 | -static void console_chr_add_read_handler(CharDriverState *chr, | ||
| 1025 | - IOCanRWHandler *fd_can_read, | ||
| 1026 | - IOReadHandler *fd_read, void *opaque) | ||
| 1027 | -{ | ||
| 1028 | - TextConsole *s = chr->opaque; | ||
| 1029 | - s->fd_can_read = fd_can_read; | ||
| 1030 | - s->fd_read = fd_read; | ||
| 1031 | - s->fd_opaque = opaque; | ||
| 1032 | -} | ||
| 1033 | - | ||
| 1034 | static void console_send_event(CharDriverState *chr, int event) | 1021 | static void console_send_event(CharDriverState *chr, int event) |
| 1035 | { | 1022 | { |
| 1036 | TextConsole *s = chr->opaque; | 1023 | TextConsole *s = chr->opaque; |
| @@ -1052,14 +1039,14 @@ static void kbd_send_chars(void *opaque) | @@ -1052,14 +1039,14 @@ static void kbd_send_chars(void *opaque) | ||
| 1052 | int len; | 1039 | int len; |
| 1053 | uint8_t buf[16]; | 1040 | uint8_t buf[16]; |
| 1054 | 1041 | ||
| 1055 | - len = s->fd_can_read(s->fd_opaque); | 1042 | + len = qemu_chr_can_read(s->chr); |
| 1056 | if (len > s->out_fifo.count) | 1043 | if (len > s->out_fifo.count) |
| 1057 | len = s->out_fifo.count; | 1044 | len = s->out_fifo.count; |
| 1058 | if (len > 0) { | 1045 | if (len > 0) { |
| 1059 | if (len > sizeof(buf)) | 1046 | if (len > sizeof(buf)) |
| 1060 | len = sizeof(buf); | 1047 | len = sizeof(buf); |
| 1061 | qemu_fifo_read(&s->out_fifo, buf, len); | 1048 | qemu_fifo_read(&s->out_fifo, buf, len); |
| 1062 | - s->fd_read(s->fd_opaque, buf, len); | 1049 | + qemu_chr_read(s->chr, buf, len); |
| 1063 | } | 1050 | } |
| 1064 | /* characters are pending: we send them a bit later (XXX: | 1051 | /* characters are pending: we send them a bit later (XXX: |
| 1065 | horrible, should change char device API) */ | 1052 | horrible, should change char device API) */ |
| @@ -1110,7 +1097,7 @@ void kbd_put_keysym(int keysym) | @@ -1110,7 +1097,7 @@ void kbd_put_keysym(int keysym) | ||
| 1110 | } else { | 1097 | } else { |
| 1111 | *q++ = keysym; | 1098 | *q++ = keysym; |
| 1112 | } | 1099 | } |
| 1113 | - if (s->fd_read) { | 1100 | + if (s->chr->chr_read) { |
| 1114 | qemu_fifo_write(&s->out_fifo, buf, q - buf); | 1101 | qemu_fifo_write(&s->out_fifo, buf, q - buf); |
| 1115 | kbd_send_chars(s); | 1102 | kbd_send_chars(s); |
| 1116 | } | 1103 | } |
| @@ -1186,9 +1173,9 @@ CharDriverState *text_console_init(DisplayState *ds) | @@ -1186,9 +1173,9 @@ CharDriverState *text_console_init(DisplayState *ds) | ||
| 1186 | } | 1173 | } |
| 1187 | chr->opaque = s; | 1174 | chr->opaque = s; |
| 1188 | chr->chr_write = console_puts; | 1175 | chr->chr_write = console_puts; |
| 1189 | - chr->chr_add_read_handler = console_chr_add_read_handler; | ||
| 1190 | chr->chr_send_event = console_send_event; | 1176 | chr->chr_send_event = console_send_event; |
| 1191 | 1177 | ||
| 1178 | + s->chr = chr; | ||
| 1192 | s->out_fifo.buf = s->out_fifo_buf; | 1179 | s->out_fifo.buf = s->out_fifo_buf; |
| 1193 | s->out_fifo.buf_size = sizeof(s->out_fifo_buf); | 1180 | s->out_fifo.buf_size = sizeof(s->out_fifo_buf); |
| 1194 | s->kbd_timer = qemu_new_timer(rt_clock, kbd_send_chars, s); | 1181 | s->kbd_timer = qemu_new_timer(rt_clock, kbd_send_chars, s); |
hw/pl011.c
| @@ -243,8 +243,8 @@ void pl011_init(uint32_t base, void *pic, int irq, | @@ -243,8 +243,8 @@ void pl011_init(uint32_t base, void *pic, int irq, | ||
| 243 | s->cr = 0x300; | 243 | s->cr = 0x300; |
| 244 | s->flags = 0x90; | 244 | s->flags = 0x90; |
| 245 | if (chr){ | 245 | if (chr){ |
| 246 | - qemu_chr_add_read_handler(chr, pl011_can_recieve, pl011_recieve, s); | ||
| 247 | - qemu_chr_add_event_handler(chr, pl011_event); | 246 | + qemu_chr_add_handlers(chr, pl011_can_recieve, pl011_recieve, |
| 247 | + pl011_event, s); | ||
| 248 | } | 248 | } |
| 249 | /* ??? Save/restore. */ | 249 | /* ??? Save/restore. */ |
| 250 | } | 250 | } |
hw/serial.c
| @@ -365,8 +365,8 @@ SerialState *serial_init(SetIRQFunc *set_irq, void *opaque, | @@ -365,8 +365,8 @@ SerialState *serial_init(SetIRQFunc *set_irq, void *opaque, | ||
| 365 | register_ioport_write(base, 8, 1, serial_ioport_write, s); | 365 | register_ioport_write(base, 8, 1, serial_ioport_write, s); |
| 366 | register_ioport_read(base, 8, 1, serial_ioport_read, s); | 366 | register_ioport_read(base, 8, 1, serial_ioport_read, s); |
| 367 | s->chr = chr; | 367 | s->chr = chr; |
| 368 | - qemu_chr_add_read_handler(chr, serial_can_receive1, serial_receive1, s); | ||
| 369 | - qemu_chr_add_event_handler(chr, serial_event); | 368 | + qemu_chr_add_handlers(chr, serial_can_receive1, serial_receive1, |
| 369 | + serial_event, s); | ||
| 370 | return s; | 370 | return s; |
| 371 | } | 371 | } |
| 372 | 372 | ||
| @@ -453,7 +453,7 @@ SerialState *serial_mm_init (SetIRQFunc *set_irq, void *opaque, | @@ -453,7 +453,7 @@ SerialState *serial_mm_init (SetIRQFunc *set_irq, void *opaque, | ||
| 453 | serial_mm_write, s); | 453 | serial_mm_write, s); |
| 454 | cpu_register_physical_memory(base, 8 << it_shift, s_io_memory); | 454 | cpu_register_physical_memory(base, 8 << it_shift, s_io_memory); |
| 455 | s->chr = chr; | 455 | s->chr = chr; |
| 456 | - qemu_chr_add_read_handler(chr, serial_can_receive1, serial_receive1, s); | ||
| 457 | - qemu_chr_add_event_handler(chr, serial_event); | 456 | + qemu_chr_add_handlers(chr, serial_can_receive1, serial_receive1, |
| 457 | + serial_event, s); | ||
| 458 | return s; | 458 | return s; |
| 459 | } | 459 | } |
hw/sh7750.c
| @@ -299,9 +299,8 @@ static void init_serial1(SH7750State * s, int serial_nb) | @@ -299,9 +299,8 @@ static void init_serial1(SH7750State * s, int serial_nb) | ||
| 299 | } | 299 | } |
| 300 | 300 | ||
| 301 | s->serial1 = chr; | 301 | s->serial1 = chr; |
| 302 | - qemu_chr_add_read_handler(chr, serial1_can_receive, | ||
| 303 | - serial1_receive, s); | ||
| 304 | - qemu_chr_add_event_handler(chr, serial1_event); | 302 | + qemu_chr_add_handlers(chr, serial1_can_receive, |
| 303 | + serial1_receive, serial1_event, s); | ||
| 305 | } | 304 | } |
| 306 | 305 | ||
| 307 | /********************************************************************** | 306 | /********************************************************************** |
| @@ -415,9 +414,8 @@ static void init_serial2(SH7750State * s, int serial_nb) | @@ -415,9 +414,8 @@ static void init_serial2(SH7750State * s, int serial_nb) | ||
| 415 | } | 414 | } |
| 416 | 415 | ||
| 417 | s->serial2 = chr; | 416 | s->serial2 = chr; |
| 418 | - qemu_chr_add_read_handler(chr, serial2_can_receive, | ||
| 419 | - serial2_receive, s); | ||
| 420 | - qemu_chr_add_event_handler(chr, serial2_event); | 417 | + qemu_chr_add_handlers(chr, serial2_can_receive, |
| 418 | + serial2_receive, serial1_event, s); | ||
| 421 | } | 419 | } |
| 422 | 420 | ||
| 423 | static void init_serial_ports(SH7750State * s) | 421 | static void init_serial_ports(SH7750State * s) |
hw/slavio_serial.c
| @@ -565,8 +565,8 @@ SerialState *slavio_serial_init(int base, int irq, CharDriverState *chr1, CharDr | @@ -565,8 +565,8 @@ SerialState *slavio_serial_init(int base, int irq, CharDriverState *chr1, CharDr | ||
| 565 | s->chn[i].chn = 1 - i; | 565 | s->chn[i].chn = 1 - i; |
| 566 | s->chn[i].type = ser; | 566 | s->chn[i].type = ser; |
| 567 | if (s->chn[i].chr) { | 567 | if (s->chn[i].chr) { |
| 568 | - qemu_chr_add_read_handler(s->chn[i].chr, serial_can_receive, serial_receive1, &s->chn[i]); | ||
| 569 | - qemu_chr_add_event_handler(s->chn[i].chr, serial_event); | 568 | + qemu_chr_add_handlers(s->chn[i].chr, serial_can_receive, |
| 569 | + serial_receive1, serial_event, &s->chn[i]); | ||
| 570 | } | 570 | } |
| 571 | } | 571 | } |
| 572 | s->chn[0].otherchn = &s->chn[1]; | 572 | s->chn[0].otherchn = &s->chn[1]; |
monitor.c
| @@ -2455,8 +2455,7 @@ void monitor_init(CharDriverState *hd, int show_banner) | @@ -2455,8 +2455,7 @@ void monitor_init(CharDriverState *hd, int show_banner) | ||
| 2455 | monitor_hd = hd; | 2455 | monitor_hd = hd; |
| 2456 | hide_banner = !show_banner; | 2456 | hide_banner = !show_banner; |
| 2457 | 2457 | ||
| 2458 | - qemu_chr_add_read_handler(hd, term_can_read, term_read, NULL); | ||
| 2459 | - qemu_chr_add_event_handler(hd, term_event); | 2458 | + qemu_chr_add_handlers(hd, term_can_read, term_read, term_event, NULL); |
| 2460 | } | 2459 | } |
| 2461 | 2460 | ||
| 2462 | /* XXX: use threads ? */ | 2461 | /* XXX: use threads ? */ |
vl.c
| @@ -1119,11 +1119,17 @@ void quit_timers(void) | @@ -1119,11 +1119,17 @@ void quit_timers(void) | ||
| 1119 | /***********************************************************/ | 1119 | /***********************************************************/ |
| 1120 | /* character device */ | 1120 | /* character device */ |
| 1121 | 1121 | ||
| 1122 | +static void qemu_chr_event(CharDriverState *s, int event) | ||
| 1123 | +{ | ||
| 1124 | + if (!s->chr_event) | ||
| 1125 | + return; | ||
| 1126 | + s->chr_event(s->handler_opaque, event); | ||
| 1127 | +} | ||
| 1128 | + | ||
| 1122 | static void qemu_chr_reset_bh(void *opaque) | 1129 | static void qemu_chr_reset_bh(void *opaque) |
| 1123 | { | 1130 | { |
| 1124 | CharDriverState *s = opaque; | 1131 | CharDriverState *s = opaque; |
| 1125 | - if (s->chr_event) | ||
| 1126 | - s->chr_event(s, CHR_EVENT_RESET); | 1132 | + qemu_chr_event(s, CHR_EVENT_RESET); |
| 1127 | qemu_bh_delete(s->bh); | 1133 | qemu_bh_delete(s->bh); |
| 1128 | s->bh = NULL; | 1134 | s->bh = NULL; |
| 1129 | } | 1135 | } |
| @@ -1148,6 +1154,19 @@ int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg) | @@ -1148,6 +1154,19 @@ int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg) | ||
| 1148 | return s->chr_ioctl(s, cmd, arg); | 1154 | return s->chr_ioctl(s, cmd, arg); |
| 1149 | } | 1155 | } |
| 1150 | 1156 | ||
| 1157 | +int qemu_chr_can_read(CharDriverState *s) | ||
| 1158 | +{ | ||
| 1159 | + if (!s->chr_can_read) | ||
| 1160 | + return 0; | ||
| 1161 | + return s->chr_can_read(s->handler_opaque); | ||
| 1162 | +} | ||
| 1163 | + | ||
| 1164 | +void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len) | ||
| 1165 | +{ | ||
| 1166 | + s->chr_read(s->handler_opaque, buf, len); | ||
| 1167 | +} | ||
| 1168 | + | ||
| 1169 | + | ||
| 1151 | void qemu_chr_printf(CharDriverState *s, const char *fmt, ...) | 1170 | void qemu_chr_printf(CharDriverState *s, const char *fmt, ...) |
| 1152 | { | 1171 | { |
| 1153 | char buf[4096]; | 1172 | char buf[4096]; |
| @@ -1164,29 +1183,25 @@ void qemu_chr_send_event(CharDriverState *s, int event) | @@ -1164,29 +1183,25 @@ void qemu_chr_send_event(CharDriverState *s, int event) | ||
| 1164 | s->chr_send_event(s, event); | 1183 | s->chr_send_event(s, event); |
| 1165 | } | 1184 | } |
| 1166 | 1185 | ||
| 1167 | -void qemu_chr_add_read_handler(CharDriverState *s, | ||
| 1168 | - IOCanRWHandler *fd_can_read, | ||
| 1169 | - IOReadHandler *fd_read, void *opaque) | 1186 | +void qemu_chr_add_handlers(CharDriverState *s, |
| 1187 | + IOCanRWHandler *fd_can_read, | ||
| 1188 | + IOReadHandler *fd_read, | ||
| 1189 | + IOEventHandler *fd_event, | ||
| 1190 | + void *opaque) | ||
| 1170 | { | 1191 | { |
| 1171 | - s->chr_add_read_handler(s, fd_can_read, fd_read, opaque); | 1192 | + s->chr_can_read = fd_can_read; |
| 1193 | + s->chr_read = fd_read; | ||
| 1194 | + s->chr_event = fd_event; | ||
| 1195 | + s->handler_opaque = opaque; | ||
| 1196 | + if (s->chr_update_read_handler) | ||
| 1197 | + s->chr_update_read_handler(s); | ||
| 1172 | } | 1198 | } |
| 1173 | 1199 | ||
| 1174 | -void qemu_chr_add_event_handler(CharDriverState *s, IOEventHandler *chr_event) | ||
| 1175 | -{ | ||
| 1176 | - s->chr_event = chr_event; | ||
| 1177 | -} | ||
| 1178 | - | ||
| 1179 | static int null_chr_write(CharDriverState *chr, const uint8_t *buf, int len) | 1200 | static int null_chr_write(CharDriverState *chr, const uint8_t *buf, int len) |
| 1180 | { | 1201 | { |
| 1181 | return len; | 1202 | return len; |
| 1182 | } | 1203 | } |
| 1183 | 1204 | ||
| 1184 | -static void null_chr_add_read_handler(CharDriverState *chr, | ||
| 1185 | - IOCanRWHandler *fd_can_read, | ||
| 1186 | - IOReadHandler *fd_read, void *opaque) | ||
| 1187 | -{ | ||
| 1188 | -} | ||
| 1189 | - | ||
| 1190 | static CharDriverState *qemu_chr_open_null(void) | 1205 | static CharDriverState *qemu_chr_open_null(void) |
| 1191 | { | 1206 | { |
| 1192 | CharDriverState *chr; | 1207 | CharDriverState *chr; |
| @@ -1195,7 +1210,6 @@ static CharDriverState *qemu_chr_open_null(void) | @@ -1195,7 +1210,6 @@ static CharDriverState *qemu_chr_open_null(void) | ||
| 1195 | if (!chr) | 1210 | if (!chr) |
| 1196 | return NULL; | 1211 | return NULL; |
| 1197 | chr->chr_write = null_chr_write; | 1212 | chr->chr_write = null_chr_write; |
| 1198 | - chr->chr_add_read_handler = null_chr_add_read_handler; | ||
| 1199 | return chr; | 1213 | return chr; |
| 1200 | } | 1214 | } |
| 1201 | 1215 | ||
| @@ -1287,9 +1301,6 @@ void socket_set_nonblock(int fd) | @@ -1287,9 +1301,6 @@ void socket_set_nonblock(int fd) | ||
| 1287 | 1301 | ||
| 1288 | typedef struct { | 1302 | typedef struct { |
| 1289 | int fd_in, fd_out; | 1303 | int fd_in, fd_out; |
| 1290 | - IOCanRWHandler *fd_can_read; | ||
| 1291 | - IOReadHandler *fd_read; | ||
| 1292 | - void *fd_opaque; | ||
| 1293 | int max_size; | 1304 | int max_size; |
| 1294 | } FDCharDriver; | 1305 | } FDCharDriver; |
| 1295 | 1306 | ||
| @@ -1309,7 +1320,7 @@ static int fd_chr_read_poll(void *opaque) | @@ -1309,7 +1320,7 @@ static int fd_chr_read_poll(void *opaque) | ||
| 1309 | CharDriverState *chr = opaque; | 1320 | CharDriverState *chr = opaque; |
| 1310 | FDCharDriver *s = chr->opaque; | 1321 | FDCharDriver *s = chr->opaque; |
| 1311 | 1322 | ||
| 1312 | - s->max_size = s->fd_can_read(s->fd_opaque); | 1323 | + s->max_size = qemu_chr_can_read(chr); |
| 1313 | return s->max_size; | 1324 | return s->max_size; |
| 1314 | } | 1325 | } |
| 1315 | 1326 | ||
| @@ -1332,20 +1343,15 @@ static void fd_chr_read(void *opaque) | @@ -1332,20 +1343,15 @@ static void fd_chr_read(void *opaque) | ||
| 1332 | return; | 1343 | return; |
| 1333 | } | 1344 | } |
| 1334 | if (size > 0) { | 1345 | if (size > 0) { |
| 1335 | - s->fd_read(s->fd_opaque, buf, size); | 1346 | + qemu_chr_read(chr, buf, size); |
| 1336 | } | 1347 | } |
| 1337 | } | 1348 | } |
| 1338 | 1349 | ||
| 1339 | -static void fd_chr_add_read_handler(CharDriverState *chr, | ||
| 1340 | - IOCanRWHandler *fd_can_read, | ||
| 1341 | - IOReadHandler *fd_read, void *opaque) | 1350 | +static void fd_chr_update_read_handler(CharDriverState *chr) |
| 1342 | { | 1351 | { |
| 1343 | FDCharDriver *s = chr->opaque; | 1352 | FDCharDriver *s = chr->opaque; |
| 1344 | 1353 | ||
| 1345 | if (s->fd_in >= 0) { | 1354 | if (s->fd_in >= 0) { |
| 1346 | - s->fd_can_read = fd_can_read; | ||
| 1347 | - s->fd_read = fd_read; | ||
| 1348 | - s->fd_opaque = opaque; | ||
| 1349 | if (nographic && s->fd_in == 0) { | 1355 | if (nographic && s->fd_in == 0) { |
| 1350 | } else { | 1356 | } else { |
| 1351 | qemu_set_fd_handler2(s->fd_in, fd_chr_read_poll, | 1357 | 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) | @@ -1372,7 +1378,7 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out) | ||
| 1372 | s->fd_out = fd_out; | 1378 | s->fd_out = fd_out; |
| 1373 | chr->opaque = s; | 1379 | chr->opaque = s; |
| 1374 | chr->chr_write = fd_chr_write; | 1380 | chr->chr_write = fd_chr_write; |
| 1375 | - chr->chr_add_read_handler = fd_chr_add_read_handler; | 1381 | + chr->chr_update_read_handler = fd_chr_update_read_handler; |
| 1376 | 1382 | ||
| 1377 | qemu_chr_reset(chr); | 1383 | qemu_chr_reset(chr); |
| 1378 | 1384 | ||
| @@ -1465,7 +1471,7 @@ static void stdio_received_byte(int ch) | @@ -1465,7 +1471,7 @@ static void stdio_received_byte(int ch) | ||
| 1465 | 1471 | ||
| 1466 | chr = stdio_clients[client_index]; | 1472 | chr = stdio_clients[client_index]; |
| 1467 | s = chr->opaque; | 1473 | s = chr->opaque; |
| 1468 | - chr->chr_event(s->fd_opaque, CHR_EVENT_BREAK); | 1474 | + qemu_chr_event(chr, CHR_EVENT_BREAK); |
| 1469 | } | 1475 | } |
| 1470 | break; | 1476 | break; |
| 1471 | case 'c': | 1477 | case 'c': |
| @@ -1492,13 +1498,11 @@ static void stdio_received_byte(int ch) | @@ -1492,13 +1498,11 @@ static void stdio_received_byte(int ch) | ||
| 1492 | if (client_index < stdio_nb_clients) { | 1498 | if (client_index < stdio_nb_clients) { |
| 1493 | uint8_t buf[1]; | 1499 | uint8_t buf[1]; |
| 1494 | CharDriverState *chr; | 1500 | CharDriverState *chr; |
| 1495 | - FDCharDriver *s; | ||
| 1496 | 1501 | ||
| 1497 | chr = stdio_clients[client_index]; | 1502 | chr = stdio_clients[client_index]; |
| 1498 | - s = chr->opaque; | ||
| 1499 | - if (s->fd_can_read(s->fd_opaque) > 0) { | 1503 | + if (qemu_chr_can_read(chr) > 0) { |
| 1500 | buf[0] = ch; | 1504 | buf[0] = ch; |
| 1501 | - s->fd_read(s->fd_opaque, buf, 1); | 1505 | + qemu_chr_read(chr, buf, 1); |
| 1502 | } else if (term_fifo_size == 0) { | 1506 | } else if (term_fifo_size == 0) { |
| 1503 | term_fifo[term_fifo_size++] = ch; | 1507 | term_fifo[term_fifo_size++] = ch; |
| 1504 | } | 1508 | } |
| @@ -1509,14 +1513,12 @@ static void stdio_received_byte(int ch) | @@ -1509,14 +1513,12 @@ static void stdio_received_byte(int ch) | ||
| 1509 | static int stdio_read_poll(void *opaque) | 1513 | static int stdio_read_poll(void *opaque) |
| 1510 | { | 1514 | { |
| 1511 | CharDriverState *chr; | 1515 | CharDriverState *chr; |
| 1512 | - FDCharDriver *s; | ||
| 1513 | 1516 | ||
| 1514 | if (client_index < stdio_nb_clients) { | 1517 | if (client_index < stdio_nb_clients) { |
| 1515 | chr = stdio_clients[client_index]; | 1518 | chr = stdio_clients[client_index]; |
| 1516 | - s = chr->opaque; | ||
| 1517 | /* try to flush the queue if needed */ | 1519 | /* try to flush the queue if needed */ |
| 1518 | - if (term_fifo_size != 0 && s->fd_can_read(s->fd_opaque) > 0) { | ||
| 1519 | - s->fd_read(s->fd_opaque, term_fifo, 1); | 1520 | + if (term_fifo_size != 0 && qemu_chr_can_read(chr) > 0) { |
| 1521 | + qemu_chr_read(chr, term_fifo, 1); | ||
| 1520 | term_fifo_size = 0; | 1522 | term_fifo_size = 0; |
| 1521 | } | 1523 | } |
| 1522 | /* see if we can absorb more chars */ | 1524 | /* see if we can absorb more chars */ |
| @@ -1855,7 +1857,6 @@ static CharDriverState *qemu_chr_open_pp(const char *filename) | @@ -1855,7 +1857,6 @@ static CharDriverState *qemu_chr_open_pp(const char *filename) | ||
| 1855 | } | 1857 | } |
| 1856 | chr->opaque = (void *)fd; | 1858 | chr->opaque = (void *)fd; |
| 1857 | chr->chr_write = null_chr_write; | 1859 | chr->chr_write = null_chr_write; |
| 1858 | - chr->chr_add_read_handler = null_chr_add_read_handler; | ||
| 1859 | chr->chr_ioctl = pp_ioctl; | 1860 | chr->chr_ioctl = pp_ioctl; |
| 1860 | 1861 | ||
| 1861 | qemu_chr_reset(chr); | 1862 | qemu_chr_reset(chr); |
| @@ -1874,9 +1875,6 @@ static CharDriverState *qemu_chr_open_pty(void) | @@ -1874,9 +1875,6 @@ static CharDriverState *qemu_chr_open_pty(void) | ||
| 1874 | 1875 | ||
| 1875 | #ifdef _WIN32 | 1876 | #ifdef _WIN32 |
| 1876 | typedef struct { | 1877 | typedef struct { |
| 1877 | - IOCanRWHandler *fd_can_read; | ||
| 1878 | - IOReadHandler *fd_read; | ||
| 1879 | - void *win_opaque; | ||
| 1880 | int max_size; | 1878 | int max_size; |
| 1881 | HANDLE hcom, hrecv, hsend; | 1879 | HANDLE hcom, hrecv, hsend; |
| 1882 | OVERLAPPED orecv, osend; | 1880 | OVERLAPPED orecv, osend; |
| @@ -2020,10 +2018,10 @@ static int win_chr_write(CharDriverState *chr, const uint8_t *buf, int len1) | @@ -2020,10 +2018,10 @@ static int win_chr_write(CharDriverState *chr, const uint8_t *buf, int len1) | ||
| 2020 | 2018 | ||
| 2021 | static int win_chr_read_poll(WinCharState *s) | 2019 | static int win_chr_read_poll(WinCharState *s) |
| 2022 | { | 2020 | { |
| 2023 | - s->max_size = s->fd_can_read(s->win_opaque); | 2021 | + s->max_size = qemu_chr_can_read(s->chr); |
| 2024 | return s->max_size; | 2022 | return s->max_size; |
| 2025 | } | 2023 | } |
| 2026 | - | 2024 | + |
| 2027 | static void win_chr_readfile(WinCharState *s) | 2025 | static void win_chr_readfile(WinCharState *s) |
| 2028 | { | 2026 | { |
| 2029 | int ret, err; | 2027 | int ret, err; |
| @@ -2041,7 +2039,7 @@ static void win_chr_readfile(WinCharState *s) | @@ -2041,7 +2039,7 @@ static void win_chr_readfile(WinCharState *s) | ||
| 2041 | } | 2039 | } |
| 2042 | 2040 | ||
| 2043 | if (size > 0) { | 2041 | if (size > 0) { |
| 2044 | - s->fd_read(s->win_opaque, buf, size); | 2042 | + qemu_chr_read(s->chr, buf, size); |
| 2045 | } | 2043 | } |
| 2046 | } | 2044 | } |
| 2047 | 2045 | ||
| @@ -2071,17 +2069,6 @@ static int win_chr_poll(void *opaque) | @@ -2071,17 +2069,6 @@ static int win_chr_poll(void *opaque) | ||
| 2071 | return 0; | 2069 | return 0; |
| 2072 | } | 2070 | } |
| 2073 | 2071 | ||
| 2074 | -static void win_chr_add_read_handler(CharDriverState *chr, | ||
| 2075 | - IOCanRWHandler *fd_can_read, | ||
| 2076 | - IOReadHandler *fd_read, void *opaque) | ||
| 2077 | -{ | ||
| 2078 | - WinCharState *s = chr->opaque; | ||
| 2079 | - | ||
| 2080 | - s->fd_can_read = fd_can_read; | ||
| 2081 | - s->fd_read = fd_read; | ||
| 2082 | - s->win_opaque = opaque; | ||
| 2083 | -} | ||
| 2084 | - | ||
| 2085 | static CharDriverState *qemu_chr_open_win(const char *filename) | 2072 | static CharDriverState *qemu_chr_open_win(const char *filename) |
| 2086 | { | 2073 | { |
| 2087 | CharDriverState *chr; | 2074 | CharDriverState *chr; |
| @@ -2097,7 +2084,6 @@ static CharDriverState *qemu_chr_open_win(const char *filename) | @@ -2097,7 +2084,6 @@ static CharDriverState *qemu_chr_open_win(const char *filename) | ||
| 2097 | } | 2084 | } |
| 2098 | chr->opaque = s; | 2085 | chr->opaque = s; |
| 2099 | chr->chr_write = win_chr_write; | 2086 | chr->chr_write = win_chr_write; |
| 2100 | - chr->chr_add_read_handler = win_chr_add_read_handler; | ||
| 2101 | chr->chr_close = win_chr_close; | 2087 | chr->chr_close = win_chr_close; |
| 2102 | 2088 | ||
| 2103 | if (win_chr_init(s, filename) < 0) { | 2089 | if (win_chr_init(s, filename) < 0) { |
| @@ -2201,7 +2187,6 @@ static CharDriverState *qemu_chr_open_win_pipe(const char *filename) | @@ -2201,7 +2187,6 @@ static CharDriverState *qemu_chr_open_win_pipe(const char *filename) | ||
| 2201 | } | 2187 | } |
| 2202 | chr->opaque = s; | 2188 | chr->opaque = s; |
| 2203 | chr->chr_write = win_chr_write; | 2189 | chr->chr_write = win_chr_write; |
| 2204 | - chr->chr_add_read_handler = win_chr_add_read_handler; | ||
| 2205 | chr->chr_close = win_chr_close; | 2190 | chr->chr_close = win_chr_close; |
| 2206 | 2191 | ||
| 2207 | if (win_chr_pipe_init(s, filename) < 0) { | 2192 | if (win_chr_pipe_init(s, filename) < 0) { |
| @@ -2229,7 +2214,6 @@ static CharDriverState *qemu_chr_open_win_file(HANDLE fd_out) | @@ -2229,7 +2214,6 @@ static CharDriverState *qemu_chr_open_win_file(HANDLE fd_out) | ||
| 2229 | s->hcom = fd_out; | 2214 | s->hcom = fd_out; |
| 2230 | chr->opaque = s; | 2215 | chr->opaque = s; |
| 2231 | chr->chr_write = win_chr_write; | 2216 | chr->chr_write = win_chr_write; |
| 2232 | - chr->chr_add_read_handler = win_chr_add_read_handler; | ||
| 2233 | qemu_chr_reset(chr); | 2217 | qemu_chr_reset(chr); |
| 2234 | return chr; | 2218 | return chr; |
| 2235 | } | 2219 | } |
| @@ -2251,9 +2235,6 @@ static CharDriverState *qemu_chr_open_win_file_out(const char *file_out) | @@ -2251,9 +2235,6 @@ static CharDriverState *qemu_chr_open_win_file_out(const char *file_out) | ||
| 2251 | /* UDP Net console */ | 2235 | /* UDP Net console */ |
| 2252 | 2236 | ||
| 2253 | typedef struct { | 2237 | typedef struct { |
| 2254 | - IOCanRWHandler *fd_can_read; | ||
| 2255 | - IOReadHandler *fd_read; | ||
| 2256 | - void *fd_opaque; | ||
| 2257 | int fd; | 2238 | int fd; |
| 2258 | struct sockaddr_in daddr; | 2239 | struct sockaddr_in daddr; |
| 2259 | char buf[1024]; | 2240 | char buf[1024]; |
| @@ -2275,15 +2256,15 @@ static int udp_chr_read_poll(void *opaque) | @@ -2275,15 +2256,15 @@ static int udp_chr_read_poll(void *opaque) | ||
| 2275 | CharDriverState *chr = opaque; | 2256 | CharDriverState *chr = opaque; |
| 2276 | NetCharDriver *s = chr->opaque; | 2257 | NetCharDriver *s = chr->opaque; |
| 2277 | 2258 | ||
| 2278 | - s->max_size = s->fd_can_read(s->fd_opaque); | 2259 | + s->max_size = qemu_chr_can_read(chr); |
| 2279 | 2260 | ||
| 2280 | /* If there were any stray characters in the queue process them | 2261 | /* If there were any stray characters in the queue process them |
| 2281 | * first | 2262 | * first |
| 2282 | */ | 2263 | */ |
| 2283 | while (s->max_size > 0 && s->bufptr < s->bufcnt) { | 2264 | while (s->max_size > 0 && s->bufptr < s->bufcnt) { |
| 2284 | - s->fd_read(s->fd_opaque, &s->buf[s->bufptr], 1); | 2265 | + qemu_chr_read(chr, &s->buf[s->bufptr], 1); |
| 2285 | s->bufptr++; | 2266 | s->bufptr++; |
| 2286 | - s->max_size = s->fd_can_read(s->fd_opaque); | 2267 | + s->max_size = qemu_chr_can_read(chr); |
| 2287 | } | 2268 | } |
| 2288 | return s->max_size; | 2269 | return s->max_size; |
| 2289 | } | 2270 | } |
| @@ -2302,22 +2283,17 @@ static void udp_chr_read(void *opaque) | @@ -2302,22 +2283,17 @@ static void udp_chr_read(void *opaque) | ||
| 2302 | 2283 | ||
| 2303 | s->bufptr = 0; | 2284 | s->bufptr = 0; |
| 2304 | while (s->max_size > 0 && s->bufptr < s->bufcnt) { | 2285 | while (s->max_size > 0 && s->bufptr < s->bufcnt) { |
| 2305 | - s->fd_read(s->fd_opaque, &s->buf[s->bufptr], 1); | 2286 | + qemu_chr_read(chr, &s->buf[s->bufptr], 1); |
| 2306 | s->bufptr++; | 2287 | s->bufptr++; |
| 2307 | - s->max_size = s->fd_can_read(s->fd_opaque); | 2288 | + s->max_size = qemu_chr_can_read(chr); |
| 2308 | } | 2289 | } |
| 2309 | } | 2290 | } |
| 2310 | 2291 | ||
| 2311 | -static void udp_chr_add_read_handler(CharDriverState *chr, | ||
| 2312 | - IOCanRWHandler *fd_can_read, | ||
| 2313 | - IOReadHandler *fd_read, void *opaque) | 2292 | +static void udp_chr_update_read_handler(CharDriverState *chr) |
| 2314 | { | 2293 | { |
| 2315 | NetCharDriver *s = chr->opaque; | 2294 | NetCharDriver *s = chr->opaque; |
| 2316 | 2295 | ||
| 2317 | if (s->fd >= 0) { | 2296 | if (s->fd >= 0) { |
| 2318 | - s->fd_can_read = fd_can_read; | ||
| 2319 | - s->fd_read = fd_read; | ||
| 2320 | - s->fd_opaque = opaque; | ||
| 2321 | qemu_set_fd_handler2(s->fd, udp_chr_read_poll, | 2297 | qemu_set_fd_handler2(s->fd, udp_chr_read_poll, |
| 2322 | udp_chr_read, NULL, chr); | 2298 | udp_chr_read, NULL, chr); |
| 2323 | } | 2299 | } |
| @@ -2367,7 +2343,7 @@ static CharDriverState *qemu_chr_open_udp(const char *def) | @@ -2367,7 +2343,7 @@ static CharDriverState *qemu_chr_open_udp(const char *def) | ||
| 2367 | s->bufptr = 0; | 2343 | s->bufptr = 0; |
| 2368 | chr->opaque = s; | 2344 | chr->opaque = s; |
| 2369 | chr->chr_write = udp_chr_write; | 2345 | chr->chr_write = udp_chr_write; |
| 2370 | - chr->chr_add_read_handler = udp_chr_add_read_handler; | 2346 | + chr->chr_update_read_handler = udp_chr_update_read_handler; |
| 2371 | return chr; | 2347 | return chr; |
| 2372 | 2348 | ||
| 2373 | return_err: | 2349 | return_err: |
| @@ -2384,13 +2360,11 @@ return_err: | @@ -2384,13 +2360,11 @@ return_err: | ||
| 2384 | /* TCP Net console */ | 2360 | /* TCP Net console */ |
| 2385 | 2361 | ||
| 2386 | typedef struct { | 2362 | typedef struct { |
| 2387 | - IOCanRWHandler *fd_can_read; | ||
| 2388 | - IOReadHandler *fd_read; | ||
| 2389 | - void *fd_opaque; | ||
| 2390 | int fd, listen_fd; | 2363 | int fd, listen_fd; |
| 2391 | int connected; | 2364 | int connected; |
| 2392 | int max_size; | 2365 | int max_size; |
| 2393 | int do_telnetopt; | 2366 | int do_telnetopt; |
| 2367 | + int do_nodelay; | ||
| 2394 | int is_unix; | 2368 | int is_unix; |
| 2395 | } TCPCharDriver; | 2369 | } TCPCharDriver; |
| 2396 | 2370 | ||
| @@ -2413,9 +2387,7 @@ static int tcp_chr_read_poll(void *opaque) | @@ -2413,9 +2387,7 @@ static int tcp_chr_read_poll(void *opaque) | ||
| 2413 | TCPCharDriver *s = chr->opaque; | 2387 | TCPCharDriver *s = chr->opaque; |
| 2414 | if (!s->connected) | 2388 | if (!s->connected) |
| 2415 | return 0; | 2389 | return 0; |
| 2416 | - if (!s->fd_can_read) | ||
| 2417 | - return 0; | ||
| 2418 | - s->max_size = s->fd_can_read(s->fd_opaque); | 2390 | + s->max_size = qemu_chr_can_read(chr); |
| 2419 | return s->max_size; | 2391 | return s->max_size; |
| 2420 | } | 2392 | } |
| 2421 | 2393 | ||
| @@ -2448,7 +2420,7 @@ static void tcp_chr_process_IAC_bytes(CharDriverState *chr, | @@ -2448,7 +2420,7 @@ static void tcp_chr_process_IAC_bytes(CharDriverState *chr, | ||
| 2448 | } else { | 2420 | } else { |
| 2449 | if ((unsigned char)buf[i] == IAC_BREAK && s->do_telnetopt == 2) { | 2421 | if ((unsigned char)buf[i] == IAC_BREAK && s->do_telnetopt == 2) { |
| 2450 | /* Handle IAC break commands by sending a serial break */ | 2422 | /* Handle IAC break commands by sending a serial break */ |
| 2451 | - chr->chr_event(s->fd_opaque, CHR_EVENT_BREAK); | 2423 | + qemu_chr_event(chr, CHR_EVENT_BREAK); |
| 2452 | s->do_telnetopt++; | 2424 | s->do_telnetopt++; |
| 2453 | } | 2425 | } |
| 2454 | s->do_telnetopt++; | 2426 | s->do_telnetopt++; |
| @@ -2495,21 +2467,10 @@ static void tcp_chr_read(void *opaque) | @@ -2495,21 +2467,10 @@ static void tcp_chr_read(void *opaque) | ||
| 2495 | if (s->do_telnetopt) | 2467 | if (s->do_telnetopt) |
| 2496 | tcp_chr_process_IAC_bytes(chr, s, buf, &size); | 2468 | tcp_chr_process_IAC_bytes(chr, s, buf, &size); |
| 2497 | if (size > 0) | 2469 | if (size > 0) |
| 2498 | - s->fd_read(s->fd_opaque, buf, size); | 2470 | + qemu_chr_read(chr, buf, size); |
| 2499 | } | 2471 | } |
| 2500 | } | 2472 | } |
| 2501 | 2473 | ||
| 2502 | -static void tcp_chr_add_read_handler(CharDriverState *chr, | ||
| 2503 | - IOCanRWHandler *fd_can_read, | ||
| 2504 | - IOReadHandler *fd_read, void *opaque) | ||
| 2505 | -{ | ||
| 2506 | - TCPCharDriver *s = chr->opaque; | ||
| 2507 | - | ||
| 2508 | - s->fd_can_read = fd_can_read; | ||
| 2509 | - s->fd_read = fd_read; | ||
| 2510 | - s->fd_opaque = opaque; | ||
| 2511 | -} | ||
| 2512 | - | ||
| 2513 | static void tcp_chr_connect(void *opaque) | 2474 | static void tcp_chr_connect(void *opaque) |
| 2514 | { | 2475 | { |
| 2515 | CharDriverState *chr = opaque; | 2476 | CharDriverState *chr = opaque; |
| @@ -2658,7 +2619,6 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str, | @@ -2658,7 +2619,6 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str, | ||
| 2658 | 2619 | ||
| 2659 | chr->opaque = s; | 2620 | chr->opaque = s; |
| 2660 | chr->chr_write = tcp_chr_write; | 2621 | chr->chr_write = tcp_chr_write; |
| 2661 | - chr->chr_add_read_handler = tcp_chr_add_read_handler; | ||
| 2662 | chr->chr_close = tcp_chr_close; | 2622 | chr->chr_close = tcp_chr_close; |
| 2663 | 2623 | ||
| 2664 | if (is_listen) { | 2624 | if (is_listen) { |
vl.h
| @@ -293,11 +293,12 @@ typedef void IOEventHandler(void *opaque, int event); | @@ -293,11 +293,12 @@ typedef void IOEventHandler(void *opaque, int event); | ||
| 293 | 293 | ||
| 294 | typedef struct CharDriverState { | 294 | typedef struct CharDriverState { |
| 295 | int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len); | 295 | int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len); |
| 296 | - void (*chr_add_read_handler)(struct CharDriverState *s, | ||
| 297 | - IOCanRWHandler *fd_can_read, | ||
| 298 | - IOReadHandler *fd_read, void *opaque); | 296 | + void (*chr_update_read_handler)(struct CharDriverState *s); |
| 299 | int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg); | 297 | int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg); |
| 300 | IOEventHandler *chr_event; | 298 | IOEventHandler *chr_event; |
| 299 | + IOCanRWHandler *chr_can_read; | ||
| 300 | + IOReadHandler *chr_read; | ||
| 301 | + void *handler_opaque; | ||
| 301 | void (*chr_send_event)(struct CharDriverState *chr, int event); | 302 | void (*chr_send_event)(struct CharDriverState *chr, int event); |
| 302 | void (*chr_close)(struct CharDriverState *chr); | 303 | void (*chr_close)(struct CharDriverState *chr); |
| 303 | void *opaque; | 304 | void *opaque; |
| @@ -308,12 +309,15 @@ CharDriverState *qemu_chr_open(const char *filename); | @@ -308,12 +309,15 @@ CharDriverState *qemu_chr_open(const char *filename); | ||
| 308 | void qemu_chr_printf(CharDriverState *s, const char *fmt, ...); | 309 | void qemu_chr_printf(CharDriverState *s, const char *fmt, ...); |
| 309 | int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len); | 310 | int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len); |
| 310 | void qemu_chr_send_event(CharDriverState *s, int event); | 311 | void qemu_chr_send_event(CharDriverState *s, int event); |
| 311 | -void qemu_chr_add_read_handler(CharDriverState *s, | ||
| 312 | - IOCanRWHandler *fd_can_read, | ||
| 313 | - IOReadHandler *fd_read, void *opaque); | ||
| 314 | -void qemu_chr_add_event_handler(CharDriverState *s, IOEventHandler *chr_event); | 312 | +void qemu_chr_add_handlers(CharDriverState *s, |
| 313 | + IOCanRWHandler *fd_can_read, | ||
| 314 | + IOReadHandler *fd_read, | ||
| 315 | + IOEventHandler *fd_event, | ||
| 316 | + void *opaque); | ||
| 315 | int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg); | 317 | int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg); |
| 316 | void qemu_chr_reset(CharDriverState *s); | 318 | void qemu_chr_reset(CharDriverState *s); |
| 319 | +int qemu_chr_can_read(CharDriverState *s); | ||
| 320 | +void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len); | ||
| 317 | 321 | ||
| 318 | /* consoles */ | 322 | /* consoles */ |
| 319 | 323 |