static void FreeDeviceList(void* pv) { DEVICELIST_INTERNAL* pInt = ((DEVICELIST_INTERNAL*)pv) - 1; WacomFreeList(pInt->pSerialList); WacomFreeList(pInt->pUSBList); free(pInt); }
void Usage(void) { int i, j, nClsSize, nDevSize; unsigned int uDeviceCls; WACOMCLASSREC* pCls; WACOMDEVICEREC* pDev; fprintf(stderr,"Usage: wacdump [options] device\n" "Options:\n" " -h, --help - usage\n" " -c, --class device_cls - use specified class (see below)\n" " -f, --force device_name - use specified device (see below)\n" " -l, --list - list all supported devices\n" " -v, --verbose - increase log output; multiple OK\n" " -V, --version - display version number\n" " --logfile log_file - output log to file\n" "\n"); fprintf(stderr, "Example devices:\n" #ifdef WCM_ENABLE_LINUXINPUT " /dev/input/event0 - usb tablet device\n" #endif " /dev/ttyS0 - serial tablet on com1\n" " /dev/ttyUSB0 - serial tablet on USB adapter\n" "\n" "Supported device classes:\n"); if (!WacomGetSupportedClassList(&pCls,&nClsSize)) { fprintf(stderr," "); for (i=0; i<nClsSize; ++i) fprintf(stderr,"%s%s", i ? ", " : "", pCls[i].pszName); fprintf(stderr,"\n"); fprintf(stderr,"Supported device names:\n"); for (i=0; i<nClsSize; ++i) { fprintf(stderr," %s: ",pCls[i].pszName); uDeviceCls = pCls[i].uDeviceClass; if (!WacomGetSupportedDeviceList(uDeviceCls,&pDev,&nDevSize)) { for (j=0; j<nDevSize; ++j) fprintf(stderr,"%s%s", j ? ", " : "", pDev[j].pszName); fprintf(stderr,"\n"); WacomFreeList(pDev); } } WacomFreeList(pCls); } }
int WacomGetSupportedDeviceList(unsigned int uDeviceClass, WACOMDEVICEREC** ppList, int* pnSize) { int nSerialCnt=0, nUSBCnt=0, nTotalBytes; WACOMDEVICEREC* pSerial=NULL, *pUSB=NULL, *pList; DEVICELIST_INTERNAL* pInt; if (!ppList || !pnSize) { errno = EINVAL; return 1; } /* get serial list */ if (((!uDeviceClass) || (uDeviceClass == WACOMCLASS_SERIAL)) && WacomGetSupportedSerialDeviceList(&pSerial, &nSerialCnt)) return 1; /* get usb list */ if (((!uDeviceClass) || (uDeviceClass == WACOMCLASS_USB)) && WacomGetSupportedUSBDeviceList(&pUSB, &nUSBCnt)) { if (pSerial) WacomFreeList(pSerial); return 1; } /* need memory for duplicate records and list internal structure */ nTotalBytes = sizeof(WACOMDEVICEREC) * (nSerialCnt + nUSBCnt) + sizeof(DEVICELIST_INTERNAL); /* allocate memory */ pInt = (DEVICELIST_INTERNAL*)malloc(nTotalBytes); /* copy initial list pointers */ pInt->pSerialList = pSerial; pInt->pUSBList = pUSB; pInt->pfnFree = FreeDeviceList; /* copy records */ pList = (WACOMDEVICEREC*)(pInt + 1); if (pSerial) memcpy(pList,pSerial,sizeof(WACOMDEVICEREC) * nSerialCnt); if (pUSB) memcpy(pList + nSerialCnt, pUSB, sizeof(WACOMDEVICEREC) * nUSBCnt); *ppList = pList; *pnSize = nSerialCnt + nUSBCnt; return 0; }
void ListSupportedDevices(void) { int i, nListSize; WACOMDEVICEREC* pList; if (!WacomGetSupportedDeviceList(0,&pList,&nListSize)) { for (i=0; i<nListSize; ++i) { fprintf(stdout,"%s\t%s\t%s\t\"%s\"\n", pList[i].pszName, pList[i].pszVendorName, pList[i].pszClass, pList[i].pszDesc); } WacomFreeList(pList); } }