Changeset 31644 in vbox for trunk/src/VBox/Main
- Timestamp:
- Aug 13, 2010 12:47:07 PM (14 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/HostHardwareLinux.h
r28882 r31644 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 USBInterfaceList 115 static inline void USBInterfaceListCleanup(char **ppsz) 116 { 117 RTStrFree(*ppsz); 118 } 119 #define VECTOR_DESTRUCTOR USBInterfaceListCleanup 120 #include "vector.h" 121 122 /** Structure describing a host USB device */ 123 typedef struct USBDeviceInfo 124 { 125 /** The device node of the device. */ 126 char *mDevice; 127 /** The system identifier of the device. Specific to the probing 128 * 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 USBDeviceInfo 163 #define VECTOR_TYPENAME USBDeviceInfoList 164 #define VECTOR_DESTRUCTOR USBDevInfoCleanup 165 #include "vector.h" 166 167 111 168 /** 112 169 * Class for probing and returning information about host USB devices. … … 114 171 * actual probing and use the iterator methods to get the result of the probe. 115 172 */ 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: 173 typedef struct VBoxMainUSBDeviceInfo 174 { 163 175 /** The list of currently available USB devices */ 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; 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 173 214 174 215 /** Implementation of the hotplug waiter class below */ -
trunk/src/VBox/Main/linux/HostHardwareLinux.cpp
r31581 r31644 995 995 996 996 997 int VBoxMainUSBDeviceInfo::UpdateDevices ()998 { 999 LogFlow ThisFunc(("entered\n"));997 int USBDevInfoUpdateDevices (VBoxMainUSBDeviceInfo *pSelf) 998 { 999 LogFlowFunc(("entered\n")); 1000 1000 int rc = VINF_SUCCESS; 1001 1001 bool success = false; /* Have we succeeded in finding anything yet? */ 1002 try 1003 { 1004 mDeviceList.clear(); 1002 USBDeviceInfoList_clear(&pSelf->mDeviceList); 1005 1003 #ifdef VBOX_USB_WITH_SYSFS 1006 1004 # ifdef VBOX_USB_WITH_INOTIFY 1007 1008 1009 rc = getUSBDeviceInfoFromSysfs(&mDeviceList, &success);1005 if ( RT_SUCCESS(rc) 1006 && (!success || testing())) 1007 rc = getUSBDeviceInfoFromSysfs(&pSelf->mDeviceList, &success); 1010 1008 # endif 1011 1009 #else /* !VBOX_USB_WITH_SYSFS */ 1012 1010 NOREF(success); 1013 1011 #endif /* !VBOX_USB_WITH_SYSFS */ 1014 } 1015 catch(std::bad_alloc &e) 1016 { 1017 rc = VERR_NO_MEMORY; 1018 } 1019 LogFlowThisFunc(("rc=%Rrc\n", rc)); 1012 LogFlowFunc(("rc=%Rrc\n", rc)); 1020 1013 return rc; 1021 1014 } … … 1504 1497 if (cchDevPath < 0) 1505 1498 return true; 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; 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; 1515 1506 } 1516 1507 … … 1568 1559 AssertReturn(pParent->handle == muiHandle, false); 1569 1560 matchUSBInterface *pSelf = (matchUSBInterface *)pParent; 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; 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; 1581 1569 } 1582 1570 … … 1613 1601 LogFlowFunc (("pList=%p, pfSuccess=%p\n", 1614 1602 pList, pfSuccess)); 1615 size_t cDevices = pList->size();1616 1603 matchUSBDevice devHandler; 1617 1604 mudInit(&devHandler, pList); … … 1620 1607 if (RT_FAILURE(rc)) 1621 1608 break; 1622 for (USBDeviceInfoList::iterator pInfo = pList->begin(); 1623 pInfo != pList->end(); ++pInfo) 1609 USBDeviceInfoList_iterator info; 1610 USBDeviceInfoList_iter_init(&info, 1611 USBDeviceInfoList_begin(pList)); 1612 while (!USBDeviceInfoList_iter_eq(&info, 1613 USBDeviceInfoList_end(pList))) 1624 1614 { 1625 1615 matchUSBInterface ifaceHandler; 1626 muiInit(&ifaceHandler, &*pInfo);1616 muiInit(&ifaceHandler, USBDeviceInfoList_iter_target(&info)); 1627 1617 rc = getDeviceInfoFromSysfs("/sys/bus/usb/devices", 1628 1618 &ifaceHandler.mParent); 1629 1619 if (RT_FAILURE(rc)) 1630 1620 break; 1621 USBDeviceInfoList_iter_incr(&info); 1631 1622 } 1632 1623 } while(0); 1633 if (RT_FAILURE(rc))1634 /* Clean up again */1635 while (pList->size() > cDevices)1636 pList->pop_back();1637 1624 if (pfSuccess) 1638 1625 *pfSuccess = RT_SUCCESS(rc); -
trunk/src/VBox/Main/testcase/tstHostHardwareLinux.cpp
r31564 r31644 92 92 #ifdef VBOX_USB_WITH_SYSFS 93 93 VBoxMainUSBDeviceInfo deviceInfo; 94 rc = deviceInfo.UpdateDevices(); 94 AssertReturn(VBoxMainUSBDevInfoInit(&deviceInfo), 1); 95 rc = USBDevInfoUpdateDevices(&deviceInfo); 95 96 if (RT_FAILURE(rc)) 96 97 { … … 100 101 } 101 102 RTPrintf ("Listing USB devices detected:\n"); 102 for (USBDeviceInfoList::const_iterator it = deviceInfo.DevicesBegin(); 103 it != deviceInfo.DevicesEnd(); ++it) 103 USBDeviceInfoList_iterator it; 104 USBDeviceInfoList_iter_init(&it, USBDevInfoBegin(&deviceInfo)); 105 for (; !USBDeviceInfoList_iter_eq(&it, USBDevInfoEnd(&deviceInfo)); 106 USBDeviceInfoList_iter_incr(&it)) 104 107 { 105 108 char szProduct[1024]; 109 USBDeviceInfo *pInfo = USBDeviceInfoList_iter_target(&it); 106 110 if (RTLinuxSysFsReadStrFile(szProduct, sizeof(szProduct), 107 "%s/product", it->mSysfsPath.c_str()) == -1)111 "%s/product", pInfo->mSysfsPath) == -1) 108 112 { 109 113 if (errno != ENOENT) 110 114 { 111 115 RTPrintf ("Failed to get the product name for device %s: error %s\n", 112 it->mDevice.c_str(), strerror(errno));116 pInfo->mDevice, strerror(errno)); 113 117 return 1; 114 118 } … … 116 120 szProduct[0] = '\0'; 117 121 } 118 RTPrintf (" device: %s (%s), sysfs path: %s\n", szProduct, it->mDevice.c_str(),119 it->mSysfsPath.c_str());122 RTPrintf (" device: %s (%s), sysfs path: %s\n", szProduct, pInfo->mDevice, 123 pInfo->mSysfsPath); 120 124 RTPrintf (" interfaces:\n"); 121 for (USBInterfaceList::const_iterator it2 = it->mInterfaces.begin(); 122 it2 != it->mInterfaces.end(); ++it2) 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)) 123 129 { 124 130 char szDriver[RTPATH_MAX]; 131 char *pszIf = *USBInterfaceList_iter_target(&it2); 125 132 strcpy(szDriver, "none"); 126 133 ssize_t size = RTLinuxSysFsGetLinkDest(szDriver, sizeof(szDriver), 127 "%s/driver", it2->c_str());134 "%s/driver", pszIf); 128 135 if (size == -1 && errno != ENOENT) 129 136 { 130 137 RTPrintf ("Failed to get the driver for interface %s of device %s: error %s\n", 131 it2->c_str(), it->mDevice.c_str(), strerror(errno));138 pszIf, pInfo->mDevice, strerror(errno)); 132 139 return 1; 133 140 } 134 if (RTLinuxSysFsExists("%s/driver", it2->c_str()) != (size != -1))141 if (RTLinuxSysFsExists("%s/driver", pszIf) != (size != -1)) 135 142 { 136 143 RTPrintf ("RTLinuxSysFsExists did not return the expected value for the driver link of interface %s of device %s.\n", 137 it2->c_str(), it->mDevice.c_str());144 pszIf, pInfo->mDevice); 138 145 return 1; 139 146 } 140 147 uint64_t u64InterfaceClass; 141 148 u64InterfaceClass = RTLinuxSysFsReadIntFile(16, "%s/bInterfaceClass", 142 it2->c_str());149 pszIf); 143 150 RTPrintf (" sysfs path: %s, driver: %s, interface class: 0x%x\n", 144 it2->c_str(), szDriver, u64InterfaceClass);151 pszIf, szDriver, u64InterfaceClass); 145 152 } 146 153 }
Note:
See TracChangeset
for help on using the changeset viewer.