- Timestamp:
- Jan 20, 2009 5:04:08 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/linux/HostHardwareLinux.cpp
r16068 r16093 93 93 bool *pfSuccess); 94 94 static int getUSBDeviceInfoFromHal(USBDeviceInfoList *pList, bool *pfSuccess); 95 static int getOldUSBDeviceInfoFromHal(USBDeviceInfoList *pList, bool *pfSuccess); 95 96 static int getUSBInterfacesFromHal(std::vector <std::string> *pList, 96 97 const char *pcszUdi, bool *pfSuccess); … … 198 199 if (RT_SUCCESS (rc) && VBoxDBusCheckPresence() && (!success || testing())) 199 200 rc = getUSBDeviceInfoFromHal(&mDeviceList, &success); 201 if (RT_SUCCESS (rc) && VBoxDBusCheckPresence() && (!success || testing())) 202 rc = getOldUSBDeviceInfoFromHal(&mDeviceList, &success); 200 203 #endif /* VBOX_WITH_DBUS defined */ 201 204 #endif /* RT_OS_LINUX */ … … 952 955 DBusMessageIter iterFind, iterUdis; 953 956 957 /* Connect to hal */ 954 958 rc = halInit (&dbusConnection); 955 959 if (!dbusConnection) 956 960 halSuccess = false; 961 /* Get an array of all devices in the usb_device subsystem */ 957 962 if (halSuccess && RT_SUCCESS (rc)) 958 963 { 959 964 rc = halFindDeviceStringMatch (dbusConnection.get(), "info.subsystem", 960 965 "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);965 966 if (!replyFind) 966 967 halSuccess = false; … … 972 973 halSuccess = false; 973 974 } 975 /* Recurse down into the array and query interesting information about the 976 * entries. */ 974 977 if (halSuccess && RT_SUCCESS (rc)) 975 978 dbus_message_iter_recurse (&iterFind, &iterUdis); … … 978 981 dbus_message_iter_next(&iterUdis)) 979 982 { 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. */ 981 984 const char *pszUdi; 982 985 dbus_message_iter_get_basic (&iterUdis, &pszUdi); … … 987 990 std::string description; 988 991 const char *pszDevice = papszValues[0], *pszSysfsPath = papszValues[1]; 989 /* Get the interfaces for this device. */992 /* Get the interfaces. */ 990 993 if (!!replyGet && pszDevice && pszSysfsPath) 991 994 { … … 994 997 * skip this one device. */ 995 998 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 */ 1023 int 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); 996 1080 if (RT_SUCCESS(rc) && halSuccess && ifaceSuccess) 997 1081 pList->push_back (info);
Note:
See TracChangeset
for help on using the changeset viewer.