VirtualBox

Changeset 87611 in vbox


Ignore:
Timestamp:
Feb 4, 2021 4:31:28 PM (4 years ago)
Author:
vboxsync
Message:

Shared Clipboard/Transfers: More callback code. ​bugref:9437

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/GuestHost/SharedClipboard-transfers.h

    r87452 r87611  
    612612/**
    613613 * Shared Clipboard transfer provider interface table.
     614 *
     615 * A transfer provider inteface implementation realizes all low level functions
     616 * needed for making a Shared Clipboard transfer happen.
    614617 */
    615618typedef struct _SHCLTXPROVIDERIFACE
    616619{
    617     /** Called when the transfer gets initialized. */
    618     DECLCALLBACKMEMBER(int,  pfnInitialize,(PSHCLTXPROVIDERCTX pCtx));
    619     /** Called before the transfer will be started. */
    620     DECLCALLBACKMEMBER(int,  pfnStart,(PSHCLTXPROVIDERCTX pCtx));
    621     /** Called when the transfer has been complete. */
    622     DECLCALLBACKMEMBER(void, pfnCompleted,(PSHCLTXPROVIDERCTX pCtx, int rc));
    623     /** Called when the transfer has been canceled. */
    624     DECLCALLBACKMEMBER(void, pfnCanceled,(PSHCLTXPROVIDERCTX pCtx));
    625     /** Called when transfer resulted in an unrecoverable error. */
    626     DECLCALLBACKMEMBER(void, pfnError,(PSHCLTXPROVIDERCTX pCtx, int rc));
    627     /** Called when transfer got registered to a transfer context. */
    628     DECLCALLBACKMEMBER(void, pfnRegistered,(PSHCLTXPROVIDERCTX pCtx, PSHCLTRANSFERCTX pTransferCtx));
    629     /** Called when transfer got unregistered from a transfer context. */
    630     DECLCALLBACKMEMBER(void, pfnUnregistered,(PSHCLTXPROVIDERCTX pCtx, PSHCLTRANSFERCTX pTransferCtx));
    631 
    632620    DECLCALLBACKMEMBER(int, pfnRootsGet,(PSHCLTXPROVIDERCTX pCtx, PSHCLROOTLIST *ppRootList));
    633621    DECLCALLBACKMEMBER(int, pfnListOpen,(PSHCLTXPROVIDERCTX pCtx, PSHCLLISTOPENPARMS pOpenParms, PSHCLLISTHANDLE phList));
     
    661649
    662650/**
     651 * Structure maintaining clipboard transfer callback context data.
     652 */
     653typedef struct _SHCLTRANSFERCALLBACKCTX
     654{
     655    /** Pointer to the related Shared Clipboard transfer. */
     656    PSHCLTRANSFER pTransfer;
     657    /** User-defined data pointer. Can be NULL if not needed. */
     658    void         *pvUser;
     659    /** Size (in bytes) of data at user pointer. */
     660    size_t        cbUser;
     661} SHCLTRANSFERCALLBACKCTX, *PSHCLTRANSFERCALLBACKCTX;
     662
     663/**
     664 * Shared Clipboard transfer callback table.
     665 *
     666 * All callbacks are optional and can provide additional information / feedback to a frontend.
     667 */
     668typedef struct _SHCLTRANSFERCALLBACKTABLE
     669{
     670    /**
     671     * Called when the transfer gets initialized.
     672     *
     673     * @param   pCbCtx              Pointer to callback context to use.
     674     */
     675    DECLCALLBACKMEMBER(int,  pfnOnInitialize,(PSHCLTRANSFERCALLBACKCTX pCbCtx));
     676    /**
     677     * Called before the transfer will be started.
     678     *
     679     * @param   pCbCtx              Pointer to callback context to use.
     680     */
     681    DECLCALLBACKMEMBER(int,  pfnOnStart,(PSHCLTRANSFERCALLBACKCTX pCbCtx));
     682    /**
     683     * Called when the transfer has been complete.
     684     *
     685     * @param   pCbCtx              Pointer to callback context to use.
     686     * @param   rcCompletion        Completion result.
     687     *                              VERR_CANCELED if transfer has been canceled.
     688     */
     689    DECLCALLBACKMEMBER(void, pfnOnCompleted,(PSHCLTRANSFERCALLBACKCTX pCbCtx, int rcCompletion));
     690    /**
     691     * Called when transfer resulted in an unrecoverable error.
     692     *
     693     * @param   pCbCtx              Pointer to callback context to use.
     694     * @param   rcError             Error reason, IPRT-style.
     695     */
     696    DECLCALLBACKMEMBER(void, pfnOnError,(PSHCLTRANSFERCALLBACKCTX pCbCtx, int rcError));
     697    /**
     698     * Called when transfer got registered to a transfer context.
     699     *
     700     * @param   pCbCtx              Pointer to callback context to use.
     701     * @param   pTransferCtx        Transfer context transfer was registered to.
     702     */
     703    DECLCALLBACKMEMBER(void, pfnOnRegistered,(PSHCLTRANSFERCALLBACKCTX pCbCtx, PSHCLTRANSFERCTX pTransferCtx));
     704    /**
     705     * Called when transfer got unregistered from a transfer context.
     706     *
     707     * @param   pCbCtx              Pointer to callback context to use.
     708     * @param   pTransferCtx        Transfer context transfer was unregistered from.
     709     */
     710    DECLCALLBACKMEMBER(void, pfnOnUnregistered,(PSHCLTRANSFERCALLBACKCTX pCbCtx, PSHCLTRANSFERCTX pTransferCtx));
     711
     712    /** User-provided callback data. Can be NULL if not used. */
     713    void  *pvUser;
     714    /** Size (in bytes) of data pointer at \a pvUser. */
     715    size_t cbUser;
     716} SHCLTRANSFERCALLBACKTABLE, *PSHCLTRANSFERCALLBACKTABLE;
     717
     718/**
    663719 * Structure for thread-related members for a single Shared Clipboard transfer.
    664720 */
     
    684740{
    685741    /** The node member for using this struct in a RTList. */
    686     RTLISTNODE               Node;
     742    RTLISTNODE                Node;
    687743    /** The transfer's state (for SSM, later). */
    688     SHCLTRANSFERSTATE        State;
     744    SHCLTRANSFERSTATE         State;
    689745    /** Absolute path to root entries. */
    690     char                    *pszPathRootAbs;
     746    char                     *pszPathRootAbs;
    691747    /** Timeout (in ms) for waiting of events. Default is 30s. */
    692     RTMSINTERVAL             uTimeoutMs;
     748    RTMSINTERVAL              uTimeoutMs;
    693749    /** Maximum data chunk size (in bytes) to transfer. Default is 64K. */
    694     uint32_t                 cbMaxChunkSize;
     750    uint32_t                  cbMaxChunkSize;
    695751    /** The transfer's own event source. */
    696     SHCLEVENTSOURCE          Events;
     752    SHCLEVENTSOURCE           Events;
    697753    /** Current number of concurrent list handles. */
    698     uint32_t                 cListHandles;
     754    uint32_t                  cListHandles;
    699755    /** Maximum number of concurrent list handles. */
    700     uint32_t                 cMaxListHandles;
     756    uint32_t                  cMaxListHandles;
    701757    /** Next upcoming list handle. */
    702     SHCLLISTHANDLE           uListHandleNext;
     758    SHCLLISTHANDLE            uListHandleNext;
    703759    /** List of all list handles elated to this transfer. */
    704     RTLISTANCHOR             lstList;
     760    RTLISTANCHOR              lstList;
    705761    /** Number of root entries in list. */
    706     uint64_t                 cRoots;
     762    uint64_t                  cRoots;
    707763    /** List of root entries of this transfer. */
    708     RTLISTANCHOR             lstRoots;
     764    RTLISTANCHOR              lstRoots;
    709765    /** Current number of concurrent object handles. */
    710     uint32_t                 cObjHandles;
     766    uint32_t                  cObjHandles;
    711767    /** Maximum number of concurrent object handles. */
    712     uint32_t                 cMaxObjHandles;
     768    uint32_t                  cMaxObjHandles;
    713769    /** Next upcoming object handle. */
    714     SHCLOBJHANDLE            uObjHandleNext;
     770    SHCLOBJHANDLE             uObjHandleNext;
    715771    /** Map of all objects handles related to this transfer. */
    716     RTLISTANCHOR             lstObj;
     772    RTLISTANCHOR              lstObj;
    717773    /** The transfer's own provider context. */
    718     SHCLTXPROVIDERCTX        ProviderCtx;
     774    SHCLTXPROVIDERCTX         ProviderCtx;
    719775    /** The transfer's provider interface. */
    720     SHCLTXPROVIDERIFACE      ProviderIface;
     776    SHCLTXPROVIDERIFACE       ProviderIface;
     777    /** The transfer's callback context. */
     778    SHCLTRANSFERCALLBACKCTX   CallbackCtx;
     779    /** The transfer's callback table. */
     780    SHCLTRANSFERCALLBACKTABLE Callbacks;
    721781    /** Opaque pointer to implementation-specific parameters. */
    722     void                    *pvUser;
     782    void                     *pvUser;
    723783    /** Size (in bytes) of implementation-specific parameters. */
    724     size_t                   cbUser;
     784    size_t                    cbUser;
    725785    /** Contains thread-related attributes. */
    726     SHCLTRANSFERTHREAD       Thread;
     786    SHCLTRANSFERTHREAD        Thread;
    727787    /** Critical section for serializing access. */
    728     RTCRITSECT               CritSect;
     788    RTCRITSECT                CritSect;
    729789} SHCLTRANSFER, *PSHCLTRANSFER;
    730790
     
    863923bool ShClTransferListEntryIsValid(PSHCLLISTENTRY pListEntry);
    864924
     925void ShClTransferSetCallbacks(PSHCLTRANSFER pTransfer, PSHCLTRANSFERCALLBACKTABLE pCallbacks);
    865926int ShClTransferSetProviderIface(PSHCLTRANSFER pTransfer, PSHCLTXPROVIDERCREATIONCTX pCreationCtx);
    866927int ShClTransferRootsSet(PSHCLTRANSFER pTransfer, const char *pszRoots, size_t cbRoots);
  • trunk/include/VBox/VBoxGuestLib.h

    r87452 r87611  
    589589     * This is set by VbglR3ClipboardConnectEx(). */
    590590    uint32_t                    cbMaxChunkSize;
     591    /** Optional callbacks to invoke. */
     592    SHCLTRANSFERCALLBACKTABLE   Callbacks;
    591593} VBGLR3SHCLTRANSFERCTX;
    592594/** Pointer to a Shared Clipboard transfer context. */
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp

    r87452 r87611  
    9797 * Cleanup helper function for transfer callbacks.
    9898 *
    99  * @param   pData               Callback data to cleanup.
     99 * @param   pTransferCtx        Pointer to transfer context that the transfer contains.
     100 * @param   pTransfer           Pointer to transfer to cleanup.
    100101 */
    101 static void vboxClipboardTransferCallbackCleanup(PSHCLTXPROVIDERCTX pCtx)
     102static void vboxClipboardTransferCallbackCleanup(PSHCLTRANSFERCTX pTransferCtx, PSHCLTRANSFER pTransfer)
    102103{
    103104    LogFlowFuncEnter();
    104105
    105     PSHCLTRANSFERCTX pCtx = (PSHCLTRANSFERCTX)pData->pvUser;
    106     AssertPtr(pCtx);
    107 
    108     PSHCLTRANSFER pTransfer = pData->pTransfer;
    109     AssertPtr(pTransfer);
     106    if (!pTransferCtx || !pTransfer)
     107        return;
    110108
    111109    if (pTransfer->pvUser) /* SharedClipboardWinTransferCtx */
     
    115113    }
    116114
    117     int rc2 = ShClTransferCtxTransferUnregister(pCtx, pTransfer->State.uID);
     115    int rc2 = ShClTransferCtxTransferUnregister(pTransferCtx, pTransfer->State.uID);
    118116    AssertRC(rc2);
    119117
     
    124122}
    125123
    126 static DECLCALLBACK(int)  vboxClipboardOnTransferInitCallback(PSHCLTXPROVIDERCTX pCtx)
    127 {
    128     PSHCLCONTEXT pCtx = (PSHCLCONTEXT)pData->pvUser;
     124/** @copydoc SHCLTRANSFERCALLBACKTABLE::pfnOnInitialize */
     125static DECLCALLBACK(int) vboxClipboardOnTransferInitCallback(PSHCLTRANSFERCALLBACKCTX pCbCtx)
     126{
     127    PSHCLCONTEXT pCtx = (PSHCLCONTEXT)pCbCtx->pvUser;
    129128    AssertPtr(pCtx);
    130129
    131130    LogFlowFunc(("pCtx=%p\n", pCtx));
    132131
    133     RT_NOREF(pData, pCtx);
     132    RT_NOREF(pCtx);
    134133
    135134    return VINF_SUCCESS;
    136135}
    137136
    138 static DECLCALLBACK(int) vboxClipboardOnTransferStartCallback(PSHCLTXPROVIDERCTX pCtx)
    139 {
    140     PSHCLCONTEXT pCtx = (PSHCLCONTEXT)pData->pvUser;
     137/** @copydoc SHCLTRANSFERCALLBACKTABLE::pfnOnStart */
     138static DECLCALLBACK(int) vboxClipboardOnTransferStartCallback(PSHCLTRANSFERCALLBACKCTX pCbCtx)
     139{
     140    PSHCLCONTEXT pCtx = (PSHCLCONTEXT)pCbCtx->pvUser;
    141141    AssertPtr(pCtx);
    142     Assert(pData->cbUser == sizeof(SHCLCONTEXT));
    143 
    144     PSHCLTRANSFER pTransfer = pData->pTransfer;
     142
     143    PSHCLTRANSFER pTransfer = pCbCtx->pTransfer;
    145144    AssertPtr(pTransfer);
    146145
     
    192191}
    193192
    194 static DECLCALLBACK(void) vboxClipboardOnTransferCompleteCallback(PSHCLTXPROVIDERCTX pCtx, int rc)
    195 {
    196     PSHCLCONTEXT pCtx = (PSHCLCONTEXT)pData->pvUser;
     193/** @copydoc SHCLTRANSFERCALLBACKTABLE::pfnOnCompleted */
     194static DECLCALLBACK(void) vboxClipboardOnTransferCompletedCallback(PSHCLTRANSFERCALLBACKCTX pCbCtx, int rcCompletion)
     195{
     196    PSHCLCONTEXT pCtx = (PSHCLCONTEXT)pCbCtx->pvUser;
    197197    AssertPtr(pCtx);
    198198
    199     RT_NOREF(pCtx, rc);
    200 
    201     LogFlowFunc(("pCtx=%p, rc=%Rrc\n", pCtx, rc));
    202 
    203     LogRel2(("Shared Clipboard: Transfer to destination complete\n"));
    204 
    205     vboxClipboardTransferCallbackCleanup(pData);
    206 }
    207 
    208 static DECLCALLBACK(void) vboxClipboardOnTransferErrorCallback(PSHCLTXPROVIDERCTX pCtx, int rc)
    209 {
    210     PSHCLCONTEXT pCtx = (PSHCLCONTEXT)pData->pvUser;
     199    LogRel2(("Shared Clipboard: Transfer to destination %s\n",
     200             rcCompletion == VERR_CANCELLED ? "canceled" : "complete"));
     201
     202    vboxClipboardTransferCallbackCleanup(&pCtx->TransferCtx, pCbCtx->pTransfer);
     203}
     204
     205/** @copydoc SHCLTRANSFERCALLBACKTABLE::pfnOnError */
     206static DECLCALLBACK(void) vboxClipboardOnTransferErrorCallback(PSHCLTRANSFERCALLBACKCTX pCbCtx, int rcError)
     207{
     208    PSHCLCONTEXT pCtx = (PSHCLCONTEXT)pCbCtx->pvUser;
    211209    AssertPtr(pCtx);
    212210
    213     RT_NOREF(pCtx, rc);
    214 
    215     LogFlowFunc(("pCtx=%p, rc=%Rrc\n", pCtx, rc));
    216 
    217     LogRel(("Shared Clipboard: Transfer to destination failed with %Rrc\n", rc));
    218 
    219     vboxClipboardTransferCallbackCleanup(pData);
     211    LogRel(("Shared Clipboard: Transfer to destination failed with %Rrc\n", rcError));
     212
     213    vboxClipboardTransferCallbackCleanup(&pCtx->TransferCtx, pCbCtx->pTransfer);
    220214}
    221215
     
    883877
    884878#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
    885     /* Install callbacks. */
     879    /*
     880     * Set callbacks.
     881     * Those will be registered within VbglR3 when a new transfer gets initialized.
     882     */
    886883    RT_ZERO(pCtx->CmdCtx.Transfers.Callbacks);
    887884
     
    889886    pCtx->CmdCtx.Transfers.Callbacks.cbUser = sizeof(SHCLCONTEXT);
    890887
    891     pCtx->CmdCtx.Transfers.Callbacks.pfnTransferInitialize = vboxClipboardOnTransferInitCallback;
    892     pCtx->CmdCtx.Transfers.Callbacks.pfnTransferStart      = vboxClipboardOnTransferStartCallback;
    893     pCtx->CmdCtx.Transfers.Callbacks.pfnTransferComplete   = vboxClipboardOnTransferCompleteCallback;
    894     pCtx->CmdCtx.Transfers.Callbacks.pfnTransferError      = vboxClipboardOnTransferErrorCallback;
     888    pCtx->CmdCtx.Transfers.Callbacks.pfnOnInitialize = vboxClipboardOnTransferInitCallback;
     889    pCtx->CmdCtx.Transfers.Callbacks.pfnOnStart      = vboxClipboardOnTransferStartCallback;
     890    pCtx->CmdCtx.Transfers.Callbacks.pfnOnCompleted  = vboxClipboardOnTransferCompletedCallback;
     891    pCtx->CmdCtx.Transfers.Callbacks.pfnOnError      = vboxClipboardOnTransferErrorCallback;
    895892#endif
    896893
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibClipboard.cpp

    r87452 r87611  
    18031803    if (RT_SUCCESS(rc))
    18041804    {
     1805        ShClTransferSetCallbacks(pTransfer, &pCmdCtx->Transfers.Callbacks);
     1806
    18051807        rc = ShClTransferInit(pTransfer, enmDir, enmSource);
    18061808        if (RT_SUCCESS(rc))
  • trunk/src/VBox/GuestHost/SharedClipboard/ClipboardDataObjectImpl-win.cpp

    r87452 r87611  
    353353
    354354    PSHCLROOTLIST pRootList;
    355     rc = ShClTransferRootsGet(pTransfer, &pRootList);
     355    int rc = ShClTransferRootsGet(pTransfer, &pRootList);
    356356    if (RT_SUCCESS(rc))
    357357    {
     
    967967    logFormat(pFormatEtc->cfFormat);
    968968}
    969 
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-transfers.cpp

    r87452 r87611  
    12671267        pTransfer->uObjHandleNext  = 1;
    12681268
    1269         if (pTransfer->ProviderIface.pfnInitialize)
    1270             rc = pTransfer->ProviderIface.pfnInitialize(&pTransfer->ProviderCtx);
     1269        if (pTransfer->Callbacks.pfnOnInitialize)
     1270            rc = pTransfer->Callbacks.pfnOnInitialize(&pTransfer->CallbackCtx);
    12711271    }
    12721272
     
    20162016
    20172017/**
     2018 * Sets or unsets the callback table to be used for a Shared Clipboard transfer.
     2019 *
     2020 * @returns VBox status code.
     2021 * @param   pTransfer           Clipboard transfer to set callbacks for.
     2022 * @param   pCallbacks          Pointer to callback table to set.
     2023 */
     2024void ShClTransferSetCallbacks(PSHCLTRANSFER pTransfer,
     2025                              PSHCLTRANSFERCALLBACKTABLE pCallbacks)
     2026{
     2027    AssertPtrReturnVoid(pTransfer);
     2028    AssertPtrReturnVoid(pCallbacks);
     2029
     2030    LogFlowFunc(("pCallbacks=%p\n", pCallbacks));
     2031
     2032#define SET_CALLBACK(a_pfnCallback)             \
     2033    if (pCallbacks->a_pfnCallback)              \
     2034        pTransfer->Callbacks.a_pfnCallback = pCallbacks->a_pfnCallback
     2035
     2036    SET_CALLBACK(pfnOnInitialize);
     2037    SET_CALLBACK(pfnOnStart);
     2038    SET_CALLBACK(pfnOnCompleted);
     2039    SET_CALLBACK(pfnOnError);
     2040    SET_CALLBACK(pfnOnRegistered);
     2041    SET_CALLBACK(pfnOnUnregistered);
     2042
     2043#undef SET_CALLBACK
     2044
     2045    pTransfer->Callbacks.pvUser = pCallbacks->pvUser;
     2046    pTransfer->Callbacks.cbUser = pCallbacks->cbUser;
     2047}
     2048
     2049/**
    20182050 * Sets the transfer provider interface for a given transfer.
    20192051 *
     
    24842516    int rc;
    24852517
    2486     if (pTransfer->ProviderIface.pfnStart)
    2487     {
    2488         rc = pTransfer->ProviderIface.pfnStart(&pTransfer->ProviderCtx);
     2518    if (pTransfer->Callbacks.pfnOnStart)
     2519    {
     2520        rc = pTransfer->Callbacks.pfnOnStart(&pTransfer->CallbackCtx);
    24892521    }
    24902522    else
     
    27882820    pTransferCtx->cTransfers++;
    27892821
    2790     if (pTransfer->ProviderIface.pfnRegistered)
    2791         pTransfer->ProviderIface.pfnRegistered(&pTransfer->ProviderCtx, pTransferCtx);
     2822    if (pTransfer->Callbacks.pfnOnRegistered)
     2823        pTransfer->Callbacks.pfnOnRegistered(&pTransfer->CallbackCtx, pTransferCtx);
    27922824
    27932825    if (pidTransfer)
     
    28202852            pTransfer->State.uID = idTransfer;
    28212853
    2822             if (pTransfer->ProviderIface.pfnRegistered)
    2823                 pTransfer->ProviderIface.pfnRegistered(&pTransfer->ProviderCtx, pTransferCtx);
     2854            if (pTransfer->Callbacks.pfnOnRegistered)
     2855                pTransfer->Callbacks.pfnOnRegistered(&pTransfer->CallbackCtx, pTransferCtx);
    28242856
    28252857            pTransferCtx->cTransfers++;
     
    28492881    Assert(pTransferCtx->cTransfers >= pTransferCtx->cRunning);
    28502882
    2851     if (pTransfer->ProviderIface.pfnUnregistered)
    2852         pTransfer->ProviderIface.pfnUnregistered(&pTransfer->ProviderCtx, pTransferCtx);
     2883    if (pTransfer->Callbacks.pfnOnUnregistered)
     2884        pTransfer->Callbacks.pfnOnUnregistered(&pTransfer->CallbackCtx, pTransferCtx);
    28532885
    28542886    LogFlowFunc(("Now %RU32 transfers left\n", pTransferCtx->cTransfers));
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