Added support for testing deviceinfo information.
library.c: addred workaround for devices not supporting getstorageids. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@4519 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
@@ -583,7 +583,8 @@ file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
|
||||
for (i = 0; i < params->handles.n; i++) {
|
||||
if (params->objectinfo[i].ParentObject==parent)
|
||||
if (params->objectinfo[i].ObjectFormat != PTP_OFC_Association)
|
||||
if (params->objectinfo[i].StorageID == storage)
|
||||
if (!ptp_operation_issupported(params,PTP_OC_GetStorageIDs)
|
||||
|| (params->objectinfo[i].StorageID == storage))
|
||||
CR (gp_list_append (list, params->objectinfo[i].Filename, NULL));
|
||||
}
|
||||
|
||||
@@ -602,14 +603,22 @@ folder_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
|
||||
/* add storage pseudofolders in root folder */
|
||||
if (!strcmp(folder, "/")) {
|
||||
PTPStorageIDs storageids;
|
||||
CPR (context, ptp_getstorageids(params,
|
||||
&storageids));
|
||||
|
||||
if (ptp_operation_issupported(params,PTP_OC_GetStorageIDs)) {
|
||||
CPR (context, ptp_getstorageids(params,
|
||||
&storageids));
|
||||
} else {
|
||||
storageids.n = 1;
|
||||
storageids.storage[0]=0xdeadbeef;
|
||||
}
|
||||
for (i=0; i<storageids.n; i++) {
|
||||
char fname[MAXFILENAMELEN];
|
||||
PTPStorageInfo storageinfo;
|
||||
if ((storageids.storage[i]&0x0000ffff)==0) continue;
|
||||
CPR (context, ptp_getstorageinfo(params,
|
||||
storageids.storage[i], &storageinfo));
|
||||
if (ptp_operation_issupported(params,PTP_OC_GetStorageIDs)) {
|
||||
CPR (context, ptp_getstorageinfo(params,
|
||||
storageids.storage[i], &storageinfo));
|
||||
}
|
||||
snprintf(fname, MAXFILENAMELEN, STORAGE_FOLDER_PREFIX"%8.8x",
|
||||
storageids.storage[i]);
|
||||
CR (gp_list_append (list, fname, NULL));
|
||||
@@ -633,7 +642,8 @@ folder_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
|
||||
find_folder_handle(folder,parent,data);
|
||||
for (i = 0; i < params->handles.n; i++) {
|
||||
if (params->objectinfo[i].ParentObject==parent)
|
||||
if (params->objectinfo[i].StorageID == storage)
|
||||
if ((!ptp_operation_issupported(params,PTP_OC_GetStorageIDs)) ||
|
||||
(params->objectinfo[i].StorageID == storage))
|
||||
if (params->objectinfo[i].ObjectFormat==PTP_OFC_Association &&
|
||||
params->objectinfo[i].AssociationType==PTP_AT_GenericFolder)
|
||||
CR (gp_list_append (list, params->objectinfo[i].Filename, NULL));
|
||||
@@ -926,6 +936,8 @@ init_ptp_fs (Camera *camera, GPContext *context)
|
||||
camera->pl->params.objectinfo =
|
||||
(PTPObjectInfo*)malloc(sizeof(PTPObjectInfo)*
|
||||
camera->pl->params.handles.n);
|
||||
// XXX !!!
|
||||
//memset (camera->pl->params.objectinfo,0,sizeof(PTPObjectInfo));
|
||||
for (i = 0; i < camera->pl->params.handles.n; i++) {
|
||||
CPR (context, ptp_getobjectinfo(&camera->pl->params,
|
||||
camera->pl->params.handles.handler[i],
|
||||
@@ -1005,6 +1017,13 @@ camera_init (Camera *camera, GPContext *context)
|
||||
/* init internal ptp objectfiles (required for fs implementation) */
|
||||
init_ptp_fs (camera, context);
|
||||
|
||||
CPR(context, ptp_getdeviceinfo(&camera->pl->params,
|
||||
&camera->pl->params.deviceinfo));
|
||||
|
||||
GP_DEBUG ("Manufacturer: %s",camera->pl->params.deviceinfo.Manufacturer);
|
||||
GP_DEBUG ("model: %s", camera->pl->params.deviceinfo.Model);
|
||||
GP_DEBUG ("device version: %s", camera->pl->params.deviceinfo.DeviceVersion);
|
||||
|
||||
{
|
||||
PTPEvent event;
|
||||
// ptp_event_check (&camera->pl->params,event);
|
||||
|
||||
@@ -110,12 +110,12 @@ ptp_unpack_uint32_t_array(PTPParams *params, PTPReq *req, uint16_t offset, uint3
|
||||
static inline uint32_t
|
||||
ptp_unpack_uint16_t_array(PTPParams *params, PTPReq *req, uint16_t offset, uint16_t **array)
|
||||
{
|
||||
uint32_t n, i=0;
|
||||
uint32_t n, i=1;
|
||||
|
||||
n=dtoh32a(&req->data[offset]);
|
||||
*array = malloc (n*sizeof(uint16_t));
|
||||
while (n>i) {
|
||||
(*array)[i]=dtoh16a(&req->data[offset+(sizeof(uint16_t)*(i+1))]);
|
||||
while (n>=i) {
|
||||
(*array)[i-1]=dtoh16a(&req->data[offset+(sizeof(uint16_t)*i)]);
|
||||
i++;
|
||||
}
|
||||
return n;
|
||||
@@ -134,7 +134,7 @@ static inline void
|
||||
ptp_unpack_DI (PTPParams *params, PTPReq *req, PTPDeviceInfo *di)
|
||||
{
|
||||
uint8_t len, totallen;
|
||||
|
||||
|
||||
di->StaqndardVersion = dtoh16a(&req->data[PTP_di_StandardVersion]);
|
||||
di->VendorExtensionID =
|
||||
dtoh32a(&req->data[PTP_di_VendorExtensionID]);
|
||||
@@ -149,27 +149,40 @@ ptp_unpack_DI (PTPParams *params, PTPReq *req, PTPDeviceInfo *di)
|
||||
di->OperationsSupported_len = ptp_unpack_uint16_t_array(params, req,
|
||||
PTP_di_OperationsSupported+totallen,
|
||||
&di->OperationsSupported);
|
||||
totallen=totallen+di->OperationsSupported_len+sizeof(uint32_t);
|
||||
totallen=totallen+di->OperationsSupported_len*sizeof(uint16_t)+sizeof(uint32_t);
|
||||
di->EventsSupported_len = ptp_unpack_uint16_t_array(params, req,
|
||||
PTP_di_OperationsSupported+totallen,
|
||||
&di->EventsSupported);
|
||||
totallen=totallen+di->EventsSupported_len+sizeof(uint32_t);
|
||||
totallen=totallen+di->EventsSupported_len*sizeof(uint16_t)+sizeof(uint32_t);
|
||||
di->DevicePropertiesSupported_len =
|
||||
ptp_unpack_uint16_t_array(params, req,
|
||||
PTP_di_OperationsSupported+totallen,
|
||||
&di->DevicePropertiesSupported);
|
||||
totallen=totallen+di->DevicePropertiesSupported_len+sizeof(uint32_t);
|
||||
totallen=totallen+di->DevicePropertiesSupported_len*sizeof(uint16_t)+sizeof(uint32_t);
|
||||
di->CaptureFormats_len = ptp_unpack_uint16_t_array(params, req,
|
||||
PTP_di_OperationsSupported+totallen,
|
||||
&di->CaptureFormats);
|
||||
totallen=totallen+di->CaptureFormats_len+sizeof(uint32_t);
|
||||
totallen=totallen+di->CaptureFormats_len*sizeof(uint16_t)+sizeof(uint32_t);
|
||||
di->ImageFormats_len = ptp_unpack_uint16_t_array(params, req,
|
||||
PTP_di_OperationsSupported+totallen,
|
||||
&di->ImageFormats);
|
||||
totallen=totallen+di->ImageFormats_len+sizeof(uint32_t);
|
||||
totallen=totallen+di->ImageFormats_len*sizeof(uint16_t)+sizeof(uint32_t);
|
||||
di->Manufacturer = ptp_unpack_string(params, req,
|
||||
PTP_di_OperationsSupported+totallen,
|
||||
&len);
|
||||
totallen+=len*2+1;
|
||||
di->Model = ptp_unpack_string(params, req,
|
||||
PTP_di_OperationsSupported+totallen,
|
||||
&len);
|
||||
totallen+=len*2+1;
|
||||
di->DeviceVersion = ptp_unpack_string(params, req,
|
||||
PTP_di_OperationsSupported+totallen,
|
||||
&len);
|
||||
totallen+=len*2+1;
|
||||
di->SerialNumber = ptp_unpack_string(params, req,
|
||||
PTP_di_OperationsSupported+totallen,
|
||||
&len);
|
||||
|
||||
}
|
||||
|
||||
// ObjectHandles array pack/unpack
|
||||
|
||||
@@ -581,3 +581,17 @@ ptp_ek_sendfileobject (PTPParams* params, PTPReq* object, uint32_t size)
|
||||
PTP_DP_SENDDATA | PTP_RQ_PARAM0, size, object);
|
||||
}
|
||||
|
||||
|
||||
/* devinfo testing functions */
|
||||
|
||||
int
|
||||
ptp_operation_issupported(PTPParams* params, uint16_t operation)
|
||||
{
|
||||
int i=0;
|
||||
|
||||
for (;i<params->deviceinfo.OperationsSupported_len;i++) {
|
||||
if (params->deviceinfo.OperationsSupported[i]==operation)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ struct _PTPDeviceInfo {
|
||||
uint16_t *ImageFormats;
|
||||
char *Manufacturer;
|
||||
char *Model;
|
||||
char *DeviceVersionl;
|
||||
char *DeviceVersion;
|
||||
char *SerialNumber;
|
||||
};
|
||||
typedef struct _PTPDeviceInfo PTPDeviceInfo;
|
||||
@@ -353,6 +353,7 @@ struct _PTPParams {
|
||||
/* internal structures used by ptp driver */
|
||||
PTPObjectHandles handles;
|
||||
PTPObjectInfo * objectinfo;
|
||||
PTPDeviceInfo deviceinfo;
|
||||
};
|
||||
typedef struct _PTPParams PTPParams;
|
||||
|
||||
@@ -395,4 +396,7 @@ uint16_t ptp_ek_sendfileobjectinfo (PTPParams* params, uint32_t* store,
|
||||
PTPObjectInfo* objectinfo);
|
||||
uint16_t ptp_ek_sendfileobject (PTPParams* params, PTPReq* object,
|
||||
uint32_t size);
|
||||
|
||||
int ptp_operation_issupported (PTPParams* params, uint16_t operation);
|
||||
|
||||
#endif /* __PTP_H__ */
|
||||
|
||||
Reference in New Issue
Block a user