diff options
author | Linus Walleij <triad@df.lth.se> | 2006-03-21 06:51:22 +0000 |
---|---|---|
committer | Linus Walleij <triad@df.lth.se> | 2006-03-21 06:51:22 +0000 |
commit | 6946ac5852401e69f95056a841707dc96444f952 (patch) | |
tree | 0352a02c56efb7b4da1942e33bb428f9cede7a25 | |
parent | 9b28da341a771881c20d620c334f050d06aec512 (diff) | |
download | libmtp-6946ac5852401e69f95056a841707dc96444f952.tar.gz |
New functions...libmtp-0-0-2
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | examples/gettr.c | 2 | ||||
-rw-r--r-- | examples/sendtr.c | 2 | ||||
-rw-r--r-- | src/libmtp.c | 33 | ||||
-rw-r--r-- | src/libmtp.h.in | 6 | ||||
-rw-r--r-- | src/libusb-glue.c | 100 |
7 files changed, 91 insertions, 60 deletions
@@ -1,3 +1,9 @@ +2006-03-18 Linus Walleij <triad@df.lth.se> + + * Fixed up callback interface to a simpler version, + the old one was bloated stuff from libnjb anyway. + Bump to 0.0.2. + 2006-03-16 Linus Walleij <triad@df.lth.se> * Fixed the .h file and implementation so you really only diff --git a/configure.ac b/configure.ac index cc1ea8e..38c3c93 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.52) -AC_INIT([libmtp], [0.0.1], [libmtp-users@lists.sourceforge.net]) +AC_INIT([libmtp], [0.0.2], [libmtp-users@lists.sourceforge.net]) AM_INIT_AUTOMAKE([foreign]) AC_CONFIG_SRCDIR([src/libmtp.c]) AC_CONFIG_HEADER([config.h]) diff --git a/examples/gettr.c b/examples/gettr.c index 773b8e2..551cca9 100644 --- a/examples/gettr.c +++ b/examples/gettr.c @@ -1,6 +1,6 @@ #include "common.h" -static int progress (u_int64_t sent, u_int64_t total, const char* buf, unsigned len, void *data) +static int progress (u_int64_t const sent, u_int64_t const total, void const * const data) { int percent = (sent*100)/total; #ifdef __WIN32__ diff --git a/examples/sendtr.c b/examples/sendtr.c index 80e8030..a320e50 100644 --- a/examples/sendtr.c +++ b/examples/sendtr.c @@ -26,7 +26,7 @@ static char *basename(char *in) { } #endif -static int progress (uint64_t const sent, uint64_t const total, uint8_t const * const buf, uint32_t const len, void const * const data) +static int progress (uint64_t const sent, uint64_t const total, void const * const data) { int percent = (sent*100)/total; #ifdef __WIN32__ diff --git a/src/libmtp.c b/src/libmtp.c index f1fb92f..047b6d8 100644 --- a/src/libmtp.c +++ b/src/libmtp.c @@ -17,6 +17,26 @@ static int send_file_object(LIBMTP_mtpdevice_t *device, void const * const data); static int delete_item(LIBMTP_mtpdevice_t *device, uint32_t item_id); +// Map this libptp2 single-threaded callback to the LIBMTP callback type +extern Progress_Callback* globalCallback; +static void *single_threaded_callback_data; +static LIBMTP_progressfunc_t *single_threaded_callback; +static Progress_Callback single_threaded_callback_helper; + +/** + * This is a ugly workaround due to limitations in callback set by + * libptp2... + */ +static int single_threaded_callback_helper(uint32_t sent, uint32_t total) { + if (single_threaded_callback != NULL) { + /* + * If the callback return anything else than 0, we should interrupt the processing, + * but currently libptp2 does not offer anything meaningful here so we have to ignore + * the return value. + */ + (void) single_threaded_callback(sent, total, single_threaded_callback_data); + } +} /** * Initialize the library. @@ -613,11 +633,10 @@ int LIBMTP_Get_Track_To_File_Descriptor(LIBMTP_mtpdevice_t *device, void *image; int ret; PTPParams *params = (PTPParams *) device->params; - // Map this to the LIBMTP callback type - extern Progress_Callback* globalCallback; - - // Not yet compatible. - globalCallback = NULL; + + single_threaded_callback_data = data; + single_threaded_callback = callback; + globalCallback = single_threaded_callback_helper; if (ptp_getobjectinfo(params, id, &oi) != PTP_RC_OK) { printf("LIBMTP_Get_Track_To_File_Descriptor(): Could not get object info\n"); @@ -783,7 +802,7 @@ static int send_file_object(LIBMTP_mtpdevice_t *device, if (callback != NULL) { // If the callback return anything else than 0, interrupt the processing - int callret = callback(bytesdone, size, buffer, readsize, data); + int callret = callback(bytesdone, size, data); if (callret != 0) { printf("LIBMTP_Send_Track_From_File_Descriptor: transfer interrupted by callback\n"); free(buffer); @@ -805,7 +824,7 @@ static int send_file_object(LIBMTP_mtpdevice_t *device, if (callback != NULL) { // This last call will not be able to abort execution and is just // done so progress bars go up to 100% - (void) callback(size, size, NULL, 0, data); + (void) callback(size, size, data); } // Signal to USB that this is the last transfer if the last chunk diff --git a/src/libmtp.h.in b/src/libmtp.h.in index e8b3c13..8935d62 100644 --- a/src/libmtp.h.in +++ b/src/libmtp.h.in @@ -111,14 +111,12 @@ extern "C" { * <code>total</code>. * @param sent the number of bytes sent so far * @param total the total number of bytes to send - * @param buf intermediate buffer - * @param len intermediate buffer length * @param data a user-defined dereferencable pointer * @return if anything else than 0 is returned, the current transfer will be - * interrupted. + * interrupted / cancelled. */ typedef int LIBMTP_progressfunc_t (uint64_t const sent, uint64_t const total, - uint8_t const * const buf, uint32_t const len, void const * const data); + void const * const data); /** * @defgroup internals The libmtp internal state manipulation API. diff --git a/src/libusb-glue.c b/src/libusb-glue.c index d58461a..348eb1f 100644 --- a/src/libusb-glue.c +++ b/src/libusb-glue.c @@ -282,56 +282,64 @@ struct usb_device* find_device (int busn, int devn, short force) return NULL; } -/* this is a temporary function to connect to the first device we can, that has vendor ID CREATIVE_VENDOR_ID */ - +/** + * This function scans through the device list to see if there are + * some devices to connect to. The table at the top of this file is + * used to identify potential devices. + */ uint16_t connect_first_device(PTPParams *params, PTP_USB *ptp_usb, uint8_t *interfaceNumber) { - struct usb_bus *bus; - struct usb_device *dev; + struct usb_bus *bus; + struct usb_device *dev; + + bus = init_usb(); + for (; bus; bus = bus->next) { + for (dev = bus->devices; dev; dev = dev->next) { + int i; + + // Loop over the list of supported devices + for (i = 0; i < mtp_device_table_size; i++) { + mtp_device_entry_t const *mtp_device = &mtp_device_table[i]; - bus=init_usb(); - for (; bus; bus = bus->next) - { - for (dev = bus->devices; dev; dev = dev->next) - { - if (dev->descriptor.bDeviceClass!=USB_CLASS_HUB && dev->descriptor.idVendor==CREATIVE_VENDOR_ID) - { - uint16_t ret=0; - int n; - struct usb_endpoint_descriptor *ep; - PTPDeviceInfo deviceinfo; - - ep = dev->config->interface->altsetting->endpoint; - n=dev->config->interface->altsetting->bNumEndpoints; - - find_endpoints(dev,&(ptp_usb->inep),&(ptp_usb->outep),&(ptp_usb->intep)); - init_ptp_usb(params, ptp_usb, dev); - - ret = ptp_opensession(params,1); - if (ret != PTP_RC_OK) - { - printf("Could not open session!\n Try to reset the device.\n"); - usb_release_interface(ptp_usb->handle,dev->config->interface->altsetting->bInterfaceNumber); - continue; - } - - ret = ptp_getdeviceinfo(params, &deviceinfo); - if (ret != PTP_RC_OK) - { - printf("Could not get device info!\n"); - usb_release_interface(ptp_usb->handle,dev->config->interface->altsetting->bInterfaceNumber); - return PTP_CD_RC_ERROR_CONNECTING; - } - - /* we're connected, return ok */ - *interfaceNumber = dev->config->interface->altsetting->bInterfaceNumber; - - return PTP_CD_RC_CONNECTED; - } - } + if (dev->descriptor.bDeviceClass != USB_CLASS_HUB && + dev->descriptor.idVendor == mtp_device->vendor_id && + dev->descriptor.idProduct == mtp_device->product_id ) { + uint16_t ret=0; + int n; + struct usb_endpoint_descriptor *ep; + PTPDeviceInfo deviceinfo; + + printf("Found device \"%s\" on USB bus...\n", mtp_device->name); + ep = dev->config->interface->altsetting->endpoint; + n=dev->config->interface->altsetting->bNumEndpoints; + + find_endpoints(dev,&(ptp_usb->inep),&(ptp_usb->outep),&(ptp_usb->intep)); + init_ptp_usb(params, ptp_usb, dev); + + ret = ptp_opensession(params,1); + if (ret != PTP_RC_OK) { + printf("Could not open session!\n Try to reset the device.\n"); + usb_release_interface(ptp_usb->handle,dev->config->interface->altsetting->bInterfaceNumber); + continue; + } + + ret = ptp_getdeviceinfo(params, &deviceinfo); + if (ret != PTP_RC_OK) { + printf("Could not get device info!\n"); + usb_release_interface(ptp_usb->handle,dev->config->interface->altsetting->bInterfaceNumber); + return PTP_CD_RC_ERROR_CONNECTING; + } + + /* we're connected, return ok */ + *interfaceNumber = dev->config->interface->altsetting->bInterfaceNumber; + + return PTP_CD_RC_CONNECTED; } - /* none found */ - return PTP_CD_RC_NO_DEVICES; + } + } + } + /* none found */ + return PTP_CD_RC_NO_DEVICES; } void find_endpoints(struct usb_device *dev, int* inep, int* outep, int* intep) |