VirtualBox

Ignore:
Timestamp:
Sep 26, 2019 4:13:25 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
133628
Message:

Shared Clipboard/Transfers: Update.

Location:
trunk/src/VBox/GuestHost/SharedClipboard
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/ClipboardDataObjectImpl-win.cpp

    r80905 r81025  
    367367                if (ASMAtomicReadBool(&pTransfer->Thread.fStop))
    368368                {
    369                     LogRel2(("Shared Clipboard: Stopping transfer calculating ...\n"));
     369                    LogRel2(("Shared Clipboard: Stopping transfer calculation ...\n"));
    370370                    break;
    371371                }
     
    378378            pRootList = NULL;
    379379
    380             if (RT_SUCCESS(rc))
     380            if (   RT_SUCCESS(rc)
     381                && !ASMAtomicReadBool(&pTransfer->Thread.fStop))
    381382            {
    382383                LogRel2(("Shared Clipboard: Transfer calculation complete (%zu root entries)\n", pThis->m_lstEntries.size()));
     
    402403                   LogRel(("Shared Clipboard: No transfer root entries found -- should not happen, please file a bug report\n"));
    403404            }
    404             else
     405            else if (RT_FAILURE(rc))
    405406                LogRel(("Shared Clipboard: Transfer failed with %Rrc\n", rc));
    406407        }
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-common.cpp

    r80990 r81025  
    890890        RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_MSG_PEEK_WAIT);
    891891        RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_MSG_GET);
    892         RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_STATUS);
    893892        RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_REPLY);
    894893        RT_CASE_RET_STR(VBOX_SHCL_GUEST_FN_ROOT_LIST_HDR_READ);
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-transfers.cpp

    r80990 r81025  
    11781178        if (pTransfer->Callbacks.pfnTransferInitialize)
    11791179        {
    1180             SHCLTRANSFERCALLBACKDATA Data = { pTransfer, pTransfer->Callbacks.pvUser };
     1180            SHCLTRANSFERCALLBACKDATA Data = { pTransfer, pTransfer->Callbacks.pvUser, pTransfer->Callbacks.cbUser };
    11811181            rc = pTransfer->Callbacks.pfnTransferInitialize(&Data);
    11821182        }
     
    22852285    if (pTransfer->Callbacks.pfnTransferStart)
    22862286    {
    2287         SHCLTRANSFERCALLBACKDATA Data = { pTransfer, pTransfer->Callbacks.pvUser };
     2287        SHCLTRANSFERCALLBACKDATA Data = { pTransfer, pTransfer->Callbacks.pvUser, pTransfer->Callbacks.cbUser };
    22882288        rc = pTransfer->Callbacks.pfnTransferStart(&Data);
    22892289    }
     
    23262326
    23272327    pTransfer->Callbacks.pvUser = pCallbacks->pvUser;
     2328    pTransfer->Callbacks.cbUser = pCallbacks->cbUser;
    23282329}
    23292330
     
    26382639    AssertPtrReturnVoid(pTransferCtx);
    26392640
    2640     LogFlowFunc(("pTransferCtx=%p, cTransfers=%RU32, cRunning=%RU32\n",
     2641    LogFlowFunc(("pTransferCtx=%p, cTransfers=%RU16 cRunning=%RU16\n",
    26412642                 pTransferCtx, pTransferCtx->cTransfers, pTransferCtx->cRunning));
    26422643
    2643     /* Remove all transfers which are not in a running state (e.g. only announced). */
    2644     PSHCLTRANSFER pTransfer, pTransferNext;
    2645     RTListForEachSafe(&pTransferCtx->List, pTransfer, pTransferNext, SHCLTRANSFER, Node)
    2646     {
    2647         if (SharedClipboardTransferGetStatus(pTransfer) != SHCLTRANSFERSTATUS_STARTED)
    2648         {
    2649             SharedClipboardTransferDestroy(pTransfer);
    2650             RTListNodeRemove(&pTransfer->Node);
    2651 
    2652             RTMemFree(pTransfer);
    2653             pTransfer = NULL;
    2654 
    2655             Assert(pTransferCtx->cTransfers);
    2656             pTransferCtx->cTransfers--;
     2644    if (!RTListIsEmpty(&pTransferCtx->List))
     2645    {
     2646        /* Remove all transfers which are not in a running state (e.g. only announced). */
     2647        PSHCLTRANSFER pTransfer, pTransferNext;
     2648        RTListForEachSafe(&pTransferCtx->List, pTransfer, pTransferNext, SHCLTRANSFER, Node)
     2649        {
     2650            if (SharedClipboardTransferGetStatus(pTransfer) != SHCLTRANSFERSTATUS_STARTED)
     2651            {
     2652                SharedClipboardTransferDestroy(pTransfer);
     2653                RTListNodeRemove(&pTransfer->Node);
     2654
     2655                RTMemFree(pTransfer);
     2656                pTransfer = NULL;
     2657
     2658                Assert(pTransferCtx->cTransfers);
     2659                pTransferCtx->cTransfers--;
     2660            }
    26572661        }
    26582662    }
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-win.cpp

    r80966 r81025  
    181181    if (!pWinCtx)
    182182        return;
     183
     184    LogFlowFuncEnter();
    183185
    184186    if (RTCritSectIsInitialized(&pWinCtx->CritSect))
     
    894896    AssertPtrReturn(pTransfer, VERR_INVALID_POINTER);
    895897
    896     LogFlowFuncEnter();
    897 
    898     int rc;
     898    LogFlowFunc(("pWinCtx=%p\n", pWinCtx));
    899899
    900900    AssertReturn(pTransfer->pvUser == NULL, VERR_WRONG_ORDER);
    901901
    902     SharedClipboardWinTransferCtx *pWinURITransferCtx = new SharedClipboardWinTransferCtx();
    903     if (pWinURITransferCtx)
    904     {
    905         pTransfer->pvUser = pWinURITransferCtx;
    906         pTransfer->cbUser = sizeof(SharedClipboardWinTransferCtx);
    907 
    908         pWinURITransferCtx->pDataObj = new SharedClipboardWinDataObject(pTransfer);
    909         if (pWinURITransferCtx->pDataObj)
    910         {
    911             rc = pWinURITransferCtx->pDataObj->Init();
    912             if (RT_SUCCESS(rc))
     902    /* Make sure to enter the critical section before setting the clipboard data, as otherwise WM_CLIPBOARDUPDATE
     903     * might get called *before* we had the opportunity to set pWinCtx->hWndClipboardOwnerUs below. */
     904    int rc = RTCritSectEnter(&pWinCtx->CritSect);
     905    if (RT_SUCCESS(rc))
     906    {
     907        SharedClipboardWinTransferCtx *pWinURITransferCtx = new SharedClipboardWinTransferCtx();
     908        if (pWinURITransferCtx)
     909        {
     910            pTransfer->pvUser = pWinURITransferCtx;
     911            pTransfer->cbUser = sizeof(SharedClipboardWinTransferCtx);
     912
     913            pWinURITransferCtx->pDataObj = new SharedClipboardWinDataObject(pTransfer);
     914            if (pWinURITransferCtx->pDataObj)
    913915            {
    914                 SharedClipboardWinClose();
    915                 /* Note: Clipboard must be closed first before calling OleSetClipboard(). */
    916 
    917                 /** @todo There is a potential race between SharedClipboardWinClose() and OleSetClipboard(),
    918                  *        where another application could own the clipboard (open), and thus the call to
    919                  *        OleSetClipboard() will fail. Needs (better) fixing. */
    920                 HRESULT hr = S_OK;
    921 
    922                 for (unsigned uTries = 0; uTries < 3; uTries++)
     916                rc = pWinURITransferCtx->pDataObj->Init();
     917                if (RT_SUCCESS(rc))
    923918                {
    924                     /* Make sure to enter the critical section before setting the clipboard data, as otherwise WM_CLIPBOARDUPDATE
    925                      * might get called *before* we had the opportunity to set pWinCtx->hWndClipboardOwnerUs below. */
    926                     rc = RTCritSectEnter(&pWinCtx->CritSect);
    927                     if (RT_SUCCESS(rc))
     919                    SharedClipboardWinClose();
     920                    /* Note: Clipboard must be closed first before calling OleSetClipboard(). */
     921
     922                    /** @todo There is a potential race between SharedClipboardWinClose() and OleSetClipboard(),
     923                     *        where another application could own the clipboard (open), and thus the call to
     924                     *        OleSetClipboard() will fail. Needs (better) fixing. */
     925                    HRESULT hr = S_OK;
     926
     927                    for (unsigned uTries = 0; uTries < 3; uTries++)
    928928                    {
    929929                        hr = OleSetClipboard(pWinURITransferCtx->pDataObj);
     
    939939                            pWinCtx->hWndClipboardOwnerUs = GetClipboardOwner();
    940940
    941                             rc = RTCritSectLeave(&pWinCtx->CritSect);
    942                             AssertRC(rc);
     941                            LogFlowFunc(("hWndClipboardOwnerUs=%p\n", pWinCtx->hWndClipboardOwnerUs));
    943942                            break;
    944943                        }
     944
     945                        LogFlowFunc(("Failed with %Rhrc (try %u/3)\n", hr, uTries + 1));
     946                        RTThreadSleep(500); /* Wait a bit. */
    945947                    }
    946948
    947                     rc = RTCritSectLeave(&pWinCtx->CritSect);
    948                     AssertRCBreak(rc);
    949 
    950                     LogFlowFunc(("Failed with %Rhrc (try %u/3)\n", hr, uTries + 1));
    951                     RTThreadSleep(500); /* Wait a bit. */
    952                 }
    953 
    954                 if (FAILED(hr))
    955                 {
    956                     rc = VERR_ACCESS_DENIED; /** @todo Fudge; fix this. */
    957                     LogRel(("Shared Clipboard: Failed with %Rhrc when setting data object to clipboard\n", hr));
     949                    if (FAILED(hr))
     950                    {
     951                        rc = VERR_ACCESS_DENIED; /** @todo Fudge; fix this. */
     952                        LogRel(("Shared Clipboard: Failed with %Rhrc when setting data object to clipboard\n", hr));
     953                    }
    958954                }
    959955            }
     956            else
     957                rc = VERR_NO_MEMORY;
    960958        }
    961959        else
    962960            rc = VERR_NO_MEMORY;
    963     }
    964     else
    965         rc = VERR_NO_MEMORY;
     961
     962        int rc2 = RTCritSectLeave(&pWinCtx->CritSect);
     963        AssertRC(rc2);
     964    }
    966965
    967966    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