VirtualBox

Ignore:
Timestamp:
Apr 3, 2009 5:55:59 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
45652
Message:

GuestHost/SharedClipboard: reorganise constructor and destructor funcions

File:
1 edited

Legend:

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

    r18633 r18708  
    694694
    695695/**
    696  * Initialise the X11 backend of the shared clipboard.
     696 * Construct the X11 backend of the shared clipboard.
    697697 * @note  X11 backend code
    698698 */
    699 int VBoxX11ClipboardInitX11(VBOXCLIPBOARDCONTEXT *pFrontend,
    700                             VBOXCLIPBOARDCONTEXTX11 **ppBackend)
     699VBOXCLIPBOARDCONTEXTX11 *VBoxX11ClipboardConstructX11
     700                                 (VBOXCLIPBOARDCONTEXT *pFrontend)
    701701{
    702702    int rc;
     
    704704    VBOXCLIPBOARDCONTEXTX11 *pCtx = &g_ctxX11;
    705705    /** @todo we still only support one backend at a time, because the X
    706      * toolkit intrinsics don't support user data in XtOwnSelection.  Not
    707      * a big problem, but not clean either. */
    708     AssertReturn(g_pCtx == NULL, VERR_NOT_SUPPORTED);
     706     * toolkit intrinsics don't support user data in XtOwnSelection.
     707     * This function should not fail like this. */
     708    AssertReturn(g_pCtx == NULL, NULL);
    709709    g_pCtx = &g_ctxX11;
    710710    if (!RTEnvGet("DISPLAY"))
    711711    {
    712712        /*
    713          * If we don't find the DISPLAY environment variable we assume that we are not
    714          * connected to an X11 server. Don't actually try to do this then, just fail
    715          * silently and report success on every call. This is important for VBoxHeadless.
     713         * If we don't find the DISPLAY environment variable we assume that
     714         * we are not connected to an X11 server. Don't actually try to do
     715         * this then, just fail silently and report success on every call.
     716         * This is important for VBoxHeadless.
    716717         */
    717718        LogRelFunc(("X11 DISPLAY variable not set -- disabling shared clipboard\n"));
    718719        g_fHaveX11 = false;
    719         return VINF_SUCCESS;
     720        return pCtx;
    720721    }
    721722
     
    746747    pCtx->pFrontend = pFrontend;
    747748    RTSemEventCreate(&pCtx->waitForData);
    748     rc = vboxClipboardInitX11(pCtx);
    749     if (RT_SUCCESS(rc))
    750     {
    751         rc = RTThreadCreate(&pCtx->thread, vboxClipboardThread, pCtx, 0,
    752                             RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "SHCLIP");
    753         if (RT_FAILURE(rc))
    754             LogRel(("Failed to initialise the shared clipboard X11 backend.\n"));
    755     }
    756     if (RT_FAILURE(rc))
    757         RTSemEventDestroy(pCtx->waitForData);
    758     *ppBackend = pCtx;
    759     return rc;
    760 }
    761 
    762 /**
    763  * Terminate the shared clipboard X11 backend.
     749    return pCtx;
     750}
     751
     752/**
     753 * Destruct the shared clipboard X11 backend.
    764754 * @note  X11 backend code
    765755 */
    766 int VBoxX11ClipboardTermX11(VBOXCLIPBOARDCONTEXTX11 *pCtx)
    767 {
    768     int rc, rcThread;
    769     unsigned count = 0;
    770     XEvent ev;
    771 
     756void VBoxX11ClipboardDestructX11(VBOXCLIPBOARDCONTEXTX11 *pCtx)
     757{
     758    /*
     759     * Immediately return if we are not connected to the host X server.
     760     */
     761    if (!g_fHaveX11)
     762        return;
     763
     764    RTSemEventDestroy(pCtx->waitForData);
     765}
     766
     767/**
     768 * Announce to the X11 backend that we are ready to start.
     769 * @param  owner who is the initial clipboard owner
     770 */
     771int VBoxX11ClipboardStartX11(VBOXCLIPBOARDCONTEXTX11 *pCtx,
     772                             bool fOwnsClipboard)
     773{
     774    int rc = VINF_SUCCESS;
     775    LogFlowFunc(("\n"));
    772776    /*
    773777     * Immediately return if we are not connected to the host X server.
     
    776780        return VINF_SUCCESS;
    777781
    778     LogRelFunc(("shutting down the shared clipboard X11 backend\n"));
     782    rc = vboxClipboardInitX11(pCtx);
     783    if (RT_SUCCESS(rc))
     784    {
     785        rc = RTThreadCreate(&pCtx->thread, vboxClipboardThread, pCtx, 0,
     786                            RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "SHCLIP");
     787        if (RT_FAILURE(rc))
     788            LogRel(("Failed to initialise the shared clipboard X11 backend.\n"));
     789    }
     790    if (RT_SUCCESS(rc))
     791    {
     792        if (fOwnsClipboard)
     793        {
     794            pCtx->eOwner = X11;
     795            pCtx->notifyVBox = true;
     796        }
     797        else
     798        {
     799            /** @todo Check whether the guest gets a format announcement at
     800              *       startup. */
     801            pCtx->eOwner = VB;
     802            VBoxX11ClipboardAnnounceVBoxFormat(pCtx, 0);
     803        }
     804    }
     805    return rc;
     806}
     807
     808/**
     809 * Called when the VBox may have fallen out of sync with the backend.
     810 * @note  X11 backend code
     811 */
     812void VBoxX11ClipboardRequestSyncX11(VBOXCLIPBOARDCONTEXTX11 *pCtx)
     813{
     814    /*
     815     * Immediately return if we are not connected to the host X server.
     816     */
     817    if (!g_fHaveX11)
     818        return;
     819    pCtx->notifyVBox = true;
     820}
     821
     822/**
     823 * Shut down the shared clipboard X11 backend.
     824 * @note  X11 backend code
     825 */
     826int VBoxX11ClipboardStopX11(VBOXCLIPBOARDCONTEXTX11 *pCtx)
     827{
     828    int rc, rcThread;
     829    unsigned count = 0;
     830    XEvent ev;
     831    /*
     832     * Immediately return if we are not connected to the host X server.
     833     */
     834    if (!g_fHaveX11)
     835        return VINF_SUCCESS;
     836
     837    pCtx->eOwner = NONE;
     838    pCtx->X11TextFormat = INVALID;
     839    pCtx->X11BitmapFormat = INVALID;
     840    LogRelFunc(("stopping the shared clipboard X11 backend\n"));
    779841
    780842    /* Set the termination flag.  This has been observed to block if it was set
     
    795857    } while ((VERR_TIMEOUT == rc) && (count < 300));
    796858    if (RT_SUCCESS(rc))
    797     {
    798         /* We can safely destroy this now, as only this thread ever waits
    799          * for it. */
    800         RTSemEventDestroy(pCtx->waitForData);
    801859        AssertRC(rcThread);
    802     }
    803860    else
    804         LogRel(("vboxClipboardDestroy: rc=%Rrc\n", rc));
     861        LogRelFunc(("rc=%Rrc\n", rc));
    805862    XtCloseDisplay(XtDisplay(pCtx->widget));
    806863    LogFlowFunc(("returning %Rrc.\n", rc));
    807864    return rc;
    808 }
    809 
    810 /**
    811  * Announce to the X11 backend that we are ready to start.
    812  * @param  owner who is the initial clipboard owner
    813  */
    814 int VBoxX11ClipboardStartX11(VBOXCLIPBOARDCONTEXTX11 *pCtx,
    815                              enum g_eOwner owner)
    816 {
    817     LogFlowFunc(("\n"));
    818     /*
    819      * Immediately return if we are not connected to the host X server.
    820      */
    821     if (!g_fHaveX11)
    822         return VINF_SUCCESS;
    823 
    824     pCtx->eOwner = owner;
    825     if (owner == X11)
    826         pCtx->notifyVBox = true;
    827     else
    828     {
    829         /** @todo Check whether the guest gets a format announcement at
    830           *       startup. */
    831         VBoxX11ClipboardAnnounceVBoxFormat(pCtx, 0);
    832     }
    833     return VINF_SUCCESS;
    834 }
    835 
    836 /**
    837  * Called when the VBox may have fallen out of sync with the backend.
    838  * @note  X11 backend code
    839  */
    840 void VBoxX11ClipboardRequestSyncX11(VBOXCLIPBOARDCONTEXTX11 *pCtx)
    841 {
    842     /*
    843      * Immediately return if we are not connected to the host X server.
    844      */
    845     if (!g_fHaveX11)
    846         return;
    847     pCtx->notifyVBox = true;
    848 }
    849 
    850 /**
    851  * Shut down the shared clipboard X11 backend.
    852  * @note  X11 backend code
    853  */
    854 void VBoxX11ClipboardStopX11(VBOXCLIPBOARDCONTEXTX11 *pCtx)
    855 {
    856     /*
    857      * Immediately return if we are not connected to the host X server.
    858      */
    859     if (!g_fHaveX11)
    860         return;
    861 
    862     pCtx->eOwner = NONE;
    863     pCtx->X11TextFormat = INVALID;
    864     pCtx->X11BitmapFormat = INVALID;
    865865}
    866866
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette