Remove QEMU-ism from UI code.

This gets rid of qemu_set_fd_handler() users in the UI
program. We can remove its implementation from vl-android-ui.c

+ Really remove qemu-timer-ui.c :-)

Change-Id: I490df8ad5d5eea36b332bf54e2b156f6b5872bf4
diff --git a/android/protocol/fb-updates-impl.c b/android/protocol/fb-updates-impl.c
index 170fb47..2f3ff71 100644
--- a/android/protocol/fb-updates-impl.c
+++ b/android/protocol/fb-updates-impl.c
@@ -15,7 +15,6 @@
  * from the core.
  */
 
-#include "sysemu.h"
 #include "android/utils/system.h"
 #include "android/utils/debug.h"
 #include "android/utils/panic.h"
@@ -60,6 +59,9 @@
     /* Socket descriptor for the framebuffer client. */
     int             sock;
 
+    /* Custom i/o handler */
+    LoopIo          io[1];
+
     /* Number of bits used to encode single pixel. */
     int             bits_per_pixel;
 } ImplFramebuffer;
@@ -103,7 +105,7 @@
  *  opaque - ImplFramebuffer instance.
  */
 static void
-_implFb_read_cb(void* opaque)
+_implFb_io_callback(void* opaque, int fd, unsigned events)
 {
     ImplFramebuffer* fb_client = opaque;
     int  ret;
@@ -165,7 +167,10 @@
 }
 
 int
-implFb_create(SockAddress* console_socket, const char* protocol, QFrameBuffer* fb)
+implFb_create(SockAddress* console_socket,
+              const char* protocol,
+              QFrameBuffer* fb,
+              Looper* looper)
 {
     char* handshake = NULL;
     char switch_cmd[256];
@@ -212,11 +217,9 @@
     _implFb.sock = core_connection_get_socket(_implFb.core_connection);
 
     // At last setup read callback, and start receiving the updates.
-    if (qemu_set_fd_handler(_implFb.sock, _implFb_read_cb, NULL, &_implFb)) {
-        derror("Unable to set up framebuffer read callback.\n");
-        implFb_destroy();
-        return -1;
-    }
+    loopIo_init(_implFb.io, looper, _implFb.sock,
+                _implFb_io_callback, &_implFb);
+    loopIo_wantRead(_implFb.io);
     {
         // Force the core to send us entire framebuffer now, when we're prepared
         // to receive it.
@@ -248,7 +251,7 @@
 {
     if (_implFb.core_connection != NULL) {
         // Disable the reader callback.
-        qemu_set_fd_handler(_implFb.sock, NULL, NULL, NULL);
+        loopIo_done(_implFb.io);
 
         // Close framebuffer connection.
         core_connection_close(_implFb.core_connection);
diff --git a/android/protocol/fb-updates-impl.h b/android/protocol/fb-updates-impl.h
index c4dd2e0..db06244 100644
--- a/android/protocol/fb-updates-impl.h
+++ b/android/protocol/fb-updates-impl.h
@@ -18,7 +18,7 @@
 #ifndef _ANDROID_FRAMEBUFFER_UI_H
 #define _ANDROID_FRAMEBUFFER_UI_H
 
-#include "console.h"
+#include "android/looper.h"
 #include "android/framebuffer.h"
 #include "android/looper.h"
 #include "android/async-utils.h"
@@ -35,7 +35,8 @@
  */
 int implFb_create(SockAddress* console_socket,
                   const char* protocol,
-                  QFrameBuffer* fb);
+                  QFrameBuffer* fb,
+                  Looper* looper);
 
 /* Disconnects and destroys framebuffer client. */
 void implFb_destroy(void);
diff --git a/android/protocol/ui-commands-impl.c b/android/protocol/ui-commands-impl.c
index 2ca4194..f07a1ad 100644
--- a/android/protocol/ui-commands-impl.c
+++ b/android/protocol/ui-commands-impl.c
@@ -16,7 +16,7 @@
  * from the Core.
  */
 
-#include "console.h"
+#include <unistd.h>
 #include "android/looper.h"
 #include "android/async-utils.h"
 #include "android/sync-utils.h"
@@ -44,6 +44,9 @@
     /* Socket descriptor for the UI service. */
     int             sock;
 
+    /* Custom i/o handler */
+    LoopIo          io[1];
+
     /* Command reader state. */
     UICmdImplState  reader_state;
 
@@ -113,7 +116,7 @@
  *  opaque - UICmdImpl instance.
  */
 static void
-_uiCmdImpl_io_read(void* opaque)
+_uiCmdImpl_io_callback(void* opaque, int fd, unsigned events)
 {
     UICmdImpl* uicmd = opaque;
     int status;
@@ -181,7 +184,7 @@
 }
 
 int
-uiCmdImpl_create(SockAddress* console_socket)
+uiCmdImpl_create(SockAddress* console_socket, Looper* looper)
 {
     char* handshake = NULL;
 
@@ -203,16 +206,10 @@
 
     // Initialize UI command reader.
     _uiCmdImpl.sock = core_connection_get_socket(_uiCmdImpl.core_connection);
-    if (qemu_set_fd_handler(_uiCmdImpl.sock, _uiCmdImpl_io_read, NULL,
-                            &_uiCmdImpl)) {
-        derror("Unable to set up UI _uiCmdImpl_io_read callback: %s\n",
-               errno_str);
-        uiCmdImpl_destroy();
-        if (handshake != NULL) {
-            free(handshake);
-        }
-        return -1;
-    }
+    loopIo_init(_uiCmdImpl.io, looper, _uiCmdImpl.sock,
+                _uiCmdImpl_io_callback,
+                &_uiCmdImpl);
+    loopIo_wantRead(_uiCmdImpl.io);
 
     fprintf(stdout, "core-ui-control is now connected to the core at %s.",
             sock_address_to_string(console_socket));
@@ -232,7 +229,7 @@
 {
     if (_uiCmdImpl.core_connection != NULL) {
         // Disable I/O callbacks.
-        qemu_set_fd_handler(_uiCmdImpl.sock, NULL, NULL, NULL);
+        loopIo_done(_uiCmdImpl.io);
         core_connection_close(_uiCmdImpl.core_connection);
         core_connection_free(_uiCmdImpl.core_connection);
         _uiCmdImpl.core_connection = NULL;
diff --git a/android/protocol/ui-commands-impl.h b/android/protocol/ui-commands-impl.h
index fa05e8e..f575bd0 100644
--- a/android/protocol/ui-commands-impl.h
+++ b/android/protocol/ui-commands-impl.h
@@ -14,6 +14,7 @@
 #define _ANDROID_PROTOCOL_UI_COMMANDS_IMPL_H
 
 #include "sockets.h"
+#include "android/looper.h"
 #include "android/protocol/ui-commands.h"
 
 /*
@@ -29,7 +30,7 @@
  * Return:
  *  0 on success, or < 0 on failure.
  */
-extern int uiCmdImpl_create(SockAddress* console_socket);
+extern int uiCmdImpl_create(SockAddress* console_socket, Looper* looper);
 
 /* Destroys UI-side of the "core-ui-control" service. */
 extern void uiCmdImpl_destroy();