diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-10-09 16:28:57 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-10-09 16:39:41 +0200 |
commit | f5a4783b701e9e620767d6ac3b2f96b4966278c2 (patch) | |
tree | 6fe2d08d66a57543d69ea8c5ce112c1ba889a3f3 /io_libusb.c | |
parent | e5c0adc53e6f5e34857e42e42b5cf5e606430857 (diff) |
io: Create an io indirection to allow to compile multiple io backends
Right now only one io driver is compiled in and this one will be
selected at application start.
Diffstat (limited to 'io_libusb.c')
-rw-r--r-- | io_libusb.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/io_libusb.c b/io_libusb.c index 0c30494..4890747 100644 --- a/io_libusb.c +++ b/io_libusb.c @@ -1,3 +1,14 @@ +/* + * io_libusb.c + * + * Copyright (C) 200X ??? + * Copyright (C) 2011 Holger Hans Peter Freyther + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + * + */ #include "config.h" #include <usb.h> @@ -8,7 +19,7 @@ static usb_dev_handle *io_handle; -int io_init( char *dev ) +static int lusb_io_init( char *dev ) { struct usb_bus *bus; struct usb_device *usbdev; @@ -43,7 +54,7 @@ int io_init( char *dev ) return -1; } -int io_cleanup( void ) +static int lusb_io_cleanup( void ) { usb_release_interface(io_handle, 1); usb_close(io_handle); @@ -51,7 +62,7 @@ int io_cleanup( void ) } -int io_write( void *buff, int len ) +static int lusb_io_write( void *buff, int len ) { int ret = usb_bulk_write(io_handle, 0x1, buff, len, 5000); if( ret < 0 ) { @@ -60,7 +71,7 @@ int io_write( void *buff, int len ) return ret; } -int io_read( void *buff, int len ) +static int lusb_io_read( void *buff, int len ) { int ret = usb_bulk_read(io_handle, 0x82, buff, len, 5000); if( ret < 0 ) { @@ -68,3 +79,16 @@ int io_read( void *buff, int len ) } return ret; } + +static struct io_driver lusb_driver = { + .name = "libusb", + .io_init = lusb_io_init, + .io_cleanup = lusb_io_cleanup, + .io_write = lusb_io_write, + .io_read = lusb_io_read, +}; + +static void __attribute__((constructor)) lusb_on_load(void) +{ + io_driver_register(&lusb_driver); +} |