MCPcopy Create free account
hub / github.com/OpenNI/OpenNI / xnUSBInitReadThread

Function xnUSBInitReadThread

Source/OpenNI/Win32/XnUSBWin32.cpp:1488–1553  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1486}
1487
1488XN_C_API XnStatus xnUSBInitReadThread(XN_USB_EP_HANDLE pEPHandle, XnUInt32 nBufferSize, XnUInt32 nNumBuffers, XnUInt32 nTimeOut, XnUSBReadCallbackFunctionPtr pCallbackFunction, PVOID pCallbackData)
1489{
1490 // Local variables
1491 XnStatus nRetVal = XN_STATUS_OK;
1492 xnUSBReadThreadData* pThreadData = NULL;
1493 XnUInt32 nBufIdx = 0;
1494
1495 // Validate xnUSB
1496 XN_VALIDATE_USB_INIT();
1497 XN_VALIDATE_USB_PEP_HANDLE(pEPHandle);
1498
1499 // Validate the input/output pointers
1500 XN_VALIDATE_INPUT_PTR(pCallbackFunction);
1501
1502 // Dereference the ThreadData
1503 pThreadData = &pEPHandle->ThreadData;
1504
1505 // Does this EP already have a read thread?
1506 if (pThreadData->bInUse == TRUE)
1507 {
1508 return (XN_STATUS_USB_READTHREAD_ALREADY_INIT);
1509 }
1510
1511 // Wipe the ThreadData memory
1512 xnOSMemSet(pThreadData, 0, sizeof(xnUSBReadThreadData));
1513
1514 // Init the ThreadData structure
1515 pThreadData->pEPHandle = pEPHandle;
1516 pThreadData->nBufferSize = nBufferSize;
1517 pThreadData->nNumBuffers = nNumBuffers;
1518 pThreadData->nTimeOut = nTimeOut;
1519 pThreadData->pCallbackFunction = pCallbackFunction;
1520 pThreadData->pCallbackData = pCallbackData;
1521 pThreadData->bKillReadThread = FALSE;
1522
1523 // Update the EP timeout
1524 if (nTimeOut != pEPHandle->nTimeOut)
1525 {
1526 nRetVal = xnUSBSetPipeProperty(pEPHandle, PSUSBDRV_PIPE_PROPERTY_TIMEOUT, nTimeOut);
1527 XN_IS_STATUS_OK(nRetVal);
1528
1529 pEPHandle->nTimeOut = nTimeOut;
1530 }
1531
1532 // Allocate the read buffers and create the overlapped I/O events
1533 XN_VALIDATE_ALIGNED_CALLOC(pThreadData->pBuffersInfo, xnUSBBuffersInfo, nNumBuffers, XN_DEFAULT_MEM_ALIGN);
1534 XN_VALIDATE_ALIGNED_CALLOC(pThreadData->pOvlpIO, OVERLAPPED, nNumBuffers, XN_DEFAULT_MEM_ALIGN);
1535
1536 for (nBufIdx=0; nBufIdx<nNumBuffers; nBufIdx++)
1537 {
1538 nRetVal = xnOSCreateEvent(&pThreadData->pOvlpIO[nBufIdx].hEvent, FALSE);
1539 XN_IS_STATUS_OK(nRetVal); // Add cleanup memory!
1540
1541 XN_VALIDATE_ALIGNED_CALLOC(pThreadData->pBuffersInfo[nBufIdx].pBuffer, XnUChar, nBufferSize, XN_DEFAULT_MEM_ALIGN); // Add cleanup memory!
1542 }
1543
1544 // Create the read thread
1545 nRetVal = xnOSCreateThread(xnUSBReadThreadMain, &pEPHandle->ThreadData, &pThreadData->hReadThread);

Callers

nothing calls this directly

Calls 4

xnUSBSetPipePropertyFunction · 0.85
xnOSMemSetFunction · 0.70
xnOSCreateEventFunction · 0.70
xnOSCreateThreadFunction · 0.70

Tested by

no test coverage detected