Changeset 9dbfd288 in mainline for uspace/lib/usbdev/src/devpoll.c


Ignore:
Timestamp:
2011-11-28T18:01:48Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7711296
Parents:
69b9740
Message:

libusbdev: Shorten variable name to increase readability.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/src/devpoll.c

    r69b9740 r9dbfd288  
    6363static int polling_fibril(void *arg)
    6464{
    65         polling_data_t *polling_data = (polling_data_t *) arg;
    66         assert(polling_data);
     65        assert(arg);
     66        const polling_data_t *data = arg;
     67        /* Helper to reduce typing. */
     68        const usb_device_auto_polling_t *params = &data->auto_polling;
    6769
    6870        usb_pipe_t *pipe
    69             = &polling_data->dev->pipes[polling_data->pipe_index].pipe;
    70        
    71         if (polling_data->auto_polling.debug > 0) {
     71            = &data->dev->pipes[data->pipe_index].pipe;
     72
     73        if (params->debug > 0) {
    7274                const usb_endpoint_mapping_t *mapping
    73                     = &polling_data->dev->pipes[polling_data->pipe_index];
     75                    = &data->dev->pipes[data->pipe_index];
    7476                usb_log_debug("Poll%p: started polling of `%s' - " \
    7577                    "interface %d (%s,%d,%d), %zuB/%zu.\n",
    76                     polling_data,
    77                     polling_data->dev->ddf_dev->name,
     78                    data, data->dev->ddf_dev->name,
    7879                    (int) mapping->interface->interface_number,
    7980                    usb_str_class(mapping->interface->interface_class),
    8081                    (int) mapping->interface->interface_subclass,
    8182                    (int) mapping->interface->interface_protocol,
    82                     polling_data->request_size, pipe->max_packet_size);
     83                    data->request_size, pipe->max_packet_size);
    8384        }
    8485
    8586        usb_pipe_start_long_transfer(pipe);
    8687        size_t failed_attempts = 0;
    87         while (failed_attempts <= polling_data->auto_polling.max_failures) {
     88        while (failed_attempts <= params->max_failures) {
    8889                size_t actual_size;
    89                 const int rc = usb_pipe_read(pipe, polling_data->buffer,
    90                     polling_data->request_size, &actual_size);
    91 
    92                 if (polling_data->auto_polling.debug > 1) {
     90                const int rc = usb_pipe_read(pipe, data->buffer,
     91                    data->request_size, &actual_size);
     92
     93                if (params->debug > 1) {
    9394                        if (rc == EOK) {
    9495                                usb_log_debug(
    9596                                    "Poll%p: received: '%s' (%zuB).\n",
    96                                     polling_data,
    97                                     usb_debug_str_buffer(polling_data->buffer,
     97                                    data,
     98                                    usb_debug_str_buffer(data->buffer,
    9899                                        actual_size, 16),
    99100                                    actual_size);
     
    101102                                usb_log_debug(
    102103                                    "Poll%p: polling failed: %s.\n",
    103                                     polling_data, str_error(rc));
     104                                    data, str_error(rc));
    104105                        }
    105106                }
    106107
    107108                /* If the pipe stalled, we can try to reset the stall. */
    108                 if ((rc == ESTALL) && (polling_data->auto_polling.auto_clear_halt)) {
     109                if ((rc == ESTALL) && (params->auto_clear_halt)) {
    109110                        /*
    110111                         * We ignore error here as this is usually a futile
     
    112113                         */
    113114                        usb_request_clear_endpoint_halt(
    114                             &polling_data->dev->ctrl_pipe, pipe->endpoint_no);
     115                            &data->dev->ctrl_pipe, pipe->endpoint_no);
    115116                }
    116117
    117118                if (rc != EOK) {
    118                         if (polling_data->auto_polling.on_error != NULL) {
    119                                 bool cont = polling_data->auto_polling.on_error(
    120                                     polling_data->dev, rc,
    121                                     polling_data->custom_arg);
    122                                 if (!cont) {
    123                                         failed_attempts
    124                                             = polling_data->auto_polling.max_failures;
    125                                 }
     119                        ++failed_attempts;
     120                        const bool cont = (params->on_error == NULL) ? true :
     121                            params->on_error(data->dev, rc, data->custom_arg);
     122                        if (!cont) {
     123                                failed_attempts = params->max_failures;
    126124                        }
    127                         failed_attempts++;
    128125                        continue;
    129126                }
    130127
    131128                /* We have the data, execute the callback now. */
    132                 const bool carry_on = polling_data->auto_polling.on_data(
    133                     polling_data->dev, polling_data->buffer, actual_size,
    134                     polling_data->custom_arg);
     129                assert(params->on_data);
     130                const bool carry_on = params->on_data(
     131                    data->dev, data->buffer, actual_size, data->custom_arg);
    135132
    136133                if (!carry_on) {
     134                        /* This is user requested abort, erases failures. */
    137135                        failed_attempts = 0;
    138136                        break;
     
    143141
    144142                /* Take a rest before next request. */
    145                 async_usleep(polling_data->auto_polling.delay);
     143                async_usleep(params->delay);
    146144        }
    147145
    148146        usb_pipe_end_long_transfer(pipe);
    149         if (polling_data->auto_polling.on_polling_end != NULL) {
    150                 polling_data->auto_polling.on_polling_end(polling_data->dev,
    151                     failed_attempts > 0, polling_data->custom_arg);
    152         }
    153 
    154         if (polling_data->auto_polling.debug > 0) {
    155                 if (failed_attempts > 0) {
    156                         usb_log_error(
    157                             "Polling of device `%s' terminated: %s.\n",
    158                             polling_data->dev->ddf_dev->name,
    159                             "recurring failures");
     147
     148        const bool failed = failed_attempts > 0;
     149
     150        if (params->on_polling_end != NULL) {
     151                params->on_polling_end(data->dev, failed, data->custom_arg);
     152        }
     153
     154        if (params->debug > 0) {
     155                if (failed) {
     156                        usb_log_error("Polling of device `%s' terminated: "
     157                            "recurring failures.\n", data->dev->ddf_dev->name);
    160158                } else {
    161                         usb_log_debug(
    162                             "Polling of device `%s' terminated by user.\n",
    163                             polling_data->dev->ddf_dev->name
    164                         );
     159                        usb_log_debug("Polling of device `%s' terminated: "
     160                            "driver request.\n", data->dev->ddf_dev->name);
    165161                }
    166162        }
    167163
    168164        /* Free the allocated memory. */
    169         free(polling_data->buffer);
    170         free(polling_data);
     165        free(data->buffer);
     166        free(data);
    171167
    172168        return EOK;
Note: See TracChangeset for help on using the changeset viewer.