cache storageids (not used currently)

on store addition or store removal, reset the libgphoto2 filesystem
(Currently just triggered on wait-event)

working on https://github.com/gphoto/libgphoto2/issues/132
This commit is contained in:
Marcus Meissner
2017-03-05 22:17:46 +01:00
parent 12b7c22234
commit 8d416ea268
3 changed files with 74 additions and 18 deletions

View File

@@ -3890,6 +3890,19 @@ camera_sony_capture (Camera *camera, CameraCaptureType type, CameraFilePath *pat
return add_objectid_and_upload (camera, path, context, newobject, &oi);
}
static int
check_ptp_filesystem (Camera *camera) {
PTPParams *params = &camera->pl->params;
ptp_check_event_queue(params);
if (params->storagechanged) {
params->storagechanged = 0;
gp_filesystem_reset (camera->fs);
}
return GP_OK;
}
static int
camera_capture (Camera *camera, CameraCaptureType type, CameraFilePath *path,
GPContext *context)
@@ -4900,25 +4913,8 @@ downloadnow:
*eventtype = GP_EVENT_CAPTURE_COMPLETE;
*eventdata = NULL;
return GP_OK;
case PTP_EC_DevicePropChanged:
*eventtype = GP_EVENT_UNKNOWN;
C_MEM (*eventdata = malloc(strlen("PTP Property 0123 changed")+1));
sprintf (*eventdata, "PTP Property %04x changed", event.Param1 & 0xffff);
return GP_OK;
/* as we can read multiple events we should retrieve a good one if possible
* and not a random one.*/
case PTP_EC_ObjectRemoved:
ptp_remove_object_from_cache(params, event.Param1);
gp_filesystem_reset (camera->fs);
*eventtype = GP_EVENT_UNKNOWN;
C_MEM (*eventdata = malloc(strlen("PTP ObjectRemoved, Param1 01234567")+1));
sprintf (*eventdata, "PTP ObjectRemoved, Param1 %08x", event.Param1);
break;
default:
*eventtype = GP_EVENT_UNKNOWN;
C_MEM (*eventdata = malloc(strlen("PTP Event 0123, Param1 01234567")+1));
sprintf (*eventdata, "PTP Event %04x, Param1 %08x", event.Code, event.Param1);
return GP_OK;
goto handleregular;
}
}
gp_context_idle (context);
@@ -5091,6 +5087,18 @@ handleregular:
C_MEM (*eventdata = malloc(strlen("PTP ObjectRemoved, Param1 01234567")+1));
sprintf (*eventdata, "PTP ObjectRemoved, Param1 %08x", event.Param1);
break;
case PTP_EC_StoreAdded:
gp_filesystem_reset (camera->fs);
*eventtype = GP_EVENT_UNKNOWN;
C_MEM (*eventdata = malloc(strlen("PTP StoreAdded, Param1 01234567")+1));
sprintf (*eventdata, "PTP StoreAdded, Param1 %08x", event.Param1);
break;
case PTP_EC_StoreRemoved:
gp_filesystem_reset (camera->fs);
*eventtype = GP_EVENT_UNKNOWN;
C_MEM (*eventdata = malloc(strlen("PTP StoreRemoved, Param1 01234567")+1));
sprintf (*eventdata, "PTP StoreRemoved, Param1 %08x", event.Param1);
break;
default:
*eventtype = GP_EVENT_UNKNOWN;
C_MEM (*eventdata = malloc(strlen("PTP Event 0123, Param1 01234567")+1));

View File

@@ -1128,6 +1128,7 @@ ptp_free_params (PTPParams *params)
for (i=0;i<params->nrofobjects;i++)
ptp_free_object (&params->objects[i]);
free (params->objects);
free (params->storageids.Storage);
free (params->events);
for (i=0;i<params->nrofcanon_props;i++) {
free (params->canon_props[i].data);
@@ -2152,11 +2153,53 @@ handle_event_internal (PTPParams *params, PTPContainer *event)
}
break;
}
case PTP_EC_StoreAdded:
case PTP_EC_StoreRemoved: {
int i;
/* refetch storage IDs and also invalidate whole object tree */
free (params->storageids.Storage);
params->storageids.Storage = NULL;
params->storageids.n = 0;
ptp_getstorageids (params, &params->storageids);
/* free object storage as it might be associated with the storage ids */
/* FIXME: enhance and just delete the ones from the storage */
for (i=0;i<params->nrofobjects;i++)
ptp_free_object (&params->objects[i]);
free (params->objects);
params->objects = NULL;
params->nrofobjects = 0;
params->storagechanged = 1;
break;
}
default: /* check if we should handle it internally too */
break;
}
}
uint16_t
ptp_check_event_queue (PTPParams *params)
{
PTPContainer event;
uint16_t ret;
/* We try to do a event check without I/O */
/* Basically this means just looking at the meanwhile queued events */
ret = params->event_check_queue(params,&event);
if (ret == PTP_RC_OK) {
ptp_debug (params, "event: nparams=0x%X, code=0x%X, trans_id=0x%X, p1=0x%X, p2=0x%X, p3=0x%X", event.Nparam,event.Code,event.Transaction_ID, event.Param1, event.Param2, event.Param3);
ptp_add_event (params, &event);
handle_event_internal (params, &event);
}
if (ret == PTP_ERROR_TIMEOUT) /* ok, just new events */
ret = PTP_RC_OK;
return ret;
}
uint16_t
ptp_check_event (PTPParams *params)
{

View File

@@ -2494,6 +2494,10 @@ struct _PTPParams {
/* PTP: caching time for properties, default 2 */
int cachetime;
/* PTP: Storage Caching */
PTPStorageIDs storageids;
int storagechanged;
/* PTP: Device Property Caching */
PTPDeviceProperty *deviceproperties;
unsigned int nrofdeviceproperties;
@@ -2718,6 +2722,7 @@ uint16_t ptp_getfilesystemmanifest (PTPParams* params, uint32_t storage,
uint16_t ptp_check_event (PTPParams *params);
uint16_t ptp_check_event_queue (PTPParams *params);
uint16_t ptp_wait_event (PTPParams *params);
uint16_t ptp_add_event (PTPParams *params, PTPContainer *evt);
int ptp_get_one_event (PTPParams *params, PTPContainer *evt);