Index: uspace/srv/hid/console/console.c
===================================================================
--- uspace/srv/hid/console/console.c	(revision 8c74d15d2b1a8df5daa8ef5f730232c826c40c95)
+++ uspace/srv/hid/console/console.c	(revision 79ae36ddc409577eb0da3750b3a7280e034566a2)
@@ -39,5 +39,6 @@
 #include <ipc/fb.h>
 #include <ipc/services.h>
-#include <ipc/ns.h>
+#include <ns.h>
+#include <ns_obsolete.h>
 #include <errno.h>
 #include <str_error.h>
@@ -45,4 +46,5 @@
 #include <unistd.h>
 #include <async.h>
+#include <async_obsolete.h>
 #include <adt/fifo.h>
 #include <sys/mman.h>
@@ -52,4 +54,5 @@
 #include <event.h>
 #include <devmap.h>
+#include <devmap_obsolete.h>
 #include <fcntl.h>
 #include <vfs/vfs.h>
@@ -63,7 +66,10 @@
 #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)
@@ -71,4 +77,5 @@
 /* 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 };
@@ -97,6 +104,4 @@
 } console_t;
 
-
-
 /** Array of data for virtual consoles */
 static console_t consoles[CONSOLE_COUNT];
@@ -122,55 +127,55 @@
 static void curs_visibility(bool visible)
 {
-	async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible); 
+	async_obsolete_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible); 
 }
 
 static void curs_hide_sync(void)
 {
-	async_req_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false); 
+	async_obsolete_req_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false); 
 }
 
 static void curs_goto(sysarg_t x, sysarg_t y)
 {
-	async_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y);
+	async_obsolete_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y);
 }
 
 static void screen_clear(void)
 {
-	async_msg_0(fb_info.phone, FB_CLEAR);
+	async_obsolete_msg_0(fb_info.phone, FB_CLEAR);
 }
 
 static void screen_yield(void)
 {
-	async_req_0_0(fb_info.phone, FB_SCREEN_YIELD);
+	async_obsolete_req_0_0(fb_info.phone, FB_SCREEN_YIELD);
 }
 
 static void screen_reclaim(void)
 {
-	async_req_0_0(fb_info.phone, FB_SCREEN_RECLAIM);
+	async_obsolete_req_0_0(fb_info.phone, FB_SCREEN_RECLAIM);
 }
 
 static void kbd_yield(void)
 {
-	async_req_0_0(kbd_phone, KBD_YIELD);
+	async_obsolete_req_0_0(kbd_phone, KBD_YIELD);
 }
 
 static void kbd_reclaim(void)
 {
-	async_req_0_0(kbd_phone, KBD_RECLAIM);
+	async_obsolete_req_0_0(kbd_phone, KBD_RECLAIM);
 }
 
 static void set_style(uint8_t style)
 {
-	async_msg_1(fb_info.phone, FB_SET_STYLE, style);
+	async_obsolete_msg_1(fb_info.phone, FB_SET_STYLE, style);
 }
 
 static void set_color(uint8_t fgcolor, uint8_t bgcolor, uint8_t flags)
 {
-	async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags);
+	async_obsolete_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags);
 }
 
 static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor)
 {
-	async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor); 
+	async_obsolete_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor); 
 }
 
@@ -227,5 +232,5 @@
 		}
 		
-		async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
+		async_obsolete_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
 		    x0, y0, width, height);
 	}
@@ -268,5 +273,5 @@
 static void fb_putchar(wchar_t c, sysarg_t col, sysarg_t row)
 {
-	async_msg_3(fb_info.phone, FB_PUTCHAR, c, col, row);
+	async_obsolete_msg_3(fb_info.phone, FB_PUTCHAR, c, col, row);
 }
 
@@ -317,5 +322,5 @@
 		
 		if (cons == active_console)
-			async_msg_1(fb_info.phone, FB_SCROLL, 1);
+			async_obsolete_msg_1(fb_info.phone, FB_SCROLL, 1);
 	}
 	
