summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2017-03-05 22:17:46 +0100
committerMarcus Meissner <marcus@jet.franken.de>2017-03-05 22:17:46 +0100
commit8d416ea26849b8efe1f4fa67c60f186d6f1cb45d (patch)
treedfb1acd94005fb2ec690a3ac76073ceab5da02c3
parent12b7c2223432599671a47f1c735c55f1826589be (diff)
downloadlibgphoto2-8d416ea26849b8efe1f4fa67c60f186d6f1cb45d.tar.gz
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
-rw-r--r--camlibs/ptp2/library.c44
-rw-r--r--camlibs/ptp2/ptp.c43
-rw-r--r--camlibs/ptp2/ptp.h5
3 files changed, 74 insertions, 18 deletions
diff --git a/camlibs/ptp2/library.c b/camlibs/ptp2/library.c
index 397d9a4ca..cb35ca562 100644
--- a/camlibs/ptp2/library.c
+++ b/camlibs/ptp2/library.c
@@ -3891,6 +3891,19 @@ camera_sony_capture (Camera *camera, CameraCaptureType type, CameraFilePath *pat
}
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));
diff --git a/camlibs/ptp2/ptp.c b/camlibs/ptp2/ptp.c
index ddefc6ad2..b421512ab 100644
--- a/camlibs/ptp2/ptp.c
+++ b/camlibs/ptp2/ptp.c
@@ -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,12 +2153,54 @@ 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)
{
PTPContainer event;
diff --git a/camlibs/ptp2/ptp.h b/camlibs/ptp2/ptp.h
index 3b817fa44..f54d957b8 100644
--- a/camlibs/ptp2/ptp.h
+++ b/camlibs/ptp2/ptp.h
@@ -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);