libusb10.h (195560) | libusb10.h (195957) |
---|---|
1/* $FreeBSD: head/lib/libusb/libusb10.h 195560 2009-07-10 14:15:53Z thompsa $ */ | 1/* $FreeBSD: head/lib/libusb/libusb10.h 195957 2009-07-30 00:11:41Z alfred $ */ |
2/*- 3 * Copyright (c) 2009 Sylvestre Gallon. 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 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. --- 10 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#ifndef __LIBUSB10_H__ | 2/*- 3 * Copyright (c) 2009 Sylvestre Gallon. 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 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. --- 10 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#ifndef __LIBUSB10_H__ |
28#define __LIBUSB10_H__ | 28#define __LIBUSB10_H__ |
29 | 29 |
30/* 31 * The two following macros were taken from the original LibUSB v1.0 32 * for sake of compatibility: 33 */ | 30#include <sys/queue.h> |
34 | 31 |
35static int get_next_timeout(libusb_context *ctx, struct timeval *tv, struct timeval *out); 36static int handle_timeouts(struct libusb_context *ctx); 37static int handle_events(struct libusb_context *ctx, struct timeval *tv); 38extern struct libusb_context *usbi_default_context; 39extern pthread_mutex_t libusb20_lock; | 32#define GET_CONTEXT(ctx) (((ctx) == NULL) ? usbi_default_context : (ctx)) 33#define UNEXPORTED __attribute__((__visibility__("hidden"))) 34#define CTX_LOCK(ctx) pthread_mutex_lock(&(ctx)->ctx_lock) 35#define CTX_TRYLOCK(ctx) pthread_mutex_trylock(&(ctx)->ctx_lock) 36#define CTX_UNLOCK(ctx) pthread_mutex_unlock(&(ctx)->ctx_lock) |
40 | 37 |
41/* if ctx is NULL use default context*/ | 38#define DPRINTF(ctx, dbg, format, args...) do { \ 39 if ((ctx)->debug == dbg) { \ 40 switch (dbg) { \ 41 case LIBUSB_DEBUG_FUNCTION: \ 42 printf("LIBUSB_FUNCTION: " \ 43 format "\n", ## args); \ 44 break; \ 45 case LIBUSB_DEBUG_TRANSFER: \ 46 printf("LIBUSB_TRANSFER: " \ 47 format "\n", ## args); \ 48 break; \ 49 default: \ 50 break; \ 51 } \ 52 } \ 53} while(0) |
42 | 54 |
43#define GET_CONTEXT(ctx) \ 44 if (ctx == NULL) ctx = usbi_default_context; | 55/* internal structures */ |
45 | 56 |
46#define MAX(a,b) (((a)>(b))?(a):(b)) 47#define USB_TIMED_OUT (1<<0) 48#define UNEXPORTED __attribute__((__visibility__("hidden"))) | 57struct libusb_super_pollfd { 58 TAILQ_ENTRY(libusb_super_pollfd) entry; 59 struct libusb20_device *pdev; 60 struct libusb_pollfd pollfd; 61}; |
49 | 62 |
50#define DPRINTF(ctx, dbg, format, args...) \ 51if (ctx->debug == dbg) { \ 52 printf("LIBUSB_%s : ", (ctx->debug == LIBUSB_DEBUG_FUNCTION) ? "FUNCTION" : "TRANSFER"); \ 53 switch(ctx->debug) { \ 54 case LIBUSB_DEBUG_FUNCTION: \ 55 printf(format, ## args);\ 56 break ; \ 57 case LIBUSB_DEBUG_TRANSFER: \ 58 printf(format, ## args);\ 59 break ; \ 60 } \ 61 printf("\n"); \ 62} | 63struct libusb_super_transfer { 64 TAILQ_ENTRY(libusb_super_transfer) entry; 65 uint8_t *curr_data; 66 uint32_t rem_len; 67 uint32_t last_len; 68 uint8_t flags; 69}; |
63 | 70 |
64UNEXPORTED int usb_add_pollfd(libusb_context *ctx, int fd, short events); 65UNEXPORTED void usb_remove_pollfd(libusb_context *ctx, int fd); 66UNEXPORTED void usb_handle_transfer_completion(struct usb_transfer *uxfer, 67 enum libusb_transfer_status status); 68UNEXPORTED void usb_handle_disconnect(struct libusb_device_handle *devh); | 71struct libusb_context { 72 int debug; 73 int debug_fixed; 74 int ctrl_pipe[2]; 75 int tr_done_ref; 76 int tr_done_gen; |
69 | 77 |
70#endif /*__LIBUSB10_H__*/ | 78 pthread_mutex_t ctx_lock; 79 pthread_cond_t ctx_cond; 80 pthread_t ctx_handler; 81#define NO_THREAD ((pthread_t)-1) 82 83 TAILQ_HEAD(, libusb_super_pollfd) pollfds; 84 TAILQ_HEAD(, libusb_super_transfer) tr_done; 85 86 struct libusb_super_pollfd ctx_poll; 87 88 libusb_pollfd_added_cb fd_added_cb; 89 libusb_pollfd_removed_cb fd_removed_cb; 90 void *fd_cb_user_data; 91}; 92 93struct libusb_device { 94 int refcnt; 95 96 uint32_t claimed_interfaces; 97 98 struct libusb_super_pollfd dev_poll; 99 100 struct libusb_context *ctx; 101 102 TAILQ_HEAD(, libusb_super_transfer) tr_head; 103 104 struct libusb20_device *os_priv; 105}; 106 107extern struct libusb_context *usbi_default_context; 108 109void libusb10_add_pollfd(libusb_context *ctx, struct libusb_super_pollfd *pollfd, struct libusb20_device *pdev, int fd, short events); 110void libusb10_remove_pollfd(libusb_context *ctx, struct libusb_super_pollfd *pollfd); 111void libusb10_cancel_all_transfer(libusb_device *dev); 112 113#endif /* __LIBUSB10_H__ */ |