VirtualBox

Ignore:
Timestamp:
Apr 30, 2015 12:28:26 PM (10 years ago)
Author:
vboxsync
Message:

DnD: Update.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/GuestDnDTargetImpl.cpp

    r55539 r55549  
    496496    else
    497497        rc = VERR_COM_INVALID_OBJECT_STATE;
     498
     499    ASMAtomicWriteBool(&pTarget->mDataBase.mfTransferIsPending, false);
    498500
    499501    LogFlowFunc(("pTarget=%p returning rc=%Rrc\n", (GuestDnDTarget *)pTarget, rc));
     
    521523#else /* VBOX_WITH_DRAG_AND_DROP */
    522524
    523     /** @todo Add input validation. */
    524     /** @todo Check if another sendData() call currently is being processed. */
    525 
    526525    AutoCaller autoCaller(this);
    527526    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    528527
    529     /* Note: At the moment we only support one response at a time. */
     528    /* Input validation. */
     529    if (RT_UNLIKELY((aFormat.c_str()) == NULL || *(aFormat.c_str()) == '\0'))
     530        return setError(E_INVALIDARG, tr("No data format specified"));
     531    if (RT_UNLIKELY(!aData.size()))
     532        return setError(E_INVALIDARG, tr("No data to send specified"));
     533
     534    /* Note: At the moment we only support one transfer at a time. */
     535    if (ASMAtomicReadBool(&mDataBase.mfTransferIsPending))
     536        return setError(E_INVALIDARG, tr("Another send operation already is in progress"));
     537
     538    ASMAtomicWriteBool(&mDataBase.mfTransferIsPending, true);
     539
     540    /* Dito. */
    530541    GuestDnDResponse *pResp = GuestDnDInst()->response();
    531542    AssertPtr(pResp);
     
    549560        AssertReturn(pTask->isOk(), pTask->getRC());
    550561
    551         RTTHREAD sendThread;
    552         int rc = RTThreadCreate(&sendThread, GuestDnDTarget::i_sendDataThread,
     562        int rc = RTThreadCreate(NULL, GuestDnDTarget::i_sendDataThread,
    553563                                (void *)pTask, 0, RTTHREADTYPE_MAIN_WORKER, 0, "dndTgtSndData");
    554564        if (RT_SUCCESS(rc))
     
    569579        hr = setError(E_OUTOFMEMORY);
    570580    }
     581
     582    /* Note: mDataBase.mfTransferIsPending will be set to false again by i_sendDataThread. */
    571583
    572584    LogFlowFunc(("Returning hr=%Rhrc\n", hr));
     
    608620
    609621    ASMAtomicWriteBool(&pCtx->mIsActive, true);
     622
     623    /* Clear all remaining outgoing messages. */
     624    mDataBase.mListOutgoing.clear();
    610625
    611626    do
     
    694709        rc = aFile.OpenEx(strPathSrc, DnDURIObject::File, DnDURIObject::Source,
    695710                          RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE, 0 /* fFlags */);
     711        if (RT_FAILURE(rc))
     712            LogRel2(("DnD: Error opening host file \"%s\", rc=%Rrc\n", strPathSrc.c_str(), rc));
    696713    }
    697714
     
    718735
    719736                LogFlowFunc(("Sending file header ...\n"));
     737                LogRel2(("DnD: Transferring host file to guest: %s (%RU64 bytes, mode 0x%x)\n",
     738                         strPathSrc.c_str(), aFile.GetSize(), aFile.GetMode()));
    720739            }
    721740            else
     
    800819        if (aFile.IsComplete()) /* Done reading? */
    801820        {
     821            LogRel2(("DnD: File transfer to guest complete: %s\n", aFile.GetSourcePath().c_str()));
    802822            LogFlowFunc(("File \"%s\" complete\n", aFile.GetSourcePath().c_str()));
    803823            rc = VINF_EOF;
     
    821841
    822842    int rc = VINF_SUCCESS;
    823     bool fNotify = false;
    824843
    825844    switch (uMsg)
     
    849868
    850869                if (RT_FAILURE(rc))
    851                 {
    852                     if (rc == VERR_NO_DATA) /* All URI objects processed? */
    853                     {
    854                         /* Unregister this callback. */
    855                         AssertPtr(pCtx->mpResp);
    856                         int rc2 = pCtx->mpResp->setCallback(uMsg, NULL /* PFNGUESTDNDCALLBACK */);
    857                         if (RT_FAILURE(rc2))
    858                             LogFlowFunc(("Error: Unable to unregister callback for message %RU32, rc=%Rrc\n", uMsg, rc2));
    859                     }
    860 
    861870                    delete pMsg;
    862                 }
    863871            }
    864872            catch(std::bad_alloc & /*e*/)
     
    866874                rc = VERR_NO_MEMORY;
    867875            }
     876            break;
     877        }
     878        case DragAndDropSvc::GUEST_DND_GH_EVT_ERROR:
     879        {
     880            DragAndDropSvc::PVBOXDNDCBEVTERRORDATA pCBData = reinterpret_cast<DragAndDropSvc::PVBOXDNDCBEVTERRORDATA>(pvParms);
     881            AssertPtr(pCBData);
     882            AssertReturn(sizeof(DragAndDropSvc::VBOXDNDCBEVTERRORDATA) == cbParms, VERR_INVALID_PARAMETER);
     883            AssertReturn(DragAndDropSvc::CB_MAGIC_DND_GH_EVT_ERROR == pCBData->hdr.u32Magic, VERR_INVALID_PARAMETER);
     884
     885            pCtx->mpResp->reset();
     886            rc = pCtx->mpResp->setProgress(100, DragAndDropSvc::DND_PROGRESS_ERROR, pCBData->rc);
     887            if (RT_SUCCESS(rc))
     888                rc = pCBData->rc;
    868889            break;
    869890        }
     
    917938    }
    918939
    919     if (fNotify)
    920     {
    921         int rc2 = pCtx->mCallback.Notify(rc);
     940    if (RT_FAILURE(rc))
     941    {
     942        switch (rc)
     943        {
     944            case VERR_NO_DATA:
     945                LogRel2(("DnD: Transfer complete\n"));
     946                break;
     947
     948            case VERR_CANCELLED:
     949                LogRel2(("DnD: Transfer canceled\n"));
     950                break;
     951
     952            default:
     953                LogRel(("DnD: Error %Rrc occurred, aborting transfer\n", rc));
     954                break;
     955        }
     956
     957        /* Unregister this callback. */
     958        AssertPtr(pCtx->mpResp);
     959        int rc2 = pCtx->mpResp->setCallback(uMsg, NULL /* PFNGUESTDNDCALLBACK */);
     960        AssertRC(rc2);
     961
     962        /* Notify waiters. */
     963        rc2 = pCtx->mCallback.Notify(rc);
    922964        AssertRC(rc2);
    923965    }
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