Ejemplo n.º 1
0
 idevice_error_t idevice_get_device_list(char ***devices, int *count)
{
	usbmuxd_device_info_t *dev_list;

	*devices = NULL;
	*count = 0;
	int ret=0;
	if ((ret=usbmuxd_get_device_list(&dev_list)) < 0) {
		debug_info("ERROR: usbmuxd is not running!", __func__);
		return IDEVICE_E_NO_DEVICE;
	}

	char **newlist = NULL;
	int i, newcount = 0;

	for (i = 0; dev_list[i].handle > 0; i++) {
		newlist = (char**)realloc(*devices, sizeof(char*)* (newcount + 1));
		newlist[newcount++] = _strdup(dev_list[i].udid);
		*devices = newlist;
	}
	usbmuxd_device_list_free(&dev_list);

	*count = newcount;
	newlist = (char**)realloc(*devices, sizeof(char*)* (newcount + 1));
	newlist[newcount] = NULL;
	*devices = newlist;

	return IDEVICE_E_SUCCESS;
}
Ejemplo n.º 2
0
/**
 * Get a list of currently available devices.
 *
 * @param devices List of uuids of devices that are currently available.
 *   This list is terminated by a NULL pointer.
 * @param count Number of devices found.
 *
 * @return IPHONE_E_SUCCESS on success or an error value when an error occured.
 */
iphone_error_t iphone_get_device_list(char ***devices, int *count)
{
	usbmuxd_device_info_t *dev_list;

	*devices = NULL;
	*count = 0;

	if (usbmuxd_get_device_list(&dev_list) < 0) {
		log_debug_msg("%s: ERROR: usbmuxd is not running!\n", __func__);
		return IPHONE_E_NO_DEVICE;
	}

	char **newlist = NULL;
	int i, newcount = 0;

	for (i = 0; dev_list[i].handle > 0; i++) {
		newlist = realloc(*devices, sizeof(char*) * (newcount+1));
		newlist[newcount++] = strdup(dev_list[i].uuid);
		*devices = newlist;
	}
	usbmuxd_device_list_free(&dev_list);

	*count = newcount;
	newlist = realloc(*devices, sizeof(char*) * (newcount+1));
	newlist[newcount] = NULL;
	*devices = newlist;

	return IPHONE_E_SUCCESS;
}
Ejemplo n.º 3
0
LIBIMOBILEDEVICE_API idevice_error_t idevice_get_device_list(char ***devices, int *count)
{
	usbmuxd_device_info_t *dev_list;

	*devices = NULL;
	*count = 0;

	if (usbmuxd_get_device_list(&dev_list) < 0) {
		debug_info("ERROR: usbmuxd is not running!", __func__);
		return IDEVICE_E_NO_DEVICE;
	}

	char **newlist = NULL;
	int i, newcount = 0;

	for (i = 0; dev_list[i].handle > 0; i++) {
		newlist = realloc(*devices, sizeof(char*) * (newcount+1));
		const char * connectionType = NULL;
		switch (dev_list[i].connection_type) {
			case UC_USB:
				connectionType = "USB";
				break;
			case UC_WIFI:
				connectionType = "WIFI";
				break;
			default:
				connectionType = "unknown";
		}
		size_t devNameLen = strlen(connectionType) + strlen(dev_list[i].udid) + strlen("%s (%s)") + 1;
		newlist[newcount] = malloc(devNameLen);
		snprintf(newlist[newcount],devNameLen, "%s (%s)",dev_list[i].udid,connectionType);
		newcount++;
		*devices = newlist;
	}
	usbmuxd_device_list_free(&dev_list);

	*count = newcount;
	newlist = realloc(*devices, sizeof(char*) * (newcount+1));
	newlist[newcount] = NULL;
	*devices = newlist;

	return IDEVICE_E_SUCCESS;
}