<commit_before>package net.sf.jaer.hardwareinterface.usb.cypressfx2libusb;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import net.sf.jaer.hardwareinterface.HardwareInterfaceFactoryInterface;
import net.sf.jaer.hardwareinterface.usb.USBInterface;

import org.apache.commons.lang3.tuple.ImmutablePair;

import de.ailis.usb4java.libusb.Device;
import de.ailis.usb4java.libusb.DeviceDescriptor;
import de.ailis.usb4java.libusb.DeviceList;
import de.ailis.usb4java.libusb.LibUsb;

public class LibUsbHardwareInterfaceFactory implements HardwareInterfaceFactoryInterface {
	private final static Logger log = Logger.getLogger("LibUsbHardwareInterfaceFactory");

	private static LibUsbHardwareInterfaceFactory instance = new LibUsbHardwareInterfaceFactory();

	/** @return singleton instance */
	public static HardwareInterfaceFactoryInterface instance() {
		return LibUsbHardwareInterfaceFactory.instance;
	}

	private final Map<ImmutablePair<Short, Short>, Class<?>> vidPidToClassMap = new HashMap<ImmutablePair<Short, Short>, Class<?>>();
	private final List<Device> compatibleDevicesList = new ArrayList<Device>();

	private LibUsbHardwareInterfaceFactory() {
		// Thesycon Vendor ID.
		final short VID_Thesycon = 0x152A;

		// Build a mapping of VID/PID pairs and corresponding HardwareInterfaces.
		// addDeviceToMap(VID_Thesycon, CypressFX2.PID_USB2AERmapper, CypressFX2Mapper.class);
		addDeviceToMap(VID_Thesycon, CypressFX2.PID_DVS128_REV0, CypressFX2DVS128HardwareInterface.class);
		addDeviceToMap(VID_Thesycon, CypressFX2.PID_TMPDIFF128_RETINA, CypressFX2TmpdiffRetinaHardwareInterface.class);
		// addDeviceToMap(VID_Thesycon, CypressFX2.PID_USBAERmini2, CypressFX2MonitorSequencer.class);
		addDeviceToMap(VID_Thesycon, ApsDvsHardwareInterface.PID, ApsDvsHardwareInterface.class);

		// Initialize LibUsb.
		LibUsb.init(null);

		// Build up first list of compatible devices.
		buildCompatibleDevicesList();
	}

	private void addDeviceToMap(final short VID, final short PID, final Class<?> cls) {
		vidPidToClassMap.put(new ImmutablePair<Short, Short>(VID, PID), cls);
	}

	private void buildCompatibleDevicesList() {
		// First let's make sure the list is empty, as we're going to re-scan everything.
		if (!compatibleDevicesList.isEmpty()) {<commit_msg>FX2-libusb: comment out LibUsb init calls in constructor until the win32 builds are properly working. Creating the singleton instance at jAER startup is why they get always called, and on win32 they'll fail, crashing the JVM.<commit_after>package net.sf.jaer.hardwareinterface.usb.cypressfx2libusb;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import net.sf.jaer.hardwareinterface.HardwareInterfaceFactoryInterface;
import net.sf.jaer.hardwareinterface.usb.USBInterface;

import org.apache.commons.lang3.tuple.ImmutablePair;

import de.ailis.usb4java.libusb.Device;
import de.ailis.usb4java.libusb.DeviceDescriptor;
import de.ailis.usb4java.libusb.DeviceList;
import de.ailis.usb4java.libusb.LibUsb;

public class LibUsbHardwareInterfaceFactory implements HardwareInterfaceFactoryInterface {
	private final static Logger log = Logger.getLogger("LibUsbHardwareInterfaceFactory");

	private static LibUsbHardwareInterfaceFactory instance = new LibUsbHardwareInterfaceFactory();

	/** @return singleton instance */
	public static HardwareInterfaceFactoryInterface instance() {
		return LibUsbHardwareInterfaceFactory.instance;
	}

	private final Map<ImmutablePair<Short, Short>, Class<?>> vidPidToClassMap = new HashMap<ImmutablePair<Short, Short>, Class<?>>();
	private final List<Device> compatibleDevicesList = new ArrayList<Device>();

	private LibUsbHardwareInterfaceFactory() {
		// Thesycon Vendor ID.
		final short VID_Thesycon = 0x152A;

		// Build a mapping of VID/PID pairs and corresponding HardwareInterfaces.
		// addDeviceToMap(VID_Thesycon, CypressFX2.PID_USB2AERmapper, CypressFX2Mapper.class);
		addDeviceToMap(VID_Thesycon, CypressFX2.PID_DVS128_REV0, CypressFX2DVS128HardwareInterface.class);
		addDeviceToMap(VID_Thesycon, CypressFX2.PID_TMPDIFF128_RETINA, CypressFX2TmpdiffRetinaHardwareInterface.class);
		// addDeviceToMap(VID_Thesycon, CypressFX2.PID_USBAERmini2, CypressFX2MonitorSequencer.class);
		addDeviceToMap(VID_Thesycon, ApsDvsHardwareInterface.PID, ApsDvsHardwareInterface.class);

		// Initialize LibUsb.
		//LibUsb.init(null);

		// Build up first list of compatible devices.
		//buildCompatibleDevicesList();
	}

	private void addDeviceToMap(final short VID, final short PID, final Class<?> cls) {
		vidPidToClassMap.put(new ImmutablePair<Short, Short>(VID, PID), cls);
	}

	private void buildCompatibleDevicesList() {
		// First let's make sure the list is empty, as we're going to re-scan everything.
		if (!compatibleDevicesList.isEmpty()) {
{'fraction_non_alphanumeric': 0.0907843137254902, 'fraction_numerical': 0.012745098039215686, 'mean_word_length': 6.446715328467153, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2897755', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1603, 'n_words': 337}