VirtualBox

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

Last change on this file since 87062 was 86908, checked in by vboxsync, 4 years ago

Shared Clipboard/Transfers: Removed clipboard area handling code. bugref:9437

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.1 KB
Line 
1/* $Id: VBoxSharedClipboardSvc-internal.h 86908 2020-11-18 10:56:12Z vboxsync $ */
2/** @file
3 * Shared Clipboard Service - Internal header.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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 * A queued message for the guest.
47 */
48typedef struct _SHCLCLIENTMSG
49{
50 /** The queue list entry. */
51 RTLISTNODE ListEntry;
52 /** Stored message ID (VBOX_SHCL_HOST_MSG_XXX). */
53 uint32_t idMsg;
54 /** Context ID. */
55 uint64_t idCtx;
56 /** Number of stored parameters in aParms. */
57 uint32_t cParms;
58 /** HGCM parameters. */
59 RT_FLEXIBLE_ARRAY_EXTENSION
60 VBOXHGCMSVCPARM aParms[RT_FLEXIBLE_ARRAY];
61} SHCLCLIENTMSG;
62/** Pointer to a queue message for the guest. */
63typedef SHCLCLIENTMSG *PSHCLCLIENTMSG;
64
65typedef struct SHCLCLIENTTRANSFERSTATE
66{
67 /** Directory of the transfer to start. */
68 SHCLTRANSFERDIR enmTransferDir;
69} SHCLCLIENTTRANSFERSTATE, *PSHCLCLIENTTRANSFERSTATE;
70
71/**
72 * Structure for holding a single POD (plain old data) transfer.
73 *
74 * This mostly is plain text, but also can be stuff like bitmap (BMP) or other binary data.
75 */
76typedef struct SHCLCLIENTPODSTATE
77{
78 /** POD transfer direction. */
79 SHCLTRANSFERDIR enmDir;
80 /** Format of the data to be read / written. */
81 SHCLFORMAT uFormat;
82 /** How much data (in bytes) to read/write for the current operation. */
83 uint64_t cbToReadWriteTotal;
84 /** How much data (in bytes) already has been read/written for the current operation. */
85 uint64_t cbReadWritten;
86 /** Timestamp (in ms) of Last read/write operation. */
87 uint64_t tsLastReadWrittenMs;
88} SHCLCLIENTPODSTATE, *PSHCLCLIENTPODSTATE;
89
90/** @name SHCLCLIENTSTATE_FLAGS_XXX
91 * @note Part of saved state!
92 * @{ */
93/** No Shared Clipboard client flags defined. */
94#define SHCLCLIENTSTATE_FLAGS_NONE 0
95/** Client has a guest read operation active. Currently unused. */
96#define SHCLCLIENTSTATE_FLAGS_READ_ACTIVE RT_BIT(0)
97/** Client has a guest write operation active. Currently unused. */
98#define SHCLCLIENTSTATE_FLAGS_WRITE_ACTIVE RT_BIT(1)
99/** @} */
100
101/**
102 * Structure needed to support backwards compatbility for old(er) Guest Additions (< 6.1),
103 * which did not know the context ID concept then.
104 */
105typedef struct SHCLCLIENTLEGACYCID
106{
107 /** List node. */
108 RTLISTNODE Node;
109 /** The actual context ID. */
110 uint64_t uCID;
111 /** Not used yet; useful to have it in the saved state though. */
112 uint32_t enmType;
113 /** @todo Add an union here as soon as we utilize \a enmType. */
114 SHCLFORMAT uFormat;
115} SHCLCLIENTLEGACYCID;
116/** Pointer to a SHCLCLIENTLEGACYCID struct. */
117typedef SHCLCLIENTLEGACYCID *PSHCLCLIENTLEGACYCID;
118
119/**
120 * Structure for keeping legacy state, required for keeping backwards compatibility
121 * to old(er) Guest Additions.
122 */
123typedef struct SHCLCLIENTLEGACYSTATE
124{
125 /** List of context IDs (of type SHCLCLIENTLEGACYCID) for older Guest Additions which (< 6.1)
126 * which did not know the concept of context IDs. */
127 RTLISTANCHOR lstCID;
128 /** Number of context IDs currently in \a lstCID. */
129 uint16_t cCID;
130} SHCLCLIENTLEGACYSTATE;
131
132/**
133 * Structure for keeping generic client state data within the Shared Clipboard host service.
134 * This structure needs to be serializable by SSM (must be a POD type).
135 */
136typedef struct SHCLCLIENTSTATE
137{
138 struct SHCLCLIENTSTATE *pNext;
139 struct SHCLCLIENTSTATE *pPrev;
140
141 SHCLCONTEXT *pCtx;
142
143 /** The client's HGCM ID. Not related to the session ID below! */
144 uint32_t uClientID;
145 /** The client's session ID. */
146 SHCLSESSIONID uSessionID;
147 /** Guest feature flags, VBOX_SHCL_GF_0_XXX. */
148 uint64_t fGuestFeatures0;
149 /** Guest feature flags, VBOX_SHCL_GF_1_XXX. */
150 uint64_t fGuestFeatures1;
151 /** Chunk size to use for data transfers. */
152 uint32_t cbChunkSize;
153 /** Where the transfer sources its data from. */
154 SHCLSOURCE enmSource;
155 /** Client state flags of type SHCLCLIENTSTATE_FLAGS_. */
156 uint32_t fFlags;
157 /** POD (plain old data) state. */
158 SHCLCLIENTPODSTATE POD;
159 /** The client's transfers state. */
160 SHCLCLIENTTRANSFERSTATE Transfers;
161} SHCLCLIENTSTATE, *PSHCLCLIENTSTATE;
162
163typedef struct _SHCLCLIENTCMDCTX
164{
165 uint64_t uContextID;
166} SHCLCLIENTCMDCTX, *PSHCLCLIENTCMDCTX;
167
168typedef struct _SHCLCLIENT
169{
170 /** General client state data. */
171 SHCLCLIENTSTATE State;
172 /** The critical section protecting the queue, event source and whatnot. */
173 RTCRITSECT CritSect;
174 /** The client's message queue (SHCLCLIENTMSG). */
175 RTLISTANCHOR MsgQueue;
176 /** Number of allocated messages (updated atomically, not under critsect). */
177 uint32_t volatile cMsgAllocated;
178 /** Legacy cruft we have to keep to support old(er) Guest Additions. */
179 SHCLCLIENTLEGACYSTATE Legacy;
180 /** The client's own event source.
181 * Needed for events which are not bound to a specific transfer. */
182 SHCLEVENTSOURCE EventSrc;
183#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
184 /** Transfer contextdata. */
185 SHCLTRANSFERCTX TransferCtx;
186#endif
187 /** Structure for keeping the client's pending (deferred return) state.
188 * A client is in a deferred state when it asks for the next HGCM message,
189 * but the service can't provide it yet. That way a client will block (on the guest side, does not return)
190 * until the service can complete the call. */
191 struct
192 {
193 /** The client's HGCM call handle. Needed for completing a deferred call. */
194 VBOXHGCMCALLHANDLE hHandle;
195 /** Message type (function number) to use when completing the deferred call.
196 * A non-0 value means the client is in pending mode. */
197 uint32_t uType;
198 /** Parameter count to use when completing the deferred call. */
199 uint32_t cParms;
200 /** Parameters to use when completing the deferred call. */
201 PVBOXHGCMSVCPARM paParms;
202 } Pending;
203} SHCLCLIENT, *PSHCLCLIENT;
204
205/**
206 * Structure for keeping a single event source map entry.
207 * Currently empty.
208 */
209typedef struct _SHCLEVENTSOURCEMAPENTRY
210{
211} SHCLEVENTSOURCEMAPENTRY;
212
213/** Map holding information about connected HGCM clients. Key is the (unique) HGCM client ID.
214 * The value is a weak pointer to PSHCLCLIENT, which is owned by HGCM. */
215typedef std::map<uint32_t, PSHCLCLIENT> ClipboardClientMap;
216
217/** Map holding information about event sources. Key is the (unique) event source ID. */
218typedef std::map<SHCLEVENTSOURCEID, SHCLEVENTSOURCEMAPENTRY> ClipboardEventSourceMap;
219
220/** Simple queue (list) which holds deferred (waiting) clients. */
221typedef std::list<uint32_t> ClipboardClientQueue;
222
223/**
224 * Structure for keeping the Shared Clipboard service extension state.
225 *
226 * A service extension is optional, and can be installed by a host component
227 * to communicate with the Shared Clipboard host service.
228 */
229typedef struct _SHCLEXTSTATE
230{
231 /** Pointer to the actual service extension handle. */
232 PFNHGCMSVCEXT pfnExtension;
233 /** Opaque pointer to extension-provided data. Don't touch. */
234 void *pvExtension;
235 /** The HGCM client ID currently assigned to this service extension.
236 * At the moment only one HGCM client can be assigned per extension. */
237 uint32_t uClientID;
238 /** Whether the host service is reading clipboard data currently. */
239 bool fReadingData;
240 /** Whether the service extension has sent the clipboard formats while
241 * the the host service is reading clipboard data from it. */
242 bool fDelayedAnnouncement;
243 /** The actual clipboard formats announced while the host service
244 * is reading clipboard data from the extension. */
245 uint32_t fDelayedFormats;
246} SHCLEXTSTATE, *PSHCLEXTSTATE;
247
248int shClSvcSetSource(PSHCLCLIENT pClient, SHCLSOURCE enmSource);
249
250void shClSvcMsgQueueReset(PSHCLCLIENT pClient);
251PSHCLCLIENTMSG shClSvcMsgAlloc(PSHCLCLIENT pClient, uint32_t uMsg, uint32_t cParms);
252void shClSvcMsgFree(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg);
253void shClSvcMsgAdd(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg, bool fAppend);
254int shClSvcMsgAddAndWakeupClient(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg);
255
256int shClSvcClientInit(PSHCLCLIENT pClient, uint32_t uClientID);
257void shClSvcClientDestroy(PSHCLCLIENT pClient);
258void shClSvcClientReset(PSHCLCLIENT pClient);
259
260int shClSvcClientStateInit(PSHCLCLIENTSTATE pClientState, uint32_t uClientID);
261int shClSvcClientStateDestroy(PSHCLCLIENTSTATE pClientState);
262void shclSvcClientStateReset(PSHCLCLIENTSTATE pClientState);
263
264int shClSvcClientWakeup(PSHCLCLIENT pClient);
265
266# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
267int shClSvcTransferModeSet(uint32_t fMode);
268int shClSvcTransferStart(PSHCLCLIENT pClient, SHCLTRANSFERDIR enmDir, SHCLSOURCE enmSource, PSHCLTRANSFER *ppTransfer);
269int shClSvcTransferStop(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
270bool shClSvcTransferMsgIsAllowed(uint32_t uMode, uint32_t uMsg);
271void shClSvcClientTransfersReset(PSHCLCLIENT pClient);
272#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
273
274/** @name Service functions, accessible by the backends.
275 * Locking is between the (host) service thread and the platform-dependent (window) thread.
276 * @{
277 */
278int ShClSvcGuestDataRequest(PSHCLCLIENT pClient, SHCLFORMATS fFormats, PSHCLEVENTID pidEvent);
279int ShClSvcGuestDataSignal(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat, void *pvData, uint32_t cbData);
280int ShClSvcHostReportFormats(PSHCLCLIENT pClient, SHCLFORMATS fFormats);
281uint32_t ShClSvcGetMode(void);
282bool ShClSvcGetHeadless(void);
283bool ShClSvcLock(void);
284void ShClSvcUnlock(void);
285/** @} */
286
287
288/** @name Platform-dependent implementations for the Shared Clipboard host service, called *only* by the host service.
289 * @{
290 */
291/**
292 * Called on initialization.
293 */
294int ShClBackendInit(void);
295/**
296 * Called on destruction.
297 */
298void ShClBackendDestroy(void);
299/**
300 * Called when a new HGCM client connects.
301 *
302 * @returns VBox status code.
303 * @param pClient Shared Clipboard client context.
304 * @param fHeadless Whether this is a headless connection or not.
305 */
306int ShClBackendConnect(PSHCLCLIENT pClient, bool fHeadless);
307/**
308 * Called when a HGCM client disconnects.
309 *
310 * @returns VBox status code.
311 * @param pClient Shared Clipboard client context.
312 */
313int ShClBackendDisconnect(PSHCLCLIENT pClient);
314/**
315 * Called when the guest reported available clipboard formats to the host OS.
316 *
317 * @returns VBox status code.
318 * @param pClient Shared Clipboard client context.
319 * @param fFormats The announced formats from the guest,
320 * VBOX_SHCL_FMT_XXX.
321 */
322int ShClBackendFormatAnnounce(PSHCLCLIENT pClient, SHCLFORMATS fFormats);
323/** @todo Document: Can return VINF_HGCM_ASYNC_EXECUTE to defer returning read data.*/
324/**
325 * Called when the guest wants to read host clipboard data.
326 *
327 * @returns VBox status code.
328 * @param pClient Shared Clipboard client context.
329 * @param pCmdCtx Shared Clipboard command context.
330 * @param uFormat Clipboard format to read.
331 * @param pvData Where to return the read clipboard data.
332 * @param cbData Size (in bytes) of buffer where to return the clipboard data.
333 * @param pcbActual Where to return the amount of bytes read.
334 */
335int ShClBackendReadData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat, void *pvData, uint32_t cbData, uint32_t *pcbActual);
336/**
337 * Called when the guest writes clipboard data to the host.
338 *
339 * @returns VBox status code.
340 * @param pClient Shared Clipboard client context.
341 * @param pCmdCtx Shared Clipboard command context.
342 * @param uFormat Clipboard format to write.
343 * @param pvData Clipboard data to write.
344 * @param cbData Size (in bytes) of buffer clipboard data to write.
345 */
346int ShClBackendWriteData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat, void *pvData, uint32_t cbData);
347/**
348 * Called when synchronization of the clipboard contents of the host clipboard with the guest is needed.
349 *
350 * @returns VBox status code.
351 * @param pClient Shared Clipboard client context.
352 */
353int ShClBackendSync(PSHCLCLIENT pClient);
354/** @} */
355
356#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
357/** @name Host implementations for Shared Clipboard transfers.
358 * @{
359 */
360/**
361 * Called when a transfer gets created.
362 *
363 * @returns VBox status code.
364 * @param pClient Shared Clipboard client context.
365 * @param pTransfer Shared Clipboard transfer created.
366 */
367int ShClBackendTransferCreate(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
368/**
369 * Called when a transfer gets destroyed.
370 *
371 * @returns VBox status code.
372 * @param pClient Shared Clipboard client context.
373 * @param pTransfer Shared Clipboard transfer to destroy.
374 */
375int ShClBackendTransferDestroy(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
376/**
377 * Called when getting (determining) the transfer roots on the host side.
378 *
379 * @returns VBox status code.
380 * @param pClient Shared Clipboard client context.
381 * @param pTransfer Shared Clipboard transfer to get roots for.
382 */
383int ShClBackendTransferGetRoots(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
384/** @} */
385#endif
386
387#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
388/** @name Internal Shared Clipboard transfer host service functions.
389 * @{
390 */
391int shClSvcTransferHandler(PSHCLCLIENT pClient, VBOXHGCMCALLHANDLE callHandle, uint32_t u32Function,
392 uint32_t cParms, VBOXHGCMSVCPARM paParms[], uint64_t tsArrival);
393int shClSvcTransferHostHandler(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
394/** @} */
395
396/** @name Shared Clipboard transfer interface implementations for the host service.
397 * @{
398 */
399int shClSvcTransferIfaceOpen(PSHCLPROVIDERCTX pCtx);
400int shClSvcTransferIfaceClose(PSHCLPROVIDERCTX pCtx);
401
402int shClSvcTransferIfaceGetRoots(PSHCLPROVIDERCTX pCtx, PSHCLROOTLIST *ppRootList);
403
404int shClSvcTransferIfaceListOpen(PSHCLPROVIDERCTX pCtx, PSHCLLISTOPENPARMS pOpenParms, PSHCLLISTHANDLE phList);
405int shClSvcTransferIfaceListClose(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList);
406int shClSvcTransferIfaceListHdrRead(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
407int shClSvcTransferIfaceListHdrWrite(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
408int shClSvcTransferIfaceListEntryRead(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
409int shClSvcTransferIfaceListEntryWrite(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
410
411int shClSvcTransferIfaceObjOpen(PSHCLPROVIDERCTX pCtx, PSHCLOBJOPENCREATEPARMS pCreateParms,
412 PSHCLOBJHANDLE phObj);
413int shClSvcTransferIfaceObjClose(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj);
414int shClSvcTransferIfaceObjRead(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
415 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbRead);
416int shClSvcTransferIfaceObjWrite(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
417 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbWritten);
418/** @} */
419
420/** @name Shared Clipboard transfer callbacks for the host service.
421 * @{
422 */
423DECLCALLBACK(void) VBoxSvcClipboardTransferPrepareCallback(PSHCLTRANSFERCALLBACKDATA pData);
424DECLCALLBACK(void) VBoxSvcClipboardDataHeaderCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData);
425DECLCALLBACK(void) VBoxSvcClipboardDataCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData);
426DECLCALLBACK(void) VBoxSvcClipboardTransferCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData, int rc);
427DECLCALLBACK(void) VBoxSvcClipboardTransferCanceledCallback(PSHCLTRANSFERCALLBACKDATA pData);
428DECLCALLBACK(void) VBoxSvcClipboardTransferErrorCallback(PSHCLTRANSFERCALLBACKDATA pData, int rc);
429/** @} */
430#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
431
432/* Host unit testing interface */
433#ifdef UNIT_TEST
434uint32_t TestClipSvcGetMode(void);
435#endif
436
437#endif /* !VBOX_INCLUDED_SRC_SharedClipboard_VBoxSharedClipboardSvc_internal_h */
438
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