source: mainline/uspace/lib/usbhost/src/usb_transfer_batch.c@ 296d22fc

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 296d22fc was 296d22fc, checked in by Ondřej Hlavatý <aearsis@…>, 7 years ago

usbhub: revert the runtime binding of bus methods

It was just a dead end.

  • Property mode set to 100644
File size: 3.6 KB
RevLine 
[81dce9f]1/*
2 * Copyright (c) 2011 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
[160b75e]28/** @addtogroup libusbhost
[81dce9f]29 * @{
30 */
31/** @file
[c92c13f]32 * USB transfer transaction structures (implementation).
[81dce9f]33 */
34
[8d2e251]35#include <assert.h>
36#include <errno.h>
[64fea02]37#include <stdlib.h>
[2b61945]38#include <str_error.h>
[64fea02]39#include <usb/debug.h>
40
41#include "endpoint.h"
42#include "bus.h"
[5fd9c30]43
[64fea02]44#include "usb_transfer_batch.h"
[5fd9c30]45
[1102eca]46/**
47 * Create a batch on a given endpoint.
48 *
49 * If the bus callback is not defined, it just creates a default batch.
[549ff23]50 */
[5fd9c30]51usb_transfer_batch_t *usb_transfer_batch_create(endpoint_t *ep)
[81dce9f]52{
[5fd9c30]53 assert(ep);
54
[6832245]55 bus_t *bus = endpoint_get_bus(ep);
[5fd9c30]56
[296d22fc]57 if (!bus->ops->batch_create) {
[6832245]58 usb_transfer_batch_t *batch = calloc(1, sizeof(usb_transfer_batch_t));
[1102eca]59 if (!batch)
60 return NULL;
[6832245]61 usb_transfer_batch_init(batch, ep);
62 return batch;
63 }
64
[296d22fc]65 return bus->ops->batch_create(ep);
[2cc6e97]66}
[a76b01b4]67
[1102eca]68/**
69 * Initialize given batch structure.
[5fd9c30]70 */
71void usb_transfer_batch_init(usb_transfer_batch_t *batch, endpoint_t *ep)
72{
[6832245]73 assert(ep);
[1102eca]74 /* Batch reference */
[6832245]75 endpoint_add_ref(ep);
[5fd9c30]76 batch->ep = ep;
77}
78
[1102eca]79/**
80 * Destroy the batch. If there's no bus callback, just free it.
[549ff23]81 */
[5fd9c30]82void usb_transfer_batch_destroy(usb_transfer_batch_t *batch)
[549ff23]83{
[5fd9c30]84 assert(batch);
85 assert(batch->ep);
[549ff23]86
[6832245]87 bus_t *bus = endpoint_get_bus(batch->ep);
[296d22fc]88 endpoint_t *ep = batch->ep;
[6832245]89
[296d22fc]90 if (bus->ops) {
[a1732929]91 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " destroying.",
[2b61945]92 batch, USB_TRANSFER_BATCH_ARGS(*batch));
[296d22fc]93 bus->ops->batch_destroy(batch);
[2b61945]94 }
95 else {
[a1732929]96 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " disposing.",
[2b61945]97 batch, USB_TRANSFER_BATCH_ARGS(*batch));
[5fd9c30]98 free(batch);
[2b61945]99 }
[296d22fc]100
101 /* Batch reference */
102 endpoint_del_ref(ep);
[5fd9c30]103}
104
[1102eca]105/**
106 * Finish a transfer batch: call handler, destroy batch, release endpoint.
[5fd9c30]107 *
108 * Call only after the batch have been scheduled && completed!
109 */
110void usb_transfer_batch_finish(usb_transfer_batch_t *batch)
111{
[17873ac7]112 assert(batch);
113 assert(batch->ep);
114
[a1732929]115 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " finishing.",
[17873ac7]116 batch, USB_TRANSFER_BATCH_ARGS(*batch));
117
118 if (batch->on_complete) {
[db51a6a6]119 const int err = batch->on_complete(batch->on_complete_data, batch->error, batch->transferred_size);
[17873ac7]120 if (err)
121 usb_log_warning("batch %p failed to complete: %s",
122 batch, str_error(err));
123 }
[5fd9c30]124
125 usb_transfer_batch_destroy(batch);
126}
127
[81dce9f]128/**
129 * @}
130 */
Note: See TracBrowser for help on using the repository browser.