Changeset 31648 in vbox for trunk/src/VBox/Main
- Timestamp:
- Aug 13, 2010 1:08:27 PM (14 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/HostHardwareLinux.h
r31644 r31648 109 109 typedef VBoxMainDriveInfo::DriveInfo DriveInfo; 110 110 111 112 /** Vector type for the list of interfaces. */113 #define VECTOR_TYPE char *114 #define VECTOR_TYPENAME USBInterfaceList115 static inline void USBInterfaceListCleanup(char **ppsz)116 {117 RTStrFree(*ppsz);118 }119 #define VECTOR_DESTRUCTOR USBInterfaceListCleanup120 #include "vector.h"121 122 /** Structure describing a host USB device */123 typedef struct USBDeviceInfo124 {125 /** The device node of the device. */126 char *mDevice;127 /** The system identifier of the device. Specific to the probing128 * method. */129 char *mSysfsPath;130 /** Type for the list of interfaces. */131 USBInterfaceList mInterfaces;132 } USBDeviceInfo;133 134 135 /** Destructor. */136 static inline void USBDevInfoCleanup(USBDeviceInfo *pSelf)137 {138 RTStrFree(pSelf->mDevice);139 RTStrFree(pSelf->mSysfsPath);140 pSelf->mDevice = pSelf->mSysfsPath = NULL;141 USBInterfaceList_cleanup(&pSelf->mInterfaces);142 }143 144 145 /** Constructor - the strings will be duplicated. */146 static inline int USBDevInfoInit(USBDeviceInfo *pSelf, const char *aDevice,147 const char *aSystemID)148 {149 pSelf->mDevice = aDevice ? RTStrDup(aDevice) : NULL;150 pSelf->mSysfsPath = aSystemID ? RTStrDup(aSystemID) : NULL;151 if ( !USBInterfaceList_init(&pSelf->mInterfaces)152 || (aDevice && !pSelf->mDevice) || (aSystemID && ! pSelf->mSysfsPath))153 {154 USBDevInfoCleanup(pSelf);155 return 0;156 }157 return 1;158 }159 160 161 /** Vector type holding device information */162 #define VECTOR_TYPE USBDeviceInfo163 #define VECTOR_TYPENAME USBDeviceInfoList164 #define VECTOR_DESTRUCTOR USBDevInfoCleanup165 #include "vector.h"166 167 168 111 /** 169 112 * Class for probing and returning information about host USB devices. … … 171 114 * actual probing and use the iterator methods to get the result of the probe. 172 115 */ 173 typedef struct VBoxMainUSBDeviceInfo 174 { 116 class VBoxMainUSBDeviceInfo 117 { 118 public: 119 /** Structure describing a host USB device */ 120 struct USBDeviceInfo 121 { 122 /** The device node of the device. */ 123 iprt::MiniString mDevice; 124 /** The system identifier of the device. Specific to the probing 125 * method. */ 126 iprt::MiniString mSysfsPath; 127 /** Type for the list of interfaces. */ 128 typedef std::vector<iprt::MiniString> InterfaceList; 129 /** The system IDs of the device's interfaces. */ 130 InterfaceList mInterfaces; 131 132 /** Constructors */ 133 USBDeviceInfo(const iprt::MiniString &aDevice, 134 const iprt::MiniString &aSystemID) 135 : mDevice(aDevice), 136 mSysfsPath(aSystemID) 137 { } 138 }; 139 140 /** List (resp vector) holding drive information */ 141 typedef std::vector<USBDeviceInfo> DeviceInfoList; 142 143 /** 144 * Search for host USB devices and rebuild the list, which remains empty 145 * until the first time this method is called. 146 * @returns iprt status code 147 */ 148 int UpdateDevices (); 149 150 /** Get the first element in the list of USB devices. */ 151 DeviceInfoList::const_iterator DevicesBegin() 152 { 153 return mDeviceList.begin(); 154 } 155 156 /** Get the last element in the list of USB devices. */ 157 DeviceInfoList::const_iterator DevicesEnd() 158 { 159 return mDeviceList.end(); 160 } 161 162 private: 175 163 /** The list of currently available USB devices */ 176 USBDeviceInfoList mDeviceList; 177 } VBoxMainUSBDeviceInfo; 178 179 /** Constructor */ 180 static inline int VBoxMainUSBDevInfoInit(VBoxMainUSBDeviceInfo *pSelf) 181 { 182 return USBDeviceInfoList_init(&pSelf->mDeviceList); 183 } 184 185 /** Destructor */ 186 static inline void VBoxMainUSBDevInfoCleanup(VBoxMainUSBDeviceInfo *pSelf) 187 { 188 USBDeviceInfoList_cleanup(&pSelf->mDeviceList); 189 } 190 191 /** 192 * Search for host USB devices and rebuild the list, which remains empty 193 * until the first time this method is called. 194 * @returns iprt status code 195 */ 196 int USBDevInfoUpdateDevices(VBoxMainUSBDeviceInfo *pSelf); 197 198 199 /** Get the first element in the list of USB devices. */ 200 static inline const USBDeviceInfoList_iterator *USBDevInfoBegin 201 (VBoxMainUSBDeviceInfo *pSelf) 202 { 203 return USBDeviceInfoList_begin(&pSelf->mDeviceList); 204 } 205 206 207 /** Get the last element in the list of USB devices. */ 208 static inline const USBDeviceInfoList_iterator *USBDevInfoEnd 209 (VBoxMainUSBDeviceInfo *pSelf) 210 { 211 return USBDeviceInfoList_end(&pSelf->mDeviceList); 212 } 213 164 DeviceInfoList mDeviceList; 165 }; 166 167 /** Convenience typedef. */ 168 typedef VBoxMainUSBDeviceInfo::DeviceInfoList USBDeviceInfoList; 169 /** Convenience typedef. */ 170 typedef VBoxMainUSBDeviceInfo::USBDeviceInfo USBDeviceInfo; 171 /** Convenience typedef. */ 172 typedef VBoxMainUSBDeviceInfo::USBDeviceInfo::InterfaceList USBInterfaceList; 214 173 215 174 /** Implementation of the hotplug waiter class below */ -
trunk/src/VBox/Main/linux/HostHardwareLinux.cpp
r31644 r31648 995 995 996 996 997 int USBDevInfoUpdateDevices (VBoxMainUSBDeviceInfo *pSelf)998 { 999 LogFlow Func(("entered\n"));997 int VBoxMainUSBDeviceInfo::UpdateDevices () 998 { 999 LogFlowThisFunc(("entered\n")); 1000 1000 int rc = VINF_SUCCESS; 1001 1001 bool success = false; /* Have we succeeded in finding anything yet? */ 1002 USBDeviceInfoList_clear(&pSelf->mDeviceList); 1002 try 1003 { 1004 mDeviceList.clear(); 1003 1005 #ifdef VBOX_USB_WITH_SYSFS 1004 1006 # ifdef VBOX_USB_WITH_INOTIFY 1005 if ( RT_SUCCESS(rc)1006 && (!success || testing()))1007 rc = getUSBDeviceInfoFromSysfs(&pSelf->mDeviceList, &success);1007 if ( RT_SUCCESS(rc) 1008 && (!success || testing())) 1009 rc = getUSBDeviceInfoFromSysfs(&mDeviceList, &success); 1008 1010 # endif 1009 1011 #else /* !VBOX_USB_WITH_SYSFS */ 1010 NOREF(success);1012 NOREF(success); 1011 1013 #endif /* !VBOX_USB_WITH_SYSFS */ 1012 LogFlowFunc(("rc=%Rrc\n", rc)); 1014 } 1015 catch(std::bad_alloc &e) 1016 { 1017 rc = VERR_NO_MEMORY; 1018 } 1019 LogFlowThisFunc(("rc=%Rrc\n", rc)); 1013 1020 return rc; 1014 1021 } … … 1497 1504 if (cchDevPath < 0) 1498 1505 return true; 1499 1500 USBDeviceInfo info; 1501 if (USBDevInfoInit(&info, szDevPath, pcszNode)) 1502 if (USBDeviceInfoList_push_back(pSelf->mList, &info)) 1503 return true; 1504 USBDevInfoCleanup(&info); 1505 return false; 1506 try 1507 { 1508 pSelf->mList->push_back(USBDeviceInfo(szDevPath, pcszNode)); 1509 } 1510 catch(std::bad_alloc &e) 1511 { 1512 return false; 1513 } 1514 return true; 1506 1515 } 1507 1516 … … 1559 1568 AssertReturn(pParent->handle == muiHandle, false); 1560 1569 matchUSBInterface *pSelf = (matchUSBInterface *)pParent; 1561 if (!muiIsAnInterfaceOf(pcszNode, pSelf->mInfo->mSysfsPath)) 1562 return true; 1563 char *pcszDup = RTStrDup(pcszNode); 1564 if (pcszDup) 1565 if (USBInterfaceList_push_back(&pSelf->mInfo->mInterfaces, &pcszDup)) 1566 return true; 1567 RTStrFree(pcszDup); 1568 return false; 1570 if (!muiIsAnInterfaceOf(pcszNode, pSelf->mInfo->mSysfsPath.c_str())) 1571 return true; 1572 try 1573 { 1574 pSelf->mInfo->mInterfaces.push_back(pcszNode); 1575 } 1576 catch(std::bad_alloc &e) 1577 { 1578 return false; 1579 } 1580 return true; 1569 1581 } 1570 1582 … … 1601 1613 LogFlowFunc (("pList=%p, pfSuccess=%p\n", 1602 1614 pList, pfSuccess)); 1615 size_t cDevices = pList->size(); 1603 1616 matchUSBDevice devHandler; 1604 1617 mudInit(&devHandler, pList); … … 1607 1620 if (RT_FAILURE(rc)) 1608 1621 break; 1609 USBDeviceInfoList_iterator info; 1610 USBDeviceInfoList_iter_init(&info, 1611 USBDeviceInfoList_begin(pList)); 1612 while (!USBDeviceInfoList_iter_eq(&info, 1613 USBDeviceInfoList_end(pList))) 1622 for (USBDeviceInfoList::iterator pInfo = pList->begin(); 1623 pInfo != pList->end(); ++pInfo) 1614 1624 { 1615 1625 matchUSBInterface ifaceHandler; 1616 muiInit(&ifaceHandler, USBDeviceInfoList_iter_target(&info));1626 muiInit(&ifaceHandler, &*pInfo); 1617 1627 rc = getDeviceInfoFromSysfs("/sys/bus/usb/devices", 1618 1628 &ifaceHandler.mParent); 1619 1629 if (RT_FAILURE(rc)) 1620 1630 break; 1621 USBDeviceInfoList_iter_incr(&info);1622 1631 } 1623 1632 } while(0); 1633 if (RT_FAILURE(rc)) 1634 /* Clean up again */ 1635 while (pList->size() > cDevices) 1636 pList->pop_back(); 1624 1637 if (pfSuccess) 1625 1638 *pfSuccess = RT_SUCCESS(rc); -
trunk/src/VBox/Main/testcase/tstHostHardwareLinux.cpp
r31644 r31648 92 92 #ifdef VBOX_USB_WITH_SYSFS 93 93 VBoxMainUSBDeviceInfo deviceInfo; 94 AssertReturn(VBoxMainUSBDevInfoInit(&deviceInfo), 1); 95 rc = USBDevInfoUpdateDevices(&deviceInfo); 94 rc = deviceInfo.UpdateDevices(); 96 95 if (RT_FAILURE(rc)) 97 96 { … … 101 100 } 102 101 RTPrintf ("Listing USB devices detected:\n"); 103 USBDeviceInfoList_iterator it; 104 USBDeviceInfoList_iter_init(&it, USBDevInfoBegin(&deviceInfo)); 105 for (; !USBDeviceInfoList_iter_eq(&it, USBDevInfoEnd(&deviceInfo)); 106 USBDeviceInfoList_iter_incr(&it)) 102 for (USBDeviceInfoList::const_iterator it = deviceInfo.DevicesBegin(); 103 it != deviceInfo.DevicesEnd(); ++it) 107 104 { 108 105 char szProduct[1024]; 109 USBDeviceInfo *pInfo = USBDeviceInfoList_iter_target(&it);110 106 if (RTLinuxSysFsReadStrFile(szProduct, sizeof(szProduct), 111 "%s/product", pInfo->mSysfsPath) == -1)107 "%s/product", it->mSysfsPath.c_str()) == -1) 112 108 { 113 109 if (errno != ENOENT) 114 110 { 115 111 RTPrintf ("Failed to get the product name for device %s: error %s\n", 116 pInfo->mDevice, strerror(errno));112 it->mDevice.c_str(), strerror(errno)); 117 113 return 1; 118 114 } … … 120 116 szProduct[0] = '\0'; 121 117 } 122 RTPrintf (" device: %s (%s), sysfs path: %s\n", szProduct, pInfo->mDevice,123 pInfo->mSysfsPath);118 RTPrintf (" device: %s (%s), sysfs path: %s\n", szProduct, it->mDevice.c_str(), 119 it->mSysfsPath.c_str()); 124 120 RTPrintf (" interfaces:\n"); 125 USBInterfaceList_iterator it2; 126 USBInterfaceList_iter_init(&it2, USBInterfaceList_begin(&pInfo->mInterfaces)); 127 for (; !USBInterfaceList_iter_eq(&it2, USBInterfaceList_end(&pInfo->mInterfaces)); 128 USBInterfaceList_iter_incr(&it2)) 121 for (USBInterfaceList::const_iterator it2 = it->mInterfaces.begin(); 122 it2 != it->mInterfaces.end(); ++it2) 129 123 { 130 124 char szDriver[RTPATH_MAX]; 131 char *pszIf = *USBInterfaceList_iter_target(&it2);132 125 strcpy(szDriver, "none"); 133 126 ssize_t size = RTLinuxSysFsGetLinkDest(szDriver, sizeof(szDriver), 134 "%s/driver", pszIf);127 "%s/driver", it2->c_str()); 135 128 if (size == -1 && errno != ENOENT) 136 129 { 137 130 RTPrintf ("Failed to get the driver for interface %s of device %s: error %s\n", 138 pszIf, pInfo->mDevice, strerror(errno));131 it2->c_str(), it->mDevice.c_str(), strerror(errno)); 139 132 return 1; 140 133 } 141 if (RTLinuxSysFsExists("%s/driver", pszIf) != (size != -1))134 if (RTLinuxSysFsExists("%s/driver", it2->c_str()) != (size != -1)) 142 135 { 143 136 RTPrintf ("RTLinuxSysFsExists did not return the expected value for the driver link of interface %s of device %s.\n", 144 pszIf, pInfo->mDevice);137 it2->c_str(), it->mDevice.c_str()); 145 138 return 1; 146 139 } 147 140 uint64_t u64InterfaceClass; 148 141 u64InterfaceClass = RTLinuxSysFsReadIntFile(16, "%s/bInterfaceClass", 149 pszIf);142 it2->c_str()); 150 143 RTPrintf (" sysfs path: %s, driver: %s, interface class: 0x%x\n", 151 pszIf, szDriver, u64InterfaceClass);144 it2->c_str(), szDriver, u64InterfaceClass); 152 145 } 153 146 }
Note:
See TracChangeset
for help on using the changeset viewer.