summaryrefslogtreecommitdiffstats
path: root/libusbmuxd
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-09-08 20:42:00 +0200
committerGravatar Nikias Bassen2009-09-08 20:42:00 +0200
commita93c66e2bff0065ad2ac93998048f065e51a784c (patch)
tree8e56c01bdb584f5bbe1d3ef085ed7b68501b7c8a /libusbmuxd
parent8bd54babbe6d3309f78f9d8729d93f83c14d23f5 (diff)
downloadusbmuxd-a93c66e2bff0065ad2ac93998048f065e51a784c.tar.gz
usbmuxd-a93c66e2bff0065ad2ac93998048f065e51a784c.tar.bz2
Protocol definition updated.
renamed: usbmuxd_scan() -> usbmuxd_get_device_list() new: usbmuxd_get_device_by_uuid()
Diffstat (limited to 'libusbmuxd')
-rw-r--r--libusbmuxd/libusbmuxd.c47
-rw-r--r--libusbmuxd/usbmuxd.h24
2 files changed, 61 insertions, 10 deletions
diff --git a/libusbmuxd/libusbmuxd.c b/libusbmuxd/libusbmuxd.c
index 584e930..a00ceb0 100644
--- a/libusbmuxd/libusbmuxd.c
+++ b/libusbmuxd/libusbmuxd.c
@@ -296,7 +296,7 @@ int usbmuxd_unsubscribe()
return 0;
}
-int usbmuxd_scan(usbmuxd_device_info_t ** available_devices)
+int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list)
{
struct usbmuxd_listen_request s_req;
int sfd;
@@ -340,7 +340,7 @@ int usbmuxd_scan(usbmuxd_device_info_t ** available_devices)
return -1;
}
- *available_devices = NULL;
+ *device_list = NULL;
// receive device list
while (1) {
if (recv_buf_timeout(sfd, &hdr, sizeof(hdr), 0, 1000) == sizeof(hdr)) {
@@ -362,7 +362,7 @@ int usbmuxd_scan(usbmuxd_device_info_t ** available_devices)
fprintf(stderr,
"%s: received less data than specified in header!\n", __func__);
} else {
- newlist = (usbmuxd_device_info_t *) realloc(*available_devices, sizeof(usbmuxd_device_info_t) * (dev_cnt + 1));
+ newlist = (usbmuxd_device_info_t *) realloc(*device_list, sizeof(usbmuxd_device_info_t) * (dev_cnt + 1));
if (newlist) {
newlist[dev_cnt].handle =
(int) dev_info.device_id;
@@ -373,7 +373,7 @@ int usbmuxd_scan(usbmuxd_device_info_t ** available_devices)
memcpy(newlist[dev_cnt].uuid,
dev_info.serial_number,
sizeof(newlist[dev_cnt].uuid));
- *available_devices = newlist;
+ *device_list = newlist;
dev_cnt++;
} else {
fprintf(stderr,
@@ -390,13 +390,48 @@ int usbmuxd_scan(usbmuxd_device_info_t ** available_devices)
}
// terminating zero record
- newlist = (usbmuxd_device_info_t*) realloc(*available_devices, sizeof(usbmuxd_device_info_t) * (dev_cnt + 1));
+ newlist = (usbmuxd_device_info_t*) realloc(*device_list, sizeof(usbmuxd_device_info_t) * (dev_cnt + 1));
memset(newlist + dev_cnt, 0, sizeof(usbmuxd_device_info_t));
- *available_devices = newlist;
+ *device_list = newlist;
return dev_cnt;
}
+int usbmuxd_get_device_by_uuid(const char *uuid, usbmuxd_device_info_t *device)
+{
+ usbmuxd_device_info_t *dev_list = NULL;
+
+ if (!device) {
+ return -EINVAL;
+ }
+ if (usbmuxd_get_device_list(&dev_list) < 0) {
+ return -ENODEV;
+ }
+
+ int i;
+ int result = 0;
+ for (i = 0; dev_list[i].handle > 0; i++) {
+ if (!uuid) {
+ device->handle = dev_list[i].handle;
+ device->product_id = dev_list[i].product_id;
+ strcpy(device->uuid, dev_list[i].uuid);
+ result = 1;
+ break;
+ }
+ if (!strcmp(uuid, dev_list[i].uuid)) {
+ device->handle = dev_list[i].handle;
+ device->product_id = dev_list[i].product_id;
+ strcpy(device->uuid, dev_list[i].uuid);
+ result = 1;
+ break;
+ }
+ }
+
+ free(dev_list);
+
+ return result;
+}
+
int usbmuxd_connect(const int handle, const unsigned short port)
{
int sfd;
diff --git a/libusbmuxd/usbmuxd.h b/libusbmuxd/usbmuxd.h
index a4e7e4a..106f921 100644
--- a/libusbmuxd/usbmuxd.h
+++ b/libusbmuxd/usbmuxd.h
@@ -57,12 +57,28 @@ int usbmuxd_unsubscribe();
/**
* Contacts usbmuxd and retrieves a list of connected devices.
*
- * @param available_devices pointer to an array of usbmuxd_device_info_t
- * that will hold records of the connected devices.
+ * @param device_list A pointer to an array of usbmuxd_device_info_t
+ * that will hold records of the connected devices. The last record
+ * is a null-terminated record with all fields set to 0/NULL.
+ * @note The user has to free the list returned.
*
- * @return number of available devices, zero on no devices, or negative on error
+ * @return number of attached devices, zero on no devices, or negative
+ * if an error occured.
*/
-int usbmuxd_scan(usbmuxd_device_info_t **available_devices);
+int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list);
+
+/**
+ * Gets device information for the device specified by uuid.
+ *
+ * @param uuid A device uuid of the device to look for. If uuid is NULL,
+ * This function will return the first device found.
+ * @param device Pointer to a previously allocated (or static)
+ * usbmuxd_device_info_t that will be filled with the device info.
+ *
+ * @return 0 if no matching device is connected, 1 if the device was found,
+ * or a negative value on error.
+ */
+int usbmuxd_get_device_by_uuid(const char *uuid, usbmuxd_device_info_t *device);
/**
* Request proxy connect to