Changeset 38714 in vbox for trunk/src/VBox/HostDrivers/VBoxUSB/win/lib/VBoxUsbLib-win.cpp
- Timestamp:
- Sep 12, 2011 11:58:43 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxUSB/win/lib/VBoxUsbLib-win.cpp
r38713 r38714 1170 1170 } 1171 1171 1172 static void usbLibOnDeviceChange( )1172 static void usbLibOnDeviceChange(void) 1173 1173 { 1174 1174 /* we're getting series of events like that especially on device re-attach … … 1183 1183 { 1184 1184 DWORD winEr = GetLastError(); 1185 AssertMsg(winEr == ERROR_IO_PENDING, ( __FUNCTION__":DeleteTimerQueueTimer failed, winEr (%d)\n", winEr));1185 AssertMsg(winEr == ERROR_IO_PENDING, ("DeleteTimerQueueTimer failed, winEr (%d)\n", winEr)); 1186 1186 } 1187 1187 } 1188 1188 1189 1189 if (!CreateTimerQueueTimer(&g_VBoxUsbGlobal.hTimer, g_VBoxUsbGlobal.hTimerQueue, 1190 usbLibTimerCallback, 1191 NULL, 1192 500, /* ms*/ 1193 0, 1194 WT_EXECUTEONLYONCE)) 1195 { 1196 DWORD winEr = GetLastError(); 1197 AssertMsgFailed(("CreateTimerQueueTimer failed, winEr (%d)\n", winEr)); 1198 1199 /* call it directly */ 1200 usbLibTimerCallback(NULL, FALSE); 1201 } 1202 } 1203 1204 static LRESULT CALLBACK usbLibWndProc(HWND hwnd, 1205 UINT uMsg, 1206 WPARAM wParam, 1207 LPARAM lParam 1208 ) 1190 usbLibTimerCallback, 1191 NULL, 1192 500, /* ms*/ 1193 0, 1194 WT_EXECUTEONLYONCE)) 1195 { 1196 DWORD winEr = GetLastError(); 1197 AssertMsgFailed(("CreateTimerQueueTimer failed, winEr (%d)\n", winEr)); 1198 1199 /* call it directly */ 1200 usbLibTimerCallback(NULL, FALSE); 1201 } 1202 } 1203 1204 static LRESULT CALLBACK usbLibWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 1209 1205 { 1210 1206 switch (uMsg) … … 1231 1227 } 1232 1228 1233 static LPCSTR g_VBoxUsbWndClassName = "VBoxUsbLibClass"; 1234 1235 static DWORD WINAPI usbLibMsgThreadProc(__in LPVOID lpParameter) 1236 { 1237 HWND hwnd = 0; 1238 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle (NULL); 1239 bool bExit = false; 1229 static DWORD WINAPI usbLibMsgThreadProc(__in LPVOID lpParameter) 1230 { 1231 static LPCSTR s_szVBoxUsbWndClassName = "VBoxUsbLibClass"; 1232 HWND hwnd = 0; 1233 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL); 1234 bool bExit = false; 1240 1235 1241 1236 /* Register the Window Class. */ … … 1250 1245 wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1); 1251 1246 wc.lpszMenuName = NULL; 1252 wc.lpszClassName = g_VBoxUsbWndClassName;1247 wc.lpszClassName = s_szVBoxUsbWndClassName; 1253 1248 1254 1249 ATOM atomWindowClass = RegisterClass(&wc); … … 1257 1252 { 1258 1253 /* Create the window. */ 1259 g_VBoxUsbGlobal.hWnd = CreateWindowEx 1260 g_VBoxUsbWndClassName, g_VBoxUsbWndClassName,1261 1262 1254 g_VBoxUsbGlobal.hWnd = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST, 1255 s_szVBoxUsbWndClassName, s_szVBoxUsbWndClassName, 1256 WS_POPUPWINDOW, 1257 -200, -200, 100, 100, NULL, NULL, hInstance, NULL); 1263 1258 SetEvent(g_VBoxUsbGlobal.hNotifyEvent); 1264 1259 … … 1275 1270 } 1276 1271 1277 DestroyWindow 1272 DestroyWindow(hwnd); 1278 1273 1279 1274 bExit = true; 1280 1275 } 1281 1276 1282 UnregisterClass (g_VBoxUsbWndClassName, hInstance);1277 UnregisterClass(s_szVBoxUsbWndClassName, hInstance); 1283 1278 } 1284 1279 1285 if(bExit) 1280 /** @todo r=bird: Please explain why the USB library needs 1281 * this exit(0) hack! */ 1282 if (bExit) 1286 1283 { 1287 1284 /* no need any accuracy here, in anyway the DHCP server usually gets terminated with TerminateProcess */ … … 1308 1305 g_VBoxUsbGlobal.hMonitor = INVALID_HANDLE_VALUE; 1309 1306 1310 g_VBoxUsbGlobal.hNotifyEvent = CreateEvent(NULL, /* LPSECURITY_ATTRIBUTES lpEventAttributes */1311 FALSE, /* BOOL bManualReset */1307 g_VBoxUsbGlobal.hNotifyEvent = CreateEvent(NULL, /* LPSECURITY_ATTRIBUTES lpEventAttributes */ 1308 FALSE, /* BOOL bManualReset */ 1312 1309 #ifndef VBOX_USB_USE_DEVICE_NOTIFICATION 1313 TRUE, /* BOOL bInitialState */1310 TRUE, /* BOOL bInitialState */ 1314 1311 #else 1315 FALSE, /* set to false since it will be initially used for notification thread startup sync */1316 #endif 1317 NULL/* LPCTSTR lpName */);1312 FALSE, /* set to false since it will be initially used for notification thread startup sync */ 1313 #endif 1314 NULL /* LPCTSTR lpName */); 1318 1315 if (g_VBoxUsbGlobal.hNotifyEvent) 1319 1316 { 1320 g_VBoxUsbGlobal.hInterruptEvent = CreateEvent(NULL, /* LPSECURITY_ATTRIBUTES lpEventAttributes */1321 FALSE, /* BOOL bManualReset */1322 FALSE,/* BOOL bInitialState */1323 NULL/* LPCTSTR lpName */);1317 g_VBoxUsbGlobal.hInterruptEvent = CreateEvent(NULL, /* LPSECURITY_ATTRIBUTES lpEventAttributes */ 1318 FALSE, /* BOOL bManualReset */ 1319 FALSE, /* BOOL bInitialState */ 1320 NULL /* LPCTSTR lpName */); 1324 1321 if (g_VBoxUsbGlobal.hInterruptEvent) 1325 1322 { … … 1350 1347 if (DeviceIoControl(g_VBoxUsbGlobal.hMonitor, SUPUSBFLT_IOCTL_GET_VERSION, NULL, 0, &Version, sizeof (Version), &cbReturned, NULL)) 1351 1348 { 1352 if (Version.u32Major == USBMON_MAJOR_VERSION || Version.u32Minor <= USBMON_MINOR_VERSION) 1349 /** @todo r=bird: Explain why we accept any mismatching major 1350 * version as long as the minor version is less or equal! 1351 * It does not make sense to me... */ 1352 if ( Version.u32Major == USBMON_MAJOR_VERSION 1353 || Version.u32Minor <= USBMON_MINOR_VERSION) 1353 1354 { 1354 1355 #ifndef VBOX_USB_USE_DEVICE_NOTIFICATION … … 1357 1358 SetEvent.u.hEvent = g_VBoxUsbGlobal.hNotifyEvent; 1358 1359 if (DeviceIoControl(g_VBoxUsbGlobal.hMonitor, SUPUSBFLT_IOCTL_SET_NOTIFY_EVENT, 1359 &SetEvent, sizeof(SetEvent),1360 &SetEvent, sizeof(SetEvent),1361 &cbReturned, NULL))1360 &SetEvent, sizeof(SetEvent), 1361 &SetEvent, sizeof(SetEvent), 1362 &cbReturned, NULL)) 1362 1363 { 1363 1364 rc = SetEvent.u.rc; 1364 1365 AssertRC(rc); 1365 1366 if (RT_SUCCESS(rc)) 1367 { 1368 /* 1369 * We're DONE! 1370 */ 1366 1371 return VINF_SUCCESS; 1367 else1368 1372 } 1373 AssertMsgFailed(("SetEvent failed, rc (%d)\n", rc)); 1369 1374 } 1370 1375 else … … 1386 1391 NULL /*__out_opt LPDWORD lpThreadId*/ 1387 1392 ); 1388 1389 if(g_VBoxUsbGlobal.hThread) 1393 if (g_VBoxUsbGlobal.hThread) 1390 1394 { 1391 1395 DWORD dwResult = WaitForSingleObject(g_VBoxUsbGlobal.hNotifyEvent, INFINITE); 1392 1396 Assert(dwResult == WAIT_OBJECT_0); 1393 1394 1397 if (g_VBoxUsbGlobal.hWnd) 1395 1398 { 1396 /* ensure the event is set so the first "wait change" request processes */ 1399 /* 1400 * We're DONE! 1401 * 1402 * Juse ensure that the event is set so the 1403 * first "wait change" request is processed. 1404 */ 1397 1405 SetEvent(g_VBoxUsbGlobal.hNotifyEvent); 1398 1406 return VINF_SUCCESS; 1399 1407 } 1408 1400 1409 dwResult = WaitForSingleObject(g_VBoxUsbGlobal.hThread, INFINITE); 1401 1410 Assert(dwResult == WAIT_OBJECT_0); 1402 1411 BOOL bRc = CloseHandle(g_VBoxUsbGlobal.hThread); 1403 if (!bRc) 1404 { 1405 DWORD winEr = GetLastError(); 1406 AssertMsgFailed(("CloseHandle for hThread failed winEr(%d)\n", winEr)); 1407 } 1412 AssertMsg(bRc, ("CloseHandle for hThread failed winEr(%d)\n", GetLastError())); 1413 g_VBoxUsbGlobal.hThread = INVALID_HANDLE_VALUE; 1408 1414 } 1409 1415 else … … 1413 1419 rc = VERR_GENERAL_FAILURE; 1414 1420 } 1421 1422 DeleteTimerQueueEx(g_VBoxUsbGlobal.hTimerQueue, INVALID_HANDLE_VALUE /* see term */); 1423 g_VBoxUsbGlobal.hTimerQueue = NULL; 1415 1424 } 1416 1425 else … … 1438 1447 1439 1448 CloseHandle(g_VBoxUsbGlobal.hMonitor); 1449 g_VBoxUsbGlobal.hMonitor = INVALID_HANDLE_VALUE; 1440 1450 } 1441 1451 else … … 1449 1459 1450 1460 CloseHandle(g_VBoxUsbGlobal.hInterruptEvent); 1461 g_VBoxUsbGlobal.hInterruptEvent = NULL; 1451 1462 } 1452 1463 else … … 1458 1469 1459 1470 CloseHandle(g_VBoxUsbGlobal.hNotifyEvent); 1471 g_VBoxUsbGlobal.hNotifyEvent = NULL; 1460 1472 } 1461 1473 else … … 1483 1495 if (g_VBoxUsbGlobal.hMonitor == INVALID_HANDLE_VALUE) 1484 1496 { 1485 #ifdef VBOX_WITH_ANNOYING_USB_ASSERTIONS 1486 AssertFailed(); 1487 #endif 1488 return VINF_ALREADY_INITIALIZED; 1497 Assert(g_VBoxUsbGlobal.hInterruptEvent == NULL); 1498 Assert(g_VBoxUsbGlobal.hNotifyEvent == NULL); 1499 return VINF_SUCCESS; 1489 1500 } 1490 1501 1491 1502 BOOL bRc; 1492 1503 #ifdef VBOX_USB_USE_DEVICE_NOTIFICATION 1493 bRc = PostMessage(g_VBoxUsbGlobal.hWnd, WM_QUIT, 0, 0);1504 bRc = PostMessage(g_VBoxUsbGlobal.hWnd, WM_QUIT, 0, 0); 1494 1505 if (!bRc) 1495 1506 { … … 1503 1514 Assert(dwResult == WAIT_OBJECT_0); 1504 1515 bRc = CloseHandle(g_VBoxUsbGlobal.hThread); 1505 if (!bRc) 1506 { 1507 DWORD winEr = GetLastError(); 1508 AssertMsgFailed(("CloseHandle for hThread failed winEr(%d)\n", winEr)); 1509 } 1516 AssertMsg(bRc, ("CloseHandle for hThread failed winEr(%d)\n", GetLastError())); 1510 1517 } 1511 1518 … … 1513 1520 { 1514 1521 bRc = DeleteTimerQueueTimer(g_VBoxUsbGlobal.hTimerQueue, g_VBoxUsbGlobal.hTimer, 1515 INVALID_HANDLE_VALUE /* <-- to block until the timer is completed */ 1516 ); 1517 if (!bRc) 1518 { 1519 DWORD winEr = GetLastError(); 1520 AssertMsgFailed(("DeleteTimerQueueEx failed winEr(%d)\n", winEr)); 1521 } 1522 INVALID_HANDLE_VALUE); /* <-- to block until the timer is completed */ 1523 AssertMsg(bRc, ("DeleteTimerQueueTimer failed winEr(%d)\n", GetLastError())); 1522 1524 } 1523 1525 … … 1525 1527 { 1526 1528 bRc = DeleteTimerQueueEx(g_VBoxUsbGlobal.hTimerQueue, 1527 INVALID_HANDLE_VALUE /* <-- to block until all timers are completed */ 1528 ); 1529 if (!bRc) 1530 { 1531 DWORD winEr = GetLastError(); 1532 AssertMsgFailed(("DeleteTimerQueueEx failed winEr(%d)\n", winEr)); 1533 } 1534 } 1535 #endif 1529 INVALID_HANDLE_VALUE); /* <-- to block until all timers are completed */ 1530 AssertMsg(bRc, ("DeleteTimerQueueEx failed winEr(%d)\n", GetLastError())); 1531 } 1532 #endif /* VBOX_USB_USE_DEVICE_NOTIFICATION */ 1536 1533 1537 1534 bRc = CloseHandle(g_VBoxUsbGlobal.hMonitor); 1538 if (!bRc) 1539 { 1540 DWORD winEr = GetLastError(); 1541 AssertMsgFailed(("CloseHandle for hMonitor failed winEr(%d)\n", winEr)); 1542 } 1543 1535 AssertMsg(bRc, ("CloseHandle for hMonitor failed winEr(%d)\n", GetLastError())); 1536 g_VBoxUsbGlobal.hMonitor = INVALID_HANDLE_VALUE; 1537 1544 1538 bRc = CloseHandle(g_VBoxUsbGlobal.hInterruptEvent); 1545 if (!bRc) 1546 { 1547 DWORD winEr = GetLastError(); 1548 AssertMsgFailed(("CloseHandle for hInterruptEvent failed winEr(%d)\n", winEr)); 1549 } 1539 AssertMsg(bRc, ("CloseHandle for hInterruptEvent failed lasterr=%u\n", GetLastError())); 1540 g_VBoxUsbGlobal.hInterruptEvent = NULL; 1550 1541 1551 1542 bRc = CloseHandle(g_VBoxUsbGlobal.hNotifyEvent); 1552 if (!bRc) 1553 { 1554 DWORD winEr = GetLastError(); 1555 AssertMsgFailed(("CloseHandle for hNotifyEvent failed winEr(%d)\n", winEr)); 1556 } 1543 AssertMsg(bRc, ("CloseHandle for hNotifyEvent failed winEr(%d)\n", GetLastError())); 1544 g_VBoxUsbGlobal.hNotifyEvent = NULL; 1557 1545 1558 1546 return VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.