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. | |
Lei Zhang
2014/07/23 08:39:30
Please mention the caller takes ownership, and it'
kinaba
2014/07/23 09:00:11
Done.
| |
4431 */ | |
4432 | |
4433 int LIBMTP_Get_Children(LIBMTP_mtpdevice_t *device, | |
4434 uint32_t const storage, | |
4435 uint32_t const parent, | |
4436 uint32_t** out) | |
Lei Zhang
2014/07/23 08:39:30
nit: **out
kinaba
2014/07/23 08:59:53
Done.
| |
4437 { | |
4438 PTPParams *params = (PTPParams *) device->params; | |
4439 PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo; | |
4440 LIBMTP_file_t *retfiles = NULL; | |
4441 LIBMTP_file_t *curfile = NULL; | |
4442 PTPObjectHandles currentHandles; | |
4443 uint32_t storageid; | |
4444 uint16_t ret; | |
4445 int i = 0; | |
4446 | |
4447 if (device->cached) { | |
4448 // This function is only supposed to be used by devices | |
4449 // opened as uncached! | |
4450 LIBMTP_ERROR("tried to use %s on a cached device!\n", __func__); | |
4451 return -1; | |
4452 } | |
4453 | |
4454 if (FLAG_BROKEN_GET_OBJECT_PROPVAL(ptp_usb)) { | |
4455 // These devices cannot handle the commands needed for | |
4456 // Uncached access! | |
4457 LIBMTP_ERROR("tried to use %s on an unsupported device, " | |
4458 "this command does not work on all devices " | |
4459 "due to missing low-level support to read " | |
4460 "information on individual tracks\n", | |
4461 __func__); | |
4462 return -1; | |
4463 } | |
4464 | |
4465 if (storage == 0) | |
4466 storageid = PTP_GOH_ALL_STORAGE; | |
4467 else | |
4468 storageid = storage; | |
4469 | |
4470 ret = ptp_getobjecthandles(params, | |
4471 storageid, | |
4472 PTP_GOH_ALL_FORMATS, | |
4473 parent, | |
4474 ¤tHandles); | |
4475 | |
4476 if (ret != PTP_RC_OK) { | |
4477 add_ptp_error_to_errorstack(device, ret, | |
4478 "LIBMTP_Get_Children(): could not get object handles."); | |
4479 return -1; | |
4480 } | |
4481 | |
4482 if (currentHandles.Handler == NULL || currentHandles.n == 0) | |
4483 return 0; | |
4484 *out = currentHandles.Handler; | |
4485 return currentHandles.n; | |
4486 } | |
4418 | 4487 |
4419 /** | 4488 /** |
4420 * This creates a new track metadata structure and allocates memory | 4489 * This creates a new track metadata structure and allocates memory |
4421 * for it. Notice that if you add strings to this structure they | 4490 * 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> | 4491 * will be freed by the corresponding <code>LIBMTP_destroy_track_t</code> |
4423 * operation later, so be careful of using strdup() when assigning | 4492 * operation later, so be careful of using strdup() when assigning |
4424 * strings, e.g.: | 4493 * strings, e.g.: |
4425 * | 4494 * |
4426 * <pre> | 4495 * <pre> |
4427 * LIBMTP_track_t *track = LIBMTP_new_track_t(); | 4496 * 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. | 9016 * @param device the device which may have a cache to which the object should be updated. |
8948 * @param object_id the object to update. | 9017 * @param object_id the object to update. |
8949 */ | 9018 */ |
8950 static void update_metadata_cache(LIBMTP_mtpdevice_t *device, uint32_t object_id ) | 9019 static void update_metadata_cache(LIBMTP_mtpdevice_t *device, uint32_t object_id ) |
8951 { | 9020 { |
8952 PTPParams *params = (PTPParams *)device->params; | 9021 PTPParams *params = (PTPParams *)device->params; |
8953 | 9022 |
8954 ptp_remove_object_from_cache(params, object_id); | 9023 ptp_remove_object_from_cache(params, object_id); |
8955 add_object_to_cache(device, object_id); | 9024 add_object_to_cache(device, object_id); |
8956 } | 9025 } |
OLD | NEW |