- mcdp renamed to java

git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@144 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
schlaepfer
2006-05-05 08:43:29 +00:00
parent 1468369ac7
commit 86ac913d63
23 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
package ch.ntb.usb;
import java.util.Iterator;
import java.util.LinkedList;
import ch.ntb.usb.logger.LogUtil;
import ch.ntb.usb.logger.UsbLogger;
/**
* This class manages all USB devices and defines some USB specific constants.
*
* @author schlaepfer
*
*/
public class USB {
/**
* The maximum packet size of a bulk transfer when operation in highspeed
* (480 MB/s) mode.
*/
public static int HIGHSPEED_MAX_BULK_PACKET_SIZE = 512;
/**
* The maximum packet size of a bulk transfer when operation in fullspeed
* (12 MB/s) mode.
*/
public static int FULLSPEED_MAX_BULK_PACKET_SIZE = 64;
private static UsbLogger logger = LogUtil.ch_ntb_usb;
private static LinkedList<Device> devices = new LinkedList<Device>();
/**
* Create a new device an register it in a device queue or get an already
* created device.<br>
*
* @param idVendor
* the vendor id of the USB device
* @param idProduct
* the product id of the USB device
* @return a newly created device or an already registered device
*/
public static Device getDevice(short idVendor, short idProduct) {
// check if this device is already registered
Device dev = getRegisteredDevice(idVendor, idProduct);
if (dev != null) {
logger.info("return already registered device");
return dev;
}
dev = new Device(idVendor, idProduct);
logger.info("create new device");
devices.add(dev);
return dev;
}
/**
* Get an already registered device or null if the device does not exist.<br>
*
* @param idVendor
* the vendor id of the USB device
* @param idProduct
* the product id of the USB device
* @return the device or null
*/
private static Device getRegisteredDevice(short idVendor, short idProduct) {
for (Iterator<Device> iter = devices.iterator(); iter.hasNext();) {
Device dev = iter.next();
if ((dev.getIdVendor() == idVendor)
&& (dev.getIdProduct() == idProduct)) {
return dev;
}
}
return null;
}
}