Changeset 32142 in vbox
- Timestamp:
- Aug 31, 2010 1:00:46 PM (14 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/HostHardwareLinux.h
r31652 r32142 110 110 111 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 112 /** Structure describing a host USB device */ 123 113 typedef struct USBDeviceInfo … … 128 118 * method. */ 129 119 char *mSysfsPath; 130 /** Type for the list of interfaces. */131 USBInterfaceListmInterfaces;120 /** List of interfaces. Only one simulaneous traversal is possible. */ 121 struct USBInterfaceList *mInterfaces; 132 122 } USBDeviceInfo; 133 123 134 135 124 /** 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 125 void USBDevInfoCleanup(USBDeviceInfo *pSelf); 144 126 145 127 /** 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 } 128 int USBDevInfoInit(USBDeviceInfo *pSelf, const char *aDevice, 129 const char *aSystemID); 130 131 /** 132 * Return the first in a list of USB device interfaces (that is, its sysfs 133 * path), or NULL if there are none. 134 */ 135 char *USBDevInfoFirstInterface(struct USBInterfaceList *pInterfaces); 136 137 /** 138 * Return the next in a list of USB device interfaces (that is, its sysfs 139 * path), or NULL if there are none. 140 */ 141 char *USBDevInfoNextInterface(struct USBInterfaceList *pInterfaces); 159 142 160 143 … … 195 178 */ 196 179 int USBDevInfoUpdateDevices(VBoxMainUSBDeviceInfo *pSelf); 197 198 180 199 181 /** Get the first element in the list of USB devices. */ -
trunk/src/VBox/Main/linux/HostHardwareLinux.cpp
r32115 r32142 1008 1008 } 1009 1009 1010 /** Vector type for the list of interfaces. */ 1011 #define VECTOR_TYPE char * 1012 #define VECTOR_TYPENAME usbInterfaceList 1013 static void usbInterfaceListCleanup(char **ppsz) 1014 { 1015 RTStrFree(*ppsz); 1016 } 1017 #define VECTOR_DESTRUCTOR usbInterfaceListCleanup 1018 #include "vector.h" 1019 1020 struct USBInterfaceList 1021 { 1022 /** The vector of devices */ 1023 usbInterfaceList mList; 1024 /** The single traversal iterator */ 1025 usbInterfaceList_iterator mIt; 1026 }; 1027 1028 void USBDevInfoCleanup(USBDeviceInfo *pSelf) 1029 { 1030 RTStrFree(pSelf->mDevice); 1031 RTStrFree(pSelf->mSysfsPath); 1032 pSelf->mDevice = pSelf->mSysfsPath = NULL; 1033 if (pSelf->mInterfaces) 1034 { 1035 usbInterfaceList_cleanup(&pSelf->mInterfaces->mList); 1036 RTMemFree(pSelf->mInterfaces); 1037 } 1038 } 1039 1040 int USBDevInfoInit(USBDeviceInfo *pSelf, const char *aDevice, 1041 const char *aSystemID) 1042 { 1043 const usbInterfaceList_iterator *pItBegin; 1044 1045 pSelf->mDevice = aDevice ? RTStrDup(aDevice) : NULL; 1046 pSelf->mSysfsPath = aSystemID ? RTStrDup(aSystemID) : NULL; 1047 pSelf->mInterfaces = (struct USBInterfaceList *) RTMemAllocZ(sizeof(struct USBInterfaceList)); 1048 if ( !pSelf->mInterfaces 1049 || !usbInterfaceList_init(&pSelf->mInterfaces->mList) 1050 || (aDevice && !pSelf->mDevice) || (aSystemID && ! pSelf->mSysfsPath)) 1051 { 1052 USBDevInfoCleanup(pSelf); 1053 return 0; 1054 } 1055 pItBegin = usbInterfaceList_begin(&pSelf->mInterfaces->mList); 1056 usbInterfaceList_iter_init(&pSelf->mInterfaces->mIt, pItBegin); 1057 return 1; 1058 } 1010 1059 1011 1060 int USBDevInfoUpdateDevices (VBoxMainUSBDeviceInfo *pSelf) … … 1027 1076 return rc; 1028 1077 } 1078 1079 char *USBDevInfoFirstInterface(struct USBInterfaceList *pInterfaces) 1080 { 1081 const usbInterfaceList_iterator *pItBegin, *pItEnd; 1082 pItBegin = usbInterfaceList_begin(&pInterfaces->mList); 1083 pItEnd = usbInterfaceList_end(&pInterfaces->mList); 1084 usbInterfaceList_iter_init(&pInterfaces->mIt, pItBegin); 1085 if (usbInterfaceList_iter_eq(pItBegin, pItEnd)) 1086 return NULL; 1087 return *usbInterfaceList_iter_target(&pInterfaces->mIt); 1088 } 1089 1090 char *USBDevInfoNextInterface(struct USBInterfaceList *pInterfaces) 1091 { 1092 const usbInterfaceList_iterator *pItEnd; 1093 pItEnd = usbInterfaceList_end(&pInterfaces->mList); 1094 if (usbInterfaceList_iter_eq(&pInterfaces->mIt, pItEnd)) 1095 return NULL; 1096 usbInterfaceList_iter_incr(&pInterfaces->mIt); 1097 if (usbInterfaceList_iter_eq(&pInterfaces->mIt, pItEnd)) 1098 return NULL; 1099 return *usbInterfaceList_iter_target(&pInterfaces->mIt); 1100 } 1101 1029 1102 1030 1103 class hotplugNullImpl : public VBoxMainHotplugWaiterImpl … … 1644 1717 char *pcszDup = RTStrDup(pcszNode); 1645 1718 if (pcszDup) 1646 if (USBInterfaceList_push_back(&pSelf->mInfo->mInterfaces, &pcszDup)) 1719 if (usbInterfaceList_push_back(&pSelf->mInfo->mInterfaces->mList, 1720 &pcszDup)) 1647 1721 return true; 1648 1722 RTStrFree(pcszDup); -
trunk/src/VBox/Main/linux/USBProxyServiceLinux.cpp
r32080 r32142 1340 1340 { 1341 1341 #ifdef VBOX_USB_WITH_SYSFS 1342 USBDevInfoUpdateDevices(&mDeviceList);1343 1342 /* Add each of the devices found to the chain. */ 1344 1343 PUSBDEVICE pFirst = NULL; 1345 1344 PUSBDEVICE pLast = NULL; 1346 int rc = VINF_SUCCESS;1345 int rc = USBDevInfoUpdateDevices(&mDeviceList); 1347 1346 USBDeviceInfoList_iterator it; 1348 1347 USBDeviceInfoList_iter_init(&it, USBDevInfoBegin(&mDeviceList)); … … 1442 1441 1443 1442 /* Check the interfaces to see if we can support the device. */ 1444 USBInterfaceList_iterator it2;1443 char *pszIf; 1445 1444 USBDeviceInfo *udi = USBDeviceInfoList_iter_target(&it); 1446 USBInterfaceList_iter_init(&it2, USBInterfaceList_begin(&udi->mInterfaces)); 1447 for (; !USBInterfaceList_iter_eq(&it2, USBInterfaceList_end(&udi->mInterfaces)); 1448 USBInterfaceList_iter_incr(&it2)) 1445 for (pszIf = USBDevInfoFirstInterface(udi->mInterfaces); pszIf; 1446 pszIf = USBDevInfoNextInterface(udi->mInterfaces)) 1449 1447 { 1450 1448 ssize_t cb = RTLinuxSysFsGetLinkDest(szBuf, sizeof(szBuf), "%s/driver", 1451 *USBInterfaceList_iter_target(&it2));1449 pszIf); 1452 1450 if (cb > 0 && Dev->enmState != USBDEVICESTATE_UNSUPPORTED) 1453 1451 Dev->enmState = (strcmp(szBuf, "hub") == 0) … … 1455 1453 : USBDEVICESTATE_USED_BY_HOST_CAPTURABLE; 1456 1454 if (RTLinuxSysFsReadIntFile(16, "%s/bInterfaceClass", 1457 *USBInterfaceList_iter_target(&it2)) == 9 /* hub */)1455 pszIf) == 9 /* hub */) 1458 1456 Dev->enmState = USBDEVICESTATE_UNSUPPORTED; 1459 1457 } -
trunk/src/VBox/Main/testcase/tstHostHardwareLinux.cpp
r31652 r32142 123 123 pInfo->mSysfsPath); 124 124 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)) 125 char *pszIf; 126 for (pszIf = USBDevInfoFirstInterface(pInfo->mInterfaces); pszIf; 127 pszIf = USBDevInfoNextInterface(pInfo->mInterfaces)) 129 128 { 130 129 char szDriver[RTPATH_MAX]; 131 char *pszIf = *USBInterfaceList_iter_target(&it2);132 130 strcpy(szDriver, "none"); 133 131 ssize_t size = RTLinuxSysFsGetLinkDest(szDriver, sizeof(szDriver),
Note:
See TracChangeset
for help on using the changeset viewer.