VirtualBox

Changeset 100655 in vbox


Ignore:
Timestamp:
Jul 19, 2023 4:06:24 PM (17 months ago)
Author:
vboxsync
Message:

Shared Clipboard/VRDE: Integrated the logic of ShClSvcIsBackendActive() in ShClSvcReportFormats(), so that the specific backends don't need to be in charge for that anymore. Renamed VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE -> VBOX_CLIPBOARD_EXT_FN_FORMAT_REPORT_TO_HOST to emphasize its usage. Added VBOX_CLIPBOARD_EXT_FN_FORMAT_REPORT_TO_GUEST; see comment for details.

The whole concept of VRDE being a (one and only) service extension nowadays isn't optimal anymore and needs to be replaced with a more generic mechanism, which is out of this scope for this task. So just adapt this as needed and keep the current way.

bugref:9437

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/HostServices/VBoxClipboardExt.h

    r100647 r100655  
    4747
    4848/** Sets (or unsets) a clipboard extension callback. */
    49 #define VBOX_CLIPBOARD_EXT_FN_SET_CALLBACK         (0)
    50 /** The guest announces clipboard formats to the extension. */
    51 #define VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE      (1)
     49#define VBOX_CLIPBOARD_EXT_FN_SET_CALLBACK               (0)
     50/** The guest reports clipboard formats to the extension. */
     51#define VBOX_CLIPBOARD_EXT_FN_FORMAT_REPORT_TO_HOST      (1)
     52/** The clipboard service wants to report formats to the guest. */
     53#define VBOX_CLIPBOARD_EXT_FN_FORMAT_REPORT_TO_GUEST     (2)
    5254/** The clipboard service requests clipboard data from the extension. */
    53 #define VBOX_CLIPBOARD_EXT_FN_DATA_READ            (2)
     55#define VBOX_CLIPBOARD_EXT_FN_DATA_READ                  (3)
    5456/** The clipboard service writes clipboard data to the extension. */
    55 #define VBOX_CLIPBOARD_EXT_FN_DATA_WRITE           (3)
     57#define VBOX_CLIPBOARD_EXT_FN_DATA_WRITE                 (4)
    5658/** The clipboard service announces an error to the extension. */
    57 #define VBOX_CLIPBOARD_EXT_FN_ERROR                (4)
     59#define VBOX_CLIPBOARD_EXT_FN_ERROR                      (5)
    5860
    5961typedef DECLCALLBACKTYPE(int, FNSHCLEXTCALLBACK,(uint32_t u32Function, uint32_t u32Format, void *pvData, uint32_t cbData));
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-darwin.cpp

    r100646 r100655  
    9494                                       &fFormats, &fChanged);
    9595    if (   RT_SUCCESS(rc)
    96         && fChanged
    97         && ShClSvcIsBackendActive())
     96        && fChanged)
    9897        rc = ShClSvcReportFormats(pCtx->pClient, fFormats);
    9998
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-internal.h

    r100646 r100655  
    319319bool ShClSvcLock(void);
    320320void ShClSvcUnlock(void);
    321 
    322 /**
    323  * Checks if the backend is active (@c true), or if VRDE is in control of
    324  * the host side.
    325  */
    326 DECLINLINE(bool) ShClSvcIsBackendActive(void)
    327 {
    328     return g_ExtState.pfnExtension == NULL;
    329 }
    330321/** @} */
    331322
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-win.cpp

    r100646 r100655  
    789789        SHCLFORMATS fFormats = 0;
    790790        rc = SharedClipboardWinGetFormats(&pCtx->Win, &fFormats);
    791         if (   RT_SUCCESS(rc)
    792             && fFormats != VBOX_SHCL_FMT_NONE /** @todo r=bird: BUGBUG: revisit this. */
    793             && ShClSvcIsBackendActive())
     791        if (RT_SUCCESS(rc))
    794792            rc = ShClSvcReportFormats(pCtx->pClient, fFormats);
    795793    }
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-x11.cpp

    r100646 r100655  
    220220     * there is data in the host clipboard it will automatically be sent to
    221221     * the guest when the clipboard starts up. */
    222     if (ShClSvcIsBackendActive())
    223         return ShClSvcReportFormats(pClient, VBOX_SHCL_FMT_NONE);
    224     return VINF_SUCCESS;
     222    return ShClSvcReportFormats(pClient, VBOX_SHCL_FMT_NONE);
    225223}
    226224
     
    369367    AssertPtr(pClient);
    370368
    371     rc = RTCritSectEnter(&pClient->CritSect);
    372     if (RT_SUCCESS(rc))
    373     {
    374         if (ShClSvcIsBackendActive())
    375         {
    376             /** @todo r=bird: BUGBUG: Revisit this   */
    377             if (fFormats != VBOX_SHCL_FMT_NONE) /* No formats to report? */
    378             {
    379                 rc = ShClSvcReportFormats(pCtx->pClient, fFormats);
    380             }
    381         }
    382 
    383         RTCritSectLeave(&pClient->CritSect);
    384     }
     369    rc = ShClSvcReportFormats(pCtx->pClient, fFormats);
    385370
    386371    LogFlowFuncLeaveRC(rc);
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc.cpp

    r100646 r100655  
    14731473 * Reports clipboard formats to the guest.
    14741474 *
    1475  * @note    Host backend callers must check if it's active (use
    1476  *          ShClSvcIsBackendActive) before calling to prevent mixing up the
    1477  *          VRDE clipboard.
    1478  *
    14791475 * @returns VBox status code.
    14801476 * @param   pClient             Client to report clipboard formats to.
    1481  * @param   fFormats            The formats to report (VBOX_SHCL_FMT_XXX), zero
    1482  *                              is okay (empty the clipboard).
    1483  *
     1477 * @param   fFormats            The formats to report (VBOX_SHCL_FMT_XXX).
     1478 *                              VBOX_SHCL_FMT_NONE will empty (clear) the clipboard.
    14841479 * @thread  Backend thread.
    14851480 */
    14861481int ShClSvcReportFormats(PSHCLCLIENT pClient, SHCLFORMATS fFormats)
    14871482{
    1488     LogFlowFuncEnter();
     1483    AssertPtrReturn(pClient, VERR_INVALID_POINTER);
     1484
     1485    LogFlowFunc(("fFormats=%#x\n", fFormats));
    14891486
    14901487    /*
     
    15011498        return VINF_SUCCESS;
    15021499
    1503     AssertPtrReturn(pClient, VERR_INVALID_POINTER);
    1504 
    1505     LogFlowFunc(("fFormats=%#x\n", fFormats));
    1506 
    15071500#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
    15081501    bool fSkipTransfers = false;
     
    15291522#endif
    15301523
     1524    int rc;
     1525
     1526    /*
     1527     * Check if the HGCM callback can handle this first.
     1528     * This is needed in order to not mess up the clipboard if VRDE is active, for example.
     1529     */
     1530    if (g_ExtState.pfnExtension) /* Extension set? */
     1531    {
     1532        SHCLEXTPARMS parms;
     1533        RT_ZERO(parms);
     1534
     1535        parms.u.ReportFormats.uFormats = fFormats;
     1536
     1537        rc = g_ExtState.pfnExtension(g_ExtState.pvExtension, VBOX_CLIPBOARD_EXT_FN_FORMAT_REPORT_TO_GUEST, &parms, sizeof(parms));
     1538        if (rc == VERR_NOT_SUPPORTED)
     1539        {
     1540            /* Not handled by the extension, continue below. */
     1541        }
     1542        else /* Handled by the extension, bail out. */
     1543            return rc;
     1544    }
     1545
    15311546    /*
    15321547     * Allocate a message, populate parameters and post it to the client.
    15331548     */
    1534     int rc;
    15351549    PSHCLCLIENTMSG pMsg = shClSvcMsgAlloc(pClient, VBOX_SHCL_HOST_MSG_FORMATS_REPORT, 2);
    15361550    if (pMsg)
     
    15391553        HGCMSvcSetU32(&pMsg->aParms[1], fFormats);
    15401554
    1541         RTCritSectEnter(&pClient->CritSect);
     1555        shClSvcClientLock(pClient);
     1556
    15421557        rc = shClSvcMsgAddAndWakeupClient(pClient, pMsg);
    1543         RTCritSectLeave(&pClient->CritSect);
     1558
     1559        shClSvcClientUnlock(pClient);
    15441560    }
    15451561    else
     
    16201636                parms.u.ReportFormats.uFormats = fFormats;
    16211637
    1622                 rc = g_ExtState.pfnExtension(g_ExtState.pvExtension, VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE, &parms, sizeof(parms));
     1638                rc = g_ExtState.pfnExtension(g_ExtState.pvExtension, VBOX_CLIPBOARD_EXT_FN_FORMAT_REPORT_TO_HOST, &parms, sizeof(parms));
    16231639            }
    16241640            else
     
    27302746        switch (u32Function)
    27312747        {
    2732             /* The service extension announces formats to the guest. */
    2733             case VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE:
     2748            /* The service extension announces formats to the host. */
     2749            case VBOX_CLIPBOARD_EXT_FN_FORMAT_REPORT_TO_HOST:
    27342750            {
    2735                 LogFlowFunc(("VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE: g_ExtState.fReadingData=%RTbool\n", g_ExtState.fReadingData));
     2751                LogFlowFunc(("VBOX_CLIPBOARD_EXT_FN_FORMAT_REPORT_TO_HOST: g_ExtState.fReadingData=%RTbool\n", g_ExtState.fReadingData));
    27362752                if (!g_ExtState.fReadingData)
    27372753                    rc = ShClSvcReportFormats(pClient, u32Format);
     
    27752791            }
    27762792
    2777             /** @todo BUGBUG Why no VBOX_CLIPBOARD_EXT_FN_DATA_WRITE here? */
    2778 
    27792793            default:
    27802794                /* Just skip other messages. */
  • trunk/src/VBox/Main/src-client/ConsoleVRDPServer.cpp

    r100612 r100655  
    33073307            if (pServer->mpfnClipboardCallback)
    33083308            {
    3309                 vrc = pServer->mpfnClipboardCallback(VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE,
     3309                vrc = pServer->mpfnClipboardCallback(VBOX_CLIPBOARD_EXT_FN_FORMAT_REPORT_TO_HOST,
    33103310                                                     u32Format,
    33113311                                                     (void *)pvData,
     
    33343334}
    33353335
    3336 /*static*/ DECLCALLBACK(int)
    3337 ConsoleVRDPServer::ClipboardServiceExtension(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms)
     3336/**
     3337 * Service extension callback called by GuestShCl::hgcmDispatcher().
     3338 *
     3339 * @returns VBox status code.
     3340 * @retval  VERR_NOT_SUPPORTED if the extension didn't handle the requested function. This will invoke the regular backend then.
     3341 * @param   pvExtension         Pointer to service extension.
     3342 * @param   u32Function         Callback HGCM message ID.
     3343 * @param   pvParms             Pointer to optional data provided for a particular message. Optional.
     3344 * @param   cbParms             Size (in bytes) of \a pvParms.
     3345 */
     3346/* static */
     3347DECLCALLBACK(int) ConsoleVRDPServer::ClipboardServiceExtension(void *pvExtension,
     3348                                                               uint32_t u32Function, void *pvParms, uint32_t cbParms)
    33383349{
    33393350    RT_NOREF(cbParms);
     
    33443355
    33453356    ConsoleVRDPServer *pServer = static_cast <ConsoleVRDPServer *>(pvExtension);
     3357    AssertPtrReturn(pServer, VERR_INVALID_POINTER);
    33463358
    33473359    SHCLEXTPARMS *pParms = (SHCLEXTPARMS *)pvParms;
     3360    AssertPtrReturn(pParms, VERR_INVALID_POINTER);
    33483361
    33493362    switch (u32Function)
     
    33543367        } break;
    33553368
    3356         case VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE:
    3357         {
    3358             /* The guest announces clipboard formats. This must be delivered to all clients. */
     3369        case VBOX_CLIPBOARD_EXT_FN_FORMAT_REPORT_TO_HOST:
     3370        {
     3371            /* The guest announces clipboard formats to the host. This must be delivered to all clients. */
    33593372            if (mpEntryPoints && pServer->mhServer)
    33603373            {
     
    33663379                                             NULL);
    33673380            }
     3381        } break;
     3382
     3383        case VBOX_CLIPBOARD_EXT_FN_FORMAT_REPORT_TO_GUEST:
     3384        {
     3385            /* We need to handle this case here, to act as a no-op.
     3386             *
     3387             * If not being handled, this function otherwise would return VERR_NOT_SUPPORTED,
     3388             * which in turn then will invoke the host backend, messing up the VRDE clipboard handling. */
    33683389        } break;
    33693390
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