From ca1d70ef103fa3c40f85e1b536a673a3e9f8909b Mon Sep 17 00:00:00 2001 From: Lutz Mueller Date: Sat, 17 Nov 2001 00:27:06 +0000 Subject: [PATCH] =?UTF-8?q?2001-11-15=20=20Lutz=20M=EF=BF=BDller=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * camlibs/ptp: Remove a whole lot of warnings, remove unnecessary PTPResult (we've got PTP_RC_*), flesh out library.c a bit - still not functional, though. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@3068 67ed7778-7388-44ab-90cf-0a291f65f57c --- ChangeLog | 6 + camlibs/ptp/Makefile.am | 2 +- camlibs/ptp/library.c | 270 ++++++++++++++++++++++++++++++++++++---- camlibs/ptp/ptp.c | 217 ++++++++++++++++++++------------ camlibs/ptp/ptp.h | 69 +++++----- camlibs/ptp/ptperr.h | 46 ------- 6 files changed, 425 insertions(+), 185 deletions(-) delete mode 100644 camlibs/ptp/ptperr.h diff --git a/ChangeLog b/ChangeLog index a3720eef3..63285be13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2001-11-15 Lutz Müller + + * camlibs/ptp: Remove a whole lot of warnings, remove unnecessary + PTPResult (we've got PTP_RC_*), flesh out library.c a bit - still + not functional, though. + 2001-11-15 Lutz Müller Patch from Greg Ingram , slightly reworked: diff --git a/camlibs/ptp/Makefile.am b/camlibs/ptp/Makefile.am index 1641bb395..3650f7dbc 100644 --- a/camlibs/ptp/Makefile.am +++ b/camlibs/ptp/Makefile.am @@ -3,7 +3,7 @@ camlib_LTLIBRARIES = libgphoto2_ptp.la INCLUDES = -I$(top_srcdir)/libgphoto2 -libgphoto2_ptp_la_SOURCES = ptp.c ptp.h ptperr.h library.c +libgphoto2_ptp_la_SOURCES = ptp.c ptp.h library.c libgphoto2_ptp_la_LDFLAGS =\ -module -avoid-version\ diff --git a/camlibs/ptp/library.c b/camlibs/ptp/library.c index 9478aa500..f790c13be 100644 --- a/camlibs/ptp/library.c +++ b/camlibs/ptp/library.c @@ -21,8 +21,10 @@ #include #include +#include #include +#include #ifdef ENABLE_NLS # include @@ -46,7 +48,90 @@ #include "ptp.h" #define CR(result) {int r=(result);if(r<0) return (r);} -#define PCR(result) {int r=(result);if(r<0) return (PTP_ERROR);} + +static struct { + short n; + const char *txt; +} ptp_errors[] = { + {PTP_RC_Undefined, N_("PTP Udefined Error")}, + {PTP_RC_OK, N_("PTP OK!")}, + {PTP_RC_GeneralError, N_("PTP General Error")}, + {PTP_RC_SessionNotOpen, N_("PTP Session Not Open")}, + {PTP_RC_InvalidTransactionID, N_("PTP Invalid Transaction ID")}, + {PTP_RC_OperationNotSupported, N_("PTP Operation Not Supported")}, + {PTP_RC_ParameterNotSupported, N_("PTP Parameter Not Supported")}, + {PTP_RC_IncompleteTransfer, N_("PTP Incomplete Transfer")}, + {PTP_RC_InvalidStorageId, N_("PTP Invalid Storage ID")}, + {PTP_RC_InvalidObjectHandle, N_("PTP Invalid Object Handle")}, + {PTP_RC_DevicePropNotSupported, N_("PTP Device Prop Not Supported")}, + {PTP_RC_InvalidObjectFormatCode, N_("PTP Invalid Object Format Code")}, + {PTP_RC_StoreFull, N_("PTP Store Full")}, + {PTP_RC_ObjectWriteProtected, N_("PTP Object Write Protected")}, + {PTP_RC_StoreReadOnly, N_("PTP Store Read Only")}, + {PTP_RC_AccessDenied, N_("PTP Access Denied")}, + {PTP_RC_NoThumbnailPresent, N_("PTP No Thumbnail Present")}, + {PTP_RC_SelfTestFailed, N_("PTP Self Test Failed")}, + {PTP_RC_PartialDeletion, N_("PTP Partial Deletion")}, + {PTP_RC_StoreNotAvailable, N_("PTP Store Not Available")}, + {PTP_RC_SpecyficationByFormatUnsupported, + N_("PTP Specyfication By Format Unsupported")}, + {PTP_RC_NoValidObjectInfo, N_("PTP No Valid Object Info")}, + {PTP_RC_InvalidCodeFormat, N_("PTP Invalid Code Format")}, + {PTP_RC_UnknownVendorCode, N_("PTP Unknown Vendor Code")}, + {PTP_RC_CaptureAlreadyTerminated, + N_("PTP Capture Already Terminated")}, + {PTP_RC_DeviceBusy, N_("PTP Device Bus")}, + {PTP_RC_InvalidParentObject, N_("PTP Invalid Parent Object")}, + {PTP_RC_InvalidDevicePropFormat, N_("PTP Invalid Device Prop Format")}, + {PTP_RC_InvalidDevicePropValue, N_("PTP Invalid Device Prop Value")}, + {PTP_RC_InvalidParameter, N_("PTP Invalid Parameter")}, + {PTP_RC_SessionAlreadyOpened, N_("PTP Session Already Opened")}, + {PTP_RC_TransactionCanceled, N_("PTP TransactionCanceled")}, + {PTP_RC_SpecificationOfDestinationUnsupported, + N_("PTP Specification Of Destination Unsupported")}, + + {PTP_ERROR_DATA_EXPECTED, N_("PTP Protocol error, data expected")}, + {PTP_ERROR_RESP_EXPECTED, N_("PTP Protocol error, response expected")}, + {0, NULL} +}; + +static void +report_result (Camera *camera, short result) +{ + unsigned int i; + + for (i = 0; ptp_errors[i].txt; i++) + if (ptp_errors[i].n == result) + gp_camera_set_error (camera, ptp_errors[i].txt); +} + +static int +translate_ptp_result (short result) +{ + switch (result) { + case PTP_RC_ParameterNotSupported: + return (GP_ERROR_BAD_PARAMETERS); + case PTP_RC_OK: + return (GP_OK); + default: + return (GP_ERROR); + } +} + +static short +translate_gp_result (int result) +{ + switch (result) { + case GP_OK: + return (PTP_RC_OK); + case GP_ERROR: + return (PTP_RC_GeneralError); + default: + return (PTP_RC_Undefined); + } +} + +#define CPR(camera,result) {short r=(result); if (r!=PTP_RC_OK) {report_result ((camera), r); return (translate_ptp_result (r));}} static struct { const char *model; @@ -69,24 +154,40 @@ struct _CameraPrivateLibrary { PTPParams params; }; -static PTPResult -ptp_read (unsigned char *bytes, unsigned int size, void *data) +static short +ptp_read_func (unsigned char *bytes, unsigned int size, void *data) { Camera *camera = data; + int result; - PCR (gp_port_read (camera->port, bytes, size)); - - return (PTP_OK); + result = gp_port_read (camera->port, bytes, size); + return (translate_gp_result (result)); } -static PTPResult -ptp_write (unsigned char *bytes, unsigned int size, void *data) +static short +ptp_write_func (unsigned char *bytes, unsigned int size, void *data) { Camera *camera = data; + int result; - PCR (gp_port_write (camera->port, bytes, size)); + result = gp_port_write (camera->port, bytes, size); + return (translate_gp_result (result)); +} - return (PTP_OK); +static void +ptp_debug_func (void *data, const char *format, va_list args) +{ + gp_logv (GP_LOG_DEBUG, "ptp", format, args); +} + +static void +ptp_error_func (void *data, const char *format, va_list args) +{ + Camera *camera = data; + char buf[2048]; + + vsnprintf (buf, sizeof (buf), format, args); + gp_camera_set_error (camera, "%s", buf); } int @@ -123,6 +224,7 @@ static int camera_exit (Camera *camera) { if (camera->pl) { + ptp_closesession (&camera->pl->params); free (camera->pl); camera->pl = NULL; } @@ -139,28 +241,154 @@ camera_about (Camera *camera, CameraText *text) return (GP_OK); } +static int +folder_list_func (CameraFilesystem *fs, const char *folder, CameraList *lsit, + void *data) +{ + Camera *camera = data; + + camera = NULL; + + return (GP_ERROR); +} + +static int +file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list, + void *data) +{ + Camera *camera = data; + PTPObjectHandles handles; + + CPR (camera, ptp_getobjecthandles (&camera->pl->params, &handles)); + + return (GP_ERROR); +} + +static int +get_file_func (CameraFilesystem *fs, const char *folder, const char *name, + CameraFileType type, CameraFile *file, void *data) +{ + Camera *camera = data; + + camera = NULL; + + return (GP_ERROR); +} + +static int +delete_file_func (CameraFilesystem *fs, const char *folder, const char *name, + void *data) +{ + Camera *camera = data; + + camera = NULL; + + return (GP_ERROR); +} + +static int +mkdir_func (CameraFilesystem *fs, const char *folder, const char *name, + void *data) +{ + Camera *camera = data; + + camera = NULL; + + return (GP_ERROR); +} + +static int +rmdir_func (CameraFilesystem *fs, const char *folder, const char *name, + void *data) +{ + Camera *camera = data; + + camera = NULL; + + return (GP_ERROR); +} + +static int +get_info_func (CameraFilesystem *fs, const char *folder, const char *name, + CameraFileInfo *info, void *data) +{ + Camera *camera = data; + + camera = NULL; + + return (GP_ERROR); +} + +static int +set_info_func (CameraFilesystem *fs, const char *folder, const char *name, + CameraFileInfo *info, void *data) +{ + Camera *camera = data; + + camera = NULL; + + return (GP_ERROR); +} + +static int +put_file_func (CameraFilesystem *fs, const char *folder, CameraFile *file, + void *data) +{ + Camera *camera = data; + + camera = NULL; + + return (GP_ERROR); +} + int camera_init (Camera *camera) { - unsigned char c; - PTPResult result; + GPPortSettings settings; + + /* Make sure our port is a USB port */ + if (camera->port->type != GP_PORT_USB) { + gp_camera_set_error (camera, _("PTP is only possible for " + "USB cameras.")); + return (GP_ERROR_UNKNOWN_PORT); + } camera->functions->about = camera_about; camera->functions->exit = camera_exit; + /* We need some data that we pass around */ camera->pl = malloc (sizeof (CameraPrivateLibrary)); if (!camera->pl) return (GP_ERROR_NO_MEMORY); - camera->pl->params.io_write = ptp_write; - camera->pl->params.io_read = ptp_read; - camera->pl->params.io_data = camera; + camera->pl->params.write_func = ptp_write_func; + camera->pl->params.read_func = ptp_read_func; + camera->pl->params.debug_func = ptp_debug_func; + camera->pl->params.error_func = ptp_error_func; + camera->pl->params.data = camera; - result = ptp_do_something (camera->pl->params, '?', &c); - if (result != PTP_OK) { - gp_camera_set_error (camera, _("Unfortunatelly, an error " - "happened...")); - return (GP_ERROR); - } + /* Configure the port */ + CR (gp_port_set_timeout (camera->port, 2000)); + CR (gp_port_get_settings (camera->port, &settings)); + settings.usb.inep = 0x01; + settings.usb.outep = 0x01; + settings.usb.config = 1; + settings.usb.interface = 0; + settings.usb.altsetting = 0; + CR (gp_port_set_settings (camera->port, settings)); + + /* Establish a connection to the camera */ + CPR (camera, ptp_opensession (&camera->pl->params)); + + /* Configure the CameraFilesystem */ + CR (gp_filesystem_set_list_funcs (camera->fs, file_list_func, + folder_list_func, camera)); + CR (gp_filesystem_set_info_funcs (camera->fs, get_info_func, + set_info_func, camera)); + CR (gp_filesystem_set_file_funcs (camera->fs, get_file_func, + delete_file_func, camera)); + CR (gp_filesystem_set_folder_funcs (camera->fs, put_file_func, + NULL, mkdir_func, + rmdir_func, camera)); return (GP_OK); } diff --git a/camlibs/ptp/ptp.c b/camlibs/ptp/ptp.c index 660b754a2..517b781d0 100644 --- a/camlibs/ptp/ptp.c +++ b/camlibs/ptp/ptp.c @@ -18,72 +18,130 @@ * Boston, MA 02111-1307, USA. */ -#include +#include #include "ptp.h" -PTPResult +#include +#include +#include + +#ifdef ENABLE_NLS +# include +# undef _ +# define _(String) dgettext (PACKAGE, String) +# ifdef gettext_noop +# define N_(String) gettext_noop (String) +# else +# define N_(String) (String) +# endif +#else +# define textdomain(String) (String) +# define gettext(String) (String) +# define dgettext(Domain,Message) (Message) +# define dcgettext(Domain,Message,Type) (Message) +# define bindtextdomain(Domain,Directory) (Domain) +# define _(String) (String) +# define N_(String) (String) +#endif + +#define CR(p) {short ret = (p); if (ret != PTP_RC_OK) return (ret);} + +static void +ptp_debug (PTPParams *params, const char *format, ...) +{ + va_list args; + + va_start (args, format); + if (params->debug_func) + params->debug_func (params->data, format, args); + else + vfprintf (stderr, format, args); + va_end (args); +} + +static void +ptp_error (PTPParams *params, const char *format, ...) +{ + va_list args; + + va_start (args, format); + if (params->error_func) + params->error_func (params->data, format, args); + else + vfprintf (stderr, format, args); + va_end (args); +} + +static short ptp_sendreq(PTPParams* params, PTPReq* databuf, short code) { - PTPResult ret; + short ret; PTPReq* req=(databuf==NULL)? malloc(sizeof(PTPReq)):databuf; req->len = PTP_REQ_LEN; req->type = PTP_TYPE_REQ; req->code = code; - req->trans_id = params->id; - params->id++; + req->trans_id = params->transaction_id; + params->transaction_id++; - ret=params->io_write (req, PTP_REQ_LEN, params->io_data); + ptp_debug (params, "Sending request..."); + ret=params->write_func ((unsigned char *) req, PTP_REQ_LEN, + params->data); if (databuf==NULL) free (req); return ret; } -PTPResult +#if 0 +static short ptp_senddata(PTPParams* params, PTPReq* databuf, short code) { - PTPResult ret; + short ret; PTPReq* req=(databuf==NULL)? malloc(sizeof(PTPReq)):databuf; req->len = PTP_REQ_LEN; req->type = PTP_TYPE_DATA; req->code = code; - req->trans_id = params->id; + req->trans_id = params->transaction_id; - ret=params->io_write (req, PTP_REQ_LEN, params->io_data); + ret=params->write_func ((unsigned char *) req, PTP_REQ_LEN, + params->data); if (databuf==NULL) free (req); return ret; } +#endif -PTPResult +static short ptp_getdata(PTPParams* params, PTPReq* databuf) { - PTPResult ret; + short ret; PTPReq* req=(databuf==NULL)? malloc(sizeof(PTPReq)):databuf; memset(req, 0, PTP_RESP_LEN); - ret=params->io_read(req, PTP_RESP_LEN, params->io_data); + ret=params->read_func((unsigned char *) req, PTP_RESP_LEN, + params->data); if (databuf==NULL) free (req); return ret; } -PTPResult +static short ptp_getresp(PTPParams* params, PTPReq* databuf) { - PTPResult ret; + short ret; PTPReq* req=(databuf==NULL)? malloc(sizeof(PTPReq)):databuf; memset(req, 0, PTP_RESP_LEN); - ret=params->io_read(req, PTP_RESP_LEN, params->io_data); + ret=params->read_func((unsigned char*) req, PTP_RESP_LEN, params->data); if (databuf==NULL) free (req); return ret; } // Iniciates connection with device, opens session +#if 0 short ptp_getdevinfo(PTPParams* params, PTPDedviceInfo* devinfo) { @@ -94,21 +152,19 @@ ptp_getdevinfo(PTPParams* params, PTPDedviceInfo* devinfo) if (devinfo==NULL) devinfo=malloc(sizeof(PTPDedviceInfo)); memset(req, 0, PTP_RESP_LEN); ret=ptp_sendreq(params, req,PTP_OC_GetDevInfo); - if (ret!=PTP_OK) { - params->ptp_error("ptp_getdevinfo sending req"); + if (ret!=PTP_RC_OK) { + ptp_error (params, "ptp_getdevinfo sending req"); free(req); return PTP_ERROR_IO; } ret=ptp_getdata(params, req); - if ((ret!=PTP_OK) || + if ((ret!=PTP_RC_OK) || (req->type!=PTP_TYPE_DATA) || (req->code!=PTP_OC_GetDevInfo)) { - params->ptp_error("ptp_getdevinfo getting data"); -#ifdef DEBUG - params->ptp_error("GetDevInfo data returned:\nlen=0x%8.8x " + ptp_error (params, "ptp_getdevinfo getting data"); + ptp_debug (params, "GetDevInfo data returned:\nlen=0x%8.8x " "type=0x%4.4x code=0x%4.4x ID=0x%8.8x\n", req->len, req->type, req->code, req->trans_id); -#endif - if (ret!=PTP_OK) ret=PTP_ERROR_IO; else + if (ret!=PTP_RC_OK) ret=PTP_ERROR_IO; else ret=(req->type==PTP_TYPE_DATA)? req->code:PTP_ERROR_DATA_EXPECTED; free(req); @@ -116,15 +172,13 @@ ptp_getdevinfo(PTPParams* params, PTPDedviceInfo* devinfo) } memcpy(devinfo, req->data,sizeof(PTPDedviceInfo)); ret=ptp_getresp(params, req); - if ((ret!=PTP_OK) || + if ((ret!=PTP_RC_OK) || (req->type!=PTP_TYPE_RESP) || (req->code!=PTP_RC_OK)) { - params->ptp_error("ptp_getdevinfo getting resp"); -#ifdef DEBUG - params->ptp_error("GetDevInfo resp:\nlen=0x%8.8x type=0x%4.4x " + ptp_error (params, "ptp_getdevinfo getting resp"); + ptp_debug (params, "GetDevInfo resp:\nlen=0x%8.8x type=0x%4.4x " "code=0x%4.4x ID=0x%8.8x\n", req->len, req->type, req->code, req->trans_id); -#endif - if (ret!=PTP_OK) ret=PTP_ERROR_IO; else + if (ret!=PTP_RC_OK) ret=PTP_ERROR_IO; else ret=(req->type==PTP_TYPE_RESP)? req->code:PTP_ERROR_RESP_EXPECTED; free(req); @@ -133,32 +187,40 @@ ptp_getdevinfo(PTPParams* params, PTPDedviceInfo* devinfo) free(req); return PTP_RC_OK; } +#endif - +/** + * ptp_opensession: + * @params: #PTPParams + * + * Establishes a new connection. + * + * Return values: Some PTP_RC_* code. + **/ short -ptp_opensession(PTPParams* params, int session) +ptp_opensession(PTPParams* params) { short ret; PTPReq* req=malloc(sizeof(PTPReq)); memset(req, 0, PTP_RESP_LEN); - *(int *)(req->data)=session; + *(int *)(req->data)=1; ret=ptp_sendreq(params, req, PTP_OC_OpenSession); - if (ret!=PTP_OK) { - params->ptp_error("ptp_opensession sending req"); + if (ret!=PTP_RC_OK) { + ptp_error (params, "ptp_opensession sending req"); free(req); return PTP_ERROR_IO; } ret=ptp_getresp(params, req); - if ((ret!=PTP_OK) || + if ((ret!=PTP_RC_OK) || (req->type!=PTP_TYPE_RESP) || (req->code!=PTP_RC_OK)) { - params->ptp_error("ptp_opensession getting resp"); + ptp_error (params, "ptp_opensession getting resp"); #ifdef DEBUG - params->ptp_error("OpenSession resp:\nlen=0x%8.8x" + ptp_error (params, "OpenSession resp:\nlen=0x%8.8x" " type=0x%4.4x code=0x%4.4x ID=0x%8.8x\n", req->len, req->type, req->code, req->trans_id); #endif - if (ret!=PTP_OK) ret=PTP_ERROR_IO; else + if (ret!=PTP_RC_OK) ret=PTP_ERROR_IO; else ret=(req->type==PTP_TYPE_RESP)? req->code:PTP_ERROR_RESP_EXPECTED; free(req); @@ -176,21 +238,21 @@ ptp_closesession(PTPParams* params) memset(req, 0, PTP_RESP_LEN); ret=ptp_sendreq(params, req, PTP_OC_CloseSession); - if (ret!=PTP_OK) { - params->ptp_error("ptp_closesession sending req"); + if (ret!=PTP_RC_OK) { + ptp_error (params, "ptp_closesession sending req"); free(req); return PTP_ERROR_IO; } ret=ptp_getresp(params, req); - if ((ret!=PTP_OK) || + if ((ret!=PTP_RC_OK) || (req->type!=PTP_TYPE_RESP) || (req->code!=PTP_RC_OK)) { - params->ptp_error("ptp_closesession getting resp"); + ptp_error (params, "ptp_closesession getting resp"); #ifdef DEBUG - params->ptp_error("CloseSession resp:\nlen=0x%8.8x" + ptp_error (params, "CloseSession resp:\nlen=0x%8.8x" " type=0x%4.4x code=0x%4.4x ID=0x%8.8x\n", req->len, req->type, req->code, req->trans_id); #endif - if (ret!=PTP_OK) ret=PTP_ERROR_IO; else + if (ret!=PTP_RC_OK) ret=PTP_ERROR_IO; else ret=(req->type==PTP_TYPE_RESP)? req->code:PTP_ERROR_RESP_EXPECTED; free(req); @@ -213,22 +275,22 @@ ptp_getobjecthandles(PTPParams* params, PTPObjectHandles* objecthandles) memset(req, 0, PTP_RESP_LEN); *(int *)(req->data)=0xffffffff; // XXX return from ALL stores ret=ptp_sendreq(params, req, PTP_OC_GetObjectHandles); - if (ret!=PTP_OK) { - params->ptp_error("ptp_getobjecthandles sending req"); + if (ret!=PTP_RC_OK) { + ptp_error (params, "ptp_getobjecthandles sending req"); free(req); return PTP_ERROR_IO; } ret=ptp_getdata(params, req); - if ((ret!=PTP_OK) || + if ((ret!=PTP_RC_OK) || (req->type!=PTP_TYPE_DATA) || (req->code!=PTP_OC_GetObjectHandles)) { - params->ptp_error("ptp_getobjecthandles getting resp"); + ptp_error (params, "ptp_getobjecthandles getting resp"); #ifdef DEBUG - params->ptp_error("GetObjectHandles data returned:\nlen=0x%8.8x" + ptp_error (params, "GetObjectHandles data returned:\nlen=0x%8.8x" " type=0x%4.4x code=0x%4.4x ID=0x%8.8x\n", req->len, req->type, req->code, req->trans_id); #endif - if (ret!=PTP_OK) ret=PTP_ERROR_IO; else + if (ret!=PTP_RC_OK) ret=PTP_ERROR_IO; else ret=(req->type==PTP_TYPE_DATA)? req->code:PTP_ERROR_DATA_EXPECTED; free(req); @@ -236,15 +298,15 @@ ptp_getobjecthandles(PTPParams* params, PTPObjectHandles* objecthandles) } memcpy(objecthandles,req->data,sizeof(PTPObjectHandles)); ret=ptp_getresp(params, req); - if ((ret!=PTP_OK) || + if ((ret!=PTP_RC_OK) || (req->type!=PTP_TYPE_RESP) || (req->code!=PTP_RC_OK)) { - params->ptp_error("ptp_getobjecthandles getting resp"); + ptp_error (params, "ptp_getobjecthandles getting resp"); #ifdef DEBUG - params->ptp_error("GetObjectHandles resp:\nlen=0x%8.8x" + ptp_error (params, "GetObjectHandles resp:\nlen=0x%8.8x" " type=0x%4.4x code=0x%4.4x ID=0x%8.8x\n", req->len, req->type, req->code, req->trans_id); #endif - if (ret!=PTP_OK) ret=PTP_ERROR_IO; else + if (ret!=PTP_RC_OK) ret=PTP_ERROR_IO; else ret=(req->type==PTP_TYPE_RESP)? req->code:PTP_ERROR_RESP_EXPECTED; free(req); @@ -254,6 +316,7 @@ ptp_getobjecthandles(PTPParams* params, PTPObjectHandles* objecthandles) return PTP_RC_OK; } +#if 0 short ptp_getobjectinfo(PTPParams* params, PTPObjectHandles* objecthandles, int n, PTPObjectInfo* objectinfo) @@ -268,22 +331,22 @@ ptp_getobjectinfo(PTPParams* params, PTPObjectHandles* objecthandles, memset(req, 0, PTP_RESP_LEN); *(int *)(req->data)=objecthandles->handler[n]; ret=ptp_sendreq(params, req, PTP_OC_GetObjectInfo); - if (ret!=PTP_OK) { - params->ptp_error("ptp_getobjectsinfo sending req"); + if (ret!=PTP_RC_OK) { + ptp_error (params, "ptp_getobjectsinfo sending req"); free(req); return PTP_ERROR_IO; } ret=ptp_getdata(params, req); - if ((ret!=PTP_OK) || + if ((ret!=PTP_RC_OK) || (req->type!=PTP_TYPE_DATA) || (req->code!=PTP_OC_GetObjectInfo)) { - params->ptp_error("ptp_getobjectsinfo getting data"); + ptp_error (params, "ptp_getobjectsinfo getting data"); #ifdef DEBUG - params->ptp_error("GetObjectInfo data returned:\nlen=0x%8.8x" + ptp_error (params, "GetObjectInfo data returned:\nlen=0x%8.8x" "type=0x%4.4x code=0x%4.4x ID=0x%8.8x\n", req->len, req->type, req->code, req->trans_id); #endif - if (ret!=PTP_OK) ret=PTP_ERROR_IO; else + if (ret!=PTP_RC_OK) ret=PTP_ERROR_IO; else ret=(req->type==PTP_TYPE_DATA)? req->code:PTP_ERROR_DATA_EXPECTED; free(req); @@ -292,16 +355,16 @@ ptp_getobjectinfo(PTPParams* params, PTPObjectHandles* objecthandles, memcpy(objectinfo, req->data, sizeof(PTPObjectInfo)); ret=ptp_getresp(params, req); - if ((ret!=PTP_OK) || + if ((ret!=PTP_RC_OK) || (req->type!=PTP_TYPE_RESP) || (req->code!=PTP_RC_OK)) { - params->ptp_error("ptp_getobjectsinfo getting resp"); + ptp_error (params, "ptp_getobjectsinfo getting resp"); #ifdef DEBUG - params->ptp_error("PTP_OC_GetObjectInfo resp:\nlen=0x%8.8x" + ptp_error (params, "PTP_OC_GetObjectInfo resp:\nlen=0x%8.8x" " type=0x%4.4x code=0x%4.4x ID=0x%8.8x\n", req->len, req->type, req->code, req->trans_id); #endif - if (ret!=PTP_OK) ret=PTP_ERROR_IO; else + if (ret!=PTP_RC_OK) ret=PTP_ERROR_IO; else ret=(req->type==PTP_TYPE_RESP)? req->code:PTP_ERROR_RESP_EXPECTED; free(req); @@ -311,7 +374,7 @@ ptp_getobjectinfo(PTPParams* params, PTPObjectHandles* objecthandles, } return PTP_RC_OK; } - +#endif short ptp_getobject(PTPParams* params, PTPObjectHandles* objecthandles, @@ -329,25 +392,25 @@ ptp_getobject(PTPParams* params, PTPObjectHandles* objecthandles, memset(req, 0, PTP_RESP_LEN); *(int *)(req->data)=objecthandles->handler[n]; ret=ptp_sendreq(params, req, PTP_OC_GetObject); - if (ret!=PTP_OK) { - params->ptp_error("ptp_getobject sending req"); + if (ret!=PTP_RC_OK) { + ptp_error (params, "ptp_getobject sending req"); free(req); return PTP_ERROR_IO; } ptr=req; req=(PTPReq*)object; - ret=params->io_read(req, + ret=params->read_func((unsigned char *) req, objectinfo->ObjectCompressedSize+PTP_REQ_HDR_LEN, - params->io_data); - if ((ret!=PTP_OK) || + params->data); + if ((ret!=PTP_RC_OK) || (req->type!=PTP_TYPE_DATA) || (req->code!=PTP_OC_GetObject)) { - params->ptp_error("ptp_getobject getting data"); + ptp_error (params, "ptp_getobject getting data"); #ifdef DEBUG - params->ptp_error("GetObject data returned:\nlen=0x%8.8x" + ptp_error (params, "GetObject data returned:\nlen=0x%8.8x" "type=0x%4.4x code=0x%4.4x ID=0x%8.8x\n", req->len, req->type, req->code, req->trans_id); #endif - if (ret!=PTP_OK) ret=PTP_ERROR_IO; else + if (ret!=PTP_RC_OK) ret=PTP_ERROR_IO; else ret=(req->type==PTP_TYPE_DATA)? req->code:PTP_ERROR_DATA_EXPECTED; req=ptr; @@ -356,12 +419,12 @@ ptp_getobject(PTPParams* params, PTPObjectHandles* objecthandles, } req=ptr; ret=ptp_getresp(params, req); - if ((ret!=PTP_OK) || + if ((ret!=PTP_RC_OK) || (req->type!=PTP_TYPE_RESP) || (req->code!=PTP_RC_OK)) { - params->ptp_error("ptp_getobject getting resp"); + ptp_error (params, "ptp_getobject getting resp"); #ifdef DEBUG - params->ptp_error("GetObject data returned:\nlen=0x%8.8x" + ptp_error (params, "GetObject data returned:\nlen=0x%8.8x" "type=0x%4.4x code=0x%4.4x ID=0x%8.8x\n", req->len, req->type, req->code, req->trans_id); #endif diff --git a/camlibs/ptp/ptp.h b/camlibs/ptp/ptp.h index 78080f1b2..2f27878cc 100644 --- a/camlibs/ptp/ptp.h +++ b/camlibs/ptp/ptp.h @@ -21,12 +21,7 @@ #ifndef __PTP_H__ #define __PTP_H__ -// PTP protocol constatnts and structures definition folows - -// USB timeout value - -#define PTP_USB_TIMEOUT 2000 - +#include // Container types @@ -109,9 +104,6 @@ #define PTP_ERROR_RESP_EXPECTED 0x2FD #define PTP_ERROR_BADPARAM 0x2fC -// Error description structure -#include "ptperr.h" - // Requests #define PTP_REQ_DATALEN 16384 @@ -177,45 +169,42 @@ struct _PTPObjectInfo { // Glue stuff -typedef enum _PTPResult PTPResult; -enum _PTPResult { - PTP_OK, - PTP_ERROR -}; - -typedef PTPResult (* PTPIOReadFunc) (PTPReq *bytes, - unsigned int size, void *data); -typedef PTPResult (* PTPIOWriteFunc) (PTPReq *bytes, - unsigned int size, void *data); -typedef void (* PTPError) (char *errmsg,...); +typedef short (* PTPIOReadFunc) (unsigned char *bytes, unsigned int size, + void *data); +typedef short (* PTPIOWriteFunc) (unsigned char *bytes, unsigned int size, + void *data); +typedef void (* PTPErrorFunc) (void *data, const char *format, va_list args); +typedef void (* PTPDebugFunc) (void *data, const char *format, va_list args); typedef struct _PTPParams PTPParams; struct _PTPParams { - PTPIOReadFunc io_read; - PTPIOWriteFunc io_write; - PTPError ptp_error; - int id; // Transaction ID - void *io_data; + + /* Custom IO functions */ + PTPIOReadFunc read_func; + PTPIOWriteFunc write_func; + + /* Custom error and debug function */ + PTPErrorFunc error_func; + PTPDebugFunc debug_func; + + /* Data passed to above functions */ + void *data; + + /* Used by libptp */ + unsigned int transaction_id; }; // ptp functions -short -ptp_opensession(PTPParams* params, int session); -short -ptp_closesession(PTPParams* params); -short -ptp_getobjecthandles(PTPParams* params, PTPObjectHandles* objecthandles); -short -ptp_getobjectsinfo(PTPParams* params, PTPObjectHandles* objecthandles, - PTPObjectInfo** objectinfoarray, int n); -short -ptp_getobject(PTPParams* params, PTPObjectHandles* objecthandles, - PTPObjectInfo* objectinfoarray, int n, - char* object); - -/* no more yet ;) */ +short ptp_opensession (PTPParams *params); +short ptp_closesession (PTPParams *params); +short ptp_getobjecthandles (PTPParams *params, PTPObjectHandles* objecthandles); +short ptp_getobjectsinfo (PTPParams *params, PTPObjectHandles* objecthandles, + PTPObjectInfo** objectinfoarray, int n); +short ptp_getobject (PTPParams *params, PTPObjectHandles* objecthandles, + PTPObjectInfo* objectinfoarray, int n, + char* object); #endif /* __PTP_H__ */ diff --git a/camlibs/ptp/ptperr.h b/camlibs/ptp/ptperr.h deleted file mode 100644 index 4481075e8..000000000 --- a/camlibs/ptp/ptperr.h +++ /dev/null @@ -1,46 +0,0 @@ - -static struct { - short n; - const char *txt; -} ptp_errors[] = { - {PTP_RC_Undefined, "PTP Udefined Error"}, - {PTP_RC_OK, "PTP OK!"}, - {PTP_RC_GeneralError, "PTP General Error"}, - {PTP_RC_SessionNotOpen, "PTP Session Not Open"}, - {PTP_RC_InvalidTransactionID, "PTP Invalid Transaction ID"}, - {PTP_RC_OperationNotSupported, "PTP Operation Not Supportsd"}, - {PTP_RC_ParameterNotSupported, "PTP Parameter Not Supported"}, - {PTP_RC_IncompleteTransfer, "PTP Incomplete Transfer"}, - {PTP_RC_InvalidStorageId, "PTP Invalid Storage ID"}, - {PTP_RC_InvalidObjectHandle, "PTP Invalid Object Handle"}, - {PTP_RC_DevicePropNotSupported, "PTP Device Prop Not Supported"}, - {PTP_RC_InvalidObjectFormatCode, "PTP Invalid Object Format Code"}, - {PTP_RC_StoreFull, "PTP Store Full"}, - {PTP_RC_ObjectWriteProtected, "PTP Object Write Protected"}, - {PTP_RC_StoreReadOnly, "PTP Store Read Only"}, - {PTP_RC_AccessDenied, "PTP Access Denied"}, - {PTP_RC_NoThumbnailPresent, "PTP No Thumbnail Present"}, - {PTP_RC_SelfTestFailed, "PTP Self Test Failed"}, - {PTP_RC_PartialDeletion, "PTP Partial Deletion"}, - {PTP_RC_StoreNotAvailable, "PTP Store Not Available"}, - {PTP_RC_SpecyficationByFormatUnsupported, - "PTP Specyfication By Format Unsupported"}, - {PTP_RC_NoValidObjectInfo, "PTP No Valid Object Info"}, - {PTP_RC_InvalidCodeFormat, "PTP Invalid Code Format"}, - {PTP_RC_UnknownVendorCode, "PTP Unknown Vendor Code"}, - {PTP_RC_CaptureAlreadyTerminated, - "PTP Capture Already Terminated"}, - {PTP_RC_DeviceBusy, "PTP Device Bus"}, - {PTP_RC_InvalidParentObject, "PTP Invalid Parent Object"}, - {PTP_RC_InvalidDevicePropFormat, "PTP Invalid Device Prop Format"}, - {PTP_RC_InvalidDevicePropValue, "PTP Invalid Device Prop Value"}, - {PTP_RC_InvalidParameter, "PTP Invalid Parameter"}, - {PTP_RC_SessionAlreadyOpened, "PTP Session Already Opened"}, - {PTP_RC_TransactionCanceled, "PTP TransactionCanceled"}, - {PTP_RC_SpecificationOfDestinationUnsupported, - "PTP Specification Of Destination Unsupported"}, - - {PTP_ERROR_DATA_EXPECTED, "PTP Protocol error, data expected"}, - {PTP_ERROR_RESP_EXPECTED, "PTP Protocol error, response expected"}, -}; -