VirtualBox

Ignore:
Timestamp:
Jan 24, 2014 9:16:37 PM (11 years ago)
Author:
vboxsync
Message:

USB/Proxy: Start a source code cleanup, remove unused struct members and make the generic proxy code do the backend specific memory allocation (fixes a small memory leak in the VRDP backend when closing a proxy device)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/USB/vrdp/USBProxyDevice-vrdp.cpp

    r49814 r50228  
    55
    66/*
    7  * Copyright (C) 2006-2010 Oracle Corporation
     7 * Copyright (C) 2006-2014 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4343 */
    4444
    45 static int usbProxyVrdpOpen(PUSBPROXYDEV pProxyDev, const char *pszAddress, void *pvBackend)
     45static DECLCALLBACK(int) usbProxyVrdpOpen(PUSBPROXYDEV pProxyDev, const char *pszAddress, void *pvBackend)
    4646{
    4747    LogFlow(("usbProxyVrdpOpen: pProxyDev=%p pszAddress=%s, pvBackend=%p\n", pProxyDev, pszAddress, pvBackend));
    4848
     49    PUSBPROXYDEVVRDP pDevVrdp = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVVRDP);
    4950    int rc = VINF_SUCCESS;
    5051
     
    5859        if (RT_SUCCESS (rc))
    5960        {
    60             PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)RTMemAlloc (sizeof(*pDevVrdp));
    61             if (pDevVrdp)
    62             {
    63                 pDevVrdp->pCallback = pCallback;
    64                 pDevVrdp->pDevice = pDevice;
    65                 pProxyDev->Backend.pv = pDevVrdp;
    66                 pProxyDev->iActiveCfg = 1; /** @todo that may not be always true. */
    67                 pProxyDev->cIgnoreSetConfigs = 1;
    68                 return VINF_SUCCESS;
    69             }
    70 
    71             pCallback->pfnClose (pDevice);
    72             rc = VERR_NO_MEMORY;
     61            pDevVrdp->pCallback = pCallback;
     62            pDevVrdp->pDevice = pDevice;
     63            pProxyDev->iActiveCfg = 1; /** @todo that may not be always true. */
     64            pProxyDev->cIgnoreSetConfigs = 1;
     65            return VINF_SUCCESS;
    7366        }
    7467    }
     
    8275}
    8376
    84 static void usbProxyVrdpClose(PUSBPROXYDEV pProxyDev)
     77static DECLCALLBACK(void) usbProxyVrdpClose(PUSBPROXYDEV pProxyDev)
    8578{
    8679    LogFlow(("usbProxyVrdpClose: pProxyDev = %p\n", pProxyDev));
    8780
    88     PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
     81    PUSBPROXYDEVVRDP pDevVrdp = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVVRDP);
    8982
    9083    pDevVrdp->pCallback->pfnClose (pDevVrdp->pDevice);
    9184}
    9285
    93 static int usbProxyVrdpReset(PUSBPROXYDEV pProxyDev, bool fResetOnLinux)
     86static DECLCALLBACK(int) usbProxyVrdpReset(PUSBPROXYDEV pProxyDev, bool fResetOnLinux)
    9487{
    9588    LogFlow(("usbProxyVrdpReset: pProxyDev = %p\n", pProxyDev));
    9689
    97     PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
     90    PUSBPROXYDEVVRDP pDevVrdp = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVVRDP);
    9891
    9992    int rc = pDevVrdp->pCallback->pfnReset (pDevVrdp->pDevice);
     
    111104}
    112105
    113 static int usbProxyVrdpSetConfig(PUSBPROXYDEV pProxyDev, int cfg)
     106static DECLCALLBACK(int) usbProxyVrdpSetConfig(PUSBPROXYDEV pProxyDev, int cfg)
    114107{
    115108    LogFlow(("usbProxyVrdpSetConfig: pProxyDev=%s cfg=%#x\n", pProxyDev->pUsbIns->pszName, cfg));
    116109
    117     PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
     110    PUSBPROXYDEVVRDP pDevVrdp = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVVRDP);
    118111
    119112    int rc = pDevVrdp->pCallback->pfnSetConfig (pDevVrdp->pDevice, (uint8_t)cfg);
     
    128121}
    129122
    130 static int usbProxyVrdpClaimInterface(PUSBPROXYDEV pProxyDev, int ifnum)
     123static DECLCALLBACK(int) usbProxyVrdpClaimInterface(PUSBPROXYDEV pProxyDev, int ifnum)
    131124{
    132125    LogFlow(("usbProxyVrdpClaimInterface: pProxyDev=%s ifnum=%#x\n", pProxyDev->pUsbIns->pszName, ifnum));
    133126
    134     PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
     127    PUSBPROXYDEVVRDP pDevVrdp = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVVRDP);
    135128
    136129    int rc = pDevVrdp->pCallback->pfnClaimInterface (pDevVrdp->pDevice, (uint8_t)ifnum);
     
    145138}
    146139
    147 static int usbProxyVrdpReleaseInterface(PUSBPROXYDEV pProxyDev, int ifnum)
     140static DECLCALLBACK(int) usbProxyVrdpReleaseInterface(PUSBPROXYDEV pProxyDev, int ifnum)
    148141{
    149142    LogFlow(("usbProxyVrdpReleaseInterface: pProxyDev=%s ifnum=%#x\n", pProxyDev->pUsbIns->pszName, ifnum));
    150143
    151     PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
     144    PUSBPROXYDEVVRDP pDevVrdp = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVVRDP);
    152145
    153146    int rc = pDevVrdp->pCallback->pfnReleaseInterface (pDevVrdp->pDevice, (uint8_t)ifnum);
     
    162155}
    163156
    164 static int usbProxyVrdpSetInterface(PUSBPROXYDEV pProxyDev, int ifnum, int setting)
     157static DECLCALLBACK(int) usbProxyVrdpSetInterface(PUSBPROXYDEV pProxyDev, int ifnum, int setting)
    165158{
    166159    LogFlow(("usbProxyVrdpSetInterface: pProxyDev=%p ifnum=%#x setting=%#x\n", pProxyDev, ifnum, setting));
    167160
    168     PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
     161    PUSBPROXYDEVVRDP pDevVrdp = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVVRDP);
    169162
    170163    int rc = pDevVrdp->pCallback->pfnInterfaceSetting (pDevVrdp->pDevice, (uint8_t)ifnum, (uint8_t)setting);
     
    179172}
    180173
    181 static bool usbProxyVrdpClearHaltedEp(PUSBPROXYDEV pProxyDev, unsigned int ep)
     174static DECLCALLBACK(bool) usbProxyVrdpClearHaltedEp(PUSBPROXYDEV pProxyDev, unsigned int ep)
    182175{
    183176    LogFlow(("usbProxyVrdpClearHaltedEp: pProxyDev=%s ep=%u\n", pProxyDev->pUsbIns->pszName, ep));
    184177
    185     PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
     178    PUSBPROXYDEVVRDP pDevVrdp = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVVRDP);
    186179
    187180    int rc = pDevVrdp->pCallback->pfnClearHaltedEP (pDevVrdp->pDevice, (uint8_t)ep);
     
    196189}
    197190
    198 static int usbProxyVrdpUrbQueue(PVUSBURB pUrb)
     191static DECLCALLBACK(int) usbProxyVrdpUrbQueue(PVUSBURB pUrb)
    199192{
    200193    LogFlow(("usbProxyVrdpUrbQueue: pUrb=%p\n", pUrb));
     
    208201
    209202    PUSBPROXYDEV pProxyDev = PDMINS_2_DATA(pUrb->pUsbIns, PUSBPROXYDEV);
    210     PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
     203    PUSBPROXYDEVVRDP pDevVrdp = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVVRDP);
    211204
    212205    int rc = pDevVrdp->pCallback->pfnQueueURB (pDevVrdp->pDevice, pUrb->enmType, pUrb->EndPt, pUrb->enmDir, pUrb->cbData,
     
    222215}
    223216
    224 static PVUSBURB usbProxyVrdpUrbReap(PUSBPROXYDEV pProxyDev, RTMSINTERVAL cMillies)
     217static DECLCALLBACK(PVUSBURB) usbProxyVrdpUrbReap(PUSBPROXYDEV pProxyDev, RTMSINTERVAL cMillies)
    225218{
    226219    LogFlow(("usbProxyVrdpUrbReap: pProxyDev=%s\n", pProxyDev->pUsbIns->pszName));
    227220
    228     PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
     221    PUSBPROXYDEVVRDP pDevVrdp = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVVRDP);
    229222
    230223    PVUSBURB pUrb = NULL;
     
    252245}
    253246
    254 static void usbProxyVrdpUrbCancel(PVUSBURB pUrb)
     247static DECLCALLBACK(void) usbProxyVrdpUrbCancel(PVUSBURB pUrb)
    255248{
    256249    LogFlow(("usbProxyVrdpUrbCancel: pUrb=%p\n", pUrb));
    257250
    258251    PUSBPROXYDEV pProxyDev = PDMINS_2_DATA(pUrb->pUsbIns, PUSBPROXYDEV);
    259     PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
     252    PUSBPROXYDEVVRDP pDevVrdp = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVVRDP);
    260253
    261254    pDevVrdp->pCallback->pfnCancelURB (pDevVrdp->pDevice, (PREMOTEUSBQURB)pUrb->Dev.pvPrivate);
    262255}
    263256
    264 static int usbProxyVrdpWakeup(PUSBPROXYDEV pProxyDev)
     257static DECLCALLBACK(int) usbProxyVrdpWakeup(PUSBPROXYDEV pProxyDev)
    265258{
    266259    LogFlow(("usbProxyVrdpWakeup: pProxyDev=%s\n", pProxyDev->pUsbIns->pszName));
    267260
    268     PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
     261    PUSBPROXYDEVVRDP pDevVrdp = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVVRDP);
    269262
    270263    return pDevVrdp->pCallback->pfnWakeup (pDevVrdp->pDevice);
     
    276269extern const USBPROXYBACK g_USBProxyDeviceVRDP =
    277270{
     271    /* pszName */
    278272    "vrdp",
     273    /* cbBackend */
     274    sizeof(USBPROXYDEVVRDP),
    279275    usbProxyVrdpOpen,
    280276    NULL,
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