VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/VBoxClient/clipboard.cpp

Last change on this file was 100287, checked in by vboxsync, 10 months ago

Shared Clipboard/X11: Also call VBClX11ClipboardDestroy() in vbclShClTerm(). bugref:9437

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 4.4 KB
Line 
1/** $Id: clipboard.cpp 100287 2023-06-26 07:53:49Z vboxsync $ */
2/** @file
3 * Guest Additions - Common Shared Clipboard wrapper service.
4 */
5
6/*
7 * Copyright (C) 2007-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#include <iprt/alloc.h>
33#include <iprt/asm.h>
34#include <iprt/assert.h>
35#include <iprt/initterm.h>
36#include <iprt/mem.h>
37#include <iprt/string.h>
38#include <iprt/path.h>
39#include <iprt/process.h>
40#include <iprt/semaphore.h>
41
42#include <VBox/log.h>
43#include <VBox/VBoxGuestLib.h>
44#include <VBox/HostServices/VBoxClipboardSvc.h>
45#include <VBox/GuestHost/SharedClipboard.h>
46#include <VBox/GuestHost/SharedClipboard-x11.h>
47
48#include "VBoxClient.h"
49
50#include "clipboard.h"
51#include "clipboard-x11.h"
52
53
54/** Shared Clipboard context.
55 * Only one context is supported at a time for now. */
56SHCLCONTEXT g_Ctx;
57
58
59/**
60 * @interface_method_impl{VBCLSERVICE,pfnInit}
61 */
62static DECLCALLBACK(int) vbclShClInit(void)
63{
64 int rc;
65
66#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
67 rc = ShClTransferCtxInit(&g_Ctx.TransferCtx);
68#else
69 rc = VINF_SUCCESS;
70#endif
71
72 LogFlowFuncLeaveRC(rc);
73 return rc;
74}
75
76/**
77 * @interface_method_impl{VBCLSERVICE,pfnWorker}
78 */
79static DECLCALLBACK(int) vbclShClWorker(bool volatile *pfShutdown)
80{
81 RT_NOREF(pfShutdown);
82
83 int rc = VINF_SUCCESS;
84
85 if ( VBClGetDisplayServerType() == VBGHDISPLAYSERVERTYPE_X11
86 /* If Wayland w/ X fallback support is installed (also called XWayland), prefer using the X clipboard for now. */
87 || VBClGetDisplayServerType() == VBGHDISPLAYSERVERTYPE_XWAYLAND)
88 {
89 rc = VBClX11ClipboardInit();
90 if (RT_SUCCESS(rc))
91 {
92 /* Let the main thread know that it can continue spawning services. */
93 RTThreadUserSignal(RTThreadSelf());
94
95 rc = VBClX11ClipboardMain();
96 }
97 }
98 else if (VBClGetDisplayServerType() == VBGHDISPLAYSERVERTYPE_PURE_WAYLAND)
99 {
100 VBClLogError("Shared Clipboard for Wayland not supported yet!\n");
101 }
102
103 if (RT_FAILURE(rc))
104 VBClLogError("Service terminated abnormally with %Rrc\n", rc);
105
106 if (rc == VERR_HGCM_SERVICE_NOT_FOUND)
107 rc = VINF_SUCCESS; /* Prevent automatic restart by daemon script if host service not available. */
108
109 return rc;
110}
111
112/**
113 * @interface_method_impl{VBCLSERVICE,pfnStop}
114 */
115static DECLCALLBACK(void) vbclShClStop(void)
116{
117 /* Disconnect from the host service.
118 * This will also send a VBOX_SHCL_HOST_MSG_QUIT from the host so that we can break out from our message worker. */
119 VbglR3ClipboardDisconnect(g_Ctx.CmdCtx.idClient);
120 g_Ctx.CmdCtx.idClient = 0;
121}
122
123/**
124 * @interface_method_impl{VBCLSERVICE,pfnTerm}
125 */
126static DECLCALLBACK(int) vbclShClTerm(void)
127{
128#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
129 ShClTransferCtxDestroy(&g_Ctx.TransferCtx);
130#endif
131 VBClX11ClipboardDestroy();
132
133 return VINF_SUCCESS;
134}
135
136VBCLSERVICE g_SvcClipboard =
137{
138 "shcl", /* szName */
139 "Shared Clipboard", /* pszDescription */
140 ".vboxclient-clipboard", /* pszPidFilePathTemplate */
141 NULL, /* pszUsage */
142 NULL, /* pszOptions */
143 NULL, /* pfnOption */
144 vbclShClInit, /* pfnInit */
145 vbclShClWorker, /* pfnWorker */
146 vbclShClStop, /* pfnStop*/
147 vbclShClTerm /* pfnTerm */
148};
149
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use