From a700d220088b2042e3a4198ee78baf5691330db2 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Wed, 28 May 2008 23:06:14 +0000 Subject: Refactor to use raw devices internally (major change!) --- examples/detect.c | 64 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 25 deletions(-) (limited to 'examples/detect.c') diff --git a/examples/detect.c b/examples/detect.c index 4bec7b0..aef9593 100644 --- a/examples/detect.c +++ b/examples/detect.c @@ -72,6 +72,7 @@ int main (int argc, char **argv) uint8_t currbattlevel; int numrawdevices; uint32_t numdevices; + LIBMTP_error_number_t err; int ret; int probeonly = 0; @@ -80,34 +81,47 @@ int main (int argc, char **argv) fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); fprintf(stdout, "Listing raw device(s)\n"); - ret = LIBMTP_Detect_Raw_Devices(&rawdevices, &numrawdevices); - if (ret != 0) { - fprintf(stderr, "Detect: Error retrieveing raw devices.\n"); - } else if (numrawdevices == 0) { + err = LIBMTP_Detect_Raw_Devices(&rawdevices, &numrawdevices); + switch(err) { + case LIBMTP_ERROR_NO_DEVICE_ATTACHED: fprintf(stdout, " No raw devices found.\n"); - } else { - int i; - - fprintf(stdout, " Found %d device(s):\n", numrawdevices); - for (i = 0; i < numrawdevices; i++) { - if (rawdevices[i].device_entry.vendor != NULL || - rawdevices[i].device_entry.product != NULL) { - fprintf(stdout, " %s: %s (%04x:%04x) @ bus %d, dev %d\n", - rawdevices[i].device_entry.vendor, - rawdevices[i].device_entry.product, - rawdevices[i].device_entry.vendor_id, - rawdevices[i].device_entry.product_id, - rawdevices[i].bus_location, - rawdevices[i].devnum); - } else { - fprintf(stdout, " %04x:%04x @ bus %d, dev %d\n", - rawdevices[i].device_entry.vendor_id, - rawdevices[i].device_entry.product_id, - rawdevices[i].bus_location, - rawdevices[i].devnum); + break; + case LIBMTP_ERROR_CONNECTING: + fprintf(stderr, "Detect: There has been an error connecting. Exiting\n"); + return 1; + case LIBMTP_ERROR_MEMORY_ALLOCATION: + fprintf(stderr, "Detect: Encountered a Memory Allocation Error. Exiting\n"); + return 1; + case LIBMTP_ERROR_NONE: + { + int i; + + fprintf(stdout, " Found %d device(s):\n", numrawdevices); + for (i = 0; i < numrawdevices; i++) { + if (rawdevices[i].device_entry.vendor != NULL || + rawdevices[i].device_entry.product != NULL) { + fprintf(stdout, " %s: %s (%04x:%04x) @ bus %d, dev %d\n", + rawdevices[i].device_entry.vendor, + rawdevices[i].device_entry.product, + rawdevices[i].device_entry.vendor_id, + rawdevices[i].device_entry.product_id, + rawdevices[i].bus_location, + rawdevices[i].devnum); + } else { + fprintf(stdout, " %04x:%04x @ bus %d, dev %d\n", + rawdevices[i].device_entry.vendor_id, + rawdevices[i].device_entry.product_id, + rawdevices[i].bus_location, + rawdevices[i].devnum); + } } + free(rawdevices); } - free(rawdevices); + break; + case LIBMTP_ERROR_GENERAL: + default: + fprintf(stderr, "Unknown connection error.\n"); + break; } fprintf(stdout, "Attempting to connect device(s)\n"); -- cgit v1.2.1