VirtualBox

Ignore:
Timestamp:
Sep 8, 2010 3:43:32 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
65666
Message:

Main/USBProxyServiceLinux: split out USB enumeration from USBProxyServiceLinux.cpp and HostHardwareLinux.cpp into a separate file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/testcase/tstHostHardwareLinux.cpp

    r32299 r32324  
    1919
    2020#include <HostHardwareLinux.h>
     21#include <USBGetDevices.h>
    2122
    2223#include <VBox/err.h>
     
    5253    }
    5354    return rc;
     55}
     56
     57void printDevices(PUSBDEVICE pDevices, const char *pcszAccess)
     58{
     59    PUSBDEVICE pDevice = pDevices;
     60
     61    RTPrintf("Enumerating usb devices using %s\n", pcszAccess);
     62    while (pDevice)
     63    {
     64        RTPrintf("  Manufacturer: %s, product: %s, serial number string: %s\n",
     65                    pDevice->pszManufacturer, pDevice->pszProduct,
     66                    pDevice->pszSerialNumber);
     67        RTPrintf("    Device address: %s\n", pDevice->pszAddress);
     68        pDevice = pDevice->pNext;
     69    }
     70}
     71
     72void freeDevices(PUSBDEVICE pDevices)
     73{
     74    PUSBDEVICE pDevice = pDevices, pDeviceNext;
     75
     76    while (pDevice)
     77    {
     78        pDeviceNext = pDevice->pNext;
     79        deviceFree(pDevice);
     80        pDevice = pDeviceNext;
     81    }
    5482}
    5583
     
    91119    }
    92120#ifdef VBOX_USB_WITH_SYSFS
    93     VECTOR_OBJ(USBDeviceInfo) vecDevInfo;
    94     VEC_INIT_OBJ(&vecDevInfo, USBDeviceInfo, USBDevInfoCleanup);
    95     rc = USBSysfsEnumerateHostDevices(&vecDevInfo);
    96     if (RT_FAILURE(rc))
     121    PUSBDEVICE pDevice = USBProxyLinuxGetDevices(NULL);
     122    printDevices(pDevice, "sysfs");
     123    freeDevices(pDevice);
     124    if (USBProxyLinuxCheckForUsbfs("/proc/bus/usb/devices"))
    97125    {
    98         RTPrintf ("Failed to update the host USB device information, error %Rrc\n",
    99                  rc);
    100         return 1;
     126        pDevice = USBProxyLinuxGetDevices("/proc/bus/usb");
     127        printDevices(pDevice, "/proc/bus/usb");
     128        freeDevices(pDevice);
    101129    }
    102     RTPrintf ("Listing USB devices detected:\n");
    103     USBDeviceInfo *pInfo;
    104     VEC_FOR_EACH(&vecDevInfo, USBDeviceInfo, pInfo)
     130    if (USBProxyLinuxCheckForUsbfs("/dev/bus/usb/devices"))
    105131    {
    106         char szProduct[1024];
    107         if (RTLinuxSysFsReadStrFile(szProduct, sizeof(szProduct),
    108                                     "%s/product", pInfo->mSysfsPath) == -1)
    109         {
    110             if (errno != ENOENT)
    111             {
    112                 RTPrintf ("Failed to get the product name for device %s: error %s\n",
    113                           pInfo->mDevice, strerror(errno));
    114                 return 1;
    115             }
    116             else
    117                 szProduct[0] = '\0';
    118         }
    119         RTPrintf ("  device: %s (%s), sysfs path: %s\n", szProduct, pInfo->mDevice,
    120                   pInfo->mSysfsPath);
    121         RTPrintf ("    interfaces:\n");
    122         char **ppszIf;
    123         VEC_FOR_EACH(&pInfo->mvecpszInterfaces, char *, ppszIf)
    124         {
    125             char szDriver[RTPATH_MAX];
    126             strcpy(szDriver, "none");
    127             ssize_t size = RTLinuxSysFsGetLinkDest(szDriver, sizeof(szDriver),
    128                                                    "%s/driver", *ppszIf);
    129             if (size == -1 && errno != ENOENT)
    130             {
    131                 RTPrintf ("Failed to get the driver for interface %s of device %s: error %s\n",
    132                           *ppszIf, pInfo->mDevice, strerror(errno));
    133                 return 1;
    134             }
    135             if (RTLinuxSysFsExists("%s/driver", *ppszIf) != (size != -1))
    136             {
    137                 RTPrintf ("RTLinuxSysFsExists did not return the expected value for the driver link of interface %s of device %s.\n",
    138                           *ppszIf, pInfo->mDevice);
    139                 return 1;
    140             }
    141             uint64_t u64InterfaceClass;
    142             u64InterfaceClass = RTLinuxSysFsReadIntFile(16, "%s/bInterfaceClass",
    143                                                         *ppszIf);
    144             RTPrintf ("      sysfs path: %s, driver: %s, interface class: 0x%x\n",
    145                       *ppszIf, szDriver, u64InterfaceClass);
    146         }
     132        pDevice = USBProxyLinuxGetDevices("/dev/bus/usb");
     133        printDevices(pDevice, "/dev/bus/usb");
     134        freeDevices(pDevice);
    147135    }
    148     VEC_CLEANUP_OBJ(&vecDevInfo);
    149136    VBoxMainHotplugWaiter waiter;
    150137    RTPrintf ("Waiting for a hotplug event for five seconds...\n");
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette