#include "ui/console.h"
#include "sysemu/sysemu.h"
#include "qemu/timer.h"
-#include "char/char.h"
+#include "sysemu/char.h"
#include "hw/usb.h"
#include "qmp-commands.h"
{
GSource parent;
+ GIOChannel *channel;
GSource *src;
IOCanReadHandler *fd_can_read;
+ GSourceFunc fd_read;
void *opaque;
} IOWatchPoll;
{
IOWatchPoll *iwp = io_watch_poll_from_source(source);
bool now_active = iwp->fd_can_read(iwp->opaque) > 0;
- bool was_active = g_source_get_context(iwp->src) != NULL;
+ bool was_active = iwp->src != NULL;
if (was_active == now_active) {
return FALSE;
}
if (now_active) {
+ iwp->src = g_io_create_watch(iwp->channel, G_IO_IN | G_IO_ERR | G_IO_HUP);
+ g_source_set_callback(iwp->src, iwp->fd_read, iwp->opaque, NULL);
g_source_attach(iwp->src, NULL);
} else {
- g_source_remove(g_source_get_id(iwp->src));
+ g_source_destroy(iwp->src);
+ g_source_unref(iwp->src);
+ iwp->src = NULL;
}
return FALSE;
}
static void io_watch_poll_finalize(GSource *source)
{
IOWatchPoll *iwp = io_watch_poll_from_source(source);
+ g_source_destroy(iwp->src);
g_source_unref(iwp->src);
+ iwp->src = NULL;
}
static GSourceFuncs io_watch_poll_funcs = {
gpointer user_data)
{
IOWatchPoll *iwp;
+ int tag;
iwp = (IOWatchPoll *) g_source_new(&io_watch_poll_funcs, sizeof(IOWatchPoll));
iwp->fd_can_read = fd_can_read;
iwp->opaque = user_data;
- iwp->src = g_io_create_watch(channel, G_IO_IN | G_IO_ERR | G_IO_HUP);
- g_source_set_callback(iwp->src, (GSourceFunc)fd_read, user_data, NULL);
+ iwp->channel = channel;
+ iwp->fd_read = (GSourceFunc) fd_read;
+ iwp->src = NULL;
- return g_source_attach(&iwp->parent, NULL);
+ tag = g_source_attach(&iwp->parent, NULL);
+ g_source_unref(&iwp->parent);
+ return tag;
}
#ifndef _WIN32