VirtualBox

Changeset 78974 in vbox for trunk/src/VBox/GuestHost


Ignore:
Timestamp:
Jun 4, 2019 4:51:48 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131100
Message:

Shared Clipboard/URI: Update.

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

Legend:

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

    r78897 r78974  
    4545#define VBOX_CLIPBOARD_WITH_UNICODE_SUPPORT 1
    4646
    47 VBoxClipboardWinDataObject::VBoxClipboardWinDataObject(SharedClipboardProvider *pProvider,
     47VBoxClipboardWinDataObject::VBoxClipboardWinDataObject(PSHAREDCLIPBOARDURITRANSFER pTransfer,
    4848                                                       LPFORMATETC pFormatEtc, LPSTGMEDIUM pStgMed, ULONG cFormats)
    4949    : m_enmStatus(Uninitialized)
    5050    , m_lRefCount(0)
    5151    , m_cFormats(0)
    52     , m_pProvider(pProvider)
     52    , m_pTransfer(pTransfer)
    5353    , m_pStream(NULL)
    5454    , m_uObjIdx(0)
    5555{
    56     AssertPtr(pProvider);
     56    AssertPtr(m_pTransfer);
    5757
    5858    HRESULT hr;
     
    121121        m_enmStatus = Initialized;
    122122
    123         m_pProvider->AddRef();
     123        AssertPtr(m_pTransfer->pProvider);
     124        m_pTransfer->pProvider->AddRef();
    124125    }
    125126
     
    129130VBoxClipboardWinDataObject::~VBoxClipboardWinDataObject(void)
    130131{
    131     if (m_pProvider)
    132         m_pProvider->Release();
     132    if (m_pTransfer->pProvider)
     133        m_pTransfer->pProvider->Release();
    133134
    134135    if (m_pStream)
     
    394395            LogFlowFunc(("FormatIndex_FileDescriptor%s\n", fUnicode ? "W" : "A"));
    395396
    396             int rc = m_pProvider->ReadMetaData(); /** @todo Do this asynchronously some time earlier? */
     397            int rc = m_pTransfer->pProvider->ReadMetaData(); /** @todo Do this asynchronously some time earlier? */
    397398            if (   RT_SUCCESS(rc)
    398                 && !m_pProvider->GetURIList().IsEmpty())
     399                && !m_pTransfer->pProvider->GetURIList().IsEmpty())
    399400            {
    400401                HGLOBAL hGlobal;
    401                 rc = createFileGroupDescriptorFromURIList(m_pProvider->GetURIList(), fUnicode, &hGlobal);
     402                rc = createFileGroupDescriptorFromURIList(m_pTransfer->pProvider->GetURIList(), fUnicode, &hGlobal);
    402403                if (RT_SUCCESS(rc))
    403404                {
     
    416417            LogFlowFunc(("FormatIndex_FileContents: m_uObjIdx=%u\n", m_uObjIdx));
    417418
    418             SharedClipboardURIObject *pURIObj = m_pProvider->GetURIList().At(m_uObjIdx);
     419            SharedClipboardURIObject *pURIObj = m_pTransfer->pProvider->GetURIList().At(m_uObjIdx);
    419420            if (pURIObj)
    420421            {
    421422                /* Hand-in the provider so that our IStream implementation can continue working with it. */
    422                 hr = VBoxClipboardWinStreamImpl::Create(m_pProvider, pURIObj, &m_pStream);
     423                hr = VBoxClipboardWinStreamImpl::Create(this /* pParent */, m_pTransfer, pURIObj, &m_pStream);
    423424                if (SUCCEEDED(hr))
    424425                {
     
    578579    LogFlowFuncLeaveRC(VINF_SUCCESS);
    579580    return VINF_SUCCESS;
     581}
     582
     583void VBoxClipboardWinDataObject::OnTransferComplete(int rc /* = VINF_SUCESS */)
     584{
     585    RT_NOREF(rc);
     586
     587    LogFlowFuncLeaveRC(rc);
     588}
     589
     590void VBoxClipboardWinDataObject::OnTransferCanceled(void)
     591{
     592    LogFlowFuncLeave();
    580593}
    581594
  • TabularUnified trunk/src/VBox/GuestHost/SharedClipboard/ClipboardProvider-HostService.cpp

    r78942 r78974  
    4343}
    4444
    45 int SharedClipboardProviderHostService::ReadMetaData(uint32_t fFlags /* = 0 */)
    46 {
    47     RT_NOREF(fFlags);
    48     return VERR_NOT_IMPLEMENTED;
    49 }
    50 
    51 int SharedClipboardProviderHostService::WriteMetaData(const void *pvBuf, size_t cbBuf, size_t *pcbWritten, uint32_t fFlags /* = 0 */)
    52 {
    53     RT_NOREF(pvBuf, cbBuf, pcbWritten, fFlags);
    54     return VERR_NOT_IMPLEMENTED;
    55 }
    56 
    57 int SharedClipboardProviderVbglR3::ReadDirectory(PVBOXCLIPBOARDDIRDATA pDirData)
    58 {
    59     RT_NOREF(pDirData);
    60 
    61     LogFlowFuncEnter();
    62 
    63     int rc = VERR_NOT_IMPLEMENTED;
    64 
    65     LogFlowFuncLeaveRC(rc);
    66     return rc;
    67 }
    68 
    69 int SharedClipboardProviderVbglR3::WriteDirectory(const PVBOXCLIPBOARDDIRDATA pDirData)
    70 {
    71     RT_NOREF(pDirData);
    72 
    73     LogFlowFuncEnter();
    74 
    75     int rc = VERR_NOT_IMPLEMENTED;
    76 
    77     LogFlowFuncLeaveRC(rc);
    78     return rc;
    79 }
    80 
    81 int SharedClipboardProviderVbglR3::ReadFileHdr(PVBOXCLIPBOARDFILEHDR pFileHdr)
    82 {
    83     RT_NOREF(pFileHdr);
    84 
    85     LogFlowFuncEnter();
    86 
    87     int rc = VERR_NOT_IMPLEMENTED;
    88 
    89     LogFlowFuncLeaveRC(rc);
    90     return rc;
    91 }
    92 
    93 int SharedClipboardProviderVbglR3::WriteFileHdr(const PVBOXCLIPBOARDFILEHDR pFileHdr)
    94 {
    95     RT_NOREF(pFileHdr);
    96 
    97     LogFlowFuncEnter();
    98 
    99     int rc = VERR_NOT_IMPLEMENTED;
    100 
    101     LogFlowFuncLeaveRC(rc);
    102     return rc;
    103 }
    104 
    105 int SharedClipboardProviderVbglR3::ReadFileData(PVBOXCLIPBOARDFILEDATA pFileData)
    106 {
    107     RT_NOREF(pFileData);
    108 
    109     LogFlowFuncEnter();
    110 
    111     int rc = VERR_NOT_IMPLEMENTED;
    112 
    113     LogFlowFuncLeaveRC(rc);
    114     return rc;
    115 }
    116 
    117 int SharedClipboardProviderVbglR3::WriteFileData(const PVBOXCLIPBOARDFILEDATA pFileData)
    118 {
    119     RT_NOREF(pFileData);
    120 
    121     LogFlowFuncEnter();
    122 
    123     int rc = VERR_NOT_IMPLEMENTED;
    124 
    125     LogFlowFuncLeaveRC(rc);
    126     return rc;
    127 }
    128 
    129 void SharedClipboardProviderHostService::Reset(void)
    130 {
    131 }
    132 
  • TabularUnified trunk/src/VBox/GuestHost/SharedClipboard/ClipboardProvider-VbglR3.cpp

    r78942 r78974  
    163163}
    164164
    165 int SharedClipboardProviderVbglR3::ReadFileData(PVBOXCLIPBOARDFILEDATA pFileData)
    166 {
    167     LogFlowFuncEnter();
    168 
    169     int rc;
    170 
    171     SharedClipboardURIObject *pObj = m_URIList.First();
    172     if (pObj)
    173     {
    174         rc = VbglR3ClipboardReadFileData(m_uClientID, pFileData->pvData, pFileData->cbData, &pFileData->cbData);
    175     }
    176     else
    177         rc = VERR_WRONG_ORDER;
    178 
    179     LogFlowFuncLeaveRC(rc);
    180     return rc;
    181 }
    182 
    183 int SharedClipboardProviderVbglR3::WriteFileData(const PVBOXCLIPBOARDFILEDATA pFileData)
    184 {
    185     LogFlowFuncEnter();
    186 
    187     int rc;
    188 
    189     SharedClipboardURIObject *pObj = m_URIList.First();
    190     if (pObj)
    191     {
    192         uint32_t cbWrittenIgnored;
    193         rc = VbglR3ClipboardWriteFileData(m_uClientID, pFileData->pvData, pFileData->cbData, &cbWrittenIgnored);
     165int SharedClipboardProviderVbglR3::ReadFileData(PVBOXCLIPBOARDFILEDATA pFileData, uint32_t *pcbRead)
     166{
     167    AssertPtrReturn(pcbRead, VERR_INVALID_POINTER);
     168
     169    LogFlowFuncEnter();
     170
     171    int rc;
     172
     173    SharedClipboardURIObject *pObj = m_URIList.First();
     174    if (pObj)
     175    {
     176        rc = VbglR3ClipboardReadFileData(m_uClientID, pFileData->pvData, pFileData->cbData, pcbRead);
     177    }
     178    else
     179        rc = VERR_WRONG_ORDER;
     180
     181    LogFlowFuncLeaveRC(rc);
     182    return rc;
     183}
     184
     185int SharedClipboardProviderVbglR3::WriteFileData(const PVBOXCLIPBOARDFILEDATA pFileData, uint32_t *pcbWritten)
     186{
     187    AssertPtrReturn(pcbWritten, VERR_INVALID_POINTER);
     188
     189    LogFlowFuncEnter();
     190
     191    int rc;
     192
     193    SharedClipboardURIObject *pObj = m_URIList.First();
     194    if (pObj)
     195    {
     196        rc = VbglR3ClipboardWriteFileData(m_uClientID, pFileData->pvData, pFileData->cbData, pcbWritten);
    194197    }
    195198    else
  • TabularUnified trunk/src/VBox/GuestHost/SharedClipboard/ClipboardProvider.cpp

    r78897 r78974  
    7171#ifdef VBOX_WITH_SHARED_CLIPBOARD_HOST
    7272        case SHAREDCLIPBOARDPROVIDERSOURCE_HOSTSERVICE:
    73             pProvider = new SharedClipboardProviderHostService();
     73            pProvider = new SharedClipboardProvider();
    7474            break;
    7575#endif
     
    105105}
    106106
     107int SharedClipboardProvider::ReadMetaData(uint32_t fFlags /* = 0 */)
     108{
     109    RT_NOREF(fFlags);
     110    return VERR_NOT_IMPLEMENTED;
     111}
     112
     113int SharedClipboardProvider::WriteMetaData(const void *pvBuf, size_t cbBuf, size_t *pcbWritten, uint32_t fFlags /* = 0 */)
     114{
     115    RT_NOREF(pvBuf, cbBuf, pcbWritten, fFlags);
     116    return VERR_NOT_IMPLEMENTED;
     117}
     118
     119/*
     120 * Stubs.
     121 */
     122
     123int SharedClipboardProvider::ReadDirectory(PVBOXCLIPBOARDDIRDATA pDirData)
     124{
     125    RT_NOREF(pDirData);
     126
     127    LogFlowFuncEnter();
     128
     129    int rc = VERR_NOT_IMPLEMENTED;
     130
     131    LogFlowFuncLeaveRC(rc);
     132    return rc;
     133}
     134
     135int SharedClipboardProvider::ReadDirectoryObj(SharedClipboardURIObject &Obj)
     136{
     137    RT_NOREF(Obj);
     138
     139    LogFlowFuncEnter();
     140
     141    int rc = VERR_NOT_IMPLEMENTED;
     142
     143    LogFlowFuncLeaveRC(rc);
     144    return rc;
     145}
     146
     147int SharedClipboardProvider::WriteDirectory(const PVBOXCLIPBOARDDIRDATA pDirData)
     148{
     149    RT_NOREF(pDirData);
     150
     151    LogFlowFuncEnter();
     152
     153    int rc = VERR_NOT_IMPLEMENTED;
     154
     155    LogFlowFuncLeaveRC(rc);
     156    return rc;
     157}
     158
     159int SharedClipboardProvider::WriteDirectoryObj(const SharedClipboardURIObject &Obj)
     160{
     161    RT_NOREF(Obj);
     162
     163    LogFlowFuncEnter();
     164
     165    int rc = VERR_NOT_IMPLEMENTED;
     166
     167    LogFlowFuncLeaveRC(rc);
     168    return rc;
     169}
     170
     171int SharedClipboardProvider::ReadFileHdr(PVBOXCLIPBOARDFILEHDR pFileHdr)
     172{
     173    RT_NOREF(pFileHdr);
     174
     175    LogFlowFuncEnter();
     176
     177    int rc = VERR_NOT_IMPLEMENTED;
     178
     179    LogFlowFuncLeaveRC(rc);
     180    return rc;
     181}
     182
     183int SharedClipboardProvider::ReadFileHdrObj(SharedClipboardURIObject &Obj)
     184{
     185    RT_NOREF(Obj);
     186
     187    LogFlowFuncEnter();
     188
     189    int rc = VERR_NOT_IMPLEMENTED;
     190
     191    LogFlowFuncLeaveRC(rc);
     192    return rc;
     193}
     194
     195int SharedClipboardProvider::WriteFileHdr(const PVBOXCLIPBOARDFILEHDR pFileHdr)
     196{
     197    RT_NOREF(pFileHdr);
     198
     199    LogFlowFuncEnter();
     200
     201    int rc = VERR_NOT_IMPLEMENTED;
     202
     203    LogFlowFuncLeaveRC(rc);
     204    return rc;
     205}
     206
     207int SharedClipboardProvider::WriteFileHdrObj(const SharedClipboardURIObject &Obj)
     208{
     209    RT_NOREF(Obj);
     210
     211    LogFlowFuncEnter();
     212
     213    int rc = VERR_NOT_IMPLEMENTED;
     214
     215    LogFlowFuncLeaveRC(rc);
     216    return rc;
     217}
     218
     219int SharedClipboardProvider::ReadFileDataObj(SharedClipboardURIObject &Obj, uint32_t *pcbRead)
     220{
     221    RT_NOREF(Obj, pcbRead);
     222
     223    LogFlowFuncEnter();
     224
     225    int rc = VERR_NOT_IMPLEMENTED;
     226
     227    LogFlowFuncLeaveRC(rc);
     228    return rc;
     229}
     230
     231int SharedClipboardProvider::ReadFileData(PVBOXCLIPBOARDFILEDATA pFileData, uint32_t *pcbRead)
     232{
     233    RT_NOREF(pFileData, pcbRead);
     234
     235    LogFlowFuncEnter();
     236
     237    int rc = VERR_NOT_IMPLEMENTED;
     238
     239    LogFlowFuncLeaveRC(rc);
     240    return rc;
     241}
     242
     243int SharedClipboardProvider::WriteFileDataObj(const SharedClipboardURIObject &Obj, uint32_t *pcbWritten)
     244{
     245    RT_NOREF(Obj, pcbWritten);
     246
     247    LogFlowFuncEnter();
     248
     249    int rc = VERR_NOT_IMPLEMENTED;
     250
     251    LogFlowFuncLeaveRC(rc);
     252    return rc;
     253}
     254
     255int SharedClipboardProvider::WriteFileData(const PVBOXCLIPBOARDFILEDATA pFileData, uint32_t *pcbWritten)
     256{
     257    RT_NOREF(pFileData, pcbWritten);
     258
     259    LogFlowFuncEnter();
     260
     261    int rc = VERR_NOT_IMPLEMENTED;
     262
     263    LogFlowFuncLeaveRC(rc);
     264    return rc;
     265}
     266
     267void SharedClipboardProvider::Reset(void)
     268{
     269}
     270
  • TabularUnified trunk/src/VBox/GuestHost/SharedClipboard/ClipboardStreamImpl-win.cpp

    r78897 r78974  
    4646
    4747
    48 VBoxClipboardWinStreamImpl::VBoxClipboardWinStreamImpl(SharedClipboardProvider *pProvider, SharedClipboardURIObject *pURIObj)
    49     : m_lRefCount(1)
    50     , m_pProvider(pProvider)
     48VBoxClipboardWinStreamImpl::VBoxClipboardWinStreamImpl(VBoxClipboardWinDataObject *pParent,
     49                                                       PSHAREDCLIPBOARDURITRANSFER pTransfer, SharedClipboardURIObject *pURIObj)
     50    : m_pParent(pParent)
     51    , m_lRefCount(1)
     52    , m_pTransfer(pTransfer)
    5153    , m_pURIObj(pURIObj)
    5254{
    53     AssertPtr(m_pProvider);
     55    AssertPtr(m_pTransfer);
     56    AssertPtr(m_pTransfer->pProvider);
    5457    AssertPtr(m_pURIObj);
    5558
    5659    LogFunc(("szSrcPath=%s, cbSize=%RU64\n", m_pURIObj->GetSourcePathAbs().c_str(), m_pURIObj->GetSize()));
    5760
    58     m_pProvider->AddRef();
     61    m_pTransfer->pProvider->AddRef();
    5962}
    6063
     
    6265{
    6366    LogFlowThisFuncEnter();
    64     m_pProvider->Release();
     67
     68    if (   m_pTransfer
     69        && m_pTransfer->pProvider)
     70        m_pTransfer->pProvider->Release();
    6571}
    6672
     
    159165    const uint64_t cbProcessed = m_pURIObj->GetProcessed();
    160166
    161     const size_t cbToRead = RT_MIN(cbSize - cbProcessed, nBytesToRead);
    162           size_t cbRead   = 0;
     167    const uint32_t cbToRead = RT_MIN(cbSize - cbProcessed, nBytesToRead);
     168          uint32_t cbRead   = 0;
    163169
    164170    int rc = VINF_SUCCESS;
    165171
    166172    if (cbToRead)
    167         rc = m_pProvider->ReadData(pvBuffer, cbToRead, &cbRead);
     173    {
     174        VBOXCLIPBOARDFILEDATA FileData;
     175        RT_ZERO(FileData);
     176
     177        FileData.pvData = pvBuffer;
     178        FileData.cbData = cbToRead;
     179
     180        rc = m_pTransfer->pProvider->ReadFileData(&FileData, &cbRead);
     181        if (RT_SUCCESS(rc))
     182        {
     183            if (m_pURIObj->IsComplete())
     184                m_pParent->OnTransferComplete();
     185        }
     186    }
    168187
    169188    if (nBytesRead)
     
    229248 *
    230249 * @returns HRESULT
    231  * @param   pProvider           Pointer to Shared Clipboard provider to use.
     250 * @param   pParent             Pointer to the parent data object.
     251 * @param   pTransfer           Pointer to URI transfer object to use.
    232252 * @param   pURIObj             Pointer to URI object to handle.
    233253 * @param   ppStream            Where to return the created stream object on success.
    234254 */
    235255/* static */
    236 HRESULT VBoxClipboardWinStreamImpl::Create(SharedClipboardProvider *pProvider, SharedClipboardURIObject *pURIObj,
     256HRESULT VBoxClipboardWinStreamImpl::Create(VBoxClipboardWinDataObject *pParent,
     257                                           PSHAREDCLIPBOARDURITRANSFER pTransfer, SharedClipboardURIObject *pURIObj,
    237258                                           IStream **ppStream)
    238259{
    239     AssertPtrReturn(pProvider, E_POINTER);
    240 
    241     VBoxClipboardWinStreamImpl *pStream = new VBoxClipboardWinStreamImpl(pProvider, pURIObj);
     260    AssertPtrReturn(pTransfer, E_POINTER);
     261
     262    VBoxClipboardWinStreamImpl *pStream = new VBoxClipboardWinStreamImpl(pParent, pTransfer, pURIObj);
    242263    if (pStream)
    243264    {
  • TabularUnified trunk/src/VBox/GuestHost/SharedClipboard/clipboard-common.cpp

    r78161 r78974  
    2121#include <iprt/assert.h>
    2222#include <iprt/errcore.h>
     23
    2324#include <VBox/log.h>
    2425#include <VBox/GuestHost/clipboard-helper.h>
     26#ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
     27# include <VBox/GuestHost/SharedClipboard-uri.h>
     28#endif
     29
    2530
    2631/** @todo use const where appropriate; delinuxify the code (*Lin* -> *Host*); use AssertLogRel*. */
     
    307312    pFileHeader = (PBMFILEHEADER)pvDest;
    308313    pFileHeader->u16Type        = BITMAPHEADERMAGIC;
    309     pFileHeader->u32Size        = RT_H2LE_U32(cb);
     314    pFileHeader->u32Size        = (uint32_t)RT_H2LE_U32(cb);
    310315    pFileHeader->u16Reserved1   = pFileHeader->u16Reserved2 = 0;
    311     pFileHeader->u32OffBits     = RT_H2LE_U32(offPixel);
     316    pFileHeader->u32OffBits     = (uint32_t)RT_H2LE_U32(offPixel);
    312317    memcpy((uint8_t *)pvDest + sizeof(BMFILEHEADER), pvSrc, cbSrc);
    313318    *ppvDest = pvDest;
     
    336341}
    337342
     343#ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
     344/**
     345 * Initializes an URI clipboard transfer struct.
     346 *
     347 * @returns VBox status code.
     348 * @param   pCtx                Shared Clipboard provider creation context to use.
     349 * @param   ppTransfer          Where to return the created URI transfer struct.
     350 *                              Must be free'd by SharedClipboardURITransferDestroy().
     351 */
     352int SharedClipboardURITransferCreate(PSHAREDCLIPBOARDPROVIDERCREATIONCTX pCtx,
     353                                     PSHAREDCLIPBOARDURITRANSFER *ppTransfer)
     354{
     355    AssertPtrReturn(pCtx,       VERR_INVALID_POINTER);
     356    AssertPtrReturn(ppTransfer, VERR_INVALID_POINTER);
     357
     358    PSHAREDCLIPBOARDURITRANSFER pTransfer = (PSHAREDCLIPBOARDURITRANSFER)RTMemAlloc(sizeof(SHAREDCLIPBOARDURITRANSFER));
     359    if (!pTransfer)
     360        return VERR_NO_MEMORY;
     361
     362    LogFlowFuncEnter();
     363
     364    pTransfer->pProvider = SharedClipboardProvider::Create(pCtx);
     365    if (!pTransfer->pProvider)
     366        return VERR_NO_MEMORY;
     367
     368    pTransfer->Thread.fCancelled = false;
     369    pTransfer->Thread.fStarted   = false;
     370
     371    pTransfer->pvUser = NULL;
     372    pTransfer->cbUser = 0;
     373
     374    *ppTransfer = pTransfer;
     375
     376    return VINF_SUCCESS;
     377}
     378
     379/**
     380 * Destroys an URI clipboard transfer context struct.
     381 *
     382 * @param   pURI                URI clipboard transfer struct to destroy.
     383 */
     384void SharedClipboardURITransferDestroy(PSHAREDCLIPBOARDURITRANSFER pTransfer)
     385{
     386    if (!pTransfer)
     387        return;
     388
     389    LogFlowFuncEnter();
     390
     391    if (pTransfer->pProvider)
     392    {
     393        delete pTransfer->pProvider;
     394        pTransfer->pProvider = NULL;
     395    }
     396
     397    RTMemFree(pTransfer);
     398    pTransfer = NULL;
     399}
     400
     401/**
     402 * Resets an URI clipboard context struct.
     403 *
     404 * @param   pTransfer           URI clipboard transfer struct to reset.
     405 */
     406void SharedClipboardURITransferReset(PSHAREDCLIPBOARDURITRANSFER pTransfer)
     407{
     408    AssertPtrReturnVoid(pTransfer);
     409
     410    LogFlowFuncEnter();
     411
     412    if (pTransfer->pProvider)
     413        pTransfer->pProvider->Reset();
     414}
     415
     416/**
     417 * Writes all URI objects using the connected provider.
     418 *
     419 * @returns VBox status code.
     420 * @param   pTransfer           Transfer to write objects for.
     421 */
     422int SharedClipboardURITransferWrite(PSHAREDCLIPBOARDURITRANSFER pTransfer)
     423{
     424    AssertPtrReturn(pTransfer, VERR_INVALID_POINTER);
     425
     426    LogFlowFuncEnter();
     427
     428    int rc = VINF_SUCCESS;
     429
     430    SharedClipboardURIList &lstURI = pTransfer->pProvider->GetURIList();
     431
     432    while (!lstURI.IsEmpty())
     433    {
     434        SharedClipboardURIObject *pObj = lstURI.First();
     435        AssertPtrBreakStmt(pObj, rc = VERR_INVALID_POINTER);
     436
     437        switch (pObj->GetType())
     438        {
     439            case SharedClipboardURIObject::Type_Directory:
     440            {
     441                rc = pTransfer->pProvider->WriteDirectoryObj(*pObj);
     442                break;
     443            }
     444
     445            case SharedClipboardURIObject::Type_File:
     446            {
     447                rc = pTransfer->pProvider->WriteFileHdrObj(*pObj);
     448                if (RT_FAILURE(rc))
     449                    break;
     450
     451                while (!pObj->IsComplete())
     452                {
     453                    uint32_t cbWritten;
     454                    rc = pTransfer->pProvider->WriteFileDataObj(*pObj, &cbWritten);
     455                    if (RT_FAILURE(rc))
     456                        break;
     457                }
     458                break;
     459            }
     460
     461            default:
     462                AssertFailed();
     463                break;
     464        }
     465
     466        if (RT_FAILURE(rc))
     467            break;
     468
     469        /* Only remove current object on success. */
     470        lstURI.RemoveFirst();
     471    }
     472
     473    LogFlowFuncLeaveRC(rc);
     474    return rc;
     475}
     476
     477/**
     478 * Thread for transferring (writing) URI objects from source to the target.
     479 * For target to source transfers we utilize our own IDataObject / IStream implementations.
     480 *
     481 * @returns VBox status code.
     482 * @param   hThread             Thread handle.
     483 * @param   pvUser              User arguments; is PSHAREDCLIPBOARDURICTX.
     484 */
     485int SharedClipboardURITransferWriteThread(RTTHREAD hThread, void *pvUser)
     486{
     487    AssertPtrReturn(pvUser, VERR_INVALID_POINTER);
     488
     489    LogFlowFuncEnter();
     490
     491    PSHAREDCLIPBOARDURICTX pURICtx = (PSHAREDCLIPBOARDURICTX)pvUser;
     492    AssertPtr(pURICtx);
     493
     494    /* At the moment we only support one transfer at a time. */
     495    PSHAREDCLIPBOARDURITRANSFER pTransfer = SharedClipboardURICtxGetTransfer(pURICtx, 0 /* Index*/);
     496    AssertPtr(pTransfer->pProvider);
     497
     498    int rc = VINF_SUCCESS;
     499
     500    if (RT_SUCCESS(rc))
     501        pTransfer->Thread.fStarted = true;
     502
     503    int rc2 = RTThreadUserSignal(hThread);
     504    const bool fSignalled = RT_SUCCESS(rc2);
     505
     506    if (RT_SUCCESS(rc))
     507        rc = SharedClipboardURITransferWrite(pTransfer);
     508
     509    if (!fSignalled)
     510    {
     511        rc2 = RTThreadUserSignal(hThread);
     512        AssertRC(rc2);
     513    }
     514
     515    LogFlowFuncLeaveRC(rc);
     516    return rc;
     517}
     518
     519/**
     520 * Initializes an URI clipboard context struct.
     521 *
     522 * @returns VBox status code.
     523 * @param   pURI                URI clipboard context to initialize.
     524 * @param   pTransfer           Pointer to URI clipboard transfer struct to use.
     525 */
     526int SharedClipboardURICtxInit(PSHAREDCLIPBOARDURICTX pURI, PSHAREDCLIPBOARDURITRANSFER pTransfer)
     527{
     528    AssertPtrReturn(pURI,      VERR_INVALID_POINTER);
     529    AssertPtrReturn(pTransfer, VERR_INVALID_POINTER);
     530
     531    LogFlowFuncEnter();
     532
     533    int rc = RTCritSectInit(&pURI->CritSect);
     534    if (RT_SUCCESS(rc))
     535    {
     536        RTListInit(&pURI->List);
     537
     538        SharedClipboardURICtxReset(pURI);
     539    }
     540
     541    return VINF_SUCCESS;
     542}
     543
     544/**
     545 * Destroys an URI clipboard information context struct.
     546 *
     547 * @param   pURI                URI clipboard context to destroy.
     548 */
     549void SharedClipboardURICtxDestroy(PSHAREDCLIPBOARDURICTX pURI)
     550{
     551    AssertPtrReturnVoid(pURI);
     552
     553    RTCritSectDelete(&pURI->CritSect);
     554
     555    PSHAREDCLIPBOARDURITRANSFER pTransfer, pTransferNext;
     556    RTListForEachSafe(&pURI->List, pTransfer, pTransferNext, SHAREDCLIPBOARDURITRANSFER, Node)
     557    {
     558        SharedClipboardURITransferDestroy(pTransfer);
     559        RTListNodeRemove(&pTransfer->Node);
     560    }
     561
     562    LogFlowFuncEnter();
     563}
     564
     565/**
     566 * Resets an URI clipboard context struct.
     567 *
     568 * @param   pURI                URI clipboard context to reset.
     569 */
     570void SharedClipboardURICtxReset(PSHAREDCLIPBOARDURICTX pURI)
     571{
     572    AssertPtrReturnVoid(pURI);
     573
     574    LogFlowFuncEnter();
     575
     576    pURI->cTransfers = 0;
     577
     578    PSHAREDCLIPBOARDURITRANSFER pTransfer;
     579    RTListForEach(&pURI->List, pTransfer, SHAREDCLIPBOARDURITRANSFER, Node)
     580        SharedClipboardURITransferReset(pTransfer);
     581}
     582
     583/**
     584 * Adds a new transfer to an URI clipboard context struct.
     585 *
     586 * @returns VBox status code.
     587 * @param   pURI                URI clipboard context to add transfer to.
     588 * @param   pTransfer           Pointer to URI clipboard transfer struct to add.
     589 */
     590int SharedClipboardURICtxTransferAdd(PSHAREDCLIPBOARDURICTX pURI, PSHAREDCLIPBOARDURITRANSFER pTransfer)
     591{
     592    AssertPtrReturn(pURI,      VERR_INVALID_POINTER);
     593    AssertPtrReturn(pTransfer, VERR_INVALID_POINTER);
     594
     595    LogFlowFuncEnter();
     596
     597    RTListAppend(&pURI->List, &pTransfer->Node);
     598
     599    return VINF_SUCCESS;
     600}
     601
     602/**
     603 * Returns a specific URI transfer.
     604 *
     605 * @returns URI transfer, or NULL if not found.
     606 * @param   pURI                URI clipboard context to return transfer for.
     607 * @param   uIdx                Index of the transfer to return.
     608 */
     609PSHAREDCLIPBOARDURITRANSFER SharedClipboardURICtxGetTransfer(PSHAREDCLIPBOARDURICTX pURI, uint32_t uIdx)
     610{
     611    AssertReturn(uIdx == 0, NULL); /* Only one transfer allowed at the moment. */
     612    return RTListGetFirst(&pURI->List, SHAREDCLIPBOARDURITRANSFER, Node);
     613}
     614
     615/**
     616 * Returns the number of active URI transfers.
     617 *
     618 * @returns VBox status code.
     619 * @param   pURI                URI clipboard context to return number for.
     620 */
     621uint32_t SharedClipboardURICtxGetActiveTransfers(PSHAREDCLIPBOARDURICTX pURI)
     622{
     623    return pURI->cTransfers;
     624}
     625#endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
     626
  • TabularUnified trunk/src/VBox/GuestHost/SharedClipboard/clipboard-win.cpp

    r78897 r78974  
    743743    return rc;
    744744}
    745 
    746 /**
    747  * Initializes a Windows-specific URI clipboard information struct.
    748  *
    749  * @returns VBox status code.
    750  * @param   pURI                URI clipboard information struct to initialize.
    751  * @param   pCtx                Shared Clipboard provider creation context to use.
    752  */
    753 int VBoxClipboardWinURIInit(PVBOXCLIPBOARDWINURI pURI, PSHAREDCLIPBOARDPROVIDERCREATIONCTX pCtx)
    754 {
    755     AssertPtrReturn(pURI, VERR_INVALID_POINTER);
    756     AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
    757 
    758     LogFlowFuncEnter();
    759 
    760     pURI->Transfer.pProvider = SharedClipboardProvider::Create(pCtx);
    761     if (!pURI->Transfer.pProvider)
    762         return VERR_NO_MEMORY;
    763 
    764     VBoxClipboardWinURIReset(pURI);
    765 
    766     return VINF_SUCCESS;
    767 }
    768 
    769 /**
    770  * Destroys a Windows-specific URI clipboard information struct.
    771  *
    772  * @param   pURI                URI clipboard information struct to destroy.
    773  */
    774 void VBoxClipboardWinURIDestroy(PVBOXCLIPBOARDWINURI pURI)
    775 {
    776     AssertPtrReturnVoid(pURI);
    777 
    778     LogFlowFuncEnter();
    779 
    780     if (pURI->Transfer.pProvider)
    781     {
    782         delete pURI->Transfer.pProvider;
    783         pURI->Transfer.pProvider = NULL;
    784     }
    785 }
    786 
    787 /**
    788  * Resets a Windows-specific URI clipboard information struct.
    789  *
    790  * @param   pURI                URI clipboard information struct to reset.
    791  */
    792 void VBoxClipboardWinURIReset(PVBOXCLIPBOARDWINURI pURI)
    793 {
    794     AssertPtrReturnVoid(pURI);
    795 
    796     LogFlowFuncEnter();
    797 
    798     pURI->cTransfers = 0;
    799 
    800     if (pURI->Transfer.pProvider)
    801         pURI->Transfer.pProvider->Reset();
    802 }
    803745#endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
    804746
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