VirtualBox

Changeset 16093 in vbox for trunk/src


Ignore:
Timestamp:
Jan 20, 2009 5:04:08 PM (16 years ago)
Author:
vboxsync
Message:

Main: try to get the USB enumeration right on RHEL5, again

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/linux/HostHardwareLinux.cpp

    r16068 r16093  
    9393                               bool *pfSuccess);
    9494static int getUSBDeviceInfoFromHal(USBDeviceInfoList *pList, bool *pfSuccess);
     95static int getOldUSBDeviceInfoFromHal(USBDeviceInfoList *pList, bool *pfSuccess);
    9596static int getUSBInterfacesFromHal(std::vector <std::string> *pList,
    9697                                   const char *pcszUdi, bool *pfSuccess);
     
    198199        if (RT_SUCCESS (rc) && VBoxDBusCheckPresence() && (!success || testing()))
    199200            rc = getUSBDeviceInfoFromHal(&mDeviceList, &success);
     201        if (RT_SUCCESS (rc) && VBoxDBusCheckPresence() && (!success || testing()))
     202            rc = getOldUSBDeviceInfoFromHal(&mDeviceList, &success);
    200203#endif /* VBOX_WITH_DBUS defined */
    201204#endif /* RT_OS_LINUX */
     
    952955    DBusMessageIter iterFind, iterUdis;
    953956
     957    /* Connect to hal */
    954958    rc = halInit (&dbusConnection);
    955959    if (!dbusConnection)
    956960        halSuccess = false;
     961    /* Get an array of all devices in the usb_device subsystem */
    957962    if (halSuccess && RT_SUCCESS (rc))
    958963    {
    959964        rc = halFindDeviceStringMatch (dbusConnection.get(), "info.subsystem",
    960965                                       "usb_device", &replyFind);
    961         if (RT_SUCCESS(rc) && !dbusMessageIsNonEmptyArray (replyFind.get()))  /* "Old" syntax. */
    962             rc = halFindDeviceStringMatch (dbusConnection.get(),
    963                                            "linux.subsystem", "usb_device",
    964                                            &replyFind);
    965966        if (!replyFind)
    966967            halSuccess = false;
     
    972973            halSuccess = false;
    973974    }
     975    /* Recurse down into the array and query interesting information about the
     976     * entries. */
    974977    if (halSuccess && RT_SUCCESS (rc))
    975978        dbus_message_iter_recurse (&iterFind, &iterUdis);
     
    978981         dbus_message_iter_next(&iterUdis))
    979982    {
    980         /* Now get the device node and the sysfs path from the iterator */
     983        /* Get the device node and the sysfs path for the current entry. */
    981984        const char *pszUdi;
    982985        dbus_message_iter_get_basic (&iterUdis, &pszUdi);
     
    987990        std::string description;
    988991        const char *pszDevice = papszValues[0], *pszSysfsPath = papszValues[1];
    989         /* Get the interfaces for this device. */
     992        /* Get the interfaces. */
    990993        if (!!replyGet && pszDevice && pszSysfsPath)
    991994        {
     
    994997                                        * skip this one device. */           
    995998            rc = getUSBInterfacesFromHal (&info.mInterfaces, pszUdi, &ifaceSuccess);
     999            if (RT_SUCCESS(rc) && halSuccess && ifaceSuccess)
     1000                pList->push_back (info);
     1001        }
     1002    }
     1003    if (dbusError.HasName (DBUS_ERROR_NO_MEMORY))
     1004        rc = VERR_NO_MEMORY;
     1005    if (pfSuccess != NULL)
     1006        *pfSuccess = halSuccess;
     1007    LogFlow (("rc=%Rrc, halSuccess=%d\n", rc, halSuccess));
     1008    dbusError.FlowLog();
     1009    return rc;
     1010}
     1011
     1012/**
     1013 * Helper function to query the hal subsystem for information about USB devices
     1014 * attached to the system, using the older API.
     1015 * @returns iprt status code
     1016 * @param   pList      where to add information about the devices detected
     1017 * @param   pfSuccess  will be set to true if all interactions with hal
     1018 *                     succeeded and to false otherwise.  Optional.
     1019 *
     1020 * @returns IPRT status code
     1021 */
     1022/* static */
     1023int getOldUSBDeviceInfoFromHal(USBDeviceInfoList *pList, bool *pfSuccess)
     1024{
     1025    AssertReturn(VALID_PTR (pList) && (pfSuccess == NULL || VALID_PTR (pfSuccess)),
     1026                 VERR_INVALID_POINTER);
     1027    LogFlowFunc (("pList=%p, pfSuccess=%p\n", pList, pfSuccess));
     1028    int rc = VINF_SUCCESS;  /* We set this to failure on fatal errors. */
     1029    bool halSuccess = true;  /* We set this to false to abort the operation. */
     1030    autoDBusError dbusError;
     1031
     1032    RTMemAutoPtr <DBusMessage, VBoxDBusMessageUnref> message, replyFind, replyGet;
     1033    RTMemAutoPtr <DBusConnection, VBoxHalShutdown> dbusConnection;
     1034    DBusMessageIter iterFind, iterUdis;
     1035
     1036    /* Connect to hal */
     1037    rc = halInit (&dbusConnection);
     1038    if (!dbusConnection)
     1039        halSuccess = false;
     1040    /* Get an array of all devices in the usb_device subsystem */
     1041    if (halSuccess && RT_SUCCESS (rc))
     1042    {
     1043        rc = halFindDeviceStringMatch (dbusConnection.get(), "info.category",
     1044                                       "usbraw", &replyFind);
     1045        if (!replyFind)
     1046            halSuccess = false;
     1047    }
     1048    if (halSuccess && RT_SUCCESS (rc))
     1049    {
     1050        dbus_message_iter_init (replyFind.get(), &iterFind);
     1051        if (dbus_message_iter_get_arg_type (&iterFind) != DBUS_TYPE_ARRAY)
     1052            halSuccess = false;
     1053    }
     1054    /* Recurse down into the array and query interesting information about the
     1055     * entries. */
     1056    if (halSuccess && RT_SUCCESS (rc))
     1057        dbus_message_iter_recurse (&iterFind, &iterUdis);
     1058    for (;    halSuccess && RT_SUCCESS (rc)
     1059           && dbus_message_iter_get_arg_type (&iterUdis) == DBUS_TYPE_STRING;
     1060         dbus_message_iter_next(&iterUdis))
     1061    {
     1062        /* Get the device node and the sysfs path for the current entry. */
     1063        const char *pszUdi;
     1064        dbus_message_iter_get_basic (&iterUdis, &pszUdi);
     1065        static const char *papszKeys[] = { "linux.device_file", "linux.sysfs_path",
     1066                                           "info.parent" };
     1067        char *papszValues[RT_ELEMENTS (papszKeys)];
     1068        rc = halGetPropertyStrings (dbusConnection.get(), pszUdi, RT_ELEMENTS (papszKeys),
     1069                                    papszKeys, papszValues, &replyGet);
     1070        std::string description;
     1071        const char *pszDevice = papszValues[0], *pszSysfsPath = papszValues[1],
     1072                   *pszParent = papszValues[2];
     1073        /* Get the interfaces. */
     1074        if (!!replyGet && pszDevice && pszSysfsPath)
     1075        {
     1076            USBDeviceInfo info (pszDevice, pszSysfsPath);
     1077            bool ifaceSuccess = true;  /* If we can't get the interfaces, just
     1078                                        * skip this one device. */           
     1079            rc = getUSBInterfacesFromHal (&info.mInterfaces, pszParent, &ifaceSuccess);
    9961080            if (RT_SUCCESS(rc) && halSuccess && ifaceSuccess)
    9971081                pList->push_back (info);
Note: See TracChangeset for help on using the changeset viewer.

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