VirtualBox

Changeset 20551 in vbox for trunk/src/VBox/HostServices


Ignore:
Timestamp:
Jun 14, 2009 4:31:50 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
48555
Message:

GuestHost/SharedClipboard: refactored the shared clipboard code to move knowledge of some host-specific buffering mechanisms into the host-specific code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedClipboard/x11-clipboard.cpp

    r19875 r20551  
    197197}
    198198
     199/** Structure describing a request for clipoard data from the guest. */
     200struct _CLIPREADCBREQ
     201{
     202    /** Where to write the returned data to. */
     203    void *pv;
     204    /** The size of the buffer in pv */
     205    uint32_t cb;
     206    /** The actual size of the data written */
     207    uint32_t *pcbActual;
     208};
     209
    199210/**
    200211 * Called when VBox wants to read the X11 clipboard.
     
    210221 * @param  pcbActual Where to write the actual size of the written data
    211222 * @note   We always fail or complete asynchronously
    212  * @note   On success allocates a CLIPREADX11CBCONTEXT structure which must be
     223 * @note   On success allocates a CLIPREADCBREQ structure which must be
    213224 *         freed in ClipCompleteDataRequestFromX11 when it is called back from
    214225 *         the backend code.
     
    222233                 pClient, u32Format, pv, cb, pcbActual));
    223234   
    224     int rc = ClipRequestDataFromX11(pClient->pCtx->pBackend, u32Format, pv,
    225                                     cb);
    226     if (RT_SUCCESS(rc))
    227         rc = VINF_HGCM_ASYNC_EXECUTE;
     235    int rc = VINF_SUCCESS;
     236    CLIPREADCBREQ *pReq = (CLIPREADCBREQ *) RTMemAlloc(sizeof(CLIPREADCBREQ));
     237    if (!pReq)
     238        rc = VERR_NO_MEMORY;
     239    else
     240    {
     241        pReq->pv = pv;
     242        pReq->cb = cb;
     243        pReq->pcbActual = pcbActual;
     244        rc = ClipRequestDataFromX11(pClient->pCtx->pBackend, u32Format, pReq);
     245        if (RT_SUCCESS(rc))
     246            rc = VINF_HGCM_ASYNC_EXECUTE;
     247    }
    228248    LogFlowFunc(("returning %Rrc\n", rc));
    229249    return rc;
     
    242262 */
    243263void ClipCompleteDataRequestFromX11(VBOXCLIPBOARDCONTEXT *pCtx, int rc,
    244                                     uint32_t cbActual)
    245 {
    246     vboxSvcClipboardCompleteReadData(pCtx->pClient, rc, cbActual);
     264                                    CLIPREADCBREQ *pReq, void *pv,
     265                                    uint32_t cb)
     266{
     267    if (cb <= pReq->cb)
     268        memcpy(pReq->pv, pv, cb);
     269    RTMemFree(pReq);
     270    vboxSvcClipboardCompleteReadData(pCtx->pClient, rc, cb);
    247271}
    248272
     
    410434    {
    411435        uint32_t format;
    412         void *pv;
    413         uint32_t cb;
    414436        int rc;
     437        CLIPREADCBREQ *pReq;
    415438    } readData;
    416439    struct _COMPLETEREAD
     
    478501
    479502extern int ClipRequestDataFromX11(CLIPBACKEND *pBackend, uint32_t u32Format,
    480                                   void *pv, uint32_t cb)
     503                                  CLIPREADCBREQ *pReq)
    481504{
    482505    pBackend->readData.format = u32Format;
    483     pBackend->readData.pv = pv;
    484     pBackend->readData.cb = cb;
     506    pBackend->readData.pReq = pReq;
    485507    return pBackend->readData.rc;
    486508}
     
    518540        if (   pBackend->readData.format !=
    519541                       VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT
    520             || pBackend->readData.pv != &u32Dummy
    521             || pBackend->readData.cb != 42)
     542            || pBackend->readData.pReq->pv != &u32Dummy
     543            || pBackend->readData.pReq->cb != 42
     544            || pBackend->readData.pReq->pcbActual != &u32Dummy)
    522545        {
    523             RTPrintf(TEST_NAME ": format=%u, pv=%p, cb=%u\n",
    524                      pBackend->readData.format, pBackend->readData.pv,
    525                      pBackend->readData.cb);
     546            RTPrintf(TEST_NAME ": format=%u, pReq->pv=%p, pReq->cb=%u, pReq->pcbActual=%p\n",
     547                     pBackend->readData.format, pBackend->readData.pReq->pv,
     548                     pBackend->readData.pReq->cb,
     549                     pBackend->readData.pReq->pcbActual);
    526550            ++cErrors;
    527551        }
    528552        else
    529553        {
    530             ClipCompleteDataRequestFromX11(client.pCtx, VERR_NO_DATA, 43);
     554            ClipCompleteDataRequestFromX11(client.pCtx, VERR_NO_DATA,
     555                                           pBackend->readData.pReq, NULL, 43);
    531556            if (   pBackend->completeRead.rc != VERR_NO_DATA
    532557                || pBackend->completeRead.cbActual != 43)
Note: See TracChangeset for help on using the changeset viewer.

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