return res;
}
-int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len)
+int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)
{
+ CharDriverState *s = be->chr;
int ret;
if (s->replay && replay_mode == REPLAY_MODE_PLAY) {
return ret;
}
-int qemu_chr_fe_write_all(CharDriverState *s, const uint8_t *buf, int len)
+static int qemu_chr_write_all(CharDriverState *s, const uint8_t *buf, int len)
{
int offset;
int res;
return offset;
}
-int qemu_chr_fe_read_all(CharDriverState *s, uint8_t *buf, int len)
+int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len)
{
+ CharDriverState *s = be->chr;
+
+ return qemu_chr_write_all(s, buf, len);
+}
+
+int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len)
+{
+ CharDriverState *s = be->chr;
int offset = 0, counter = 10;
int res;
return offset;
}
-int qemu_chr_fe_ioctl(CharDriverState *s, int cmd, void *arg)
+int qemu_chr_fe_ioctl(CharBackend *be, int cmd, void *arg)
{
+ CharDriverState *s = be->chr;
int res;
if (!s->chr_ioctl || s->replay) {
res = -ENOTSUP;
}
}
-int qemu_chr_fe_get_msgfd(CharDriverState *s)
+int qemu_chr_fe_get_msgfd(CharBackend *be)
{
+ CharDriverState *s = be->chr;
int fd;
- int res = (qemu_chr_fe_get_msgfds(s, &fd, 1) == 1) ? fd : -1;
+ int res = (qemu_chr_fe_get_msgfds(be, &fd, 1) == 1) ? fd : -1;
if (s->replay) {
fprintf(stderr,
"Replay: get msgfd is not supported for serial devices yet\n");
return res;
}
-int qemu_chr_fe_get_msgfds(CharDriverState *s, int *fds, int len)
+int qemu_chr_fe_get_msgfds(CharBackend *be, int *fds, int len)
{
+ CharDriverState *s = be->chr;
+
return s->get_msgfds ? s->get_msgfds(s, fds, len) : -1;
}
-int qemu_chr_fe_set_msgfds(CharDriverState *s, int *fds, int num)
+int qemu_chr_fe_set_msgfds(CharBackend *be, int *fds, int num)
{
+ CharDriverState *s = be->chr;
+
return s->set_msgfds ? s->set_msgfds(s, fds, num) : -1;
}
return s->chr_add_client ? s->chr_add_client(s, fd) : -1;
}
-void qemu_chr_fe_accept_input(CharDriverState *s)
+void qemu_chr_fe_accept_input(CharBackend *be)
{
+ CharDriverState *s = be->chr;
+
if (s->chr_accept_input)
s->chr_accept_input(s);
qemu_notify_event();
}
-void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...)
+void qemu_chr_fe_printf(CharBackend *be, const char *fmt, ...)
{
char buf[READ_BUF_LEN];
va_list ap;
vsnprintf(buf, sizeof(buf), fmt, ap);
/* XXX this blocks entire thread. Rewrite to use
* qemu_chr_fe_write and background I/O callbacks */
- qemu_chr_fe_write_all(s, (uint8_t *)buf, strlen(buf));
+ qemu_chr_fe_write_all(be, (uint8_t *)buf, strlen(buf));
va_end(ap);
}
static void remove_fd_in_watch(CharDriverState *chr);
static void
-qemu_chr_set_handlers(CharDriverState *s,
+qemu_chr_set_handlers(CharBackend *be,
IOCanReadHandler *fd_can_read,
IOReadHandler *fd_read,
IOEventHandler *fd_event,
void *opaque,
- GMainContext *context,
- int tag)
+ GMainContext *context)
{
+ CharDriverState *s = be->chr;
int fe_open;
if (!opaque && !fd_can_read && !fd_read && !fd_event) {
s->chr_event = fd_event;
s->handler_opaque = opaque;
if (s->chr_update_read_handler) {
- s->chr_update_read_handler(s, context, tag);
+ s->chr_update_read_handler(s, context, be->tag);
}
if (!s->explicit_fe_open) {
- qemu_chr_fe_set_open(s, fe_open);
+ qemu_chr_fe_set_open(be, fe_open);
}
/* We're connecting to an already opened device, so let's make sure we
also get the open event */
- if (fe_open && s->be_open) {
- qemu_chr_be_generic_open(s);
+ if (fe_open) {
+ qemu_chr_fe_take_focus(be);
+ if (s->be_open) {
+ qemu_chr_be_generic_open(s);
+ }
}
}
static void mux_chr_set_handlers(CharDriverState *chr, GMainContext *context);
static void mux_set_focus(MuxDriver *d, int focus);
-void qemu_chr_add_handlers_full(CharDriverState *s,
- IOCanReadHandler *fd_can_read,
- IOReadHandler *fd_read,
- IOEventHandler *fd_event,
- void *opaque,
- GMainContext *context)
-{
- int tag = 0;
-
- if (s->is_mux) {
- tag = mux_chr_new_handler_tag(s, &error_abort);
- mux_chr_set_handlers(s, context);
- }
-
- qemu_chr_set_handlers(s, fd_can_read, fd_read,
- fd_event, opaque, context, tag);
-
- if (s->is_mux) {
- mux_set_focus(s->opaque, tag);
- }
-}
-
-void qemu_chr_add_handlers(CharDriverState *s,
- IOCanReadHandler *fd_can_read,
- IOReadHandler *fd_read,
- IOEventHandler *fd_event,
- void *opaque)
-{
- qemu_chr_add_handlers_full(s, fd_can_read, fd_read,
- fd_event, opaque, NULL);
-}
-
static int null_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
{
return len;
IOReadHandler *chr_read[MAX_MUX];
IOEventHandler *chr_event[MAX_MUX];
void *ext_opaque[MAX_MUX];
- CharDriverState *drv;
CharBackend chr;
int focus;
int mux_cnt;
MuxDriver *d = chr->opaque;
int ret;
if (!d->timestamps) {
- ret = qemu_chr_fe_write(d->drv, buf, len);
+ ret = qemu_chr_fe_write(&d->chr, buf, len);
} else {
int i;
(int)(ti % 1000));
/* XXX this blocks entire thread. Rewrite to use
* qemu_chr_fe_write and background I/O callbacks */
- qemu_chr_fe_write_all(d->drv, (uint8_t *)buf1, strlen(buf1));
+ qemu_chr_fe_write_all(&d->chr,
+ (uint8_t *)buf1, strlen(buf1));
d->linestart = 0;
}
- ret += qemu_chr_fe_write(d->drv, buf+i, 1);
+ ret += qemu_chr_fe_write(&d->chr, buf + i, 1);
if (buf[i] == '\n') {
d->linestart = 1;
}
}
/* XXX this blocks entire thread. Rewrite to use
* qemu_chr_fe_write and background I/O callbacks */
- qemu_chr_fe_write_all(chr, (uint8_t *)cbuf, strlen(cbuf));
+ qemu_chr_write_all(chr, (uint8_t *)cbuf, strlen(cbuf));
for (i = 0; mux_help[i] != NULL; i++) {
for (j=0; mux_help[i][j] != '\0'; j++) {
if (mux_help[i][j] == '%')
- qemu_chr_fe_write_all(chr, (uint8_t *)ebuf, strlen(ebuf));
+ qemu_chr_write_all(chr, (uint8_t *)ebuf, strlen(ebuf));
else
- qemu_chr_fe_write_all(chr, (uint8_t *)&mux_help[i][j], 1);
+ qemu_chr_write_all(chr, (uint8_t *)&mux_help[i][j], 1);
}
}
}
case 'x':
{
const char *term = "QEMU: Terminated\n\r";
- qemu_chr_fe_write_all(chr, (uint8_t *)term, strlen(term));
+ qemu_chr_write_all(chr, (uint8_t *)term, strlen(term));
exit(0);
break;
}
static GSource *mux_chr_add_watch(CharDriverState *s, GIOCondition cond)
{
MuxDriver *d = s->opaque;
- return d->drv->chr_add_watch(d->drv, cond);
+ CharDriverState *chr = qemu_chr_fe_get_driver(&d->chr);
+
+ return chr->chr_add_watch(chr, cond);
}
static void mux_chr_close(struct CharDriverState *chr)
d = g_new0(MuxDriver, 1);
chr->opaque = d;
- d->drv = drv;
d->focus = -1;
chr->chr_close = mux_chr_close;
chr->chr_write = mux_chr_write;
*/
chr->explicit_be_open = muxes_realized ? 0 : 1;
chr->is_mux = 1;
- if (!qemu_chr_fe_init(&d->chr, d->drv, errp)) {
+ if (!qemu_chr_fe_init(&d->chr, drv, errp)) {
qemu_chr_free(chr);
return NULL;
}
return;
}
- qemu_chr_set_handlers(b->chr, fd_can_read, fd_read,
- fd_event, opaque, context, b->tag);
+ qemu_chr_set_handlers(b, fd_can_read, fd_read,
+ fd_event, opaque, context);
if (b->chr->is_mux) {
mux_chr_set_handlers(b->chr, context);
if (opts->has_signal) {
stdio_allow_signal = opts->signal;
}
- qemu_chr_fe_set_echo(chr, false);
+ qemu_chr_set_echo_stdio(chr, false);
return chr;
}
SetConsoleMode(stdio->hStdIn, dwMode);
chr->chr_set_echo = qemu_chr_set_echo_win_stdio;
- qemu_chr_fe_set_echo(chr, false);
+ qemu_chr_set_echo_win_stdio(chr, false);
return chr;
}
#endif /* !_WIN32 */
-
/***********************************************************/
/* UDP Net console */
return 0;
}
-int qemu_chr_wait_connected(CharDriverState *chr, Error **errp)
+static int qemu_chr_wait_connected(CharDriverState *chr, Error **errp)
{
if (chr->chr_wait_connected) {
return chr->chr_wait_connected(chr, errp);
return 0;
}
+int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp)
+{
+ return qemu_chr_wait_connected(be->chr, errp);
+}
+
static void tcp_chr_close(CharDriverState *chr)
{
TCPCharDriver *s = chr->opaque;
return chr;
}
-void qemu_chr_fe_set_echo(struct CharDriverState *chr, bool echo)
+void qemu_chr_fe_set_echo(CharBackend *be, bool echo)
{
+ CharDriverState *chr = be->chr;
+
if (chr->chr_set_echo) {
chr->chr_set_echo(chr, echo);
}
}
-void qemu_chr_fe_set_open(struct CharDriverState *chr, int fe_open)
+void qemu_chr_fe_set_open(CharBackend *be, int fe_open)
{
+ CharDriverState *chr = be->chr;
+
if (chr->fe_open == fe_open) {
return;
}
}
}
-void qemu_chr_fe_event(struct CharDriverState *chr, int event)
+void qemu_chr_fe_event(CharBackend *be, int event)
{
+ CharDriverState *chr = be->chr;
+
if (chr->chr_fe_event) {
chr->chr_fe_event(chr, event);
}
}
-guint qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond,
+guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond,
GIOFunc func, void *user_data)
{
+ CharDriverState *s = be->chr;
GSource *src;
guint tag;
s->avail_connections++;
}
-void qemu_chr_fe_disconnect(CharDriverState *chr)
+void qemu_chr_fe_disconnect(CharBackend *be)
{
+ CharDriverState *chr = be->chr;
+
if (chr->chr_disconnect) {
chr->chr_disconnect(chr);
}