Index: uspace/app/mkbd/main.c
===================================================================
--- uspace/app/mkbd/main.c	(revision 2176ed6b0d954c1d1f9b3e6e9f4e44874a0ad5d3)
+++ uspace/app/mkbd/main.c	(revision 0eff68e2235e2f4737160b4f06cd3e6c1b217a5e)
@@ -45,6 +45,4 @@
 #include <devmap.h>
 #include <usb/dev/hub.h>
-//#include <usb/host.h>
-//#include <usb/driver.h>
 #include <usb/hid/iface.h>
 #include <usb/dev/pipes.h>
@@ -58,12 +56,12 @@
 #define NAME "mkbd"
 
-static int dev_phone = -1;
-
-static int initialize_report_parser(int dev_phone, usb_hid_report_t **report)
-{
-	*report = (usb_hid_report_t *)malloc(sizeof(usb_hid_report_t));
-	if (*report == NULL) {
-		return ENOMEM;
-	}
+static async_sess_t *dev_sess = NULL;
+
+static int initialize_report_parser(async_sess_t *dev_sess,
+    usb_hid_report_t **report)
+{
+	*report = (usb_hid_report_t *) malloc(sizeof(usb_hid_report_t));
+	if (*report == NULL)
+		return ENOMEM;
 	
 	int rc = usb_hid_report_init(*report);
@@ -71,16 +69,14 @@
 		usb_hid_free_report(*report);
 		*report = NULL;
-		//printf("usb_hid_report_init() failed.\n");
-		return rc;
-	}
-	
-	// get the report descriptor length from the device
+		return rc;
+	}
+	
+	/* Get the report descriptor length from the device */
 	size_t report_desc_size;
-	rc = usbhid_dev_get_report_descriptor_length(
-	    dev_phone, &report_desc_size);
-	if (rc != EOK) {
-		usb_hid_free_report(*report);
-		*report = NULL;
-		//printf("usbhid_dev_get_report_descriptor_length() failed.\n");
+	rc = usbhid_dev_get_report_descriptor_length(dev_sess,
+	    &report_desc_size);
+	if (rc != EOK) {
+		usb_hid_free_report(*report);
+		*report = NULL;
 		return rc;
 	}
@@ -89,9 +85,9 @@
 		usb_hid_free_report(*report);
 		*report = NULL;
-		//printf("usbhid_dev_get_report_descriptor_length() returned 0.\n");
-		return EINVAL;	// TODO: other error code?
-	}
-	
-	uint8_t *desc = (uint8_t *)malloc(report_desc_size);
+		// TODO: other error code?
+		return EINVAL;
+	}
+	
+	uint8_t *desc = (uint8_t *) malloc(report_desc_size);
 	if (desc == NULL) {
 		usb_hid_free_report(*report);
@@ -100,7 +96,7 @@
 	}
 	
-	// get the report descriptor from the device
+	/* Get the report descriptor from the device */
 	size_t actual_size;
-	rc = usbhid_dev_get_report_descriptor(dev_phone, desc, report_desc_size,
+	rc = usbhid_dev_get_report_descriptor(dev_sess, desc, report_desc_size,
 	    &actual_size);
 	if (rc != EOK) {
@@ -108,5 +104,4 @@
 		*report = NULL;
 		free(desc);
-		//printf("usbhid_dev_get_report_descriptor() failed.\n");
 		return rc;
 	}
@@ -116,10 +111,9 @@
 		*report = NULL;
 		free(desc);
-//		printf("usbhid_dev_get_report_descriptor() returned wrong size:"
-//		    " %zu, expected: %zu.\n", actual_size, report_desc_size);
-		return EINVAL;	// TODO: other error code?
-	}
-	
-	// initialize the report parser
+		// TODO: other error code?
+		return EINVAL;
+	}
+	
+	/* Initialize the report parser */
 	
 	rc = usb_hid_parse_report_descriptor(*report, desc, report_desc_size);
@@ -128,5 +122,4 @@
 	if (rc != EOK) {
 		free(desc);
-//		printf("usb_hid_parse_report_descriptor() failed.\n");
 		return rc;
 	}
@@ -140,17 +133,8 @@
 	assert(report != NULL);
 	
-//	printf("Calling usb_hid_parse_report() with size %zu and "
-//	    "buffer: \n", size);
-//	for (size_t i = 0; i < size; ++i) {
-//		printf(" %X ", buffer[i]);
-//	}
-//	printf("\n");
-	
 	uint8_t report_id;
 	int rc = usb_hid_parse_report(report, buffer, size, &report_id);
