VirtualBox

Ignore:
Timestamp:
Jan 31, 2022 4:38:49 PM (3 years ago)
Author:
vboxsync
Message:

Shared Clipboard: Implemented backend callbacks and a dedicated backend context, together with a new testcase which mocks HGCM to also test the guest-side clipboard code (disabled by default for now). Work in progress, only tested on Linux so far [VBoxClient fixes].

File:
1 edited

Legend:

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

    r93495 r93505  
    5858
    5959
    60 DECLCALLBACK(int) ShClX11RequestDataCallback(PSHCLCONTEXT pCtx, SHCLFORMAT uFmt, void **ppv, uint32_t *pcb)
    61 {
     60static DECLCALLBACK(int) vbclOnRequestDataFromSourceCallback(PSHCLCONTEXT pCtx,
     61                                                             SHCLFORMAT uFmt, void **ppv, uint32_t *pcb, void *pvUser)
     62{
     63    RT_NOREF(pvUser);
     64
    6265    LogFlowFunc(("pCtx=%p, uFmt=%#x\n", pCtx, uFmt));
    6366
     
    140143{
    141144    /** The data format that was requested. */
    142     SHCLFORMAT Format;
     145    SHCLFORMAT uFmt;
    143146};
    144147
    145 DECLCALLBACK(void) ShClX11ReportFormatsCallback(PSHCLCONTEXT pCtx, SHCLFORMATS fFormats)
    146 {
    147     RT_NOREF(pCtx);
     148static DECLCALLBACK(int) vbclReportFormatsCallback(PSHCLCONTEXT pCtx, uint32_t fFormats, void *pvUser)
     149{
     150    RT_NOREF(pvUser);
    148151
    149152    LogFlowFunc(("fFormats=%#x\n", fFormats));
    150153
    151     int rc2 = VbglR3ClipboardReportFormats(pCtx->CmdCtx.idClient, fFormats);
    152     RT_NOREF(rc2);
    153     LogFlowFuncLeaveRC(rc2);
    154 }
    155 
    156 DECLCALLBACK(void) ShClX11ReportDataCallback(PSHCLCONTEXT pCtx, int rcCompletion,
    157                                              CLIPREADCBREQ *pReq, void *pv, uint32_t cb)
    158 {
    159     LogFlowFunc(("rcCompletion=%Rrc, Format=0x%x, pv=%p, cb=%RU32\n", rcCompletion, pReq->Format, pv, cb));
    160     RT_NOREF(rcCompletion);
     154    int rc = VbglR3ClipboardReportFormats(pCtx->CmdCtx.idClient, fFormats);
     155    LogFlowFuncLeaveRC(rc);
     156
     157    return rc;
     158}
     159
     160static DECLCALLBACK(int) vbclOnSendDataToDestCallback(PSHCLCONTEXT pCtx, void *pv, uint32_t cb, void *pvUser)
     161{
     162    PSHCLX11READDATAREQ pData = (PSHCLX11READDATAREQ)pvUser;
     163    AssertPtrReturn(pData, VERR_INVALID_POINTER);
     164
     165    LogFlowFunc(("rcCompletion=%Rrc, Format=0x%x, pv=%p, cb=%RU32\n", pData->rcCompletion, pData->pReq->uFmt, pv, cb));
    161166
    162167    Assert((cb == 0 && pv == NULL) || (cb != 0 && pv != NULL));
    163     rcCompletion = VbglR3ClipboardWriteDataEx(&pCtx->CmdCtx, pReq->Format, pv, cb);
    164 
    165     RTMemFree(pReq);
    166 
    167     LogFlowFuncLeaveRC(rcCompletion);
     168    pData->rcCompletion = VbglR3ClipboardWriteDataEx(&pCtx->CmdCtx, pData->pReq->uFmt, pv, cb);
     169
     170    RTMemFree(pData->pReq);
     171
     172    LogFlowFuncLeaveRC(pData->rcCompletion);
     173
     174    return VINF_SUCCESS;
    168175}
    169176
     
    177184    LogFlowFuncEnter();
    178185
    179     int rc = ShClX11Init(&g_Ctx.X11, NULL /* pCallbacks */, &g_Ctx, false /* fHeadless */);
     186    SHCLCALLBACKS Callbacks;
     187    RT_ZERO(Callbacks);
     188    Callbacks.pfnReportFormats           = vbclReportFormatsCallback;
     189    Callbacks.pfnOnRequestDataFromSource = vbclOnRequestDataFromSourceCallback;
     190    Callbacks.pfnOnSendDataToDest        = vbclOnSendDataToDestCallback;
     191
     192    int rc = ShClX11Init(&g_Ctx.X11, &Callbacks, &g_Ctx, false /* fHeadless */);
    180193    if (RT_SUCCESS(rc))
    181194    {
     
    269282                    if (pReq)
    270283                    {
    271                         pReq->Format = pEvent->u.fReadData;
    272                         ShClX11ReadDataFromX11(&g_Ctx.X11, pReq->Format, pReq);
     284                        pReq->uFmt = pEvent->u.fReadData;
     285                        ShClX11ReadDataFromX11(&g_Ctx.X11, pReq->uFmt, pReq);
    273286                    }
    274287                    else
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