diff options
Diffstat (limited to 'vl-android-ui.c')
-rw-r--r-- | vl-android-ui.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/vl-android-ui.c b/vl-android-ui.c index 6c0c934..0b63d4a 100644 --- a/vl-android-ui.c +++ b/vl-android-ui.c @@ -27,7 +27,14 @@ #define _GNU_SOURCE 1 #endif +#ifndef _WIN32 #include <sys/wait.h> +#endif // _WIN32 + +#ifdef _WIN32 +#include <windows.h> +#include <sys/timeb.h> +#endif #include "qemu-common.h" #include "net.h" @@ -54,6 +61,90 @@ static Looper* mainLooper; /***********************************************************/ +/* I/O handling */ + +typedef struct IOHandlerRecord { + LoopIo io[1]; + IOHandler* fd_read; + IOHandler* fd_write; + int running; + int deleted; + void* opaque; + struct IOHandlerRecord *next; +} IOHandlerRecord; + +static IOHandlerRecord *first_io_handler; + +static void ioh_callback(void* opaque, int fd, unsigned events) +{ + IOHandlerRecord* ioh = opaque; + ioh->running = 1; + if ((events & LOOP_IO_READ) != 0) { + ioh->fd_read(ioh->opaque); + } + if (!ioh->deleted && (events & LOOP_IO_WRITE) != 0) { + ioh->fd_write(ioh->opaque); + } + ioh->running = 0; + if (ioh->deleted) { + loopIo_done(ioh->io); + free(ioh); + } +} + +int qemu_set_fd_handler(int fd, + IOHandler *fd_read, + IOHandler *fd_write, + void *opaque) +{ + IOHandlerRecord **pioh, *ioh; + + if (!fd_read && !fd_write) { + pioh = &first_io_handler; + for(;;) { + ioh = *pioh; + if (ioh == NULL) + return 0; + if (ioh->io->fd == fd) { + break; + } + pioh = &ioh->next; + } + if (ioh->running) { + ioh->deleted = 1; + } else { + *pioh = ioh->next; + loopIo_done(ioh->io); + free(ioh); + } + } else { + for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) { + if (ioh->io->fd == fd) + goto found; + } + ANEW0(ioh); + ioh->next = first_io_handler; + first_io_handler = ioh; + loopIo_init(ioh->io, mainLooper, fd, ioh_callback, ioh); + found: + ioh->fd_read = fd_read; + ioh->fd_write = fd_write; + ioh->opaque = opaque; + + if (fd_read != NULL) + loopIo_wantRead(ioh->io); + else + loopIo_dontWantRead(ioh->io); + + if (fd_write != NULL) + loopIo_wantWrite(ioh->io); + else + loopIo_dontWantWrite(ioh->io); + } + return 0; +} + +/***********************************************************/ /* main execution loop */ static LoopTimer gui_timer[1]; |