VirtualBox

Changeset 87082 in vbox for trunk/src


Ignore:
Timestamp:
Dec 10, 2020 10:01:11 AM (4 years ago)
Author:
vboxsync
Message:

Shared Clipboard: Simplified and cleaned up the X11 callback handling to actually do what they advertise in case no data is available. This also makes the surround code a lot easier to understand / follow.

Location:
trunk/src/VBox
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/VBoxClient/clipboard.cpp

    r86969 r87082  
    103103 * @returns VBox status code. VERR_NO_DATA if no data available.
    104104 * @param   pCtx                Our context information.
    105  * @param   Format              The format of the data being requested.
    106  * @param   ppv                 On success and if pcb > 0, this will point to a buffer
    107  *                              to be freed with RTMemFree containing the data read.
    108  * @param   pcb                 On success, this contains the number of bytes of data returned.
    109  */
    110 DECLCALLBACK(int) ShClX11RequestDataForX11Callback(PSHCLCONTEXT pCtx, SHCLFORMAT Format, void **ppv, uint32_t *pcb)
    111 {
    112     RT_NOREF(pCtx);
    113 
    114     LogFlowFunc(("Format=0x%x\n", Format));
     105 * @param   uFmt                The format of the data being requested.
     106 * @param   ppv                 Returns an allocated buffer with data read from the host on success.
     107 *                              Needs to be free'd with RTMemFree() by the caller.
     108 * @param   pcb                 Returns the amount of data read (in bytes) on success.
     109 */
     110DECLCALLBACK(int) ShClX11RequestDataForX11Callback(PSHCLCONTEXT pCtx, SHCLFORMAT uFmt, void **ppv, uint32_t *pcb)
     111{
     112    LogFlowFunc(("pCtx=%p, uFmt=%#x\n", pCtx, uFmt));
    115113
    116114    int rc = VINF_SUCCESS;
    117115
    118     uint32_t cbRead = 0;
    119 
    120116#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
    121     if (Format == VBOX_SHCL_FMT_URI_LIST)
     117    if (uFmt == VBOX_SHCL_FMT_URI_LIST)
    122118    {
    123119        //rc = VbglR3ClipboardRootListRead()
     120
     121        rc = VERR_NO_DATA;
    124122    }
    125123    else
    126124#endif
    127125    {
     126        uint32_t cbRead = 0;
     127
    128128        uint32_t cbData = _4K; /** @todo Make this dynamic. */
    129129        void    *pvData = RTMemAlloc(cbData);
    130130        if (pvData)
    131131        {
    132             rc = VbglR3ClipboardReadDataEx(&pCtx->CmdCtx, Format, pvData, cbData, &cbRead);
     132            rc = VbglR3ClipboardReadDataEx(&pCtx->CmdCtx, uFmt, pvData, cbData, &cbRead);
    133133        }
    134134        else
     
    148148            if (pvData)
    149149            {
    150                 rc = VbglR3ClipboardReadDataEx(&pCtx->CmdCtx, Format, pvData, cbData, &cbRead);
     150                rc = VbglR3ClipboardReadDataEx(&pCtx->CmdCtx, uFmt, pvData, cbData, &cbRead);
    151151                if (rc == VINF_BUFFER_OVERFLOW)
    152152                    rc = VERR_BUFFER_OVERFLOW;
     
    176176    }
    177177
     178    if (RT_FAILURE(rc))
     179        LogRel(("Requesting data in format %#x from host failed with %Rrc\n", uFmt, rc));
     180
    178181    LogFlowFuncLeaveRC(rc);
    179182    return rc;
     
    201204    RT_NOREF(pCtx);
    202205
    203     LogFlowFunc(("Formats=0x%x\n", fFormats));
     206    LogFlowFunc(("fFormats=%#x\n", fFormats));
    204207
    205208    int rc2 = VbglR3ClipboardReportFormats(pCtx->CmdCtx.idClient, fFormats);
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-x11.cpp

    r87058 r87082  
    13861386
    13871387/**
    1388  * This is a wrapper around ShClX11RequestDataForX11Callback that will cache the
    1389  * data returned.
     1388 * Helper for ShClX11RequestDataForX11Callback() that will cache the data returned.
    13901389 *
    13911390 * @returns VBox status code. VERR_NO_DATA if no data available.
    13921391 * @param   pCtx                The X11 clipboard context to use.
    1393  * @param   Format              Clipboard format to read data in.
    1394  * @param   ppv                 Where to store the allocated read data on success.
    1395  *                              Needs to be free'd by the caller.
    1396  * @param   pcb                 Where to return the size (in bytes) of the allocated read data on success.
    1397  */
    1398 static int clipReadVBoxShCl(PSHCLX11CTX pCtx, SHCLFORMAT Format,
    1399                             void **ppv, uint32_t *pcb)
     1392 * @param   uFmt                Clipboard format to read data in.
     1393 * @param   ppv                 Returns an allocated buffer with data read on success.
     1394 *                              Needs to be free'd with RTMemFree() by the caller.
     1395 * @param   pcb                 Returns the amount of data read (in bytes) on success.
     1396 */
     1397static int shClX11RequestDataForX11CallbackHelper(PSHCLX11CTX pCtx, SHCLFORMAT uFmt,
     1398                                                  void **ppv, uint32_t *pcb)
    14001399{
    14011400    AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
     
    14031402    AssertPtrReturn(pcb,  VERR_INVALID_POINTER);
    14041403
    1405     LogFlowFunc(("pCtx=%p, Format=%02X\n", pCtx, Format));
     1404    LogFlowFunc(("pCtx=%p, uFmt=%#x\n", pCtx, uFmt));
    14061405
    14071406    int rc = VINF_SUCCESS;
     
    14101409    uint32_t cb = 0;
    14111410
    1412     if (Format == VBOX_SHCL_FMT_UNICODETEXT)
     1411    if (uFmt == VBOX_SHCL_FMT_UNICODETEXT)
    14131412    {
    14141413        if (pCtx->pvUnicodeCache == NULL) /** @todo r=andy Using string cache here? */
    1415             rc = ShClX11RequestDataForX11Callback(pCtx->pFrontend, Format,
     1414            rc = ShClX11RequestDataForX11Callback(pCtx->pFrontend, uFmt,
    14161415                                                  &pCtx->pvUnicodeCache,
    14171416                                                  &pCtx->cbUnicodeCache);
     
    14291428    else
    14301429    {
    1431         rc = ShClX11RequestDataForX11Callback(pCtx->pFrontend, Format, &pv, &cb);
     1430        rc = ShClX11RequestDataForX11Callback(pCtx->pFrontend, uFmt, &pv, &cb);
     1431    }
     1432
     1433
     1434    /* Safey net in case the callbacks above misbehave
     1435     * (must return VERR_NO_DATA if no data available). */
     1436    if (   RT_SUCCESS(rc)
     1437        && (pv == NULL || cb == 0))
     1438    {
     1439        rc = VERR_NO_DATA;
    14321440    }
    14331441
     
    15851593                                int *piFormatReturn)
    15861594{
    1587     int rc = VINF_SUCCESS;
     1595    int rc = VERR_NOT_SUPPORTED; /* Play safe by default. */
    15881596
    15891597    SHCLX11FMTIDX idxFmtX11 = clipFindX11FormatByAtom(pCtx, *atomTarget);
     
    16011609#endif
    16021610
    1603     if (   ((fmtX11 == SHCLX11FMT_UTF8) || (fmtX11 == SHCLX11FMT_TEXT))
     1611    void    *pv = NULL;
     1612    uint32_t cb = 0;
     1613
     1614    if (   (   (fmtX11 == SHCLX11FMT_UTF8)
     1615            || (fmtX11 == SHCLX11FMT_TEXT)
     1616           )
    16041617        && (pCtx->vboxFormats & VBOX_SHCL_FMT_UNICODETEXT))
    16051618    {
    1606         void    *pv = NULL;
    1607         uint32_t cb = 0;
    1608         rc = clipReadVBoxShCl(pCtx, VBOX_SHCL_FMT_UNICODETEXT, &pv, &cb);
    1609         if (RT_SUCCESS(rc) && (cb == 0))
    1610             rc = VERR_NO_DATA;
    1611 
     1619        rc = shClX11RequestDataForX11CallbackHelper(pCtx, VBOX_SHCL_FMT_UNICODETEXT, &pv, &cb);
    16121620        if (   RT_SUCCESS(rc)
    16131621            && (   (fmtX11 == SHCLX11FMT_UTF8)
     
    16281636             && (pCtx->vboxFormats & VBOX_SHCL_FMT_BITMAP))
    16291637    {
    1630         void    *pv = NULL;
    1631         uint32_t cb = 0;
    1632         rc = clipReadVBoxShCl(pCtx, VBOX_SHCL_FMT_BITMAP, &pv, &cb);
    1633         if (RT_SUCCESS(rc) && (cb == 0))
    1634             rc = VERR_NO_DATA;
    1635         if (RT_SUCCESS(rc) && (fmtX11 == SHCLX11FMT_BMP))
    1636         {
    1637             /* Create a full BMP from it */
     1638        rc = shClX11RequestDataForX11CallbackHelper(pCtx, VBOX_SHCL_FMT_BITMAP, &pv, &cb);
     1639        if (   RT_SUCCESS(rc)
     1640            && (fmtX11 == SHCLX11FMT_BMP))
     1641        {
     1642            /* Create a full BMP from it. */
    16381643            rc = ShClDibToBmp(pv, cb, (void **)pValReturn,
    16391644                              (size_t *)pcLenReturn);
    16401645        }
    1641         else
    1642             rc = VERR_NOT_SUPPORTED;
    16431646
    16441647        if (RT_SUCCESS(rc))
     
    16531656            && (pCtx->vboxFormats & VBOX_SHCL_FMT_HTML))
    16541657    {
    1655         void    *pv = NULL;
    1656         uint32_t cb = 0;
    1657         rc = clipReadVBoxShCl(pCtx, VBOX_SHCL_FMT_HTML, &pv, &cb);
    1658         if (RT_SUCCESS(rc) && (cb == 0))
    1659             rc = VERR_NO_DATA;
     1658        rc = shClX11RequestDataForX11CallbackHelper(pCtx, VBOX_SHCL_FMT_HTML, &pv, &cb);
    16601659        if (RT_SUCCESS(rc))
    16611660        {
     
    16791678    }
    16801679#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
    1681     else if (pCtx->vboxFormats & VBOX_SHCL_FMT_URI_LIST)
    1682     {
    1683         switch (fmtX11)
    1684         {
    1685             case SHCLX11FMT_TEXT:
    1686                 RT_FALL_THROUGH();
    1687             case SHCLX11FMT_UTF8:
    1688                 RT_FALL_THROUGH();
    1689             case SHCLX11FMT_URI_LIST:
     1680    else if (fmtX11 == SHCLX11FMT_URI_LIST)
     1681    {
     1682        if (pCtx->vboxFormats & VBOX_SHCL_FMT_URI_LIST)
     1683        {
     1684            rc = shClX11RequestDataForX11CallbackHelper(pCtx, VBOX_SHCL_FMT_URI_LIST, &pv, &cb);
     1685            if (RT_SUCCESS(rc))
    16901686            {
    1691                 break;
     1687                void *pvDst = (void *)XtMalloc(cb);
     1688                if (pvDst)
     1689                {
     1690                    memcpy(pvDst, pv, cb);
     1691
     1692                    *atomTypeReturn = *atomTarget;
     1693                    *pValReturn     = (XtPointer)pvDst;
     1694                    *pcLenReturn    = cb;
     1695                    *piFormatReturn = 8;
     1696                }
     1697                else
     1698                    rc = VERR_NO_MEMORY;
    16921699            }
    1693 
    1694             default:
    1695                 rc = VERR_NOT_SUPPORTED;
    1696                 break;
    1697         }
     1700        }
     1701        /* else not supported yet. */
    16981702    }
    16991703#endif
     
    17041708        *pcLenReturn    = 0;
    17051709        *piFormatReturn = 0;
    1706 
    1707         rc = VERR_NOT_SUPPORTED;
    17081710    }
    17091711
  • trunk/src/VBox/GuestHost/SharedClipboard/testcase/tstClipboardGH-X11.cpp

    r86737 r87082  
    120120
    121121/* Return the data in the simulated VBox clipboard. */
    122 DECLCALLBACK(int) ShClX11RequestDataForX11Callback(PSHCLCONTEXT pCtx, uint32_t Format, void **ppv, uint32_t *pcb)
    123 {
    124     RT_NOREF(pCtx, Format);
     122DECLCALLBACK(int) ShClX11RequestDataForX11Callback(PSHCLCONTEXT pCtx, uint32_t uFmt, void **ppv, uint32_t *pcb)
     123{
     124    RT_NOREF(pCtx, uFmt);
    125125    *pcb = g_tst_cbDataVBox;
    126126    if (g_tst_pvDataVBox != NULL)
     
    244244static uint32_t g_tst_uX11Formats = 0;
    245245
    246 DECLCALLBACK(void) ShClX11ReportFormatsCallback(PSHCLCONTEXT pCtx, SHCLFORMATS Formats)
     246DECLCALLBACK(void) ShClX11ReportFormatsCallback(PSHCLCONTEXT pCtx, SHCLFORMATS fFormats)
    247247{
    248248    RT_NOREF(pCtx);
    249     g_tst_uX11Formats = Formats;
     249    g_tst_uX11Formats = fFormats;
    250250}
    251251
  • trunk/src/VBox/GuestHost/SharedClipboard/testcase/tstClipboardGH-X11Smoke.cpp

    r82911 r87082  
    3030#include <VBox/GuestHost/clipboard-helper.h>
    3131
    32 DECLCALLBACK(int) ShClX11RequestDataForX11Callback(PSHCLCONTEXT pCtx, SHCLFORMAT Format, void **ppv, uint32_t *pcb)
     32DECLCALLBACK(int) ShClX11RequestDataForX11Callback(PSHCLCONTEXT pCtx, SHCLFORMAT uFmt, void **ppv, uint32_t *pcb)
    3333{
    34     RT_NOREF(pCtx, Format, ppv, pcb);
     34    RT_NOREF(pCtx, uFmt, ppv, pcb);
    3535    return VERR_NO_DATA;
    3636}
    3737
    38 DECLCALLBACK(void) ShClX11ReportFormatsCallback(PSHCLCONTEXT pCtx, SHCLFORMATS Formats)
     38DECLCALLBACK(void) ShClX11ReportFormatsCallback(PSHCLCONTEXT pCtx, SHCLFORMATS fFormats)
    3939{
    40     RT_NOREF(pCtx, Formats);
     40    RT_NOREF(pCtx, fFormats);
    4141}
    4242
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-x11.cpp

    r86889 r87082  
    325325 * Callback implementation for reading clipboard data from the guest.
    326326 *
    327  * @note   Runs in Xt event thread.
     327 * @note Runs in Xt event thread.
    328328 *
    329329 * @returns VBox status code. VERR_NO_DATA if no data available.
    330330 * @param   pCtx                Pointer to the host clipboard structure.
    331  * @param   fFormat             The format in which the data should be transferred
     331 * @param   uFmt                The format in which the data should be transferred
    332332 *                              (VBOX_SHCL_FMT_XXX).
    333  * @param   ppv                 On success and if pcb > 0, this will point to a buffer
    334  *                              to be freed with RTMemFree containing the data read.
    335  * @param   pcb                 On success, this contains the number of bytes of data returned.
    336  */
    337 DECLCALLBACK(int) ShClX11RequestDataForX11Callback(PSHCLCONTEXT pCtx, SHCLFORMAT fFormat, void **ppv, uint32_t *pcb)
    338 {
    339     LogFlowFunc(("pCtx=%p, Format=0x%x\n", pCtx, fFormat));
     333 * @param   ppv                 Returns an allocated buffer with data read from the guest on success.
     334 *                              Needs to be free'd with RTMemFree() by the caller.
     335 * @param   pcb                 Returns the amount of data read (in bytes) on success.
     336 */
     337DECLCALLBACK(int) ShClX11RequestDataForX11Callback(PSHCLCONTEXT pCtx, SHCLFORMAT uFmt, void **ppv, uint32_t *pcb)
     338{
     339    LogFlowFunc(("pCtx=%p, uFmt=0x%x\n", pCtx, uFmt));
    340340
    341341    if (pCtx->fShuttingDown)
     
    349349
    350350#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
    351     if (fFormat == VBOX_SHCL_FMT_URI_LIST)
    352         rc = VINF_SUCCESS;
     351    if (uFmt == VBOX_SHCL_FMT_URI_LIST)
     352    {
     353        *ppv = NULL;
     354        *pcb = 0;
     355
     356        rc = VERR_NO_DATA;
     357    }
    353358    else
    354359#endif
     
    356361        /* Request data from the guest. */
    357362        SHCLEVENTID idEvent;
    358         rc = ShClSvcGuestDataRequest(pCtx->pClient, fFormat, &idEvent);
     363        rc = ShClSvcGuestDataRequest(pCtx->pClient, uFmt, &idEvent);
    359364        if (RT_SUCCESS(rc))
    360365        {
     
    381386
    382387    if (RT_FAILURE(rc))
    383         LogRel(("Shared Clipboard: Requesting data in format %#x for X11 host failed with %Rrc\n", fFormat, rc));
     388        LogRel(("Shared Clipboard: Requesting data in format %#x for X11 host failed with %Rrc\n", uFmt, rc));
    384389
    385390    LogFlowFuncLeaveRC(rc);
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