Esempio n. 1
0
static int
udevman_register_udevice(IUDEVMAN* idevman, int bus_number, int dev_number, 
    int UsbDevice, uint16_t idVendor, uint16_t idProduct, char * option)
{
	UDEVMAN * udevman = (UDEVMAN *) idevman;
	IUDEVICE* pdev;

	if (option && strcmp(option, "new") == 0)
	{
		pdev = udev_new_by_addr(bus_number, dev_number);
		if (pdev == NULL)
			return 0;
	}
	else if (option && strcmp(option, "renew") == 0)
	{
		pdev = udev_new_by_id(idVendor, idProduct);
		if (pdev == NULL)
			return 0;
	}
	else
	{
		printf("udevman_register_udevice: function error!!");
		return 0;
	}

	pdev->set_UsbDevice(pdev, UsbDevice);


	if (udevman->head == NULL)
	{
		/* linked list is empty */
		udevman->head = pdev;
		udevman->tail = pdev;
	}
	else
	{
		/* append device to the end of the linked list */
		udevman->tail->set_p_next(udevman->tail, pdev);
		pdev->set_p_prev(pdev, udevman->tail);
		udevman->tail = pdev;
	}
	udevman->device_num += 1;

	return 1;
}
Esempio n. 2
0
static int
udevman_register_udevice(IUDEVMAN* idevman, int bus_number, int dev_number, 
	int UsbDevice, 
	uint16 idVendor, 
	uint16 idProduct, 
	int flag)
{
	UDEVMAN * udevman = (UDEVMAN *) idevman;
	IUDEVICE * pdev = NULL;
	IUDEVICE ** devArray;
	int i, num, addnum = 0;
	
	pdev = (IUDEVICE *)udevman_get_udevice_by_addr(idevman, bus_number, dev_number);
	if (pdev != NULL)
		return 0;
	
	if (flag == UDEVMAN_FLAG_ADD_BY_ADDR)
	{
		pdev = udev_new_by_addr(bus_number, dev_number);
		if (pdev == NULL)
			return 0;

		pdev->set_UsbDevice(pdev, UsbDevice);
		idevman->loading_lock(idevman);
		if (udevman->head == NULL)
		{
			/* linked list is empty */
			udevman->head = pdev;
			udevman->tail = pdev;
		}
		else
		{
			/* append device to the end of the linked list */
			udevman->tail->set_p_next(udevman->tail, pdev);
			pdev->set_p_prev(pdev, udevman->tail);
			udevman->tail = pdev;
		}
		udevman->device_num += 1;
		idevman->loading_unlock(idevman);
	}
	else if (flag == UDEVMAN_FLAG_ADD_BY_VID_PID)
	{
		addnum = 0;
		/* register all device that match pid vid */
		num = udev_new_by_id(idVendor, idProduct, &devArray);
		for (i = 0; i < num; i++)
		{
			pdev = devArray[i];
			if (udevman_get_udevice_by_addr(idevman, 
					pdev->get_bus_number(pdev), 
					pdev->get_dev_number(pdev)) 
				!= NULL)
			{
				zfree(pdev);
				continue;
			}

			pdev->set_UsbDevice(pdev, UsbDevice);
			idevman->loading_lock(idevman);
			if (udevman->head == NULL)
			{
				/* linked list is empty */
				udevman->head = pdev;
				udevman->tail = pdev;
			}
			else
			{
				/* append device to the end of the linked list */
				udevman->tail->set_p_next(udevman->tail, pdev);
				pdev->set_p_prev(pdev, udevman->tail);
				udevman->tail = pdev;
			}
			udevman->device_num += 1;
			idevman->loading_unlock(idevman);
			addnum++;
		}
		zfree(devArray);
		return addnum;
	}
	else
	{
		printf("udevman_register_udevice: function error!!");
		return 0;
	}
	return 1;
}