Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /** | 1 /** |
| 2 * \file libmtp.c | 2 * \file libmtp.c |
| 3 * | 3 * |
| 4 * Copyright (C) 2005-2011 Linus Walleij <triad@df.lth.se> | 4 * Copyright (C) 2005-2011 Linus Walleij <triad@df.lth.se> |
| 5 * Copyright (C) 2005-2008 Richard A. Low <richard@wentnet.com> | 5 * Copyright (C) 2005-2008 Richard A. Low <richard@wentnet.com> |
| 6 * Copyright (C) 2007 Ted Bullock <tbullock@canada.com> | 6 * Copyright (C) 2007 Ted Bullock <tbullock@canada.com> |
| 7 * Copyright (C) 2007 Tero Saarni <tero.saarni@gmail.com> | 7 * Copyright (C) 2007 Tero Saarni <tero.saarni@gmail.com> |
| 8 * Copyright (C) 2008 Florent Mertens <flomertens@gmail.com> | 8 * Copyright (C) 2008 Florent Mertens <flomertens@gmail.com> |
| 9 * | 9 * |
| 10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
| (...skipping 4954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4965 // This was not an OGG/FLAC file so discard it | 4965 // This was not an OGG/FLAC file so discard it |
| 4966 LIBMTP_destroy_track_t(track); | 4966 LIBMTP_destroy_track_t(track); |
| 4967 return NULL; | 4967 return NULL; |
| 4968 } | 4968 } |
| 4969 } | 4969 } |
| 4970 get_track_metadata(device, ob->oi.ObjectFormat, track); | 4970 get_track_metadata(device, ob->oi.ObjectFormat, track); |
| 4971 return track; | 4971 return track; |
| 4972 } | 4972 } |
| 4973 | 4973 |
| 4974 /** | 4974 /** |
| 4975 * This copies a chunk of a file off the device to memory. | |
| 4976 * @param device a pointer to the device to get the track from. | |
| 4977 * @param id the file ID of the file to retrieve. | |
| 4978 * @param offset the offset of the file to read from. | |
| 4979 * @param count the amount of data to read. | |
| 4980 * @param data a pointer to the data from the device. Must be | |
| 4981 * <coded>free()</code>:ed by the caller after use. | |
| 4982 * @param datalen the amount of data written to <code>data</code>. | |
| 4983 * @return 0 if the transfer was successful, any other value means | |
| 4984 * failure. | |
| 4985 */ | |
| 4986 int LIBMTP_Get_File_Chunk(LIBMTP_mtpdevice_t* device, uint32_t id, | |
| 4987 uint32_t offset, uint32_t count, | |
| 4988 unsigned char** data, uint32_t* datalen) | |
| 4989 { | |
| 4990 uint16_t ret; | |
| 4991 PTPParams *params = (PTPParams *) device->params; | |
| 4992 PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo; | |
| 4993 PTPObject *ob; | |
| 4994 | |
| 4995 if (!data || !datalen) { | |
| 4996 add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_Chunk (): Invalid parameter."); | |
| 4997 return -1; | |
| 4998 } | |
| 4999 | |
| 5000 ret = ptp_object_want (params, id, PTPOBJECT_OBJECTINFO_LOADED, &ob); | |
|
Jorge Lucangeli Obes
2012/11/15 01:46:10
I'm not sure what the coding standard is for third
Lei Zhang
2012/11/15 01:50:11
This is copied from line 5158. The code in this fi
| |
| 5001 if (ret != PTP_RC_OK) { | |
| 5002 add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_Chunk (): Could not get object info."); | |
| 5003 return -1; | |
| 5004 } | |
| 5005 if (ob->oi.ObjectFormat == PTP_OFC_Association) { | |
| 5006 add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_Chunk (): Bad object format."); | |
| 5007 return -1; | |
| 5008 } | |
| 5009 | |
| 5010 ret = ptp_getpartialobject(params, id, offset, count, data, datalen); | |
| 5011 | |
| 5012 if (ret == PTP_ERROR_CANCEL) { | |
| 5013 add_error_to_errorstack(device, LIBMTP_ERROR_CANCELLED, "LIBMTP_Get_File_Chu nk(): Cancelled transfer."); | |
| 5014 return -1; | |
| 5015 } | |
| 5016 if (ret != PTP_RC_OK) { | |
| 5017 add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_File_Chunk(): Could not get file from device."); | |
| 5018 return -1; | |
| 5019 } | |
| 5020 | |
| 5021 return 0; | |
| 5022 } | |
| 5023 | |
| 5024 /** | |
| 4975 * This is a manual conversion from MTPDataGetFunc to PTPDataGetFunc | 5025 * This is a manual conversion from MTPDataGetFunc to PTPDataGetFunc |
| 4976 * to isolate the internal type. | 5026 * to isolate the internal type. |
| 4977 */ | 5027 */ |
| 4978 static uint16_t get_func_wrapper(PTPParams* params, void* priv, unsigned long wa ntlen, unsigned char *data, unsigned long *gotlen) | 5028 static uint16_t get_func_wrapper(PTPParams* params, void* priv, unsigned long wa ntlen, unsigned char *data, unsigned long *gotlen) |
| 4979 { | 5029 { |
| 4980 MTPDataHandler *handler = (MTPDataHandler *)priv; | 5030 MTPDataHandler *handler = (MTPDataHandler *)priv; |
| 4981 uint16_t ret; | 5031 uint16_t ret; |
| 4982 uint32_t local_gotlen = 0; | 5032 uint32_t local_gotlen = 0; |
| 4983 ret = handler->getfunc(params, handler->priv, wantlen, data, &local_gotlen); | 5033 ret = handler->getfunc(params, handler->priv, wantlen, data, &local_gotlen); |
| 4984 *gotlen = local_gotlen; | 5034 *gotlen = local_gotlen; |
| (...skipping 3909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8894 * @param device the device which may have a cache to which the object should be updated. | 8944 * @param device the device which may have a cache to which the object should be updated. |
| 8895 * @param object_id the object to update. | 8945 * @param object_id the object to update. |
| 8896 */ | 8946 */ |
| 8897 static void update_metadata_cache(LIBMTP_mtpdevice_t *device, uint32_t object_id ) | 8947 static void update_metadata_cache(LIBMTP_mtpdevice_t *device, uint32_t object_id ) |
| 8898 { | 8948 { |
| 8899 PTPParams *params = (PTPParams *)device->params; | 8949 PTPParams *params = (PTPParams *)device->params; |
| 8900 | 8950 |
| 8901 ptp_remove_object_from_cache(params, object_id); | 8951 ptp_remove_object_from_cache(params, object_id); |
| 8902 add_object_to_cache(device, object_id); | 8952 add_object_to_cache(device, object_id); |
| 8903 } | 8953 } |
| OLD | NEW |