Example #1
0
LRESULT CALLBACK DevDetectWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_DEVICECHANGE:
			{
				PDEV_BROADCAST_HDR pBroadcastHdr = (PDEV_BROADCAST_HDR)lParam;
				PDEV_BROADCAST_DEVICEINTERFACE pDevIF = (PDEV_BROADCAST_DEVICEINTERFACE)pBroadcastHdr;

				if(pBroadcastHdr)
				{
					DWORD nEventType = (DWORD)wParam; 
					if (pBroadcastHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) 
					{
						_strlwr(pDevIF->dbcc_name);

						XnUSBEventArgs args;
						args.strDevicePath = pDevIF->dbcc_name;

						switch (nEventType)
						{
						case DBT_DEVICEARRIVAL:
							args.eventType = XN_USB_EVENT_DEVICE_CONNECT;
							break;
						case DBT_DEVICEREMOVECOMPLETE:
							args.eventType = XN_USB_EVENT_DEVICE_DISCONNECT;
							break;
						default:
							return 0;
						}

						for (XnUSBEventCallbackList::Iterator it = g_connectivityEvent.Begin(); it != g_connectivityEvent.End(); ++it)
						{
							XnUSBEventCallback* pCallback = *it;
							if (strstr(args.strDevicePath, pCallback->strVidPid) != NULL)
							{
								pCallback->pFunc(&args, pCallback->pCookie);
							}
						}
					}
				}
			}
			break;
	default:
		return DefWindowProc(hwnd, msg, wParam, lParam);	
	}

	return 0;
}
Example #2
0
void xnUSBDeviceDisconnected(struct udev_device *dev)
{
	// find dev in the connected devices' list
	XnUSBConnectedDevice *pConnected = NULL;
	for (XnUSBConnectedDeviceList::Iterator it = g_connectedDevices.Begin(); it != g_connectedDevices.End(); ++it)
	{
		if (!xnOSStrCmp(((XnUSBConnectedDevice *)*it)->strNode, udev_device_get_devnode(dev)))
		{
			pConnected = *it;
			break;
		}
	}

	if(!pConnected)
	{
		// got disconnection of an unknown device. not good.
		xnLogWarning(XN_MASK_USB, "Got device disconnection event - for an unknown device!");
		return;
	}

	// notify the proper events of the disconnection
	for (XnUSBEventCallbackList::Iterator it = g_connectivityEvent.Begin(); it != g_connectivityEvent.End(); ++it)
	{
		XnUSBEventCallback* pCallback = *it;

		if(pCallback->nVendorID == pConnected->nVendorID && pCallback->nProductID == pConnected->nProductID)
		{
			XnUSBEventArgs args;
			args.strDevicePath = pConnected->strDevicePath;
			args.eventType = XN_USB_EVENT_DEVICE_DISCONNECT;
			pCallback->pFunc(&args, pCallback->pCookie);
		}
	}

	// remove the device from connectedDevices List
	g_connectedDevices.Remove(pConnected);
	XN_DELETE(pConnected);
}
Example #3
0
void xnUSBDeviceConnected(struct udev_device *dev)
{
	XnUSBConnectedDevice *pConnected;
	pConnected = XN_NEW(XnUSBConnectedDevice);

	pConnected->nVendorID  = strtoul(udev_device_get_sysattr_value(dev,"idVendor"),  NULL, 16);
	pConnected->nProductID = strtoul(udev_device_get_sysattr_value(dev,"idProduct"), NULL, 16);
	pConnected->nBusNum    = strtoul(udev_device_get_sysattr_value(dev,"busnum"),    NULL, 10);
	pConnected->nDevNum    = strtoul(udev_device_get_sysattr_value(dev,"devnum"),    NULL, 10);

	// copy the device node path aside, to be used upon removal
	xnOSStrCopy(pConnected->strNode, udev_device_get_devnode(dev), XN_FILE_MAX_PATH);

	// generate our unique URI
	snprintf(pConnected->strDevicePath, XN_FILE_MAX_PATH,
				"%04hx/%04hx@%hhu/%hhu",
				pConnected->nVendorID,
				pConnected->nProductID,
				pConnected->nBusNum,
				pConnected->nDevNum);

	// add the device to the connectedDevices List
	g_connectedDevices.AddLast(pConnected);

	// notify the proper events of the connection
	for (XnUSBEventCallbackList::Iterator it = g_connectivityEvent.Begin(); it != g_connectivityEvent.End(); ++it)
	{
		XnUSBEventCallback* pCallback = *it;

		if(pCallback->nVendorID == pConnected->nVendorID && pCallback->nProductID == pConnected->nProductID)
		{
			XnUSBEventArgs args;
			args.strDevicePath = pConnected->strDevicePath;
			args.eventType = XN_USB_EVENT_DEVICE_CONNECT;
			pCallback->pFunc(&args, pCallback->pCookie);
		}
	}
}