Changeset 18708 in vbox
- Timestamp:
- Apr 3, 2009 5:55:59 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 45652
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/GuestHost/SharedClipboard.h
r18633 r18708 40 40 41 41 /** Does X11 or VBox currently own the clipboard? */ 42 /** @todo This is ugly, get rid of it. */ 42 43 enum g_eOwner { NONE = 0, X11, VB }; 43 44 … … 62 63 63 64 /* APIs exported by the X11 backend */ 64 extern int VBoxX11ClipboardInitX11(VBOXCLIPBOARDCONTEXT *pFrontend,65 VBOXCLIPBOARDCONTEXTX11 **ppBackend);66 extern int VBoxX11ClipboardTermX11(VBOXCLIPBOARDCONTEXTX11 *pBackend);65 extern VBOXCLIPBOARDCONTEXTX11 *VBoxX11ClipboardConstructX11 66 (VBOXCLIPBOARDCONTEXT *pFrontend); 67 extern void VBoxX11ClipboardDestructX11(VBOXCLIPBOARDCONTEXTX11 *pBackend); 67 68 extern int VBoxX11ClipboardStartX11(VBOXCLIPBOARDCONTEXTX11 *pBackend, 68 enum g_eOwner owner); 69 bool fOwnsClipboard); 70 extern int VBoxX11ClipboardStopX11(VBOXCLIPBOARDCONTEXTX11 *pBackend); 69 71 extern void VBoxX11ClipboardRequestSyncX11(VBOXCLIPBOARDCONTEXTX11 *pBackend); 70 extern void VBoxX11ClipboardStopX11(VBOXCLIPBOARDCONTEXTX11 *pBackend);71 72 extern void VBoxX11ClipboardAnnounceVBoxFormat(VBOXCLIPBOARDCONTEXTX11 72 73 *pBackend, uint32_t u32Formats); -
trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp
r18633 r18708 694 694 695 695 /** 696 * Initialisethe X11 backend of the shared clipboard.696 * Construct the X11 backend of the shared clipboard. 697 697 * @note X11 backend code 698 698 */ 699 int VBoxX11ClipboardInitX11(VBOXCLIPBOARDCONTEXT *pFrontend, 700 VBOXCLIPBOARDCONTEXTX11 **ppBackend)699 VBOXCLIPBOARDCONTEXTX11 *VBoxX11ClipboardConstructX11 700 (VBOXCLIPBOARDCONTEXT *pFrontend) 701 701 { 702 702 int rc; … … 704 704 VBOXCLIPBOARDCONTEXTX11 *pCtx = &g_ctxX11; 705 705 /** @todo we still only support one backend at a time, because the X 706 * toolkit intrinsics don't support user data in XtOwnSelection. Not707 * 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); 709 709 g_pCtx = &g_ctxX11; 710 710 if (!RTEnvGet("DISPLAY")) 711 711 { 712 712 /* 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. 716 717 */ 717 718 LogRelFunc(("X11 DISPLAY variable not set -- disabling shared clipboard\n")); 718 719 g_fHaveX11 = false; 719 return VINF_SUCCESS;720 return pCtx; 720 721 } 721 722 … … 746 747 pCtx->pFrontend = pFrontend; 747 748 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. 764 754 * @note X11 backend code 765 755 */ 766 int VBoxX11ClipboardTermX11(VBOXCLIPBOARDCONTEXTX11 *pCtx) 767 { 768 int rc, rcThread; 769 unsigned count = 0; 770 XEvent ev; 771 756 void 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 */ 771 int VBoxX11ClipboardStartX11(VBOXCLIPBOARDCONTEXTX11 *pCtx, 772 bool fOwnsClipboard) 773 { 774 int rc = VINF_SUCCESS; 775 LogFlowFunc(("\n")); 772 776 /* 773 777 * Immediately return if we are not connected to the host X server. … … 776 780 return VINF_SUCCESS; 777 781 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 */ 812 void 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 */ 826 int 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")); 779 841 780 842 /* Set the termination flag. This has been observed to block if it was set … … 795 857 } while ((VERR_TIMEOUT == rc) && (count < 300)); 796 858 if (RT_SUCCESS(rc)) 797 {798 /* We can safely destroy this now, as only this thread ever waits799 * for it. */800 RTSemEventDestroy(pCtx->waitForData);801 859 AssertRC(rcThread); 802 }803 860 else 804 LogRel (("vboxClipboardDestroy:rc=%Rrc\n", rc));861 LogRelFunc(("rc=%Rrc\n", rc)); 805 862 XtCloseDisplay(XtDisplay(pCtx->widget)); 806 863 LogFlowFunc(("returning %Rrc.\n", rc)); 807 864 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 owner813 */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 else828 {829 /** @todo Check whether the guest gets a format announcement at830 * 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 code839 */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 code853 */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;865 865 } 866 866 -
trunk/src/VBox/HostServices/SharedClipboard/x11-clipboard.cpp
r18633 r18708 164 164 RTSemEventCreate(&g_ctxHost.waitForData); 165 165 RTSemMutexCreate(&g_ctxHost.clipboardMutex); 166 rc = VBoxX11ClipboardInitX11(&g_ctxHost, &pBackend);167 if ( RT_FAILURE(rc))166 pBackend = VBoxX11ClipboardConstructX11(&g_ctxHost); 167 if (pBackend == NULL) 168 168 { 169 169 RTSemEventDestroy(g_ctxHost.waitForData); 170 170 RTSemMutexDestroy(g_ctxHost.clipboardMutex); 171 LogRel(("Failed to start the host shared clipboard service.\n")); 171 LogRel(("Failed to start the host shared clipboard service, out of memory.\n")); 172 rc = VERR_NO_MEMORY; 172 173 } 173 174 else … … 198 199 * even if we are not waiting. */ 199 200 RTSemEventSignal(g_ctxHost.waitForData); 200 rc = VBoxX11ClipboardTermX11(g_ctxHost.pBackend); 201 if (RT_SUCCESS(rc)) 202 { 203 /* We can safely destroy these as the backend has exited 204 * successfully and no other calls from the host code should be 205 * forthcoming. */ 206 /** @todo can the backend fail to exit successfully? What then? */ 207 RTSemEventDestroy(g_ctxHost.waitForData); 208 RTSemMutexDestroy(g_ctxHost.clipboardMutex); 209 } 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); 210 207 } 211 208 … … 227 224 * client at a time. */ 228 225 rc = VBoxX11ClipboardStartX11(g_ctxHost.pBackend, 229 X11 /* initial owner*/);226 true /* fOwnClipboard */); 230 227 return rc; 231 228 } … … 263 260 RTSemMutexRequest(g_ctxHost.clipboardMutex, RT_INDEFINITE_WAIT); 264 261 g_ctxHost.pClient = NULL; 265 VBoxX11ClipboardStopX11(g_ctxHost.pBackend); 262 /** @todo handle this slightly more reasonably, or be really sure 263 * it won't go wrong. */ 264 AssertRC(VBoxX11ClipboardStopX11(g_ctxHost.pBackend)); 266 265 RTSemMutexRelease(g_ctxHost.clipboardMutex); 267 266 }
Note:
See TracChangeset
for help on using the changeset viewer.