-	if (rc != EOK) {
-//		printf("Error parsing report: %s\n", str_error(rc));
+	if (rc != EOK)
 		return;
-	}
 	
 	usb_hid_report_path_t *path = usb_hid_report_path();
@@ -164,13 +148,9 @@
 
 	usb_hid_report_field_t *field = usb_hid_report_get_sibling(
-	    report, NULL, path, USB_HID_PATH_COMPARE_END 
-	    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
+	    report, NULL, path, USB_HID_PATH_COMPARE_END
+	    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
 	    USB_HID_REPORT_TYPE_INPUT);
 	
-//	printf("Field: %p\n", field);
-	
 	while (field != NULL) {
-//		printf("Field usage: %u, field value: %d\n", field->usage, 
-//		    field->value);
 		if (field->value != 0) {
 			const char *key_str = 
@@ -183,5 +163,4 @@
 		    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
 		    USB_HID_REPORT_TYPE_INPUT);
-//		printf("Next field: %p\n", field);
 	}
 	
@@ -194,9 +173,7 @@
 {
 #define _INDENT "      "
-
-       printf(NAME ": Print out what multimedia keys were pressed.\n\n");
-       printf("Usage: %s device\n", app_name);
-       printf(_INDENT "The device is a devman path to the device.\n");
-
+	printf(NAME ": Print out what multimedia keys were pressed.\n\n");
+	printf("Usage: %s device\n", app_name);
+	printf(_INDENT "The device is a devman path to the device.\n");
 #undef _OPTION
 #undef _INDENT
@@ -223,13 +200,13 @@
 	}
 	
-	rc = devman_device_connect(dev_handle, 0);
-	if (rc < 0) {
+	async_sess_t *sess = devman_device_connect(EXCHANGE_SERIALIZE,
+	    dev_handle, 0);
+	if (!sess) {
 		printf(NAME ": failed to connect to the device (handle %"
-		       PRIun "): %s.\n", dev_handle, str_error(rc));
-		return rc;
-	}
-	
-	dev_phone = rc;
-//	printf("Got phone to the device: %d\n", dev_phone);
+		       PRIun "): %s.\n", dev_handle, str_error(errno));
+		return errno;
+	}
+	
+	dev_sess = sess;
 	
 	char path[MAX_PATH_LENGTH];
@@ -243,5 +220,5 @@
 	
 	usb_hid_report_t *report = NULL;
-	rc = initialize_report_parser(dev_phone, &report);
+	rc = initialize_report_parser(dev_sess, &report);
 	if (rc != EOK) {
 		printf("Failed to initialize report parser: %s\n",
@@ -253,5 +230,5 @@
 	
 	size_t size;
-	rc = usbhid_dev_get_event_length(dev_phone, &size);
+	rc = usbhid_dev_get_event_length(dev_sess, &size);
 	if (rc != EOK) {
 		printf("Failed to get event length: %s.\n", str_error(rc));
@@ -259,25 +236,19 @@
 	}
 	
-//	printf("Event length: %zu\n", size);
 	uint8_t *event = (uint8_t *)malloc(size);
 	if (event == NULL) {
-		// hangup phone?
-		return ENOMEM;
-	}
-	
-//	printf("Event length: %zu\n", size);
+		// TODO: hangup phone?
+		return ENOMEM;
+	}
 	
 	size_t actual_size;
 	int event_nr;
 	
-	while (1) {
-		// get event from the driver
-//		printf("Getting event from the driver.\n");
-		
+	while (true) {
 		/** @todo Try blocking call. */
-		rc = usbhid_dev_get_event(dev_phone, event, size, &actual_size, 
+		rc = usbhid_dev_get_event(dev_sess, event, size, &actual_size, 
 		    &event_nr, 0);
 		if (rc != EOK) {
-			// hangup phone?
+			// TODO: hangup phone?
 			printf("Error in getting event from the HID driver:"
 			    "%s.\n", str_error(rc));
@@ -285,9 +256,4 @@
 		}
 		
-//		printf("Got buffer: %p, size: %zu, max size: %zu\n", event, 
-//		    actual_size, size);
-		
-//		printf("Event number: %d, my actual event: %d\n", event_nr, 
-//		    act_event);
 		if (event_nr > act_event) {
 			print_key(event, size, report);
@@ -301,5 +267,4 @@
 }
 
-
 /** @}
  */
