VirtualBox

Changeset 18756 in vbox


Ignore:
Timestamp:
Apr 6, 2009 1:53:45 PM (16 years ago)
Author:
vboxsync
Message:

HostServices/SharedClipboard: a couple of fixes and some assertions

Location:
trunk/src/VBox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp

    r18708 r18756  
    762762        return;
    763763
     764    /* We set this to NULL when the event thread exits.  It really should
     765     * have exited at this point, when we are about to unload the code from
     766     * memory. */
     767    Assert(pCtx->widget == NULL);
    764768    RTSemEventDestroy(pCtx->waitForData);
    765769}
     
    823827 * Shut down the shared clipboard X11 backend.
    824828 * @note  X11 backend code
     829 * @note  Any requests from this object to get clipboard data from VBox
     830 *        *must* have completed or aborted before we are called, as
     831 *        otherwise the X11 event loop will still be waiting for the request
     832 *        to return and will not be able to terminate.
    825833 */
    826834int VBoxX11ClipboardStopX11(VBOXCLIPBOARDCONTEXTX11 *pCtx)
     
    835843        return VINF_SUCCESS;
    836844
     845    /* This might mean that we are getting stopped twice. */
     846    AssertReturn(pCtx->widget != NULL, VERR_WRONG_ORDER);
    837847    pCtx->eOwner = NONE;
    838848    pCtx->X11TextFormat = INVALID;
     
    840850    LogRelFunc(("stopping the shared clipboard X11 backend\n"));
    841851
    842     /* Set the termination flag.  This has been observed to block if it was set
    843      * during a request for clipboard data coming from X11, so only we do it
    844      * after releasing any such requests. */
     852    /* Set the termination flag to tell the Xt event loop to exit.  We
     853     * reiterate that any outstanding requests from the X11 event loop to
     854     * the VBox part *must* have returned before we do this. */
    845855    XtAppSetExitFlag(pCtx->appContext);
    846856    /* Wake up the event loop */
     
    861871        LogRelFunc(("rc=%Rrc\n", rc));
    862872    XtCloseDisplay(XtDisplay(pCtx->widget));
     873    pCtx->widget = NULL;  /* For sanity assertions. */
    863874    LogFlowFunc(("returning %Rrc.\n", rc));
    864875    return rc;
  • trunk/src/VBox/HostServices/SharedClipboard/x11-clipboard.cpp

    r18708 r18756  
    185185    int rc = VINF_SUCCESS;
    186186    LogRelFunc(("shutting down host clipboard\n"));
     187    VBoxX11ClipboardDestructX11(g_ctxHost.pBackend);
     188    /* We can safely destroy these as the backend has exited
     189     * successfully and no other calls from the host code should be
     190     * forthcoming. */
     191    RTSemEventDestroy(g_ctxHost.waitForData);
     192    RTSemMutexDestroy(g_ctxHost.clipboardMutex);
     193}
     194
     195/**
     196 * Connect a guest to the shared clipboard.
     197 * @note  host glue code
     198 * @note  on the host, we assume that some other application already owns
     199 *        the clipboard and leave ownership to X11.
     200 */
     201int vboxClipboardConnect (VBOXCLIPBOARDCLIENTDATA *pClient)
     202{
     203    int rc = VINF_SUCCESS;
     204    LogFlowFunc(("\n"));
     205    /* Only one client is supported for now */
     206    AssertLogRelReturn(g_ctxHost.pClient == 0, VERR_NOT_SUPPORTED);
     207    pClient->pCtx = &g_ctxHost;
     208    pClient->pCtx->pClient = pClient;
     209    /** The pClient pointer is a dummy anyway, as we only support a single
     210     * client at a time. */
     211    rc = VBoxX11ClipboardStartX11(g_ctxHost.pBackend,
     212                                  true /* fOwnClipboard */);
     213    return rc;
     214}
     215
     216/**
     217 * Synchronise the contents of the host clipboard with the guest, called
     218 * after a save and restore of the guest.
     219 * @note  Host glue code
     220 */
     221int vboxClipboardSync (VBOXCLIPBOARDCLIENTDATA *pClient)
     222{
     223
     224    /* On a Linux host, the guest should never synchronise/cache its
     225     * clipboard contents, as we have no way of reliably telling when the
     226     * host clipboard data changes.  So instead of synchronising, we tell
     227     * the guest to empty its clipboard, and we set the cached flag so that
     228     * we report formats to the guest next time we poll for them. */
     229    /** @note  This has been changed so that the message is sent even if
     230     *         X11 is not available. */
     231    vboxSvcClipboardReportMsg (g_ctxHost.pClient,
     232                               VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS, 0);
     233    VBoxX11ClipboardRequestSyncX11(g_ctxHost.pBackend);
     234
     235    return VINF_SUCCESS;
     236}
     237
     238/**
     239 * Shut down the shared clipboard service and "disconnect" the guest.
     240 * @note  Host glue code
     241 */
     242void vboxClipboardDisconnect (VBOXCLIPBOARDCLIENTDATA *)
     243{
     244    LogFlow(("vboxClipboardDisconnect\n"));
     245
     246    RTSemMutexRequest(g_ctxHost.clipboardMutex, RT_INDEFINITE_WAIT);
    187247    /* Drop the reference to the client, in case it is still there.  This
    188248     * will cause any outstanding clipboard data requests from X11 to fail
     
    199259     *         even if we are not waiting. */
    200260    RTSemEventSignal(g_ctxHost.waitForData);
    201     VBoxX11ClipboardDestructX11(g_ctxHost.pBackend);
    202     /* We can safely destroy these as the backend has exited
    203      * successfully and no other calls from the host code should be
    204      * forthcoming. */
    205     RTSemEventDestroy(g_ctxHost.waitForData);
    206     RTSemMutexDestroy(g_ctxHost.clipboardMutex);
    207 }
    208 
    209 /**
    210  * Connect a guest to the shared clipboard.
    211  * @note  host glue code
    212  * @note  on the host, we assume that some other application already owns
    213  *        the clipboard and leave ownership to X11.
    214  */
    215 int vboxClipboardConnect (VBOXCLIPBOARDCLIENTDATA *pClient)
    216 {
    217     int rc = VINF_SUCCESS;
    218     LogFlowFunc(("\n"));
    219     /* Only one client is supported for now */
    220     AssertLogRelReturn(g_ctxHost.pClient == 0, VERR_NOT_SUPPORTED);
    221     pClient->pCtx = &g_ctxHost;
    222     pClient->pCtx->pClient = pClient;
    223     /** The pClient pointer is a dummy anyway, as we only support a single
    224      * client at a time. */
    225     rc = VBoxX11ClipboardStartX11(g_ctxHost.pBackend,
    226                                   true /* fOwnClipboard */);
    227     return rc;
    228 }
    229 
    230 /**
    231  * Synchronise the contents of the host clipboard with the guest, called
    232  * after a save and restore of the guest.
    233  * @note  Host glue code
    234  */
    235 int vboxClipboardSync (VBOXCLIPBOARDCLIENTDATA *pClient)
    236 {
    237 
    238     /* On a Linux host, the guest should never synchronise/cache its
    239      * clipboard contents, as we have no way of reliably telling when the
    240      * host clipboard data changes.  So instead of synchronising, we tell
    241      * the guest to empty its clipboard, and we set the cached flag so that
    242      * we report formats to the guest next time we poll for them. */
    243     /** @note  This has been changed so that the message is sent even if
    244      *         X11 is not available. */
    245     vboxSvcClipboardReportMsg (g_ctxHost.pClient,
    246                                VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS, 0);
    247     VBoxX11ClipboardRequestSyncX11(g_ctxHost.pBackend);
    248 
    249     return VINF_SUCCESS;
    250 }
    251 
    252 /**
    253  * Shut down the shared clipboard service and "disconnect" the guest.
    254  * @note  Host glue code
    255  */
    256 void vboxClipboardDisconnect (VBOXCLIPBOARDCLIENTDATA *)
    257 {
    258     LogFlow(("vboxClipboardDisconnect\n"));
    259 
    260     RTSemMutexRequest(g_ctxHost.clipboardMutex, RT_INDEFINITE_WAIT);
    261     g_ctxHost.pClient = NULL;
     261    int rc = VBoxX11ClipboardStopX11(g_ctxHost.pBackend);
    262262    /** @todo handle this slightly more reasonably, or be really sure
    263263     *        it won't go wrong. */
    264     AssertRC(VBoxX11ClipboardStopX11(g_ctxHost.pBackend));
     264    AssertRC(rc);
    265265    RTSemMutexRelease(g_ctxHost.clipboardMutex);
    266266}
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