summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Walleij <triad@df.lth.se>2013-04-29 21:56:38 +0200
committerLinus Walleij <triad@df.lth.se>2013-04-29 21:56:38 +0200
commita389561dddad777e3d86f6371ba1f856d3533121 (patch)
tree6ab5f1ea3481e84f17ea282d8b7298052c6c3041
parent403971069a07d46ddda4100554f5ecb49cc33121 (diff)
downloadlibmtp-a389561dddad777e3d86f6371ba1f856d3533121.tar.gz
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 <triad@df.lth.se>
-rw-r--r--src/libmtp.c39
-rw-r--r--src/libmtp.h.in27
2 files changed, 65 insertions, 1 deletions
diff --git a/src/libmtp.c b/src/libmtp.c
index 46edab7..24382cd 100644
--- a/src/libmtp.c
+++ b/src/libmtp.c
@@ -3919,6 +3919,45 @@ int LIBMTP_Get_Supported_Filetypes(LIBMTP_mtpdevice_t *device, uint16_t ** const
}
/**
+ * 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
* the device struct. It also optionally sorts this list. If you want
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 <triad@df.lth.se>
+ * Copyright (C) 2005-2013 Linus Walleij <triad@df.lth.se>
* Copyright (C) 2005-2008 Richard A. Low <richard@wentnet.com>
* Copyright (C) 2007 Ted Bullock <tbullock@canada.com>
* Copyright (C) 2008 Florent Mertens <flomertens@gmail.com>
@@ -403,6 +403,30 @@ typedef enum {
} 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*);