1.0 API style/naming points to reconsider
=========================================
-devh in general
config struct/function naming
typedef _cb or _cb_fn or _cb_t?
typedef as-is or pointers? libusb_dev_t rather than libusb_dev *?
};
static int state = 0;
-static struct libusb_dev_handle *devh = NULL;
+static struct libusb_device_handle *devh = NULL;
static unsigned char imgbuf[0x1b340];
static unsigned char irqbuf[INTR_LENGTH];
static struct libusb_transfer *img_transfer = NULL;
return dev->config;
}
-API_EXPORTED struct libusb_dev_handle *libusb_open(struct libusb_device *dev)
+API_EXPORTED struct libusb_device_handle *libusb_open(struct libusb_device *dev)
{
- struct libusb_dev_handle *devh;
+ struct libusb_device_handle *devh;
int fd;
usbi_dbg("open %04x:%04x", dev->desc.idVendor, dev->desc.idProduct);
* combination. has limitations and is hence not intended for use in "real
* applications": if multiple devices have the same VID+PID it'll only
* give you the first one, etc. */
-API_EXPORTED struct libusb_dev_handle *libusb_open_device_with_vid_pid(
+API_EXPORTED struct libusb_device_handle *libusb_open_device_with_vid_pid(
uint16_t vendor_id, uint16_t product_id)
{
struct libusb_device **devs;
struct libusb_device *found = NULL;
struct libusb_device *dev;
- struct libusb_dev_handle *devh;
+ struct libusb_device_handle *devh;
size_t i = 0;
if (libusb_get_device_list(&devs) < 0)
return devh;
}
-static void do_close(struct libusb_dev_handle *devh)
+static void do_close(struct libusb_device_handle *devh)
{
usbi_remove_pollfd(devh->fd);
close(devh->fd);
libusb_device_unref(devh->dev);
}
-API_EXPORTED void libusb_close(struct libusb_dev_handle *devh)
+API_EXPORTED void libusb_close(struct libusb_device_handle *devh)
{
if (!devh)
return;
}
API_EXPORTED struct libusb_device *libusb_devh_get_dev(
- struct libusb_dev_handle *devh)
+ struct libusb_device_handle *devh)
{
return devh->dev;
}
-API_EXPORTED int libusb_claim_interface(struct libusb_dev_handle *dev,
+API_EXPORTED int libusb_claim_interface(struct libusb_device_handle *dev,
int iface)
{
int r;
return r;
}
-API_EXPORTED int libusb_release_interface(struct libusb_dev_handle *dev,
+API_EXPORTED int libusb_release_interface(struct libusb_device_handle *dev,
int iface)
{
int r;
API_EXPORTED void libusb_exit(void)
{
- struct libusb_dev_handle *devh;
+ struct libusb_device_handle *devh;
usbi_dbg("");
if (!list_empty(&open_devs)) {
usbi_dbg("naughty app left some devices open!\n");
API_EXPORTED size_t libusb_get_pollfds(struct libusb_pollfd **pollfds)
{
- struct libusb_dev_handle *devh;
+ struct libusb_device_handle *devh;
struct libusb_pollfd *ret;
size_t cnt = 0;
size_t i = 0;
return submit_transfer(itransfer);
}
-API_EXPORTED int libusb_cancel_transfer(struct libusb_dev_handle *devh,
+API_EXPORTED int libusb_cancel_transfer(struct libusb_device_handle *devh,
struct libusb_transfer *transfer)
{
struct usbi_transfer *itransfer = TRANSFER_TO_PRIV(transfer);
return r;
}
-API_EXPORTED int libusb_cancel_transfer_sync(struct libusb_dev_handle *devh,
+API_EXPORTED int libusb_cancel_transfer_sync(struct libusb_device_handle *devh,
struct libusb_transfer *transfer)
{
struct usbi_transfer *itransfer = TRANSFER_TO_PRIV(transfer);
transfer->callback(transfer);
}
-static void handle_transfer_cancellation(struct libusb_dev_handle *devh,
+static void handle_transfer_cancellation(struct libusb_device_handle *devh,
struct usbi_transfer *transfer)
{
/* if the URB is being cancelled synchronously, raise cancellation
handle_transfer_completion(transfer, LIBUSB_TRANSFER_CANCELLED);
}
-static int reap_for_devh(struct libusb_dev_handle *devh)
+static int reap_for_devh(struct libusb_device_handle *devh)
{
int r;
struct usb_urb *urb;
static int poll_io(struct timeval *tv)
{
- struct libusb_dev_handle *devh;
+ struct libusb_device_handle *devh;
int r;
int maxfd = 0;
fd_set writefds;
struct libusb_device;
typedef struct libusb_device libusb_device;
-struct libusb_dev_handle;
-typedef struct libusb_dev_handle libusb_dev_handle;
+struct libusb_device_handle;
+typedef struct libusb_device_handle libusb_device_handle;
enum libusb_transfer_status {
LIBUSB_TRANSFER_SILENT_COMPLETION = 0,
typedef void (*libusb_transfer_cb_fn)(struct libusb_transfer *transfer);
struct libusb_transfer {
- libusb_dev_handle *dev_handle;
+ libusb_device_handle *dev_handle;
unsigned char endpoint;
unsigned char endpoint_type;
unsigned int timeout;
libusb_device *libusb_device_ref(libusb_device *dev);
void libusb_device_unref(libusb_device *dev);
-libusb_dev_handle *libusb_open(libusb_device *dev);
-void libusb_close(libusb_dev_handle *devh);
-libusb_device *libusb_devh_get_device(libusb_dev_handle *devh);
-int libusb_claim_interface(libusb_dev_handle *dev, int iface);
-int libusb_release_interface(libusb_dev_handle *dev, int iface);
+libusb_device_handle *libusb_open(libusb_device *dev);
+void libusb_close(libusb_device_handle *devh);
+libusb_device *libusb_devh_get_device(libusb_device_handle *devh);
+int libusb_claim_interface(libusb_device_handle *dev, int iface);
+int libusb_release_interface(libusb_device_handle *dev, int iface);
-libusb_dev_handle *libusb_open_device_with_vid_pid(uint16_t vendor_id,
+libusb_device_handle *libusb_open_device_with_vid_pid(uint16_t vendor_id,
uint16_t product_id);
/* async I/O */
struct libusb_transfer *libusb_alloc_transfer(void);
int libusb_submit_transfer(struct libusb_transfer *transfer);
-int libusb_cancel_transfer(libusb_dev_handle *devh,
+int libusb_cancel_transfer(libusb_device_handle *devh,
struct libusb_transfer *transfer);
-int libusb_cancel_transfer_sync(libusb_dev_handle *devh,
+int libusb_cancel_transfer_sync(libusb_device_handle *devh,
struct libusb_transfer *transfer);
void libusb_free_transfer(struct libusb_transfer *transfer);
static inline void libusb_fill_control_transfer(
- struct libusb_transfer *transfer, libusb_dev_handle *dev_handle,
+ struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
void *user_data, unsigned int timeout)
{
}
static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer,
- libusb_dev_handle *dev_handle, unsigned char endpoint,
+ libusb_device_handle *dev_handle, unsigned char endpoint,
unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
void *user_data, unsigned int timeout)
{
}
static inline void libusb_fill_interrupt_transfer(
- struct libusb_transfer *transfer, libusb_dev_handle *dev_handle,
+ struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
unsigned char endpoint, unsigned char *buffer, int length,
libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
{
/* sync I/O */
-int libusb_control_transfer(libusb_dev_handle *dev_handle,
+int libusb_control_transfer(libusb_device_handle *dev_handle,
uint8_t request_type, uint8_t request, uint16_t value, uint16_t index,
unsigned char *data, uint16_t length, unsigned int timeout);
-int libusb_bulk_transfer(libusb_dev_handle *dev_handle, unsigned char endpoint,
- unsigned char *data, int length, int *actual_length, unsigned int timeout);
+int libusb_bulk_transfer(libusb_device_handle *dev_handle,
+ unsigned char endpoint, unsigned char *data, int length,
+ int *actual_length, unsigned int timeout);
-int libusb_interrupt_transfer(libusb_dev_handle *dev_handle,
+int libusb_interrupt_transfer(libusb_device_handle *dev_handle,
unsigned char endpoint, unsigned char *data, int length,
int *actual_length, unsigned int timeout);
struct libusb_config_descriptor *config;
};
-struct libusb_dev_handle {
+struct libusb_device_handle {
struct list_head list;
struct libusb_device *dev;
int fd;
/* caller interprets result and frees transfer */
}
-API_EXPORTED int libusb_control_transfer(libusb_dev_handle *dev_handle,
+API_EXPORTED int libusb_control_transfer(libusb_device_handle *dev_handle,
uint8_t bRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
unsigned char *data, uint16_t wLength, unsigned int timeout)
{
/* caller interprets results and frees transfer */
}
-static int do_sync_bulk_transfer(struct libusb_dev_handle *dev_handle,
+static int do_sync_bulk_transfer(struct libusb_device_handle *dev_handle,
unsigned char endpoint, unsigned char *buffer, int length,
int *transferred, unsigned int timeout, unsigned char endpoint_type)
{
}
/* FIXME: should transferred be the return value? */
-API_EXPORTED int libusb_bulk_transfer(struct libusb_dev_handle *dev_handle,
+API_EXPORTED int libusb_bulk_transfer(struct libusb_device_handle *dev_handle,
unsigned char endpoint, unsigned char *data, int length, int *transferred,
unsigned int timeout)
{
}
/* FIXME: do we need an interval param here? usbfs doesn't expose it? */
-API_EXPORTED int libusb_interrupt_transfer(struct libusb_dev_handle *dev_handle,
- unsigned char endpoint, unsigned char *data, int length, int *transferred,
- unsigned int timeout)
+API_EXPORTED int libusb_interrupt_transfer(
+ struct libusb_device_handle *dev_handle, unsigned char endpoint,
+ unsigned char *data, int length, int *transferred, unsigned int timeout)
{
return do_sync_bulk_transfer(dev_handle, endpoint, data, length,
transferred, timeout, LIBUSB_ENDPOINT_TYPE_INTERRUPT);