@@ -328,17 +333,16 @@
 static void change_console(console_t *cons)
 {
-	if (cons == active_console) {
+	if (cons == active_console)
 		return;
-	}
 	
 	fb_pending_flush();
 	
 	if (cons == kernel_console) {
-		async_serialize_start();
+		async_obsolete_serialize_start();
 		curs_hide_sync();
 		gcons_in_kernel();
 		screen_yield();
 		kbd_yield();
-		async_serialize_end();
+		async_obsolete_serialize_end();
 		
 		if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) {
@@ -350,5 +354,5 @@
 	
 	if (cons != kernel_console) {
-		async_serialize_start();
+		async_obsolete_serialize_start();
 		
 		if (active_console == kernel_console) {
@@ -377,5 +381,5 @@
 			
 			/* This call can preempt, but we are already at the end */
-			rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
+			rc = async_obsolete_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
 			    0, 0, cons->scr.size_x,
 			    cons->scr.size_y);
@@ -405,5 +409,5 @@
 		curs_visibility(cons->scr.is_cursor_visible);
 		
-		async_serialize_end();
+		async_obsolete_serialize_end();
 	}
 }
@@ -416,5 +420,5 @@
 			printf("Device %" PRIxn " gone.\n", hash);
 			driver_phones[i] = 0;
-			async_hangup(i);
+			async_obsolete_hangup(i);
 			return;
 		}
@@ -431,11 +435,13 @@
 		
 		int retval;
