VirtualBox

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

Last change on this file since 87686 was 87566, checked in by vboxsync, 4 years ago

Shared Clipboard: doxygen fixes for unnecessary @copydoc in definitions and duplicate @param docs. (probably bugref:9437)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.6 KB
Line 
1/* $Id: VBoxSharedClipboardSvc-internal.h 87566 2021-02-03 13:48:48Z 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
168#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
169/**
170 * Structure for keeping transfer-related data per HGCM client.
171 */
172typedef struct _SHCLIENTTRANSFERS
173{
174 /** Transfer context. */
175 SHCLTRANSFERCTX Ctx;
176} SHCLIENTTRANSFERS, *PSHCLIENTTRANSFERS;
177#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
178
179/**
180 * Structure for keeping data per (connected) HGCM client.
181 */
182typedef struct _SHCLCLIENT
183{
184 /** General client state data. */
185 SHCLCLIENTSTATE State;
186 /** The critical section protecting the queue, event source and whatnot. */
187 RTCRITSECT CritSect;
188 /** The client's message queue (SHCLCLIENTMSG). */
189 RTLISTANCHOR MsgQueue;
190 /** Number of allocated messages (updated atomically, not under critsect). */
191 uint32_t volatile cMsgAllocated;
192 /** Legacy cruft we have to keep to support old(er) Guest Additions. */
193 SHCLCLIENTLEGACYSTATE Legacy;
194 /** The client's own event source.
195 * Needed for events which are not bound to a specific transfer. */
196 SHCLEVENTSOURCE EventSrc;
197#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
198 SHCLIENTTRANSFERS Transfers;
199#endif
200 /** Structure for keeping the client's pending (deferred return) state.
201 * A client is in a deferred state when it asks for the next HGCM message,
202 * but the service can't provide it yet. That way a client will block (on the guest side, does not return)
203 * until the service can complete the call. */
204 struct
205 {
206 /** The client's HGCM call handle. Needed for completing a deferred call. */
207 VBOXHGCMCALLHANDLE hHandle;
208 /** Message type (function number) to use when completing the deferred call.
209 * A non-0 value means the client is in pending mode. */
210 uint32_t uType;
211 /** Parameter count to use when completing the deferred call. */
212 uint32_t cParms;
213 /** Parameters to use when completing the deferred call. */
214 PVBOXHGCMSVCPARM paParms;
215 } Pending;
216} SHCLCLIENT, *PSHCLCLIENT;
217
218/**
219 * Structure for keeping a single event source map entry.
220 * Currently empty.
221 */
222typedef struct _SHCLEVENTSOURCEMAPENTRY
223{
224} SHCLEVENTSOURCEMAPENTRY;
225
226/** Map holding information about connected HGCM clients. Key is the (unique) HGCM client ID.
227 * The value is a weak pointer to PSHCLCLIENT, which is owned by HGCM. */
228typedef std::map<uint32_t, PSHCLCLIENT> ClipboardClientMap;
229
230/** Map holding information about event sources. Key is the (unique) event source ID. */
231typedef std::map<SHCLEVENTSOURCEID, SHCLEVENTSOURCEMAPENTRY> ClipboardEventSourceMap;
232
233/** Simple queue (list) which holds deferred (waiting) clients. */
234typedef std::list<uint32_t> ClipboardClientQueue;
235
236/**
237 * Structure for keeping the Shared Clipboard service extension state.
238 *
239 * A service extension is optional, and can be installed by a host component
240 * to communicate with the Shared Clipboard host service.
241 */
242typedef struct _SHCLEXTSTATE
243{
244 /** Pointer to the actual service extension handle. */
245 PFNHGCMSVCEXT pfnExtension;
246 /** Opaque pointer to extension-provided data. Don't touch. */
247 void *pvExtension;
248 /** The HGCM client ID currently assigned to this service extension.
249 * At the moment only one HGCM client can be assigned per extension. */
250 uint32_t uClientID;
251 /** Whether the host service is reading clipboard data currently. */
252 bool fReadingData;
253 /** Whether the service extension has sent the clipboard formats while
254 * the the host service is reading clipboard data from it. */
255 bool fDelayedAnnouncement;
256 /** The actual clipboard formats announced while the host service
257 * is reading clipboard data from the extension. */
258 uint32_t fDelayedFormats;
259} SHCLEXTSTATE, *PSHCLEXTSTATE;
260
261int shClSvcSetSource(PSHCLCLIENT pClient, SHCLSOURCE enmSource);
262
263void shClSvcMsgQueueReset(PSHCLCLIENT pClient);
264PSHCLCLIENTMSG shClSvcMsgAlloc(PSHCLCLIENT pClient, uint32_t uMsg, uint32_t cParms);
265void shClSvcMsgFree(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg);
266void shClSvcMsgAdd(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg, bool fAppend);
267int shClSvcMsgAddAndWakeupClient(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg);
268
269int shClSvcClientInit(PSHCLCLIENT pClient, uint32_t uClientID);
270void shClSvcClientDestroy(PSHCLCLIENT pClient);
271void shClSvcClientLock(PSHCLCLIENT pClient);
272void shClSvcClientUnlock(PSHCLCLIENT pClient);
273void shClSvcClientReset(PSHCLCLIENT pClient);
274
275int shClSvcClientStateInit(PSHCLCLIENTSTATE pClientState, uint32_t uClientID);
276int shClSvcClientStateDestroy(PSHCLCLIENTSTATE pClientState);
277void shclSvcClientStateReset(PSHCLCLIENTSTATE pClientState);
278
279int shClSvcClientWakeup(PSHCLCLIENT pClient);
280
281# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
282int shClSvcTransferModeSet(uint32_t fMode);
283int shClSvcTransferStart(PSHCLCLIENT pClient, SHCLTRANSFERDIR enmDir, SHCLSOURCE enmSource, PSHCLTRANSFER *ppTransfer);
284int shClSvcTransferStop(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
285bool shClSvcTransferMsgIsAllowed(uint32_t uMode, uint32_t uMsg);
286void shClSvcClientTransfersReset(PSHCLCLIENT pClient);
287#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
288
289/** @name Service functions, accessible by the backends.
290 * Locking is between the (host) service thread and the platform-dependent (window) thread.
291 * @{
292 */
293int ShClSvcGuestDataRequest(PSHCLCLIENT pClient, SHCLFORMATS fFormats, PSHCLEVENTID pidEvent);
294int ShClSvcGuestDataSignal(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat, void *pvData, uint32_t cbData);
295int ShClSvcHostReportFormats(PSHCLCLIENT pClient, SHCLFORMATS fFormats);
296uint32_t ShClSvcGetMode(void);
297bool ShClSvcGetHeadless(void);
298bool ShClSvcLock(void);
299void ShClSvcUnlock(void);
300/** @} */
301
302
303/** @name Platform-dependent implementations for the Shared Clipboard host service, called *only* by the host service.
304 * @{
305 */
306/**
307 * Called on initialization.
308 */
309int ShClBackendInit(void);
310
311/**
312 * Called on destruction.
313 */
314void ShClBackendDestroy(void);
315
316/**
317 * Called when a new HGCM client connects.
318 *
319 * @returns VBox status code.
320 * @param pClient Shared Clipboard client context.
321 * @param fHeadless Whether this is a headless connection or not.
322 */
323int ShClBackendConnect(PSHCLCLIENT pClient, bool fHeadless);
324
325/**
326 * Called when a HGCM client disconnects.
327 *
328 * @returns VBox status code.
329 * @param pClient Shared Clipboard client context.
330 */
331int ShClBackendDisconnect(PSHCLCLIENT pClient);
332
333/**
334 * Called when the guest reported available clipboard formats to the host OS.
335 *
336 * @returns VBox status code.
337 * @param pClient Shared Clipboard client context.
338 * @param fFormats The announced formats from the guest,
339 * VBOX_SHCL_FMT_XXX.
340 */
341int ShClBackendFormatAnnounce(PSHCLCLIENT pClient, SHCLFORMATS fFormats);
342
343/**
344 * Called when the guest wants to read host clipboard data.
345 *
346 * @returns VBox status code.
347 * @param pClient Shared Clipboard client context.
348 * @param pCmdCtx Shared Clipboard command context.
349 * @param uFormat Clipboard format to read.
350 * @param pvData Where to return the read clipboard data.
351 * @param cbData Size (in bytes) of buffer where to return the clipboard data.
352 * @param pcbActual Where to return the amount of bytes read.
353 *
354 * @todo Document: Can return VINF_HGCM_ASYNC_EXECUTE to defer returning read
355 * data
356 */
357int ShClBackendReadData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat,
358 void *pvData, uint32_t cbData, uint32_t *pcbActual);
359
360/**
361 * Called when the guest writes clipboard data to the host.
362 *
363 * @returns VBox status code.
364 * @param pClient Shared Clipboard client context.
365 * @param pCmdCtx Shared Clipboard command context.
366 * @param uFormat Clipboard format to write.
367 * @param pvData Clipboard data to write.
368 * @param cbData Size (in bytes) of buffer clipboard data to write.
369 */
370int ShClBackendWriteData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat, void *pvData, uint32_t cbData);
371
372/**
373 * Called when synchronization of the clipboard contents of the host clipboard with the guest is needed.
374 *
375 * @returns VBox status code.
376 * @param pClient Shared Clipboard client context.
377 */
378int ShClBackendSync(PSHCLCLIENT pClient);
379/** @} */
380
381#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
382/** @name Host implementations for Shared Clipboard transfers.
383 * @{
384 */
385/**
386 * Called after a transfer got created.
387 *
388 * @returns VBox status code.
389 * @param pClient Shared Clipboard client context.
390 * @param pTransfer Shared Clipboard transfer created.
391 */
392int ShClBackendTransferCreate(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
393/**
394 * Called before a transfer gets destroyed.
395 *
396 * @returns VBox status code.
397 * @param pClient Shared Clipboard client context.
398 * @param pTransfer Shared Clipboard transfer to destroy.
399 */
400int ShClBackendTransferDestroy(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
401/**
402 * Called when getting (determining) the transfer roots on the host side.
403 *
404 * @returns VBox status code.
405 * @param pClient Shared Clipboard client context.
406 * @param pTransfer Shared Clipboard transfer to get roots for.
407 */
408int ShClBackendTransferGetRoots(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
409/** @} */
410#endif
411
412#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
413/** @name Internal Shared Clipboard transfer host service functions.
414 * @{
415 */
416int shClSvcTransferHandler(PSHCLCLIENT pClient, VBOXHGCMCALLHANDLE callHandle, uint32_t u32Function,
417 uint32_t cParms, VBOXHGCMSVCPARM paParms[], uint64_t tsArrival);
418int shClSvcTransferHostHandler(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
419/** @} */
420
421/** @name Shared Clipboard transfer interface implementations for the host service.
422 * @{
423 */
424#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP
425
426#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS_HTTP */
427
428int shClSvcTransferIfaceGetRoots(PSHCLTXPROVIDERCTX pCtx, PSHCLROOTLIST *ppRootList);
429
430int shClSvcTransferIfaceListOpen(PSHCLTXPROVIDERCTX pCtx, PSHCLLISTOPENPARMS pOpenParms, PSHCLLISTHANDLE phList);
431int shClSvcTransferIfaceListClose(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList);
432int shClSvcTransferIfaceListHdrRead(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
433int shClSvcTransferIfaceListHdrWrite(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
434int shClSvcTransferIfaceListEntryRead(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
435int shClSvcTransferIfaceListEntryWrite(PSHCLTXPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
436
437int shClSvcTransferIfaceObjOpen(PSHCLTXPROVIDERCTX pCtx, PSHCLOBJOPENCREATEPARMS pCreateParms,
438 PSHCLOBJHANDLE phObj);
439int shClSvcTransferIfaceObjClose(PSHCLTXPROVIDERCTX pCtx, SHCLOBJHANDLE hObj);
440int shClSvcTransferIfaceObjRead(PSHCLTXPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
441 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbRead);
442int shClSvcTransferIfaceObjWrite(PSHCLTXPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
443 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbWritten);
444/** @} */
445
446/** @name Shared Clipboard transfer callbacks for the host service.
447 * @{
448 */
449DECLCALLBACK(void) VBoxSvcClipboardTransferPrepareCallback(PSHCLTXPROVIDERCTX pCtx);
450DECLCALLBACK(void) VBoxSvcClipboardDataHeaderCompleteCallback(PSHCLTXPROVIDERCTX pCtx);
451DECLCALLBACK(void) VBoxSvcClipboardDataCompleteCallback(PSHCLTXPROVIDERCTX pCtx);
452DECLCALLBACK(void) VBoxSvcClipboardTransferCompleteCallback(PSHCLTXPROVIDERCTX pCtx, int rc);
453DECLCALLBACK(void) VBoxSvcClipboardTransferCanceledCallback(PSHCLTXPROVIDERCTX pCtx);
454DECLCALLBACK(void) VBoxSvcClipboardTransferErrorCallback(PSHCLTXPROVIDERCTX pCtx, int rc);
455/** @} */
456#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
457
458/* Host unit testing interface */
459#ifdef UNIT_TEST
460uint32_t TestClipSvcGetMode(void);
461#endif
462
463#endif /* !VBOX_INCLUDED_SRC_SharedClipboard_VBoxSharedClipboardSvc_internal_h */
464
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