Changeset 60148 in vbox for trunk/src/VBox
- Timestamp:
- Mar 23, 2016 11:00:51 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/linux/USBGetDevices.cpp
r60147 r60148 62 62 * Structures and Typedefs * 63 63 *********************************************************************************************************************************/ 64 /** Suffix translation. */65 typedef struct USBSUFF66 {67 char szSuff[4];68 unsigned cchSuff;69 unsigned uMul;70 unsigned uDiv;71 } USBSUFF, *PUSBSUFF;72 typedef const USBSUFF *PCUSBSUFF;73 74 64 /** Structure describing a host USB device */ 75 65 typedef struct USBDeviceInfo … … 84 74 } USBDeviceInfo; 85 75 86 87 /*********************************************************************************************************************************88 * Global Variables *89 *********************************************************************************************************************************/90 /**91 * Suffixes for the endpoint polling interval.92 */93 static const USBSUFF s_aIntervalSuff[] =94 {95 { "ms", 2, 1, 0 },96 { "us", 2, 1, 1000 },97 { "ns", 2, 1, 1000000 },98 { "s", 1, 1000, 0 },99 { "", 0, 0, 0 } /* term */100 };101 102 103 /**104 * "reads" the number suffix.105 *106 * It's more like validating it and skipping the necessary number of chars.107 */108 static int usbReadSkipSuffix(char **ppszNext)109 {110 char *pszNext = *ppszNext;111 if (!RT_C_IS_SPACE(*pszNext) && *pszNext)112 {113 /* skip unit */114 if (pszNext[0] == 'm' && pszNext[1] == 's')115 pszNext += 2;116 else if (pszNext[0] == 'm' && pszNext[1] == 'A')117 pszNext += 2;118 119 /* skip parenthesis */120 if (*pszNext == '(')121 {122 pszNext = strchr(pszNext, ')');123 if (!pszNext++)124 {125 AssertMsgFailed(("*ppszNext=%s\n", *ppszNext));126 return VERR_PARSE_ERROR;127 }128 }129 130 /* blank or end of the line. */131 if (!RT_C_IS_SPACE(*pszNext) && *pszNext)132 {133 AssertMsgFailed(("pszNext=%s\n", pszNext));134 return VERR_PARSE_ERROR;135 }136 137 /* it's ok. */138 *ppszNext = pszNext;139 }140 141 return VINF_SUCCESS;142 }143 76 144 77 … … 187 120 188 121 /** 122 * "reads" the number suffix. 123 * 124 * It's more like validating it and skipping the necessary number of chars. 125 */ 126 static int usbfsReadSkipSuffix(char **ppszNext) 127 { 128 char *pszNext = *ppszNext; 129 if (!RT_C_IS_SPACE(*pszNext) && *pszNext) 130 { 131 /* skip unit */ 132 if (pszNext[0] == 'm' && pszNext[1] == 's') 133 pszNext += 2; 134 else if (pszNext[0] == 'm' && pszNext[1] == 'A') 135 pszNext += 2; 136 137 /* skip parenthesis */ 138 if (*pszNext == '(') 139 { 140 pszNext = strchr(pszNext, ')'); 141 if (!pszNext++) 142 { 143 AssertMsgFailed(("*ppszNext=%s\n", *ppszNext)); 144 return VERR_PARSE_ERROR; 145 } 146 } 147 148 /* blank or end of the line. */ 149 if (!RT_C_IS_SPACE(*pszNext) && *pszNext) 150 { 151 AssertMsgFailed(("pszNext=%s\n", pszNext)); 152 return VERR_PARSE_ERROR; 153 } 154 155 /* it's ok. */ 156 *ppszNext = pszNext; 157 } 158 159 return VINF_SUCCESS; 160 } 161 162 163 /** 189 164 * Reads a USB number returning the number and the position of the next character to parse. 190 165 */ 191 static int usbfsReadNum(const char *pszValue, unsigned uBase, uint32_t u32Mask, PCUSBSUFF paSuffs,void *pvNum, char **ppszNext)166 static int usbfsReadNum(const char *pszValue, unsigned uBase, uint32_t u32Mask, void *pvNum, char **ppszNext) 192 167 { 193 168 /* … … 224 199 } 225 200 226 /* 227 * Validate and skip stuff following the number. 228 */ 229 if (paSuffs) 230 { 231 if (!RT_C_IS_SPACE(*pszNext) && *pszNext) 232 { 233 for (PCUSBSUFF pSuff = paSuffs; pSuff->szSuff[0]; pSuff++) 234 { 235 if ( !strncmp(pSuff->szSuff, pszNext, pSuff->cchSuff) 236 && (!pszNext[pSuff->cchSuff] || RT_C_IS_SPACE(pszNext[pSuff->cchSuff]))) 237 { 238 if (pSuff->uDiv) 239 u32 /= pSuff->uDiv; 240 else 241 u32 *= pSuff->uMul; 242 break; 243 } 244 } 245 } 246 } 247 else 248 { 249 int rc = usbfsReadSkipSuffix(&pszNext); 250 if (RT_FAILURE(rc)) 251 return rc; 252 } 201 int rc = usbfsReadSkipSuffix(&pszNext); 202 if (RT_FAILURE(rc)) 203 return rc; 253 204 254 205 *ppszNext = pszNext; … … 270 221 static int usbfsRead8(const char *pszValue, unsigned uBase, uint8_t *pu8, char **ppszNext) 271 222 { 272 return usbfsReadNum(pszValue, uBase, 0xff, NULL,pu8, ppszNext);223 return usbfsReadNum(pszValue, uBase, 0xff, pu8, ppszNext); 273 224 } 274 225 … … 276 227 static int usbfsRead16(const char *pszValue, unsigned uBase, uint16_t *pu16, char **ppszNext) 277 228 { 278 return usbfsReadNum(pszValue, uBase, 0xffff, NULL, pu16, ppszNext); 279 } 280 281 282 #if 0 283 static int usbRead16Suff(const char *pszValue, unsigned uBase, PCUSBSUFF paSuffs, uint16_t *pu16, char **ppszNext) 284 { 285 return usbReadNum(pszValue, uBase, 0xffff, paSuffs, pu16, ppszNext); 286 } 287 #endif 229 return usbfsReadNum(pszValue, uBase, 0xffff, pu16, ppszNext); 230 } 288 231 289 232
Note:
See TracChangeset
for help on using the changeset viewer.