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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fa4b12d5 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
Line 
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 */
28/** @addtogroup libusbhost
29 * @{
30 */
31/** @file
32 * USB transfer transaction structures (implementation).
33 */
34
35#include <assert.h>
36#include <errno.h>
37#include <stdlib.h>
38#include <str_error.h>
39#include <usb/debug.h>
40
41#include "endpoint.h"
42#include "bus.h"
43
44#include "usb_transfer_batch.h"
45
46/**
47 * Create a batch on a given endpoint.
48 *
49 * If the bus callback is not defined, it just creates a default batch.
50 */
51usb_transfer_batch_t *usb_transfer_batch_create(endpoint_t *ep)
52{
53 assert(ep);
54
55 bus_t *bus = endpoint_get_bus(ep);
56
57 if (!bus->ops->batch_create) {
58 usb_transfer_batch_t *batch = calloc(1, sizeof(usb_transfer_batch_t));
59 if (!batch)
60 return NULL;
61 usb_transfer_batch_init(batch, ep);
62 return batch;
63 }
64
65 return bus->ops->batch_create(ep);
66}
67
68/**
69 * Initialize given batch structure.
70 */
71void usb_transfer_batch_init(usb_transfer_batch_t *batch, endpoint_t *ep)
72{
73 assert(ep);
74 /* Batch reference */
75 endpoint_add_ref(ep);
76 batch->ep = ep;
77}
78
79/**
80 * Destroy the batch. If there's no bus callback, just free it.
81 */
82void usb_transfer_batch_destroy(usb_transfer_batch_t *batch)
83{
84 assert(batch);
85 assert(batch->ep);
86
87 bus_t *bus = endpoint_get_bus(batch->ep);
88 endpoint_t *ep = batch->ep;
89
90 if (bus->ops) {
91 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " destroying.",
92 batch, USB_TRANSFER_BATCH_ARGS(*batch));
93 bus->ops->batch_destroy(batch);
94 }
95 else {
96 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " disposing.",
97 batch, USB_TRANSFER_BATCH_ARGS(*batch));
98 free(batch);
99 }
100
101 /* Batch reference */
102 endpoint_del_ref(ep);
103}
104
105/**
106 * Finish a transfer batch: call handler, destroy batch, release endpoint.
107 *
108 * Call only after the batch have been scheduled && completed!
109 */
110void usb_transfer_batch_finish(usb_transfer_batch_t *batch)
111{
112 assert(batch);
113 assert(batch->ep);
114
115 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " finishing.",
116 batch, USB_TRANSFER_BATCH_ARGS(*batch));
117
118 if (batch->on_complete) {
119 const int err = batch->on_complete(batch->on_complete_data, batch->error, batch->transferred_size);
120 if (err)
121 usb_log_warning("batch %p failed to complete: %s",
122 batch, str_error(err));
123 }
124
125 usb_transfer_batch_destroy(batch);
126}
127
128/**
129 * @}
130 */
Note: See TracBrowser for help on using the repository browser.