<commit_before>/*
 * Copyright (C) 2011 <NAME> <<EMAIL>>
 * See LICENSE.txt for licensing information.
 */

package de.ailis.usb4java.topology;

import static de.ailis.usb4java.jni.USB.USB_CLASS_HUB;
import static de.ailis.usb4java.jni.USB.usb_find_busses;
import static de.ailis.usb4java.jni.USB.usb_find_devices;
import static de.ailis.usb4java.jni.USB.usb_get_busses;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import de.ailis.usb4java.Services;
import de.ailis.usb4java.jni.USB_Bus;
import de.ailis.usb4java.jni.USB_Device;
import de.ailis.usb4java.jni.USB_Device_Descriptor;
import de.ailis.usb4java.support.Config;
import de.ailis.usb4java.support.UsbLock;

/**
 * USB Device scanner.
 *
 * @author <NAME> (<EMAIL>)
 */
public final class UsbDeviceScanner
{
    /** The scan interval in milliseconds. */
    private static final int DEFAULT_SCAN_INTERVAL = 500;

    /** The virtual USB root hub. */
    private final VirtualRootHub rootHub;

    /** If scanner already scanned for devices. */
    private boolean scanned = false;

    /** The configuration. */
    private final Config config;

    /**
     * Constructor.
     *
     * @param services
     *            The USB services.
     * @param rootHub
     *            The virtual USB root hub.
     * @param config
     *            The configuration
     */
    public UsbDeviceScanner(final Services services,
        final VirtualRootHub rootHub, final Config config)
    {
        this.rootHub = rootHub;
        this.config = config;
    }

    /**
     * Scans for USB device connection changes.
     */
    public void scan()
    {
        UsbLock.acquire();
        try
        {
            final int bussesChanged = usb_find_busses();
            final int devicesChanged = usb_find_devices();
            if (bussesChanged + devicesChanged == 0) return;

            USB_Bus bus = usb_get_busses();
            final List<USB_Device> devices = new ArrayList<USB_Device>();
            while (bus != null)
            {
                USB_Device device = bus.root_dev();
                if (this.config.getScanHierarchy())
                {
                    if (device != null) devices.add(device);<commit_msg>Use bus devices list instead of bus root device as starting point for device enumeration.<commit_after>/*
 * Copyright (C) 2011 <NAME> <<EMAIL>>
 * See LICENSE.txt for licensing information.
 */

package de.ailis.usb4java.topology;

import static de.ailis.usb4java.jni.USB.USB_CLASS_HUB;
import static de.ailis.usb4java.jni.USB.usb_find_busses;
import static de.ailis.usb4java.jni.USB.usb_find_devices;
import static de.ailis.usb4java.jni.USB.usb_get_busses;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import de.ailis.usb4java.Services;
import de.ailis.usb4java.jni.USB_Bus;
import de.ailis.usb4java.jni.USB_Device;
import de.ailis.usb4java.jni.USB_Device_Descriptor;
import de.ailis.usb4java.support.Config;
import de.ailis.usb4java.support.UsbLock;

/**
 * USB Device scanner.
 *
 * @author <NAME> (<EMAIL>)
 */
public final class UsbDeviceScanner
{
    /** The scan interval in milliseconds. */
    private static final int DEFAULT_SCAN_INTERVAL = 500;

    /** The virtual USB root hub. */
    private final VirtualRootHub rootHub;

    /** If scanner already scanned for devices. */
    private boolean scanned = false;

    /** The configuration. */
    private final Config config;

    /**
     * Constructor.
     *
     * @param services
     *            The USB services.
     * @param rootHub
     *            The virtual USB root hub.
     * @param config
     *            The configuration
     */
    public UsbDeviceScanner(final Services services,
        final VirtualRootHub rootHub, final Config config)
    {
        this.rootHub = rootHub;
        this.config = config;
    }

    /**
     * Scans for USB device connection changes.
     */
    public void scan()
    {
        UsbLock.acquire();
        try
        {
            final int bussesChanged = usb_find_busses();
            final int devicesChanged = usb_find_devices();
            if (bussesChanged + devicesChanged == 0) return;

            USB_Bus bus = usb_get_busses();
            final List<USB_Device> devices = new ArrayList<USB_Device>();
            while (bus != null)
            {
                USB_Device device = bus.devices();
                if (this.config.getScanHierarchy())
                {
                    if (device != null) devices.add(device);
{'fraction_non_alphanumeric': 0.10148131770948486, 'fraction_numerical': 0.00840150342692903, 'mean_word_length': 2.3660714285714284, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '7659157', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1356, 'n_words': 341}