Index: uspace/srv/hid/console/console.c
===================================================================
--- uspace/srv/hid/console/console.c	(revision 9934f7d3082d2ffdd107cc0c78d61d504b0f401e)
+++ uspace/srv/hid/console/console.c	(revision f3a605bea58d01160f350e7db4258753b8362dec)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2006 Josef Cejka
+ * Copyright (c) 2011 Jiri Svoboda
  * All rights reserved.
  *
@@ -36,5 +37,4 @@
 #include <ipc/input.h>
 #include <io/keycode.h>
-#include <ipc/mouse.h>
 #include <ipc/fb.h>
 #include <ipc/services.h>
@@ -60,5 +60,4 @@
 #include <io/style.h>
 #include <io/screenbuffer.h>
-#include <inttypes.h>
 
 #include "console.h"
@@ -66,24 +65,9 @@
 #include "keybuffer.h"
 
-// FIXME: remove this header
-#include <kernel/ipc/ipc_methods.h>
-
 #define NAME       "console"
 #define NAMESPACE  "term"
 
-/** Interval for checking for new keyboard (1/4s). */
-#define HOTPLUG_WATCH_INTERVAL (1000 * 250)
-
-/* Kernel defines 32 but does not export it. */
-#define MAX_IPC_OUTGOING_PHONES 128
-
-/** To allow proper phone closing. */
-static ipc_callid_t driver_phones[MAX_IPC_OUTGOING_PHONES] = { 0 };
-
-/** Phone to the keyboard driver. */
-static int kbd_phone;
-
-/** Phone to the mouse driver. */
-static int mouse_phone;
+/** Phone to the input server. */
+static int input_phone;
 
 /** Information about framebuffer */
@@ -155,12 +139,12 @@
 }
 
-static void kbd_yield(void)
-{
-	async_obsolete_req_0_0(kbd_phone, INPUT_YIELD);
-}
-
-static void kbd_reclaim(void)
-{
-	async_obsolete_req_0_0(kbd_phone, INPUT_RECLAIM);
+static void input_yield(void)
+{
+	async_obsolete_req_0_0(input_phone, INPUT_YIELD);
+}
+
+static void input_reclaim(void)
+{
+	async_obsolete_req_0_0(input_phone, INPUT_RECLAIM);
 }
 
@@ -343,5 +327,5 @@
 		gcons_in_kernel();
 		screen_yield();
-		kbd_yield();
+		input_yield();
 		async_obsolete_serialize_end();
 		
@@ -358,5 +342,5 @@
 		if (active_console == kernel_console) {
 			screen_reclaim();
-			kbd_reclaim();
+			input_reclaim();
 			gcons_redraw_console();
 		}
@@ -413,19 +397,6 @@
 }
 
-static void close_driver_phone(ipc_callid_t hash)
-{
-	int i;
-	for (i = 0; i < MAX_IPC_OUTGOING_PHONES; i++) {
-		if (driver_phones[i] == hash) {
-			printf("Device %" PRIxn " gone.\n", hash);
-			driver_phones[i] = 0;
-			async_obsolete_hangup(i);
-			return;
-		}
-	}
-}
-
-/** Handler for keyboard */
-static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
+/** Handler for input events */
+static void input_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
 {
 	/* Ignore parameters, the connection is already opened */
@@ -439,11 +410,11 @@
 		if (!IPC_GET_IMETHOD(call)) {
 			/* TODO: Handle hangup */
-			close_driver_phone(iid);
+			async_obsolete_hangup(input_phone);
 			return;
 		}
 		
 		switch (IPC_GET_IMETHOD(call)) {
-		case INPUT_EVENT:
-			/* Got event from keyboard driver. */
+		case INPUT_EVENT_KEY:
+			/* Got key press/release event */
 			retval = 0;
 			ev.type = IPC_GET_ARG1(call);
@@ -466,29 +437,12 @@
 			fibril_mutex_unlock(&input_mutex);
 			break;
-		default:
-			retval = ENOENT;
-		}
-		async_answer_0(callid, retval);
-	}
-}
-
-/** Handler for mouse events */
-static void mouse_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
-{
-	/* Ignore parameters, the connection is already opened */
-	while (true) {
-		ipc_call_t call;
-		ipc_callid_t callid = async_get_call(&call);
-		
-		int retval;
-		
-		if (!IPC_GET_IMETHOD(call)) {
-			/* TODO: Handle hangup */
-			close_driver_phone(iid);
-			return;
-		}
-		
-		switch (IPC_GET_IMETHOD(call)) {
-		case MEVENT_BUTTON:
+		case INPUT_EVENT_MOVE:
+			/* Got pointer move event */
+			gcons_mouse_move((int) IPC_GET_ARG1(call),
+			    (int) IPC_GET_ARG2(call));
+			retval = 0;
+			break;
+		case INPUT_EVENT_BUTTON:
+			/* Got pointer button press/release event */
 			if (IPC_GET_ARG1(call) == 1) {
 				int newcon = gcons_mouse_btn((bool) IPC_GET_ARG2(call));
@@ -498,13 +452,7 @@
 			retval = 0;
 			break;
-		case MEVENT_MOVE:
-			gcons_mouse_move((int) IPC_GET_ARG1(call),
-			    (int) IPC_GET_ARG2(call));
-			retval = 0;
-			break;
 		default:
 			retval = ENOENT;
 		}
-
 		async_answer_0(callid, retval);
 	}
@@ -747,31 +695,10 @@
 }
 
-static int async_connect_to_me_hack(int phone, sysarg_t arg1, sysarg_t arg2,
-    sysarg_t arg3, async_client_conn_t client_receiver, ipc_callid_t *hash)
-{
-	sysarg_t task_hash;
-	sysarg_t phone_hash;
-	int rc = async_obsolete_req_3_5(phone, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
-	    NULL, NULL, NULL, &task_hash, &phone_hash);
-	if (rc != EOK)
-		return rc;
-	
-	if (client_receiver != NULL)
-		async_new_connection(task_hash, phone_hash, phone_hash, NULL,
-		    client_receiver, NULL);
-	
-	if (hash != NULL)
-		*hash = phone_hash;
-	
-	return EOK;
-}
-
-static int connect_keyboard_or_mouse(const char *devname,
-    async_client_conn_t handler, const char *dev)
+static int connect_input(const char *dev_path)
 {
 	int phone;
 	devmap_handle_t handle;
 	
-	int rc = devmap_device_get_handle(dev, &handle, 0);
+	int rc = devmap_device_get_handle(dev_path, &handle, 0);
 	if (rc == EOK) {
 		phone = devmap_obsolete_device_connect(handle, 0);
@@ -780,11 +707,12 @@
 			return phone;
 		}
-	} else
+	} else {
 		return rc;
+	}
 	
 	/* NB: The callback connection is slotted for removal */
