From a389561dddad777e3d86f6371ba1f856d3533121 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Mon, 29 Apr 2013 21:56:38 +0200 Subject: Add capability to check for capabilities This adds and API to check a device for specific capabilities, when need be. Signed-off-by: Linus Walleij --- src/libmtp.c | 39 +++++++++++++++++++++++++++++++++++++++ src/libmtp.h.in | 27 ++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/libmtp.c b/src/libmtp.c index 46edab7..24382cd 100644 --- a/src/libmtp.c +++ b/src/libmtp.c @@ -3918,6 +3918,45 @@ int LIBMTP_Get_Supported_Filetypes(LIBMTP_mtpdevice_t *device, uint16_t ** const return 0; } +/** + * This function checks if the device has some specific capabilities, in + * order to avoid calling APIs that may disturb the device. + * + * @param device a pointer to the device to check the capability on. + * @param cap the capability to check. + * @return 0 if not supported, any other value means the device has the + * requested capability. + */ +int LIBMTP_Check_Capability(LIBMTP_mtpdevice_t *device, LIBMTP_devicecap_t cap) +{ + switch (cap) { + case LIBMTP_DEVICECAP_GetPartialObject: + return (ptp_operation_issupported(device->params, + PTP_OC_GetPartialObject) || + ptp_operation_issupported(device->params, + PTP_OC_ANDROID_GetPartialObject64)); + case LIBMTP_DEVICECAP_SendPartialObject: + return ptp_operation_issupported(device->params, + PTP_OC_ANDROID_SendPartialObject); + case LIBMTP_DEVICECAP_EditObjects: + return (ptp_operation_issupported(device->params, + PTP_OC_ANDROID_TruncateObject) && + ptp_operation_issupported(device->params, + PTP_OC_ANDROID_BeginEditObject) && + ptp_operation_issupported(device->params, + PTP_OC_ANDROID_EndEditObject)); + /* + * Handle other capabilities here, this is also a good place to + * blacklist some advanced operations on specific devices if need + * be. + */ + + default: + break; + } + return 0; +} + /** * This function updates all the storage id's of a device and their * properties, then creates a linked list and puts the list head into diff --git a/src/libmtp.h.in b/src/libmtp.h.in index 9c1c73f..7a9001e 100644 --- a/src/libmtp.h.in +++ b/src/libmtp.h.in @@ -2,7 +2,7 @@ * \file libmtp.h * Interface to the Media Transfer Protocol library. * - * Copyright (C) 2005-2012 Linus Walleij + * Copyright (C) 2005-2013 Linus Walleij * Copyright (C) 2005-2008 Richard A. Low * Copyright (C) 2007 Ted Bullock * Copyright (C) 2008 Florent Mertens @@ -402,6 +402,30 @@ typedef enum { LIBMTP_DATATYPE_UINT64, } LIBMTP_datatype_t; +/** + * These are device capabilities + */ +typedef enum { + /** + * This capability tells whether you can call the funcion getting + * partial objects, @see LIBMTP_GetPartialObject() + */ + LIBMTP_DEVICECAP_GetPartialObject, + /** + * This capability tells whether you can call the function sending + * partial objects. @see LIBMTP_SendPartialObject() + */ + LIBMTP_DEVICECAP_SendPartialObject, + /** + * This capability tells whether you can call the functions editing + * objects in-place on a device. + * @see LIBMTP_BeginEditObject() + * @see LIBMTP_EndEditObject() + * @see LIBMTP_TruncateObject() + */ + LIBMTP_DEVICECAP_EditObjects, +} LIBMTP_devicecap_t; + /** * These are the numbered error codes. You can also * get string representations for errors. @@ -825,6 +849,7 @@ int LIBMTP_Get_Batterylevel(LIBMTP_mtpdevice_t *, int LIBMTP_Get_Secure_Time(LIBMTP_mtpdevice_t *, char ** const); int LIBMTP_Get_Device_Certificate(LIBMTP_mtpdevice_t *, char ** const); int LIBMTP_Get_Supported_Filetypes(LIBMTP_mtpdevice_t *, uint16_t ** const, uint16_t * const); +int LIBMTP_Check_Capability(LIBMTP_mtpdevice_t *, LIBMTP_devicecap_t); LIBMTP_error_t *LIBMTP_Get_Errorstack(LIBMTP_mtpdevice_t*); void LIBMTP_Clear_Errorstack(LIBMTP_mtpdevice_t*); void LIBMTP_Dump_Errorstack(LIBMTP_mtpdevice_t*); -- cgit v1.2.1