VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-internal.h@ 82506

Last change on this file since 82506 was 82506, checked in by vboxsync, 5 years ago

SharedClipboardSvc,Vbgl: Reviewed and adjusted the handling of the VBOX_SHCL_GUEST_FN_DATA_WRITE message, paddling back two thirds of the parameter changes from the 6.1 dev cycle and fixing a couple of bugs introduced (buggy code commented out and marked with @todos). Fixing the broadcast approach of VBOX_SHCL_GUEST_FN_FORMATS_REPORT as the host doesn't want to know about clipboard stuff when VRDE clients are using the clipboard. Also documented the message. bugref:9437

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.8 KB
Line 
1/* $Id: VBoxSharedClipboardSvc-internal.h 82506 2019-12-09 03:18:31Z vboxsync $ */
2/** @file
3 * Shared Clipboard Service - Internal header.
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef VBOX_INCLUDED_SRC_SharedClipboard_VBoxSharedClipboardSvc_internal_h
19#define VBOX_INCLUDED_SRC_SharedClipboard_VBoxSharedClipboardSvc_internal_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <algorithm>
25#include <list>
26#include <map>
27
28#include <iprt/cpp/list.h> /* For RTCList. */
29#include <iprt/list.h>
30#include <iprt/semaphore.h>
31
32#include <VBox/hgcmsvc.h>
33#include <VBox/log.h>
34
35#include <VBox/HostServices/Service.h>
36#include <VBox/GuestHost/SharedClipboard.h>
37#include <VBox/GuestHost/SharedClipboard-transfers.h>
38
39using namespace HGCM;
40
41#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
42struct SHCLCLIENTSTATE;
43#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
44
45/**
46 * Structure for keeping a Shared Clipboard HGCM message context.
47 */
48typedef struct _SHCLMSGCTX
49{
50 /** Context ID. */
51 uint64_t uContextID;
52} SHCLMSGCTX, *PSHCLMSGCTX;
53
54/**
55 * Structure for keeping a single HGCM message.
56 */
57typedef struct _SHCLCLIENTMSG
58{
59 /** Stored message type. */
60 uint32_t uMsg;
61 /** Number of stored HGCM parameters. */
62 uint32_t cParms;
63 /** Stored HGCM parameters. */
64 PVBOXHGCMSVCPARM paParms;
65 /** Message context. */
66 SHCLMSGCTX Ctx;
67} SHCLCLIENTMSG, *PSHCLCLIENTMSG;
68
69typedef struct SHCLCLIENTTRANSFERSTATE
70{
71 /** Directory of the transfer to start. */
72 SHCLTRANSFERDIR enmTransferDir;
73} SHCLCLIENTTRANSFERSTATE, *PSHCLCLIENTTRANSFERSTATE;
74
75/**
76 * Structure for holding a single POD (plain old data) transfer.
77 *
78 * This mostly is plain text, but also can be stuff like bitmap (BMP) or other binary data.
79 */
80typedef struct SHCLCLIENTPODSTATE
81{
82 /** POD transfer direction. */
83 SHCLTRANSFERDIR enmDir;
84 /** Format of the data to be read / written. */
85 SHCLFORMAT uFormat;
86 /** How much data (in bytes) to read/write for the current operation. */
87 uint64_t cbToReadWriteTotal;
88 /** How much data (in bytes) already has been read/written for the current operation. */
89 uint64_t cbReadWritten;
90 /** Timestamp (in ms) of Last read/write operation. */
91 uint64_t tsLastReadWrittenMs;
92} SHCLCLIENTPODSTATE, *PSHCLCLIENTPODSTATE;
93
94/** @name SHCLCLIENTSTATE_FLAGS_XXX
95 * @note Part of saved state! */
96/** No Shared Clipboard client flags defined. */
97#define SHCLCLIENTSTATE_FLAGS_NONE 0
98/** Client has a guest read operation active. */
99#define SHCLCLIENTSTATE_FLAGS_READ_ACTIVE RT_BIT(0)
100/** Client has a guest write operation active. */
101#define SHCLCLIENTSTATE_FLAGS_WRITE_ACTIVE RT_BIT(1)
102/** @} */
103
104/**
105 * Structure for keeping generic client state data within the Shared Clipboard host service.
106 * This structure needs to be serializable by SSM (must be a POD type).
107 */
108typedef struct SHCLCLIENTSTATE
109{
110 struct SHCLCLIENTSTATE *pNext;
111 struct SHCLCLIENTSTATE *pPrev;
112
113 SHCLCONTEXT *pCtx;
114
115 /** The client's HGCM ID. Not related to the session ID below! */
116 uint32_t uClientID;
117 /** The client's session ID. */
118 SHCLSESSIONID uSessionID;
119 /** Guest feature flags, VBOX_SHCL_GF_0_XXX. */
120 uint64_t fGuestFeatures0;
121 /** Guest feature flags, VBOX_SHCL_GF_1_XXX. */
122 uint64_t fGuestFeatures1;
123 /** Maximum chunk size to use for data transfers. Set to _64K by default. */
124 uint32_t cbChunkSize;
125 /** Where the transfer sources its data from. */
126 SHCLSOURCE enmSource;
127 /** Client state flags of type SHCLCLIENTSTATE_FLAGS_. */
128 uint32_t fFlags;
129 /** POD (plain old data) state. */
130 SHCLCLIENTPODSTATE POD;
131 /** The client's transfers state. */
132 SHCLCLIENTTRANSFERSTATE Transfers;
133} SHCLCLIENTSTATE, *PSHCLCLIENTSTATE;
134
135typedef struct _SHCLCLIENTCMDCTX
136{
137 uint64_t uContextID;
138} SHCLCLIENTCMDCTX, *PSHCLCLIENTCMDCTX;
139
140typedef struct _SHCLCLIENT
141{
142 /** General client state data. */
143 SHCLCLIENTSTATE State;
144 RTCRITSECT CritSect;
145 /** The client's message queue (FIFO). */
146 RTCList<SHCLCLIENTMSG *> queueMsg;
147 /** The client's own event source.
148 * Needed for events which are not bound to a specific transfer.
149 * @todo r=bird: s/Events/EventSrc/ !! */
150 SHCLEVENTSOURCE Events;
151#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
152 /** Transfer contextdata. */
153 SHCLTRANSFERCTX TransferCtx;
154#endif
155 /** Structure for keeping the client's pending (deferred return) state.
156 * A client is in a deferred state when it asks for the next HGCM message,
157 * but the service can't provide it yet. That way a client will block (on the guest side, does not return)
158 * until the service can complete the call. */
159 struct
160 {
161 /** The client's HGCM call handle. Needed for completing a deferred call. */
162 VBOXHGCMCALLHANDLE hHandle;
163 /** Message type (function number) to use when completing the deferred call.
164 * A non-0 value means the client is in pending mode. */
165 uint32_t uType;
166 /** Parameter count to use when completing the deferred call. */
167 uint32_t cParms;
168 /** Parameters to use when completing the deferred call. */
169 PVBOXHGCMSVCPARM paParms;
170 } Pending;
171} SHCLCLIENT, *PSHCLCLIENT;
172
173/**
174 * Structure for keeping a single event source map entry.
175 * Currently empty.
176 */
177typedef struct _SHCLEVENTSOURCEMAPENTRY
178{
179} SHCLEVENTSOURCEMAPENTRY;
180
181/** Map holding information about connected HGCM clients. Key is the (unique) HGCM client ID.
182 * The value is a weak pointer to PSHCLCLIENT, which is owned by HGCM. */
183typedef std::map<uint32_t, PSHCLCLIENT> ClipboardClientMap;
184
185/** Map holding information about event sources. Key is the (unique) event source ID. */
186typedef std::map<SHCLEVENTSOURCEID, SHCLEVENTSOURCEMAPENTRY> ClipboardEventSourceMap;
187
188/** Simple queue (list) which holds deferred (waiting) clients. */
189typedef std::list<uint32_t> ClipboardClientQueue;
190
191/**
192 * Structure for keeping the Shared Clipboard service extension state.
193 *
194 * A service extension is optional, and can be installed by a host component
195 * to communicate with the Shared Clipboard host service.
196 */
197typedef struct _SHCLEXTSTATE
198{
199 /** Pointer to the actual service extension handle. */
200 PFNHGCMSVCEXT pfnExtension;
201 /** Opaque pointer to extension-provided data. Don't touch. */
202 void *pvExtension;
203 /** The HGCM client ID currently assigned to this service extension.
204 * At the moment only one HGCM client can be assigned per extension. */
205 uint32_t uClientID;
206 /** Whether the host service is reading clipboard data currently. */
207 bool fReadingData;
208 /** Whether the service extension has sent the clipboard formats while
209 * the the host service is reading clipboard data from it. */
210 bool fDelayedAnnouncement;
211 /** The actual clipboard formats announced while the host service
212 * is reading clipboard data from the extension. */
213 uint32_t uDelayedFormats;
214} SHCLEXTSTATE, *PSHCLEXTSTATE;
215
216int shClSvcSetSource(PSHCLCLIENT pClient, SHCLSOURCE enmSource);
217
218void shClSvcMsgQueueReset(PSHCLCLIENT pClient);
219PSHCLCLIENTMSG shClSvcMsgAlloc(uint32_t uMsg, uint32_t cParms);
220void shClSvcMsgFree(PSHCLCLIENTMSG pMsg);
221void shClSvcMsgSetPeekReturn(PSHCLCLIENTMSG pMsg, PVBOXHGCMSVCPARM paDstParms, uint32_t cDstParms);
222int shClSvcMsgAdd(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg, bool fAppend);
223int shClSvcMsgPeek(PSHCLCLIENT pClient, VBOXHGCMCALLHANDLE hCall, uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool fWait);
224int shClSvcMsgGet(PSHCLCLIENT pClient, VBOXHGCMCALLHANDLE hCall, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
225
226int shClSvcClientInit(PSHCLCLIENT pClient, uint32_t uClientID);
227void shClSvcClientDestroy(PSHCLCLIENT pClient);
228void shClSvcClientReset(PSHCLCLIENT pClient);
229
230int shClSvcClientStateInit(PSHCLCLIENTSTATE pClientState, uint32_t uClientID);
231int shClSvcClientStateDestroy(PSHCLCLIENTSTATE pClientState);
232void shclSvcClientStateReset(PSHCLCLIENTSTATE pClientState);
233
234int shClSvcClientWakeup(PSHCLCLIENT pClient);
235
236# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
237int shClSvcTransferModeSet(uint32_t fMode);
238int shClSvcTransferStart(PSHCLCLIENT pClient, SHCLTRANSFERDIR enmDir, SHCLSOURCE enmSource, PSHCLTRANSFER *ppTransfer);
239int shClSvcTransferStop(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
240bool shClSvcTransferMsgIsAllowed(uint32_t uMode, uint32_t uMsg);
241void shClSvcClientTransfersReset(PSHCLCLIENT pClient);
242#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
243
244/** @name Service functions, accessible by the backends.
245 * Locking is between the (host) service thread and the platform-dependent (window) thread.
246 * @{
247 */
248int ShClSvcDataReadRequest(PSHCLCLIENT pClient, PSHCLDATAREQ pDataReq, PSHCLEVENTID puEvent);
249int ShClSvcDataReadSignal(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLDATABLOCK pData);
250int ShClSvcFormatsReport(PSHCLCLIENT pClient, PSHCLFORMATDATA pFormats);
251uint32_t ShClSvcGetMode(void);
252bool ShClSvcGetHeadless(void);
253bool ShClSvcLock(void);
254void ShClSvcUnlock(void);
255/** @} */
256
257
258/** @name Platform-dependent implementations for the Shared Clipboard host service, called *only* by the host service.
259 * @{
260 */
261/**
262 * Called on initialization.
263 */
264int ShClSvcImplInit(void);
265/**
266 * Called on destruction.
267 */
268void ShClSvcImplDestroy(void);
269/**
270 * Called when a new HGCM client connects.
271 *
272 * @returns VBox status code.
273 * @param pClient Shared Clipboard client context.
274 * @param fHeadless Whether this is a headless connection or not.
275 */
276int ShClSvcImplConnect(PSHCLCLIENT pClient, bool fHeadless);
277/**
278 * Called when a HGCM client disconnects.
279 *
280 * @returns VBox status code.
281 * @param pClient Shared Clipboard client context.
282 */
283int ShClSvcImplDisconnect(PSHCLCLIENT pClient);
284/**
285 * Called when the guest reported available clipboard formats to the host OS.
286 *
287 * @returns VBox status code.
288 * @param pClient Shared Clipboard client context.
289 * @param pCmdCtx Shared Clipboard command context.
290 * @param pFormats Announced formats from the guest.
291 */
292int ShClSvcImplFormatAnnounce(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLFORMATDATA pFormats);
293/** @todo Document: Can return VINF_HGCM_ASYNC_EXECUTE to defer returning read data.*/
294/**
295 * Called when the guest wants to read host clipboard data.
296 *
297 * @returns VBox status code.
298 * @param pClient Shared Clipboard client context.
299 * @param pCmdCtx Shared Clipboard command context.
300 * @param pData Where to return the read clipboard data.
301 * @param pcbActual Where to return the amount of bytes read.
302 */
303int ShClSvcImplReadData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLDATABLOCK pData, uint32_t *pcbActual);
304/**
305 * Called when the guest writes clipboard data to the host.
306 *
307 * @returns VBox status code.
308 * @param pClient Shared Clipboard client context.
309 * @param pCmdCtx Shared Clipboard command context.
310 * @param pData Clipboard data from the guest.
311 */
312int ShClSvcImplWriteData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLDATABLOCK pData);
313/**
314 * Called when synchronization of the clipboard contents of the host clipboard with the guest is needed.
315 *
316 * @returns VBox status code.
317 * @param pClient Shared Clipboard client context.
318 */
319int ShClSvcImplSync(PSHCLCLIENT pClient);
320/** @} */
321
322#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
323/** @name Host implementations for Shared Clipboard transfers.
324 * @{
325 */
326/**
327 * Called when a transfer gets created.
328 *
329 * @returns VBox status code.
330 * @param pClient Shared Clipboard client context.
331 * @param pTransfer Shared Clipboard transfer created.
332 */
333int ShClSvcImplTransferCreate(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
334/**
335 * Called when a transfer gets destroyed.
336 *
337 * @returns VBox status code.
338 * @param pClient Shared Clipboard client context.
339 * @param pTransfer Shared Clipboard transfer to destroy.
340 */
341int ShClSvcImplTransferDestroy(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
342/**
343 * Called when getting (determining) the transfer roots on the host side.
344 *
345 * @returns VBox status code.
346 * @param pClient Shared Clipboard client context.
347 * @param pTransfer Shared Clipboard transfer to get roots for.
348 */
349int ShClSvcImplTransferGetRoots(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
350/** @} */
351#endif
352
353#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
354/** @name Internal Shared Clipboard transfer host service functions.
355 * @{
356 */
357int shClSvcTransferAreaDetach(PSHCLCLIENTSTATE pClientState, PSHCLTRANSFER pTransfer);
358int shClSvcTransferHandler(PSHCLCLIENT pClient, VBOXHGCMCALLHANDLE callHandle, uint32_t u32Function,
359 uint32_t cParms, VBOXHGCMSVCPARM paParms[], uint64_t tsArrival);
360int shClSvcTransferHostHandler(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
361/** @} */
362
363/** @name Shared Clipboard transfer interface implementations for the host service.
364 * @{
365 */
366int shClSvcTransferIfaceOpen(PSHCLPROVIDERCTX pCtx);
367int shClSvcTransferIfaceClose(PSHCLPROVIDERCTX pCtx);
368
369int shClSvcTransferIfaceGetRoots(PSHCLPROVIDERCTX pCtx, PSHCLROOTLIST *ppRootList);
370
371int shClSvcTransferIfaceListOpen(PSHCLPROVIDERCTX pCtx, PSHCLLISTOPENPARMS pOpenParms, PSHCLLISTHANDLE phList);
372int shClSvcTransferIfaceListClose(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList);
373int shClSvcTransferIfaceListHdrRead(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
374int shClSvcTransferIfaceListHdrWrite(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
375int shClSvcTransferIfaceListEntryRead(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
376int shClSvcTransferIfaceListEntryWrite(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
377
378int shClSvcTransferIfaceObjOpen(PSHCLPROVIDERCTX pCtx, PSHCLOBJOPENCREATEPARMS pCreateParms,
379 PSHCLOBJHANDLE phObj);
380int shClSvcTransferIfaceObjClose(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj);
381int shClSvcTransferIfaceObjRead(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
382 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbRead);
383int shClSvcTransferIfaceObjWrite(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
384 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbWritten);
385/** @} */
386
387/** @name Shared Clipboard transfer callbacks for the host service.
388 * @{
389 */
390DECLCALLBACK(void) VBoxSvcClipboardTransferPrepareCallback(PSHCLTRANSFERCALLBACKDATA pData);
391DECLCALLBACK(void) VBoxSvcClipboardDataHeaderCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData);
392DECLCALLBACK(void) VBoxSvcClipboardDataCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData);
393DECLCALLBACK(void) VBoxSvcClipboardTransferCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData, int rc);
394DECLCALLBACK(void) VBoxSvcClipboardTransferCanceledCallback(PSHCLTRANSFERCALLBACKDATA pData);
395DECLCALLBACK(void) VBoxSvcClipboardTransferErrorCallback(PSHCLTRANSFERCALLBACKDATA pData, int rc);
396/** @} */
397#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
398
399/* Host unit testing interface */
400#ifdef UNIT_TEST
401uint32_t TestClipSvcGetMode(void);
402#endif
403
404#endif /* !VBOX_INCLUDED_SRC_SharedClipboard_VBoxSharedClipboardSvc_internal_h */
405
Note: See TracBrowser for help on using the repository browser.

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