Changeset 2703331b in mainline


Ignore:
Timestamp:
2011-11-26T14:12:51Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b81410f
Parents:
3ddbd38
Message:

libusbdev: Nest usb_device_auto_polling_t instead of duplicating its members.

File:
1 edited

Legend:

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

    r3ddbd38 r2703331b  
    4646/** Data needed for polling. */
    4747typedef struct {
    48         int debug;
    49         size_t max_failures;
    50         useconds_t delay;
    51         bool auto_clear_halt;
    52         bool (*on_data)(usb_device_t *, uint8_t *, size_t, void *);
    53         void (*on_polling_end)(usb_device_t *, bool, void *);
    54         bool (*on_error)(usb_device_t *, int, void *);
     48        usb_device_auto_polling_t auto_polling;
    5549
    5650        usb_device_t *dev;
     
    7569            = &polling_data->dev->pipes[polling_data->pipe_index].pipe;
    7670       
    77         if (polling_data->debug > 0) {
     71        if (polling_data->auto_polling.debug > 0) {
    7872                usb_endpoint_mapping_t *mapping
    7973                    = &polling_data->dev->pipes[polling_data->pipe_index];
     
    9084
    9185        size_t failed_attempts = 0;
    92         while (failed_attempts <= polling_data->max_failures) {
     86        while (failed_attempts <= polling_data->auto_polling.max_failures) {
    9387                int rc;
    9488
     
    9791                    polling_data->request_size, &actual_size);
    9892
    99                 if (polling_data->debug > 1) {
     93                if (polling_data->auto_polling.debug > 1) {
    10094                        if (rc == EOK) {
    10195                                usb_log_debug(
     
    113107
    114108                /* If the pipe stalled, we can try to reset the stall. */
    115                 if ((rc == ESTALL) && (polling_data->auto_clear_halt)) {
     109                if ((rc == ESTALL) && (polling_data->auto_polling.auto_clear_halt)) {
    116110                        /*
    117111                         * We ignore error here as this is usually a futile
     
    124118
    125119                if (rc != EOK) {
    126                         if (polling_data->on_error != NULL) {
    127                                 bool cont = polling_data->on_error(
     120                        if (polling_data->auto_polling.on_error != NULL) {
     121                                bool cont = polling_data->auto_polling.on_error(
    128122                                    polling_data->dev, rc,
    129123                                    polling_data->custom_arg);
    130124                                if (!cont) {
    131125                                        failed_attempts
    132                                             = polling_data->max_failures;
     126                                            = polling_data->auto_polling.max_failures;
    133127                                }
    134128                        }
     
    138132
    139133                /* We have the data, execute the callback now. */
    140                 bool carry_on = polling_data->on_data(polling_data->dev,
    141                     polling_data->buffer, actual_size,
     134                const bool carry_on = polling_data->auto_polling.on_data(
     135                    polling_data->dev, polling_data->buffer, actual_size,
    142136                    polling_data->custom_arg);
    143137
     
    151145
    152146                /* Take a rest before next request. */
    153                 async_usleep(polling_data->delay);
    154         }
    155 
    156         if (polling_data->on_polling_end != NULL) {
    157                 polling_data->on_polling_end(polling_data->dev,
     147                async_usleep(polling_data->auto_polling.delay);
     148        }
     149
     150        if (polling_data->auto_polling.on_polling_end != NULL) {
     151                polling_data->auto_polling.on_polling_end(polling_data->dev,
    158152                    failed_attempts > 0, polling_data->custom_arg);
    159153        }
    160154
    161         if (polling_data->debug > 0) {
     155        if (polling_data->auto_polling.debug > 0) {
    162156                if (failed_attempts > 0) {
    163157                        usb_log_error(
     
    278272        polling_data->custom_arg = arg;
    279273
    280         polling_data->debug = polling->debug;
    281         polling_data->max_failures = polling->max_failures;
    282         if (polling->delay >= 0) {
    283                 polling_data->delay = (useconds_t) polling->delay;
    284         } else {
    285                 polling_data->delay = (useconds_t) dev->pipes[pipe_index]
    286                     .descriptor->poll_interval;
    287         }
    288         polling_data->auto_clear_halt = polling->auto_clear_halt;
    289 
    290         polling_data->on_data = polling->on_data;
    291         polling_data->on_polling_end = polling->on_polling_end;
    292         polling_data->on_error = polling->on_error;
     274        /* Copy provided settings. */
     275        polling_data->auto_polling = *polling;
     276
     277        /* Negative value means use descriptor provided value. */
     278        if (polling->delay < 0) {
     279                polling_data->auto_polling.delay =
     280                    (int) dev->pipes[pipe_index].descriptor->poll_interval;
     281        }
    293282
    294283        fid_t fibril = fibril_create(polling_fibril, polling_data);
Note: See TracChangeset for help on using the changeset viewer.