New API function to retrieve the number of devices in a list of connected devices
diff --git a/ChangeLog b/ChangeLog
index 4d6a0dc..36c9fc0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,13 +1,19 @@
-2007-02-22 Ted Bullock <tbullock@canada.com>
+2007-03-03 Ted Bullock <tbullock@canada.com>
* src/libusb-glue.c: Don't echo warnings about reading a single
extra byte on devices in which DEVICE_FLAG_NO_ZERO_READS has
been set
+ * src/libmtp.c: New API function to retrieve the number of devices
+ in a list of connected devices
+ * src/libmtp.h: New API function to retrieve the number of devices
+ in a list of connected devices
+ * examples/detect.c: Use new API function to count number of devices
+ that were detected
-2007-02-28 Linus Walleij <triad@df.lth.se>
+2007-03-03 Linus Walleij <triad@df.lth.se>
* src/libusb-glue.h: Tiresome ramblings to explain exactly what
- the (no renamed) device flag DEVICE_FLAG_NO_ZERO_READS really
+ the (now renamed) device flag DEVICE_FLAG_NO_ZERO_READS really
means.
* src/libusb-glue.c: Renamed flag. Indent code :-) Reading the code
and being impressed by our ability to iron out the root cause
diff --git a/examples/detect.c b/examples/detect.c
index fc28b25..9c7633f 100644
--- a/examples/detect.c
+++ b/examples/detect.c
@@ -69,6 +69,7 @@
uint16_t filetypes_len;
uint8_t maxbattlevel;
uint8_t currbattlevel;
+ uint32_t numdevices;
int ret;
int probeonly = 0;
@@ -116,8 +117,8 @@
/* Successfully connected at least one device, so continue */
case LIBMTP_ERROR_NONE:
- fprintf(stdout, "Detect: Successfully connected\n");
- fflush(stdout);
+ numdevices = LIBMTP_Number_Devices_In_List(device);
+ fprintf(stdout, "Detect: Successfully connected %u devices\n", numdevices);
}
/* iterate through connected MTP devices */
diff --git a/src/libmtp.c b/src/libmtp.c
index 99c86ab..5a8c089 100644
--- a/src/libmtp.c
+++ b/src/libmtp.c
@@ -890,6 +890,21 @@
}
/**
+ * Get the number of devices that are available in the listed device list
+ * @param DevList Pointer to a linked list of devices
+ * @return Number of devices in the device list DevList
+ */
+uint32_t LIBMTP_Number_Devices_In_List(LIBMTP_mtpdevice_t *DevList)
+{
+ uint32_t numdevices = 0;
+ LIBMTP_mtpdevice_t *iter;
+ for(iter = DevList; iter != NULL; iter = iter->next)
+ numdevices++;
+
+ return numdevices;
+}
+
+/**
* Get the first connected MTP device node in the linked list of devices.
* Currently this only provides access to USB devices
* @param Pointer to first device (if possible), filled after function executes
diff --git a/src/libmtp.h.in b/src/libmtp.h.in
index 6c0020a..d047079 100644
--- a/src/libmtp.h.in
+++ b/src/libmtp.h.in
@@ -345,6 +345,7 @@
int LIBMTP_Detect_Descriptor(uint16_t*,uint16_t*);
LIBMTP_mtpdevice_t *LIBMTP_Get_First_Device(void);
LIBMTP_error_number_t LIBMTP_Get_Connected_Devices(LIBMTP_mtpdevice_t **);
+uint32_t LIBMTP_Number_Devices_In_List(LIBMTP_mtpdevice_t *);
void LIBMTP_Release_Device_List(LIBMTP_mtpdevice_t*);
void LIBMTP_Release_Device(LIBMTP_mtpdevice_t*);
void LIBMTP_Dump_Device_Info(LIBMTP_mtpdevice_t*);