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 4397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4408 } | 4408 } |
4409 } | 4409 } |
4410 | 4410 |
4411 free(currentHandles.Handler); | 4411 free(currentHandles.Handler); |
4412 | 4412 |
4413 // Return a pointer to the original first file | 4413 // Return a pointer to the original first file |
4414 // in the big list. | 4414 // in the big list. |
4415 return retfiles; | 4415 return retfiles; |
4416 } | 4416 } |
4417 | 4417 |
| 4418 /** |
| 4419 * This function retrieves the list of ids of files and folders in a certain |
| 4420 * folder with id parent on a certain storage on a certain device. |
| 4421 * The device used with this operations must have been opened with |
| 4422 * LIBMTP_Open_Raw_Device_Uncached() or it will fail. |
| 4423 * |
| 4424 * NOTE: the request will always perform I/O with the device. |
| 4425 * @param device a pointer to the MTP device to report info from. |
| 4426 * @param storage a storage on the device to report info from. If |
| 4427 * 0 is passed in, the files for the given parent will be |
| 4428 * searched across all available storages. |
| 4429 * @param parent the parent folder id. |
| 4430 * @param out the pointer where the array of ids is returned. It is |
| 4431 * set only when the returned value > 0. The caller takes the |
| 4432 * ownership of the array and has to free() it. |
| 4433 * @return the length of the returned array or -1 in case of failure. |
| 4434 */ |
| 4435 |
| 4436 int LIBMTP_Get_Children(LIBMTP_mtpdevice_t *device, |
| 4437 uint32_t const storage, |
| 4438 uint32_t const parent, |
| 4439 uint32_t **out) |
| 4440 { |
| 4441 PTPParams *params = (PTPParams *) device->params; |
| 4442 PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo; |
| 4443 LIBMTP_file_t *retfiles = NULL; |
| 4444 LIBMTP_file_t *curfile = NULL; |
| 4445 PTPObjectHandles currentHandles; |
| 4446 uint32_t storageid; |
| 4447 uint16_t ret; |
| 4448 int i = 0; |
| 4449 |
| 4450 if (device->cached) { |
| 4451 // This function is only supposed to be used by devices |
| 4452 // opened as uncached! |
| 4453 LIBMTP_ERROR("tried to use %s on a cached device!\n", __func__); |
| 4454 return -1; |
| 4455 } |
| 4456 |
| 4457 if (FLAG_BROKEN_GET_OBJECT_PROPVAL(ptp_usb)) { |
| 4458 // These devices cannot handle the commands needed for |
| 4459 // Uncached access! |
| 4460 LIBMTP_ERROR("tried to use %s on an unsupported device, " |
| 4461 "this command does not work on all devices " |
| 4462 "due to missing low-level support to read " |
| 4463 "information on individual tracks\n", |
| 4464 __func__); |
| 4465 return -1; |
| 4466 } |
| 4467 |
| 4468 if (storage == 0) |
| 4469 storageid = PTP_GOH_ALL_STORAGE; |
| 4470 else |
| 4471 storageid = storage; |
| 4472 |
| 4473 ret = ptp_getobjecthandles(params, |
| 4474 storageid, |
| 4475 PTP_GOH_ALL_FORMATS, |
| 4476 parent, |
| 4477 ¤tHandles); |
| 4478 |
| 4479 if (ret != PTP_RC_OK) { |
| 4480 add_ptp_error_to_errorstack(device, ret, |
| 4481 "LIBMTP_Get_Children(): could not get object handles."); |
| 4482 return -1; |
| 4483 } |
| 4484 |
| 4485 if (currentHandles.Handler == NULL || currentHandles.n == 0) |
| 4486 return 0; |
| 4487 *out = currentHandles.Handler; |
| 4488 return currentHandles.n; |
| 4489 } |
4418 | 4490 |
4419 /** | 4491 /** |
4420 * This creates a new track metadata structure and allocates memory | 4492 * This creates a new track metadata structure and allocates memory |
4421 * for it. Notice that if you add strings to this structure they | 4493 * for it. Notice that if you add strings to this structure they |
4422 * will be freed by the corresponding <code>LIBMTP_destroy_track_t</code> | 4494 * will be freed by the corresponding <code>LIBMTP_destroy_track_t</code> |
4423 * operation later, so be careful of using strdup() when assigning | 4495 * operation later, so be careful of using strdup() when assigning |
4424 * strings, e.g.: | 4496 * strings, e.g.: |
4425 * | 4497 * |
4426 * <pre> | 4498 * <pre> |
4427 * LIBMTP_track_t *track = LIBMTP_new_track_t(); | 4499 * LIBMTP_track_t *track = LIBMTP_new_track_t(); |
(...skipping 4519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8947 * @param device the device which may have a cache to which the object should be
updated. | 9019 * @param device the device which may have a cache to which the object should be
updated. |
8948 * @param object_id the object to update. | 9020 * @param object_id the object to update. |
8949 */ | 9021 */ |
8950 static void update_metadata_cache(LIBMTP_mtpdevice_t *device, uint32_t object_id
) | 9022 static void update_metadata_cache(LIBMTP_mtpdevice_t *device, uint32_t object_id
) |
8951 { | 9023 { |
8952 PTPParams *params = (PTPParams *)device->params; | 9024 PTPParams *params = (PTPParams *)device->params; |
8953 | 9025 |
8954 ptp_remove_object_from_cache(params, object_id); | 9026 ptp_remove_object_from_cache(params, object_id); |
8955 add_object_to_cache(device, object_id); | 9027 add_object_to_cache(device, object_id); |
8956 } | 9028 } |
OLD | NEW |