VirtualBox

Changeset 100235 in vbox for trunk


Ignore:
Timestamp:
Jun 21, 2023 10:39:24 AM (18 months ago)
Author:
vboxsync
Message:

Shared Clipboard: Got rid of the X11 request worker, as this simplifies code (again). bugref:9437

File:
1 edited

Legend:

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

    r100205 r100235  
    5252#include "clipboard.h"
    5353
    54 #include <iprt/req.h>
    55 
    5654
    5755#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP
    58 #if 0
    59 /**
    60  * Worker for reading the transfer root list from the host.
    61  */
    62 static DECLCALLBACK(int) vbclX11ReqTransferReadRootListWorker(PSHCLCONTEXT pCtx, PSHCLTRANSFER pTransfer)
    63 {
    64     RT_NOREF(pCtx);
    65 
    66     LogFlowFuncEnter();
    67 
    68     int rc = ShClTransferRootListRead(pTransfer);
    69 
    70     LogFlowFuncLeaveRC(rc);
    71     return rc;
    72 }
    73 #endif
    74 
    7556/**
    7657 * Worker for waiting for a transfer status change.
     
    206187 * Worker for a reading clipboard from the host.
    207188 */
    208 static DECLCALLBACK(int) vbclX11ReqReadDataWorker(PSHCLCONTEXT pCtx, SHCLFORMAT uFmt, void **ppv, uint32_t *pcb, void *pvUser)
     189static DECLCALLBACK(int) vbclX11ReadDataWorker(PSHCLCONTEXT pCtx, SHCLFORMAT uFmt, void **ppv, uint32_t *pcb, void *pvUser)
    209190{
    210191    RT_NOREF(pvUser);
     
    286267    LogFlowFunc(("pCtx=%p, uFmt=%#x\n", pCtx, uFmt));
    287268
    288     /* Request reading host clipboard data. */
    289     PRTREQ pReq = NULL;
    290     int rc = RTReqQueueCallEx(pCtx->X11.hReqQ, &pReq, SHCL_TIMEOUT_DEFAULT_MS, RTREQFLAGS_IPRT_STATUS,
    291                               (PFNRT)vbclX11ReqReadDataWorker, 5, pCtx, uFmt, ppv, pcb, pvUser);
    292     RTReqRelease(pReq);
     269    int rc;
    293270
    294271#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP
     
    297274        PSHCLHTTPSERVER pSrv = &pCtx->X11.HttpCtx.HttpServer;
    298275
    299         rc = ShClTransferHttpServerWaitForStatusChange(pSrv, SHCLHTTPSERVERSTATUS_TRANSFER_REGISTERED, SHCL_TIMEOUT_DEFAULT_MS);
     276        rc = vbclX11ReadDataWorker(pCtx, uFmt, ppv, pcb, pvUser);
    300277        if (RT_SUCCESS(rc))
    301         {
    302             PSHCLTRANSFER pTransfer = ShClTransferHttpServerGetTransferFirst(pSrv);
     278            rc = ShClTransferHttpServerWaitForStatusChange(pSrv, SHCLHTTPSERVERSTATUS_TRANSFER_REGISTERED, 5000 /* SHCL_TIMEOUT_DEFAULT_MS */);
     279        if (RT_SUCCESS(rc))
     280        {
     281            PSHCLTRANSFER pTransfer = ShClTransferHttpServerGetTransferLast(pSrv);
    303282            if (pTransfer)
    304283            {
     
    313292                    *pcb = strlen(pszData) + 1 /* Include terminator */;
    314293
     294                    LogFlowFunc(("pszURL=%s\n", pszURL));
     295
    315296                    RTStrFree(pszURL);
    316297
    317298                    rc = VINF_SUCCESS;
    318 
    319                     LogFlowFunc(("pszURL=%s\n", pszURL));
    320299                }
    321300            }
     
    326305            LogRel(("Shared Clipboard: Could not start transfer, as the HTTP server is not running\n"));
    327306    }
     307    else /* Anything else */
    328308#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP */
     309    {
     310        rc = vbclX11ReadDataWorker(pCtx, uFmt, ppv, pcb, pvUser);
     311    }
    329312
    330313    if (RT_FAILURE(rc))
     
    336319
    337320/**
    338  * Worker for reporting clipboard formats to the host.
    339  */
    340 static DECLCALLBACK(int) vbclX11ReqReportFormatsWorker(PSHCLCONTEXT pCtx, uint32_t fFormats, void *pvUser)
     321 * @copydoc SHCLCALLBACKS::pfnReportFormats
     322 *
     323 * Reports clipboard formats to the host.
     324 *
     325 * @thread  X11 event thread.
     326 */
     327static DECLCALLBACK(int) vbclX11ReportFormatsCallback(PSHCLCONTEXT pCtx, uint32_t fFormats, void *pvUser)
    341328{
    342329    RT_NOREF(pvUser);
     
    345332
    346333    int rc = VbglR3ClipboardReportFormats(pCtx->CmdCtx.idClient, fFormats);
    347 
    348     LogFlowFuncLeaveRC(rc);
    349     return rc;
    350 }
    351 
    352 /**
    353  * @copydoc SHCLCALLBACKS::pfnReportFormats
    354  *
    355  * Reports clipboard formats to the host.
    356  *
    357  * @thread  X11 event thread.
    358  */
    359 static DECLCALLBACK(int) vbclX11ReportFormatsCallback(PSHCLCONTEXT pCtx, uint32_t fFormats, void *pvUser)
    360 {
    361     /* Request reading host clipboard data. */
    362     PRTREQ pReq = NULL;
    363     int rc = RTReqQueueCallEx(pCtx->X11.hReqQ, &pReq, SHCL_TIMEOUT_DEFAULT_MS, RTREQFLAGS_IPRT_STATUS,
    364                               (PFNRT)vbclX11ReqReportFormatsWorker, 3, pCtx, fFormats, pvUser);
    365     RTReqRelease(pReq);
    366334
    367335    LogFlowFuncLeaveRC(rc);
     
    430398{
    431399    PSHCLCONTEXT pCtx = &g_Ctx;
    432 
    433     int rc = RTReqQueueCreate(&pCtx->X11.hReqQ);
    434     AssertRCReturn(rc, rc);
    435400
    436401    bool fShutdown = false;
     
    459424                 pCtx->CmdCtx.fUseLegacyProtocol, pCtx->CmdCtx.fHostFeatures));
    460425
    461     /* The thread processes incoming messages from the host and the worker queue. */
    462     PVBGLR3CLIPBOARDEVENT pEvent = NULL;
     426    int rc;
     427
     428    /* The thread waits for incoming messages from the host. */
    463429    for (;;)
    464430    {
    465         if (!pEvent)
    466             pEvent = (PVBGLR3CLIPBOARDEVENT)RTMemAllocZ(sizeof(VBGLR3CLIPBOARDEVENT));
     431        PVBGLR3CLIPBOARDEVENT pEvent = (PVBGLR3CLIPBOARDEVENT)RTMemAllocZ(sizeof(VBGLR3CLIPBOARDEVENT));
    467432        AssertPtrBreakStmt(pEvent, rc = VERR_NO_MEMORY);
    468433
    469434        uint32_t idMsg  = 0;
    470435        uint32_t cParms = 0;
    471         rc = VbglR3ClipboardMsgPeek(&pCtx->CmdCtx, &idMsg, &cParms, NULL /* pidRestoreCheck */);
     436        rc = VbglR3ClipboardMsgPeekWait(&pCtx->CmdCtx, &idMsg, &cParms, NULL /* pidRestoreCheck */);
    472437        if (RT_SUCCESS(rc))
    473438        {
     
    477442            rc = VbglR3ClipboardEventGetNext(idMsg, cParms, &pCtx->CmdCtx, pEvent);
    478443#endif
    479         }
    480         else if (rc == VERR_TRY_AGAIN) /* No new message (yet). */
    481         {
    482             RTReqQueueProcess(pCtx->X11.hReqQ, RT_MS_1SEC);
    483             continue;
    484444        }
    485445
     
    592552    }
    593553
    594     RTReqQueueDestroy(pCtx->X11.hReqQ);
    595 
    596554    LogFlowFuncLeaveRC(rc);
    597555    return 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