VirtualBox

Changeset 56575 in vbox


Ignore:
Timestamp:
Jun 22, 2015 12:28:52 PM (9 years ago)
Author:
vboxsync
Message:

DnD/VbglR3: Cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibDragAndDrop.cpp

    r56505 r56575  
    347347}
    348348
    349 static int vbglR3DnDHGProcessURIMessages(PVBGLR3GUESTDNDCMDCTX  pCtx,
    350                                          uint32_t              *puScreenId,
    351                                          char                  *pszFormat,
    352                                          uint32_t               cbFormat,
    353                                          uint32_t              *pcbFormatRecv,
    354                                          void                 **ppvData,
    355                                          uint32_t               cbData,
    356                                          size_t                *pcbDataRecv)
     349static int vbglR3DnDHGProcessURIMessages(PVBGLR3GUESTDNDCMDCTX   pCtx,
     350                                         void                  **ppvData,
     351                                         uint32_t                cbData,
     352                                         size_t                 *pcbDataRecv)
    357353{
    358354    AssertPtrReturn(pCtx,        VERR_INVALID_POINTER);
     
    361357    AssertPtrReturn(pcbDataRecv, VERR_INVALID_POINTER);
    362358
    363     void    *pvData        = *ppvData;
    364     uint32_t cbDataRecv    = 0;
    365     uint64_t cbDataToRead  = *pcbDataRecv;
    366     uint64_t cbDataWritten = 0;
    367 
    368     int rc = VINF_SUCCESS;
    369 
    370     /* Allocate temp buffer. */
    371     uint32_t cbTmpData = _64K; /** @todo Make this configurable? */
    372     void *pvTmpData = RTMemAlloc(cbTmpData);
    373     if (!pvTmpData)
     359    /*
     360     * Allocate chunk buffer.
     361     */
     362    uint32_t cbChunkMax = _64K; /** @todo Make this configurable? */
     363    void *pvChunk = RTMemAlloc(cbChunkMax);
     364    if (!pvChunk)
    374365        return VERR_NO_MEMORY;
    375 
    376     /* Create and query the (unique) drop target directory in the user's temporary directory. */
     366    uint32_t cbChunkRead = 0;
     367
     368    uint64_t cbFileSize    = 0; /* Total file size (in bytes). */
     369    uint64_t cbFileWritten = 0; /* Written bytes. */
     370
     371    /*
     372     * Create and query the (unique) drop target directory in the user's temporary directory.
     373     */
    377374    DNDDIRDROPPEDFILES dirDroppedFiles;
    378375    const char *pszDropDir;
    379     rc = DnDDirDroppedFilesCreateAndOpenTemp(&dirDroppedFiles);
     376    int rc = DnDDirDroppedFilesCreateAndOpenTemp(&dirDroppedFiles);
    380377    if (RT_SUCCESS(rc))
    381378        pszDropDir = DnDDirDroppedFilesGetDirAbs(&dirDroppedFiles);
    382379
     380    /*
     381     * Enter the main loop of retieving files + directories.
     382     */
    383383    DnDURIList lstURI;
    384384    DnDURIObject objFile(DnDURIObject::File);
     
    427427                {
    428428                    if (uNextMsg == DragAndDropSvc::HOST_DND_HG_SND_FILE_HDR)
     429                    {
    429430                        rc = vbglR3DnDHGProcessSendFileHdrMessage(pCtx,
    430431                                                                  szPathName,
     
    432433                                                                  &fFlags,
    433434                                                                  &fMode,
    434                                                                   &cbDataToRead);
     435                                                                  &cbFileSize);
     436                        LogFlowFunc(("HOST_DND_HG_SND_FILE_HDR szPathName=%s, fFlags=0x%x, fMode=0x%x, cbFileSize=%RU64, rc=%Rrc\n",
     437                                     szPathName, fFlags, fMode, cbFileSize, rc));
     438                    }
    435439                    else
     440                    {
    436441                        rc = vbglR3DnDHGProcessSendFileMessage(pCtx,
    437442                                                               szPathName,
    438443                                                               sizeof(szPathName),
    439444                                                               &cbPathName,
    440                                                                pvTmpData,
    441                                                                cbTmpData,
    442                                                                &cbDataRecv,
     445                                                               pvChunk,
     446                                                               cbChunkMax,
     447                                                               &cbChunkRead,
    443448                                                               &fMode);
     449                        LogFlowFunc(("HOST_DND_HG_SND_FILE_DATA "
     450                                     "szPathName=%s, cbPathName=%RU32, cbChunkRead=%RU32, fMode=0x%x, rc=%Rrc\n",
     451                                     szPathName, cbPathName, cbChunkRead, fMode, rc));
     452                    }
     453
    444454                    if (   RT_SUCCESS(rc)
    445455                        && (   uNextMsg == DragAndDropSvc::HOST_DND_HG_SND_FILE_HDR
     
    451461                        if (pszPathAbs)
    452462                        {
    453                             LogFlowFunc(("Opening pszPathName=%s, cbPathName=%RU32, fMode=0x%x, cbSize=%RU64\n",
    454                                          szPathName, cbPathName, fMode, cbDataToRead));
     463                            LogFlowFunc(("Opening pszPathName=%s, cbPathName=%RU32, fMode=0x%x, cbFileSize=%zu\n",
     464                                         szPathName, cbPathName, fMode, cbFileSize));
    455465
    456466                            uint64_t fOpen = RTFILE_O_WRITE | RTFILE_O_DENY_ALL;
     
    463473                            if (!objFile.IsOpen())
    464474                            {
    465 
    466475                                RTCString strPathAbs(pszPathAbs);
    467476                                rc = objFile.OpenEx(strPathAbs, DnDURIObject::File, DnDURIObject::Target, fOpen,
     
    472481                                    if (RT_SUCCESS(rc))
    473482                                    {
    474                                         cbDataWritten = 0;
     483                                        cbFileWritten = 0;
    475484
    476485                                        if (pCtx->uProtocol >= 2) /* Set the expected file size. */
    477                                             objFile.SetSize(cbDataToRead);
     486                                            objFile.SetSize(cbFileSize);
    478487                                    }
    479488                                }
     
    493502                        bool fClose = false;
    494503
    495                         uint32_t cbWritten;
    496                         rc = objFile.Write(pvTmpData, cbDataRecv, &cbWritten);
     504                        uint32_t cbChunkWritten;
     505                        rc = objFile.Write(pvChunk, cbChunkRead, &cbChunkWritten);
    497506                        if (RT_SUCCESS(rc))
    498507                        {
     
    505514                                fClose = true; /* Always close the file after each chunk. */
    506515
    507                             cbDataWritten += cbWritten;
    508                             Assert(cbDataWritten <= cbDataToRead);
     516                            cbFileWritten += cbChunkWritten;
     517                            Assert(cbFileWritten <= cbFileSize);
    509518                        }
    510519
     
    525534                }
    526535                default:
     536                {
    527537                    LogFlowFunc(("Message %RU32 not supported\n", uNextMsg));
    528538                    rc = VERR_NOT_SUPPORTED;
    529539                    break;
    530             }
    531 
    532 #if 0 /* Not used yet. */
    533             if (pCtx->uProtocol >= XXX)
    534             {
    535                 /*
    536                  * Send the progress back to the host.
    537                  */
    538                 uint32_t uStatus;
    539                 int guestRc;
    540                 uint8_t uPercent;
    541                 switch (rc)
    542                 {
    543                     case VINF_SUCCESS:
    544                     {
    545                         if (!cbData)
    546                             cbData = 1;
    547                         uPercent = cbDataWritten * 100 / (cbDataToRead ? cbDataToRead : 1);
    548                         uStatus  = uPercent >= 100 ?
    549                                    DragAndDropSvc::DND_PROGRESS_COMPLETE : DragAndDropSvc::DND_PROGRESS_RUNNING;
    550                         guestRc  = VINF_SUCCESS;
    551                         break;
    552                     }
    553 
    554                     case VERR_CANCELLED:
    555                     {
    556                         uStatus  = DragAndDropSvc::DND_PROGRESS_CANCELLED;
    557                         uPercent = 100;
    558                         guestRc  = VINF_SUCCESS;
    559                         break;
    560                     }
    561 
    562                     default:
    563                     {
    564                         uStatus  = DragAndDropSvc::DND_PROGRESS_ERROR;
    565                         uPercent = 100;
    566                         guestRc  = rc;
    567                         break;
    568                     }
    569                 }
    570 
    571                 int rc2 = VbglR3DnDHGSetProgress(pCtx, uStatus, uPercent, guestRc);
    572                 LogFlowFunc(("cbDataWritten=%RU64 / cbDataToRead=%RU64 => %RU8%% (uStatus=%ld, %Rrc), rc=%Rrc\n", cbDataWritten, cbDataToRead,
    573                               uPercent, uStatus, guestRc, rc2));
    574                 if (RT_SUCCESS(rc))
    575                     rc = rc2;
    576 
    577                 /* All data transferred? */
    578                 if (   RT_SUCCESS(rc)
    579                     && uPercent == 100)
    580                 {
    581                     rc = VINF_EOF;
    582                     break;
    583540                }
    584541            }
    585 #endif
    586542        }
    587543
     
    597553        rc = VINF_SUCCESS;
    598554
    599     if (pvTmpData)
    600         RTMemFree(pvTmpData);
     555    /* Delete chunk buffer again. */
     556    if (pvChunk)
     557        RTMemFree(pvChunk);
    601558
    602559    /* Cleanup on failure or if the user has canceled the operation or
     
    610567    {
    611568        /*
    612          * Patch the old drop data with the new drop directory, so the drop target can find the files.
     569         * Now we need to transform the URI list which came from the host into
     570         * an URI list which also has the final "Dropped Files" directory as a prefix
     571         * for each URI entry.
     572         *
     573         * So patch the old drop data with the new drop directory to let the drop
     574         * target on the guest can find the files later.
    613575         */
    614         rc = lstURI.RootFromURIData(pvData, cbDataToRead, 0 /* fFlags */);
     576        void  *pvURIData = *ppvData;
     577        size_t cbURIData = *pcbDataRecv;
     578
     579        rc = lstURI.RootFromURIData(pvURIData, cbURIData, 0 /* fFlags */);
    615580        if (RT_SUCCESS(rc))
    616581        {
    617582            /* Cleanup the old data and write the new data back to the event. */
    618             RTMemFree(pvData);
     583            RTMemFree(pvURIData);
    619584
    620585            RTCString strData = lstURI.RootToString(pszDropDir);
    621             LogFlowFunc(("cbDataToRead: %zu -> %zu\n", cbDataToRead, strData.length() + 1));
    622 
    623             pvData       = RTStrDupN(strData.c_str(), strData.length());
    624             cbDataToRead = strData.length() + 1;
     586            Assert(!strData.isEmpty());
     587            LogFlowFunc(("New URI list now has %zu bytes (formerly %RU32 bytes)\n", strData.length() + 1, cbURIData));
     588
     589            pvURIData = RTStrDupN(strData.c_str(), strData.length());
     590            if (pvURIData)
     591            {
     592                cbURIData = strData.length() + 1;
     593            }
     594            else
     595                rc = VERR_NO_MEMORY;
    625596        }
    626597
    627598        if (RT_SUCCESS(rc))
    628599        {
    629             *ppvData     = pvData;
    630             *pcbDataRecv = cbDataToRead;
     600            *ppvData     = pvURIData;
     601            *pcbDataRecv = cbURIData;
    631602        }
    632603
     
    849820        {
    850821            rc = vbglR3DnDHGProcessURIMessages(pCtx,
    851                                                puScreenId,
    852                                                pszFormat,
    853                                                cbFormat,
    854                                                pcbFormatRecv,
    855822                                               ppvData,
    856823                                               cbData,
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