From def26d6b204d71f21247cd582012c21e63fa6464 Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Fri, 10 Jul 2009 17:25:44 +0000 Subject: [PATCH] generic wrapper ptp command function added ported some old wrapper functions to be just macros. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@12211 67ed7778-7388-44ab-90cf-0a291f65f57c --- camlibs/ptp2/ChangeLog | 6 +++ camlibs/ptp2/ptp.c | 103 +++++++++++++---------------------------- camlibs/ptp2/ptp.h | 37 +++++++++++++-- 3 files changed, 72 insertions(+), 74 deletions(-) diff --git a/camlibs/ptp2/ChangeLog b/camlibs/ptp2/ChangeLog index 741fc0faa..616fa4d1d 100644 --- a/camlibs/ptp2/ChangeLog +++ b/camlibs/ptp2/ChangeLog @@ -1,3 +1,9 @@ +2009-07-10 Marcus Meissner + + * ptp.c,ptp.h: Generic PTP wrapper function (no data, no output) + to avoid coding all generic functions as seperate functions. + Started converting functions to macros. + 2009-07-09 Axel Waggershauser * ptp.c: Some sprintf format adjustments. * ptp.h: EOS_RemoteRelease doc comments. diff --git a/camlibs/ptp2/ptp.c b/camlibs/ptp2/ptp.c index a31bbeba1..3c5216b53 100644 --- a/camlibs/ptp2/ptp.c +++ b/camlibs/ptp2/ptp.c @@ -447,6 +447,39 @@ ptp_canon_eos_getdeviceinfo (PTPParams* params, PTPCanonEOSDeviceInfo*di) return ret; } +/** + * ptp_generic_no_data: + * params: PTPParams* + * code PTP OP Code + * n_param count of parameters + * ... variable argument list ... + * + * Emits a generic PTP command without any data transfer. + * + * Return values: Some PTP_RC_* code. + **/ +uint16_t +ptp_generic_no_data (PTPParams* params, uint16_t code, unsigned int n_param, ...) +{ + PTPContainer ptp; + va_list args; + int i; + + if( n_param > 5 ) + return PTP_RC_InvalidParameter; + + PTP_CNT_INIT(ptp); + ptp.Code=code; + ptp.Nparam=n_param; + + va_start(args, n_param); + for( i=0; iresponse_packet_size > 0) { - free(params->response_packet); - params->response_packet = NULL; - params->response_packet_size = 0; - } - PTP_CNT_INIT(ptp); - ptp.Code=PTP_OC_CloseSession; - ptp.Nparam=0; - return ptp_transaction_new(params, &ptp, PTP_DP_NODATA, 0, NULL); -} - /** * ptp_free_params: * params: PTPParams* @@ -532,27 +538,6 @@ ptp_free_params (PTPParams *params) { ptp_free_DI (¶ms->deviceinfo); } -/** - * ptp_resetdevice: - * params: PTPParams* - * - * Uses the built-in function to reset the device - * - * Return values: Some PTP_RC_* code. - * - */ -uint16_t -ptp_resetdevice (PTPParams* params) -{ - PTPContainer ptp; - - PTP_CNT_INIT(ptp); - ptp.Code=PTP_OC_ResetDevice; - ptp.Nparam=0; - - return ptp_transaction_new(params, &ptp, PTP_DP_NODATA, 0, NULL); -} - /** * ptp_getststorageids: * params: PTPParams* @@ -609,28 +594,6 @@ ptp_getstorageinfo (PTPParams* params, uint32_t storageid, return ret; } -/** - * ptp_formatstore: - * params: PTPParams* - * storageid - StorageID - * - * Formats the storage on the device. - * - * Return values: Some PTP_RC_* code. - **/ -uint16_t -ptp_formatstore (PTPParams* params, uint32_t storageid) -{ - PTPContainer ptp; - - PTP_CNT_INIT(ptp); - ptp.Code=PTP_OC_FormatStore; - ptp.Param1=storageid; - ptp.Param2=PTP_FST_Undefined; - ptp.Nparam=2; - return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); -} - /** * ptp_getobjecthandles: * params: PTPParams* diff --git a/camlibs/ptp2/ptp.h b/camlibs/ptp2/ptp.h index 9e1528854..cc0746d31 100644 --- a/camlibs/ptp2/ptp.h +++ b/camlibs/ptp2/ptp.h @@ -1993,14 +1993,43 @@ uint16_t ptp_ptpip_event_check (PTPParams* params, PTPContainer* event); uint16_t ptp_getdeviceinfo (PTPParams* params, PTPDeviceInfo* deviceinfo); -uint16_t ptp_opensession (PTPParams *params, uint32_t session); -uint16_t ptp_closesession (PTPParams *params); +uint16_t ptp_generic_no_data (PTPParams* params, uint16_t opcode, unsigned int cnt, ...); + +uint16_t ptp_opensession (PTPParams *params, uint32_t session); + +/** + * ptp_closesession: + * params: PTPParams* + * + * Closes session. + * + * Return values: Some PTP_RC_* code. + **/ +#define ptp_closesession(params) ptp_generic_no_data(params,PTP_OC_CloseSession,0) +/** + * ptp_resetdevice: + * params: PTPParams* + * + * Uses the built-in function to reset the device + * + * Return values: Some PTP_RC_* code. + * + */ +#define ptp_resetdevice(params) ptp_generic_no_data(params,PTP_OC_ResetDevice,0) -uint16_t ptp_resetdevice (PTPParams* params); uint16_t ptp_getstorageids (PTPParams* params, PTPStorageIDs* storageids); uint16_t ptp_getstorageinfo (PTPParams* params, uint32_t storageid, PTPStorageInfo* storageinfo); -uint16_t ptp_formatstore (PTPParams* params, uint32_t storageid); +/** + * ptp_formatstore: + * params: PTPParams* + * storageid - StorageID + * + * Formats the storage on the device. + * + * Return values: Some PTP_RC_* code. + **/ +#define ptp_formatstore(params,storageid) ptp_generic_no_data(params,PTP_OC_FormatStore,1,storageid) uint16_t ptp_getobjecthandles (PTPParams* params, uint32_t storage, uint32_t objectformatcode,