-		console_event_t ev;
-		
-		switch (IPC_GET_IMETHOD(call)) {
-		case IPC_M_PHONE_HUNGUP:
+		kbd_event_t ev;
+		
+		if (!IPC_GET_IMETHOD(call)) {
 			/* TODO: Handle hangup */
 			close_driver_phone(iid);
 			return;
+		}
+		
+		switch (IPC_GET_IMETHOD(call)) {
 		case KBD_EVENT:
 			/* Got event from keyboard driver. */
@@ -477,15 +483,16 @@
 		int retval;
 		
-		switch (IPC_GET_IMETHOD(call)) {
-		case IPC_M_PHONE_HUNGUP:
+		if (!IPC_GET_IMETHOD(call)) {
 			/* TODO: Handle hangup */
 			close_driver_phone(iid);
 			return;
+		}
+		
+		switch (IPC_GET_IMETHOD(call)) {
 		case MEVENT_BUTTON:
 			if (IPC_GET_ARG1(call) == 1) {
 				int newcon = gcons_mouse_btn((bool) IPC_GET_ARG2(call));
-				if (newcon != -1) {
+				if (newcon != -1)
 					change_console(&consoles[newcon]);
-				}
 			}
 			retval = 0;
@@ -515,5 +522,5 @@
 	}
 	
-	async_serialize_start();
+	async_obsolete_serialize_start();
 	
 	size_t off = 0;
@@ -523,5 +530,5 @@
 	}
 	
-	async_serialize_end();
+	async_obsolete_serialize_end();
 	
 	gcons_notify_char(cons->index);
@@ -549,5 +556,5 @@
 	
 	size_t pos = 0;
-	console_event_t ev;
+	kbd_event_t ev;
 	fibril_mutex_lock(&input_mutex);
 	
@@ -574,5 +581,5 @@
 static void cons_get_event(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
 {
-	console_event_t ev;
+	kbd_event_t ev;
 	
 	fibril_mutex_lock(&input_mutex);
@@ -618,5 +625,5 @@
 	int rc;
 	
-	async_serialize_start();
+	async_obsolete_serialize_start();
 	if (cons->refcount == 0)
 		gcons_notify_connect(cons->index);
@@ -628,7 +635,7 @@
 	
 	while (true) {
-		async_serialize_end();
+		async_obsolete_serialize_end();
 		callid = async_get_call(&call);
-		async_serialize_start();
+		async_obsolete_serialize_start();
 		
 		arg1 = 0;
@@ -636,24 +643,26 @@
 		arg3 = 0;
 		
-		switch (IPC_GET_IMETHOD(call)) {
-		case IPC_M_PHONE_HUNGUP:
+		if (!IPC_GET_IMETHOD(call)) {
 			cons->refcount--;
 			if (cons->refcount == 0)
 				gcons_notify_disconnect(cons->index);
 			return;
+		}
+		
+		switch (IPC_GET_IMETHOD(call)) {
 		case VFS_OUT_READ:
-			async_serialize_end();
+			async_obsolete_serialize_end();
 			cons_read(cons, callid, &call);
-			async_serialize_start();
+			async_obsolete_serialize_start();
 			continue;
 		case VFS_OUT_WRITE:
-			async_serialize_end();
+			async_obsolete_serialize_end();
 			cons_write(cons, callid, &call);
-			async_serialize_start();
+			async_obsolete_serialize_start();
 			continue;
 		case VFS_OUT_SYNC:
 			fb_pending_flush();
 			if (cons == active_console) {
-				async_req_0_0(fb_info.phone, FB_FLUSH);
+				async_obsolete_req_0_0(fb_info.phone, FB_FLUSH);
 				curs_goto(cons->scr.position_x, cons->scr.position_y);
 			}
@@ -662,5 +671,5 @@
 			/* Send message to fb */
 			if (cons == active_console)
-				async_msg_0(fb_info.phone, FB_CLEAR);
+				async_obsolete_msg_0(fb_info.phone, FB_CLEAR);
 			
 			screenbuffer_clear(&cons->scr);
@@ -721,7 +730,7 @@
 			break;
 		case CONSOLE_GET_EVENT:
-			async_serialize_end();
+			async_obsolete_serialize_end();
 			cons_get_event(cons, callid, &call);
-			async_serialize_start();
+			async_obsolete_serialize_start();
 			continue;
 		case CONSOLE_KCON_ENABLE:
@@ -739,65 +748,63 @@
 
 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 arg3, async_client_conn_t client_receiver, ipc_callid_t *hash)
 {
 	sysarg_t task_hash;
 	sysarg_t phone_hash;
-	int rc = async_req_3_5(phone, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
+	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);
-
-	if (hash != 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 *path)
-{
-	int fd = open(path, O_RDONLY);
-	if (fd < 0) {
-		return fd;
-	}
-	
-	int phone = fd_phone(fd);
-	close(fd);
-	if (phone < 0) {
-		printf(NAME ": Failed to connect to input device\n");
-		return phone;
-	}
-	
+    async_client_conn_t handler, const char *dev)
+{
+	int phone;
+	devmap_handle_t handle;
+	
+	int rc = devmap_device_get_handle(dev, &handle, 0);
+	if (rc == EOK) {
+		phone = devmap_obsolete_device_connect(handle, 0);
+		if (phone < 0) {
+			printf("%s: Failed to connect to input device\n", NAME);
+			return phone;
+		}
+	} else
+		return rc;
+	
+	/* NB: The callback connection is slotted for removal */
 	ipc_callid_t hash;
-	int rc = async_connect_to_me_hack(phone, SERVICE_CONSOLE, 0, phone,
+	rc = async_connect_to_me_hack(phone, SERVICE_CONSOLE, 0, phone,
 	    handler, &hash);
 	if (rc != EOK) {
-		async_hangup(phone);
-		printf(NAME ": " \
-		    "Failed to create callback from input device: %s.\n",
-		    str_error(rc));
+		async_obsolete_hangup(phone);
+		printf("%s: Failed to create callback from input device (%s).\n",
+		    NAME, str_error(rc));
 		return rc;
 	}
 	
 	driver_phones[phone] = hash;
-
-	printf(NAME ": found %s \"%s\" (%" PRIxn ").\n", devname, path, hash);
-
+	printf("%s: found %s \"%s\" (%" PRIxn ").\n", NAME, devname, dev, hash);
 	return phone;
 }
 
-static int connect_keyboard(const char *path)
-{
-	return connect_keyboard_or_mouse("keyboard", keyboard_events, path);
-}
-
-static int connect_mouse(const char *path)
-{
-	return connect_keyboard_or_mouse("mouse", mouse_events, path);
+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);
 }
 
@@ -810,33 +817,34 @@
  *
  * @param arg Class name.
+ *
  * @return This function should never exit.
+ *
  */
 static int check_new_device_fibril(void *arg)
 {
-	struct hid_class_info *dev_info = arg;
-
+	struct hid_class_info *dev_info = (struct hid_class_info *) arg;
+	
 	size_t index = 1;
-
+	
 	while (true) {
 		async_usleep(HOTPLUG_WATCH_INTERVAL);
-		char *path;
-		int rc = asprintf(&path, "/dev/class/%s\\%zu",
+		
+		char *dev;
+		int rc = asprintf(&dev, "class/%s\\%zu",
 		    dev_info->classname, index);
-		if (rc < 0) {
+		if (rc < 0)
 			continue;
-		}
-		rc = 0;
-		rc = dev_info->connection_func(path);
+		
+		rc = dev_info->connection_func(dev);
 		if (rc > 0) {
 			/* We do not allow unplug. */
 			index++;
 		}
-
-		free(path);
-	}
-
+		
+		free(dev);
+	}
+	
 	return EOK;
 }
-
 
 /** Start a fibril monitoring hot-plugged keyboards.
@@ -847,47 +855,45 @@
 	struct hid_class_info *dev_info = malloc(sizeof(struct hid_class_info));
 	if (dev_info == NULL) {
-		printf(NAME ": " \
-		    "out of memory, will not start hot-plug-watch fibril.\n");
+		printf("%s: Out of memory, no hot-plug support.\n", NAME);
 		return;
 	}
-	int rc;
-
-	rc = asprintf(&dev_info->classname, "%s", classname);
+	
+	int rc = asprintf(&dev_info->classname, "%s", classname);
 	if (rc < 0) {
-		printf(NAME ": failed to format classname: %s.\n",
+		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);
+	
+	fid_t fid = fibril_create(check_new_device_fibril, (void *) dev_info);
 	if (!fid) {
-		printf(NAME
-		    ": failed to create hot-plug-watch fibril for %s.\n",
+		printf("%s: Failed to create hot-plug fibril for %s.\n", NAME,
 		    classname);
 		return;
 	}
+	
 	fibril_add_ready(fid);
 }
 
-static bool console_init(char *input)
+static bool console_srv_init(char *kdev)
 {
 	/* Connect to input device */
-	kbd_phone = connect_keyboard(input);
-	if (kbd_phone < 0) {
+	kbd_phone = connect_keyboard(kdev);
+	if (kbd_phone < 0)
 		return false;
-	}
-
-	mouse_phone = connect_mouse("/dev/hid_in/mouse");
+	
+	mouse_phone = connect_mouse("hid_in/mouse");
 	if (mouse_phone < 0) {
-		printf(NAME ": Failed to connect to mouse device: %s.\n",
+		printf("%s: Failed to connect to mouse device %s\n", NAME,
 		    str_error(mouse_phone));
 	}
 	
 	/* Connect to framebuffer driver */
-	fb_info.phone = service_connect_blocking(SERVICE_VIDEO, 0, 0);
+	fb_info.phone = service_obsolete_connect_blocking(SERVICE_VIDEO, 0, 0);
 	if (fb_info.phone < 0) {
-		printf(NAME ": Failed to connect to video service\n");
-		return -1;
+		printf("%s: Failed to connect to video service\n", NAME);
+		return false;
 	}
 	
@@ -895,5 +901,5 @@
 	int rc = devmap_driver_register(NAME, client_connection);
 	if (rc < 0) {
-		printf(NAME ": Unable to register driver (%d)\n", rc);
+		printf("%s: Unable to register driver (%d)\n", NAME, rc);
 		return false;
 	}
@@ -903,7 +909,7 @@
 	
 	/* Synchronize, the gcons could put something in queue */
-	async_req_0_0(fb_info.phone, FB_FLUSH);
-	async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows);
-	async_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &fb_info.color_cap);
+	async_obsolete_req_0_0(fb_info.phone, FB_FLUSH);
+	async_obsolete_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows);
+	async_obsolete_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &fb_info.color_cap);
 	
 	/* Set up shared memory buffer. */
@@ -916,5 +922,5 @@
 	
 	if (interbuffer) {
-		if (async_share_out_start(fb_info.phone, interbuffer,
+		if (async_obsolete_share_out_start(fb_info.phone, interbuffer,
 		    AS_AREA_READ) != EOK) {
 			as_area_destroy(interbuffer);
@@ -931,5 +937,5 @@
 			if (screenbuffer_init(&consoles[i].scr,
 			    fb_info.cols, fb_info.rows) == NULL) {
-				printf(NAME ": Unable to allocate screen buffer %zu\n", i);
+				printf("%s: Unable to allocate screen buffer %zu\n", NAME, i);
 				return false;
 			}
@@ -943,5 +949,5 @@
 			
 			if (devmap_device_register(vc, &consoles[i].devmap_handle) != EOK) {
-				printf(NAME ": Unable to register device %s\n", vc);
+				printf("%s: Unable to register device %s\n", NAME, vc);
 				return false;
 			}
@@ -953,5 +959,5 @@
 	
 	/* Initialize the screen */
-	async_serialize_start();
+	async_obsolete_serialize_start();
 	gcons_redraw_console();
 	set_style(STYLE_NORMAL);
@@ -959,15 +965,15 @@
 	curs_goto(0, 0);
 	curs_visibility(active_console->scr.is_cursor_visible);
-	async_serialize_end();
+	async_obsolete_serialize_end();
 	
 	/* Receive kernel notifications */
 	async_set_interrupt_received(interrupt_received);
 	if (event_subscribe(EVENT_KCONSOLE, 0) != EOK)
-		printf(NAME ": Error registering kconsole notifications\n");
+		printf("%s: Error registering kconsole notifications\n", NAME);
 	
 	/* Start fibril for checking on hot-plugged keyboards. */
 	check_new_devices_in_background(connect_keyboard, "keyboard");
 	check_new_devices_in_background(connect_mouse, "mouse");
-
+	
 	return true;
 }
@@ -987,7 +993,7 @@
 	printf(NAME ": HelenOS Console service\n");
 	
-	if (!console_init(argv[1]))
+	if (!console_srv_init(argv[1]))
 		return -1;
-
+	
 	printf(NAME ": Accepting connections\n");
 	async_manager();
