VirtualBox

Changeset 34257 in vbox


Ignore:
Timestamp:
Nov 22, 2010 4:57:23 PM (14 years ago)
Author:
vboxsync
Message:

USBLib-win: coding style and cosmetics

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxUSB/win/USBLib-win.cpp

    r33540 r34257  
    5656} USBDEV, *PUSBDEV;
    5757
    58 static PUSBDEV  pUSBDev = NULL;
    59 static uint32_t cMaxDevices = 0;
     58static PUSBDEV  g_pUSBDev = NULL;
     59static uint32_t g_cMaxDevices = 0;
    6060static uint32_t g_cUSBStateChange = 0;
    6161
     
    8585                      OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, NULL);
    8686
    87     if (INVALID_HANDLE_VALUE == hOut) {
     87    if (INVALID_HANDLE_VALUE == hOut)
     88    {
    8889        Log(( "USB: FAILED to open %s\n", pszName));
    8990        goto failure;
     
    218219    int j = 0, i = 0;
    219220
    220     while(true)
     221    while (true)
    221222    {
    222223        // SetupDiEnumDeviceInterfaces() returns information about device interfaces
     
    235236            {
    236237                uint32_t z;
    237                 for (z=0;z<cMaxDevices;z++)
     238                for (z = 0; z < g_cMaxDevices; z++)
    238239                {
    239                     if (pUSBDev[z].szName[0] == 0)
     240                    if (g_pUSBDev[z].szName[0] == 0)
    240241                    {
    241                         memcpy(&pUSBDev[z], &usbDev, sizeof(usbDev));
    242                         Log(("Captured device %s\n", pUSBDev[z].szName));
     242                        memcpy(&g_pUSBDev[z], &usbDev, sizeof(usbDev));
     243                        Log(("Captured device %s\n", g_pUSBDev[z].szName));
    243244                        j++;
    244245                        break;
    245246                    }
    246247                }
    247                 AssertMsg(z < cMaxDevices, ("z=%d cMaxDevices=%d\n", z, cMaxDevices));
     248                AssertMsg(z < g_cMaxDevices, ("z=%d g_cMaxDevices=%d\n", z, g_cMaxDevices));
    248249            }
    249250        }
     
    279280static int usblibEnumDevices(uint32_t cNumNewDevices, uint32_t *pcNumDevices)
    280281{
    281     if (pUSBDev)
    282         RTMemFree(pUSBDev);
    283     pUSBDev         = NULL;
    284     cMaxDevices     = 0;
     282    if (g_pUSBDev)
     283        RTMemFree(g_pUSBDev);
     284    g_pUSBDev         = NULL;
     285    g_cMaxDevices     = 0;
    285286    *pcNumDevices   = 0;
    286287
     
    288289        return 0;   /* nothing to do */
    289290
    290     pUSBDev = (PUSBDEV)RTMemAllocZ(cNumNewDevices*sizeof(USBDEV));
    291     if (!pUSBDev)
     291    g_pUSBDev = (PUSBDEV)RTMemAllocZ(cNumNewDevices*sizeof(USBDEV));
     292    if (!g_pUSBDev)
    292293    {
    293294        AssertFailed();
    294295        return VERR_NO_MEMORY;
    295296    }
    296     cMaxDevices = cNumNewDevices;
     297    g_cMaxDevices = cNumNewDevices;
    297298
    298299    if (OpenUsbDevices((LPGUID)&GUID_CLASS_VBOXUSB, pcNumDevices) == false)
     
    314315    int j=0;
    315316
    316     Assert(idxDev < cMaxDevices);
    317     for(uint32_t i=0;i<cMaxDevices;i++)
    318     {
    319         if (pUSBDev[i].szName[0])
     317    Assert(idxDev < g_cMaxDevices);
     318    for (uint32_t i=0; i<g_cMaxDevices; i++)
     319    {
     320        if (g_pUSBDev[i].szName[0])
    320321        {
    321322            if (j == idxDev)
    322                 return pUSBDev[i].szName;
     323                return g_pUSBDev[i].szName;
    323324            j++;
    324325        }
    325326    }
    326327
    327     Log(("USB: usblibQueryHandle returned -1; cMaxDevices = %d\n", cMaxDevices));
     328    Log(("USB: usblibQueryHandle returned -1; g_cMaxDevices = %d\n", g_cMaxDevices));
    328329    return NULL;
    329330}
     
    338339    int j=0;
    339340
    340     Assert(idxDev < cMaxDevices);
    341     for(uint32_t i=0;i<cMaxDevices;i++)
    342     {
    343         if (pUSBDev[i].szName[0])
     341    Assert(idxDev < g_cMaxDevices);
     342    for (uint32_t i=0; i<g_cMaxDevices; i++)
     343    {
     344        if (g_pUSBDev[i].szName[0])
    344345        {
    345346            if (j == idxDev)
    346                 return pUSBDev[i].szDriverRegName;
     347                return g_pUSBDev[i].szDriverRegName;
    347348            j++;
    348349        }
    349350    }
    350351
    351     Log(("USB: usblibQueryHandle returned -1; cMaxDevices = %d\n", cMaxDevices));
     352    Log(("USB: usblibQueryHandle returned -1; g_cMaxDevices = %d\n", g_cMaxDevices));
    352353    return NULL;
    353354}
     
    982983    // Port indices are 1 based, not 0 based.
    983984    //
    984     for (index=1; index <= NumPorts; index++)
     985    for (index = 1; index <= NumPorts; index++)
    985986    {
    986987        ULONG nBytes;
     
    17841785    {
    17851786#ifdef VBOX_WITH_ANNOYING_USB_ASSERTIONS
    1786         AssertMsgFailed(("DeviceIoControl IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION %d != %d\n", configDesc->wTotalLength, (nBytes - sizeof(USB_DESCRIPTOR_REQUEST)));
     1787        AssertMsgFailed(("DeviceIoControl IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION %d != %d\n", configDesc->wTotalLength, (nBytes - sizeof(USB_DESCRIPTOR_REQUEST))));
    17871788#else
    17881789        LogRel(("DeviceIoControl IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION %d != %d\n", configDesc->wTotalLength, (nBytes - sizeof(USB_DESCRIPTOR_REQUEST)) ));
     
    22062207    ULONG i;
    22072208
    2208     for (i=0; i<NumLanguageIDs; i++)
     2209    for (i = 0; i < NumLanguageIDs; i++)
    22092210    {
    22102211        StringDescNodeTail->Next = GetStringDescriptor(hHubDevice,
     
    27032704USBLIB_DECL(int) USBLibGetDevices(PUSBDEVICE *ppDevices, uint32_t *pcDevices)
    27042705{
    2705     DWORD cbReturned;
    27062706    USBSUP_GETNUMDEV numdev;
    2707     char *pszDevname = NULL;
    27082707    PUSBDEVICE pDevice = NULL;
    27092708    PUSBDEVICE pCaptured = NULL;
    27102709    PUSBDEVICE pList = NULL;
     2710    Log(("usbLibGetDevices: enter\n"));
     2711
     2712    if (g_hUSBMonitor == INVALID_HANDLE_VALUE)
     2713        return VERR_NOT_SUPPORTED;
     2714
     2715    /* 1: Enumerate all usb devices attached to the host */
    27112716    PUSBDEVICE pHostDevices = NULL;
    27122717    uint32_t   cHostDevices = 0;
    2713     Log(("usbLibGetDevices: enter\n"));
    2714 
    2715     if (g_hUSBMonitor == INVALID_HANDLE_VALUE)
    2716         return VERR_NOT_SUPPORTED;
    2717 
    2718     /* 1: Enumerate all usb devices attached to the host */
    27192718    usbLibEnumerateHostControllers(&pHostDevices, &cHostDevices);
    27202719#ifdef LOG_ENABLED
     
    27222721    pDevice = pHostDevices;
    27232722    int iDevice = 0;
    2724     while(pDevice)
     2723    while (pDevice)
    27252724    {
    27262725        iDevice++;
     
    27722771     */
    27732772
    2774     for (int i=0;i<100;i++)
     2773    for (int i = 0; i < 100; i++)
    27752774    {
    27762775        /*
    27772776         * Get the number of USB devices.
    27782777         */
    2779         cbReturned = 0;
     2778        DWORD cbReturned = 0;
    27802779        if (!DeviceIoControl(g_hUSBMonitor, SUPUSBFLT_IOCTL_GET_NUM_DEVICES, NULL, 0, &numdev, sizeof(numdev), &cbReturned, NULL))
    27812780        {
     
    27902789        Log(("Monitor detected %d captured devices\n", numdev.cUSBDevices));
    27912790
    2792         usblibEnumDevices(numdev.cUSBDevices, (uint32_t *)pcDevices);
     2791        usblibEnumDevices(numdev.cUSBDevices, pcDevices);
    27932792        Log(("usblibEnumDevices detected %d devices\n", *pcDevices));
    27942793
     
    28172816        HANDLE hDev;
    28182817
    2819         pszDevname = usblibQueryDeviceName(i);
     2818        char *pszDevname = usblibQueryDeviceName(i);
    28202819        hDev = CreateFile(pszDevname, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL,
    28212820                          OPEN_EXISTING,  FILE_ATTRIBUTE_SYSTEM, NULL);
     
    28232822        if (hDev != INVALID_HANDLE_VALUE)
    28242823        {
    2825             cbReturned = 0;
     2824            DWORD cbReturned = 0;
    28262825            if (!DeviceIoControl(hDev, SUPUSB_IOCTL_GET_DEVICE, &dev, sizeof(dev), &dev, sizeof(dev), &cbReturned, NULL))
    28272826            {
     
    28742873    /* 3: Add all host devices to array of captured devices; obviously making sure there are no duplicates */
    28752874    Assert(pHostDevices && pCaptured);
    2876     pList   = pCaptured;
    2877     for (uint32_t i=0;i<numdev.cUSBDevices;i++)
     2875    pList = pCaptured;
     2876    for (uint32_t i = 0; i < numdev.cUSBDevices; i++)
    28782877    {
    28792878        uint32_t j;
     
    28822881        Assert(pDevice);
    28832882
    2884         for (j=0;j<cHostDevices;j++)
     2883        for (j = 0; j < cHostDevices; j++)
    28852884        {
    28862885            char *pszDeviceRegPath = usblibQueryDeviceRegPath(i);
     
    29482947    pDevice = pHostDevices;
    29492948    iDevice = 0;
    2950     while(pDevice)
     2949    while (pDevice)
    29512950    {
    29522951        iDevice++;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette