Changeset 79ae36dd in mainline for uspace/app/mkbd/main.c


Ignore:
Timestamp:
2011-06-08T19:01:55Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0eff68e
Parents:
764d71e
Message:

new async framework with integrated exchange tracking

  • strict isolation between low-level IPC and high-level async framework with integrated exchange tracking
    • each IPC connection is represented by an async_sess_t structure
    • each IPC exchange is represented by an async_exch_t structure
    • exchange management is either based on atomic messages (EXCHANGE_ATOMIC), locking (EXCHANGE_SERIALIZE) or connection cloning (EXCHANGE_CLONE)
  • async_obsolete: temporary compatibility layer to keep old async clients working (several pieces of code are currently broken, but only non-essential functionality)
  • IPC_M_PHONE_HANGUP is now method no. 0 (for elegant boolean evaluation)
  • IPC_M_DEBUG_ALL has been renamed to IPC_M_DEBUG
  • IPC_M_PING has been removed (VFS protocol now has VFS_IN_PING)
  • console routines in libc have been rewritten for better abstraction
  • additional use for libc-private header files (FILE structure opaque to the client)
  • various cstyle changes (typos, indentation, missing externs in header files, improved comments, etc.)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/mkbd/main.c

    r764d71e r79ae36dd  
    4545#include <devmap.h>
    4646#include <usb/dev/hub.h>
    47 //#include <usb/host.h>
    48 //#include <usb/driver.h>
    4947#include <usb/hid/iface.h>
    5048#include <usb/dev/pipes.h>
     
    5856#define NAME "mkbd"
    5957
    60 static int dev_phone = -1;
    61 
    62 static int initialize_report_parser(int dev_phone, usb_hid_report_t **report)
    63 {
    64         *report = (usb_hid_report_t *)malloc(sizeof(usb_hid_report_t));
    65         if (*report == NULL) {
    66                 return ENOMEM;
    67         }
     58static async_sess_t *dev_sess = NULL;
     59
     60static int initialize_report_parser(async_sess_t *dev_sess,
     61    usb_hid_report_t **report)
     62{
     63        *report = (usb_hid_report_t *) malloc(sizeof(usb_hid_report_t));
     64        if (*report == NULL)
     65                return ENOMEM;
    6866       
    6967        int rc = usb_hid_report_init(*report);
     
    7169                usb_hid_free_report(*report);
    7270                *report = NULL;
    73                 //printf("usb_hid_report_init() failed.\n");
    74                 return rc;
    75         }
    76        
    77         // get the report descriptor length from the device
     71                return rc;
     72        }
     73       
     74        /* Get the report descriptor length from the device */
    7875        size_t report_desc_size;
    79         rc = usbhid_dev_get_report_descriptor_length(
    80             dev_phone, &report_desc_size);
    81         if (rc != EOK) {
    82                 usb_hid_free_report(*report);
    83                 *report = NULL;
    84                 //printf("usbhid_dev_get_report_descriptor_length() failed.\n");
     76        rc = usbhid_dev_get_report_descriptor_length(dev_sess,
     77            &report_desc_size);
     78        if (rc != EOK) {
     79                usb_hid_free_report(*report);
     80                *report = NULL;
    8581                return rc;
    8682        }
     
    8985                usb_hid_free_report(*report);
    9086                *report = NULL;
    91                 //printf("usbhid_dev_get_report_descriptor_length() returned 0.\n");
    92                 return EINVAL;  // TODO: other error code?
    93         }
    94        
    95         uint8_t *desc = (uint8_t *)malloc(report_desc_size);
     87                // TODO: other error code?
     88                return EINVAL;
     89        }
     90       
     91        uint8_t *desc = (uint8_t *) malloc(report_desc_size);
    9692        if (desc == NULL) {
    9793                usb_hid_free_report(*report);
     
    10096        }
    10197       
    102         // get the report descriptor from the device
     98        /* Get the report descriptor from the device */
    10399        size_t actual_size;
    104         rc = usbhid_dev_get_report_descriptor(dev_phone, desc, report_desc_size,
     100        rc = usbhid_dev_get_report_descriptor(dev_sess, desc, report_desc_size,
    105101            &actual_size);
    106102        if (rc != EOK) {
     
    108104                *report = NULL;
    109105                free(desc);
    110                 //printf("usbhid_dev_get_report_descriptor() failed.\n");
    111106                return rc;
    112107        }
     
    116111                *report = NULL;
    117112                free(desc);
    118 //              printf("usbhid_dev_get_report_descriptor() returned wrong size:"
    119 //                  " %zu, expected: %zu.\n", actual_size, report_desc_size);
    120                 return EINVAL;  // TODO: other error code?
    121         }
    122        
    123         // initialize the report parser
     113                // TODO: other error code?
     114                return EINVAL;
     115        }
     116       
     117        /* Initialize the report parser */
    124118       
    125119        rc = usb_hid_parse_report_descriptor(*report, desc, report_desc_size);
     
    128122        if (rc != EOK) {
    129123                free(desc);
    130 //              printf("usb_hid_parse_report_descriptor() failed.\n");
    131124                return rc;
    132125        }
     
    140133        assert(report != NULL);
    141134       
    142 //      printf("Calling usb_hid_parse_report() with size %zu and "
    143 //          "buffer: \n", size);
    144 //      for (size_t i = 0; i < size; ++i) {
    145 //              printf(" %X ", buffer[i]);
    146 //      }
    147 //      printf("\n");
    148        
    149135        uint8_t report_id;
    150136        int rc = usb_hid_parse_report(report, buffer, size, &report_id);
    151         if (rc != EOK) {
    152 //              printf("Error parsing report: %s\n", str_error(rc));
     137        if (rc != EOK)
    153138                return;
    154         }
    155139       
    156140        usb_hid_report_path_t *path = usb_hid_report_path();
     
    164148
    165149        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    166             report, NULL, path, USB_HID_PATH_COMPARE_END 
    167             | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
     150            report, NULL, path, USB_HID_PATH_COMPARE_END
     151            | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    168152            USB_HID_REPORT_TYPE_INPUT);
    169153       
    170 //      printf("Field: %p\n", field);
    171        
    172154        while (field != NULL) {
    173 //              printf("Field usage: %u, field value: %d\n", field->usage,
    174 //                  field->value);
    175155                if (field->value != 0) {
    176156                        const char *key_str =
     
    183163                    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    184164                    USB_HID_REPORT_TYPE_INPUT);
    185 //              printf("Next field: %p\n", field);
    186165        }
    187166       
     
    194173{
    195174#define _INDENT "      "
    196 
    197        printf(NAME ": Print out what multimedia keys were pressed.\n\n");
    198        printf("Usage: %s device\n", app_name);
    199        printf(_INDENT "The device is a devman path to the device.\n");
    200 
     175        printf(NAME ": Print out what multimedia keys were pressed.\n\n");
     176        printf("Usage: %s device\n", app_name);
     177        printf(_INDENT "The device is a devman path to the device.\n");
    201178#undef _OPTION
    202179#undef _INDENT
     
    223200        }
    224201       
    225         rc = devman_device_connect(dev_handle, 0);
    226         if (rc < 0) {
     202        async_sess_t *sess = devman_device_connect(EXCHANGE_SERIALIZE,
     203            dev_handle, 0);
     204        if (!sess) {
    227205                printf(NAME ": failed to connect to the device (handle %"
    228                        PRIun "): %s.\n", dev_handle, str_error(rc));
    229                 return rc;
    230         }
    231        
    232         dev_phone = rc;
    233 //      printf("Got phone to the device: %d\n", dev_phone);
     206                       PRIun "): %s.\n", dev_handle, str_error(errno));
     207                return errno;
     208        }
     209       
     210        dev_sess = sess;
    234211       
    235212        char path[MAX_PATH_LENGTH];
     
    243220       
    244221        usb_hid_report_t *report = NULL;
    245         rc = initialize_report_parser(dev_phone, &report);
     222        rc = initialize_report_parser(dev_sess, &report);
    246223        if (rc != EOK) {
    247224                printf("Failed to initialize report parser: %s\n",
     
    253230       
    254231        size_t size;
    255         rc = usbhid_dev_get_event_length(dev_phone, &size);
     232        rc = usbhid_dev_get_event_length(dev_sess, &size);
    256233        if (rc != EOK) {
    257234                printf("Failed to get event length: %s.\n", str_error(rc));
     
    259236        }
    260237       
    261 //      printf("Event length: %zu\n", size);
    262238        uint8_t *event = (uint8_t *)malloc(size);
    263239        if (event == NULL) {
    264                 // hangup phone?
    265                 return ENOMEM;
    266         }
    267        
    268 //      printf("Event length: %zu\n", size);
     240                // TODO: hangup phone?
     241                return ENOMEM;
     242        }
    269243       
    270244        size_t actual_size;
    271245        int event_nr;
    272246       
    273         while (1) {
    274                 // get event from the driver
    275 //              printf("Getting event from the driver.\n");
    276                
     247        while (true) {
    277248                /** @todo Try blocking call. */
    278                 rc = usbhid_dev_get_event(dev_phone, event, size, &actual_size,
     249                rc = usbhid_dev_get_event(dev_sess, event, size, &actual_size,
    279250                    &event_nr, 0);
    280251                if (rc != EOK) {
    281                         // hangup phone?
     252                        // TODO: hangup phone?
    282253                        printf("Error in getting event from the HID driver:"
    283254                            "%s.\n", str_error(rc));
     
    285256                }
    286257               
    287 //              printf("Got buffer: %p, size: %zu, max size: %zu\n", event,
    288 //                  actual_size, size);
    289                
    290 //              printf("Event number: %d, my actual event: %d\n", event_nr,
    291 //                  act_event);
    292258                if (event_nr > act_event) {
    293259                        print_key(event, size, report);
     
    301267}
    302268
    303 
    304269/** @}
    305270 */
Note: See TracChangeset for help on using the changeset viewer.