-	ipc_callid_t hash;
-	rc = async_connect_to_me_hack(phone, SERVICE_CONSOLE, 0, phone,
-	    handler, &hash);
+	rc = async_obsolete_connect_to_me(phone, SERVICE_CONSOLE, 0, 0,
+	    input_events, NULL);
+
 	if (rc != EOK) {
 		async_obsolete_hangup(phone);
@@ -794,100 +722,13 @@
 	}
 	
-	driver_phones[phone] = hash;
-	printf("%s: found %s \"%s\" (%" PRIxn ").\n", NAME, devname, dev, hash);
 	return phone;
 }
 
-static int connect_keyboard(const char *dev)
-{
-	return connect_keyboard_or_mouse("keyboard", keyboard_events, dev);
-}
-
-static int connect_mouse(const char *dev)
-{
-	return connect_keyboard_or_mouse("mouse", mouse_events, dev);
-}
-
-struct hid_class_info {
-	char *classname;
-	int (*connection_func)(const char *);
-};
-
-/** Periodically check for new keyboards in /dev/class/.
- *
- * @param arg Class name.
- *
- * @return This function should never exit.
- *
- */
-static int check_new_device_fibril(void *arg)
-{
-	struct hid_class_info *dev_info = (struct hid_class_info *) arg;
-	
-	size_t index = 1;
-	
-	while (true) {
-		async_usleep(HOTPLUG_WATCH_INTERVAL);
-		
-		char *dev;
-		int rc = asprintf(&dev, "class/%s\\%zu",
-		    dev_info->classname, index);
-		if (rc < 0)
-			continue;
-		
-		rc = dev_info->connection_func(dev);
-		if (rc > 0) {
-			/* We do not allow unplug. */
-			index++;
-		}
-		
-		free(dev);
-	}
-	
-	return EOK;
-}
-
-/** Start a fibril monitoring hot-plugged keyboards.
- */
-static void check_new_devices_in_background(int (*connection_func)(const char *),
-    const char *classname)
-{
-	struct hid_class_info *dev_info = malloc(sizeof(struct hid_class_info));
-	if (dev_info == NULL) {
-		printf("%s: Out of memory, no hot-plug support.\n", NAME);
-		return;
-	}
-	
-	int rc = asprintf(&dev_info->classname, "%s", classname);
-	if (rc < 0) {
-		printf("%s: Failed to format classname: %s.\n", NAME,
-		    str_error(rc));
-		return;
-	}
-	
-	dev_info->connection_func = connection_func;
-	
-	fid_t fid = fibril_create(check_new_device_fibril, (void *) dev_info);
-	if (!fid) {
-		printf("%s: Failed to create hot-plug fibril for %s.\n", NAME,
-		    classname);
-		return;
-	}
-	
-	fibril_add_ready(fid);
-}
-
-static bool console_srv_init(char *kdev)
-{
-	/* Connect to input device */
-	kbd_phone = connect_keyboard(kdev);
-	if (kbd_phone < 0)
+static bool console_srv_init(char *input_dev)
+{
+	/* Connect to input server */
+	input_phone = connect_input(input_dev);
+	if (input_phone < 0)
 		return false;
-	
-	mouse_phone = connect_mouse("hid_in/mouse");
-	if (mouse_phone < 0) {
-		printf("%s: Failed to connect to mouse device %s\n", NAME,
-		    str_error(mouse_phone));
-	}
 	
 	/* Connect to framebuffer driver */
@@ -972,7 +813,4 @@
 		printf("%s: Error registering kconsole notifications\n", NAME);
 	
-	/* Start fibril for checking on hot-plugged keyboards. */
-	check_new_devices_in_background(connect_mouse, "mouse");
-	
 	return true;
 }
@@ -980,5 +818,5 @@
 static void usage(void)
 {
-	printf("Usage: console <input>\n");
+	printf("Usage: console <input_dev>\n");
 }
 
