VirtualBox

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

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

Shared Clipboard/Host Service: Renamed cAllocatedMessages -> cMsgAllocated and use it where appropriate. bugref:9437

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.2 KB
Line 
1/* $Id: VBoxSharedClipboardSvc-internal.h 86007 2020-09-02 17:35:05Z 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/** No Shared Clipboard client flags defined. */
93#define SHCLCLIENTSTATE_FLAGS_NONE 0
94/** Client has a guest read operation active. Currently unused. */
95#define SHCLCLIENTSTATE_FLAGS_READ_ACTIVE RT_BIT(0)
96/** Client has a guest write operation active. Currently unused. */
97#define SHCLCLIENTSTATE_FLAGS_WRITE_ACTIVE RT_BIT(1)
98/** @} */
99
100/**
101 * Strucutre needed to support backwards compatbility for old(er) Guest Additions (< 6.1),
102 * which did not know the context ID concept then.
103 */
104typedef struct SHCLCLIENTLEGACYCID
105{
106 /** List node. */
107 RTLISTNODE Node;
108 /** The actual context ID. */
109 uint64_t uCID;
110 /** Not used yet; useful to have it in the saved state though. */
111 uint32_t enmType;
112 /** @todo Add an union here as soon as we utilize \a enmType. */
113 SHCLFORMAT uFormat;
114} SHCLCLIENTLEGACYCID;
115/** Pointer to a SHCLCLIENTLEGACYCID struct. */
116typedef SHCLCLIENTLEGACYCID *PSHCLCLIENTLEGACYCID;
117
118/**
119 * Strucutre for keeping legacy state, required for keeping backwards compatibility
120 * to old(er) Guest Additions.
121 */
122typedef struct SHCLCLIENTLEGACYSTATE
123{
124 /** List of context IDs (of type SHCLCLIENTLEGACYCID) for older Guest Additions which (< 6.1)
125 * which did not know the concept of context IDs. */
126 RTLISTANCHOR lstCID;
127 /** Number of context IDs currently in \a lstCID. */
128 uint16_t cCID;
129} SHCLCLIENTLEGACYSTATE;
130
131/**
132 * Structure for keeping generic client state data within the Shared Clipboard host service.
133 * This structure needs to be serializable by SSM (must be a POD type).
134 */
135typedef struct SHCLCLIENTSTATE
136{
137 struct SHCLCLIENTSTATE *pNext;
138 struct SHCLCLIENTSTATE *pPrev;
139
140 SHCLCONTEXT *pCtx;
141
142 /** The client's HGCM ID. Not related to the session ID below! */
143 uint32_t uClientID;
144 /** The client's session ID. */
145 SHCLSESSIONID uSessionID;
146 /** Guest feature flags, VBOX_SHCL_GF_0_XXX. */
147 uint64_t fGuestFeatures0;
148 /** Guest feature flags, VBOX_SHCL_GF_1_XXX. */
149 uint64_t fGuestFeatures1;
150 /** Chunk size to use for data transfers. */
151 uint32_t cbChunkSize;
152 /** Where the transfer sources its data from. */
153 SHCLSOURCE enmSource;
154 /** Client state flags of type SHCLCLIENTSTATE_FLAGS_. */
155 uint32_t fFlags;
156 /** POD (plain old data) state. */
157 SHCLCLIENTPODSTATE POD;
158 /** The client's transfers state. */
159 SHCLCLIENTTRANSFERSTATE Transfers;
160} SHCLCLIENTSTATE, *PSHCLCLIENTSTATE;
161
162typedef struct _SHCLCLIENTCMDCTX
163{
164 uint64_t uContextID;
165} SHCLCLIENTCMDCTX, *PSHCLCLIENTCMDCTX;
166
167typedef struct _SHCLCLIENT
168{
169 /** General client state data. */
170 SHCLCLIENTSTATE State;
171 /** The critical section protecting the queue, event source and whatnot. */
172 RTCRITSECT CritSect;
173 /** The client's message queue (SHCLCLIENTMSG). */
174 RTLISTANCHOR MsgQueue;
175 /** Number of allocated messages (updated atomically, not under critsect). */
176 uint32_t volatile cMsgAllocated;
177 /** Legacy cruft we have to keep to support old(er) Guest Additions. */
178 SHCLCLIENTLEGACYSTATE Legacy;
179 /** The client's own event source.
180 * Needed for events which are not bound to a specific transfer. */
181 SHCLEVENTSOURCE EventSrc;
182#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
183 /** Transfer contextdata. */
184 SHCLTRANSFERCTX TransferCtx;
185#endif
186 /** Structure for keeping the client's pending (deferred return) state.
187 * A client is in a deferred state when it asks for the next HGCM message,
188 * but the service can't provide it yet. That way a client will block (on the guest side, does not return)
189 * until the service can complete the call. */
190 struct
191 {
192 /** The client's HGCM call handle. Needed for completing a deferred call. */
193 VBOXHGCMCALLHANDLE hHandle;
194 /** Message type (function number) to use when completing the deferred call.
195 * A non-0 value means the client is in pending mode. */
196 uint32_t uType;
197 /** Parameter count to use when completing the deferred call. */
198 uint32_t cParms;
199 /** Parameters to use when completing the deferred call. */
200 PVBOXHGCMSVCPARM paParms;
201 } Pending;
202} SHCLCLIENT, *PSHCLCLIENT;
203
204/**
205 * Structure for keeping a single event source map entry.
206 * Currently empty.
207 */
208typedef struct _SHCLEVENTSOURCEMAPENTRY
209{
210} SHCLEVENTSOURCEMAPENTRY;
211
212/** Map holding information about connected HGCM clients. Key is the (unique) HGCM client ID.
213 * The value is a weak pointer to PSHCLCLIENT, which is owned by HGCM. */
214typedef std::map<uint32_t, PSHCLCLIENT> ClipboardClientMap;
215
216/** Map holding information about event sources. Key is the (unique) event source ID. */
217typedef std::map<SHCLEVENTSOURCEID, SHCLEVENTSOURCEMAPENTRY> ClipboardEventSourceMap;
218
219/** Simple queue (list) which holds deferred (waiting) clients. */
220typedef std::list<uint32_t> ClipboardClientQueue;
221
222/**
223 * Structure for keeping the Shared Clipboard service extension state.
224 *
225 * A service extension is optional, and can be installed by a host component
226 * to communicate with the Shared Clipboard host service.
227 */
228typedef struct _SHCLEXTSTATE
229{
230 /** Pointer to the actual service extension handle. */
231 PFNHGCMSVCEXT pfnExtension;
232 /** Opaque pointer to extension-provided data. Don't touch. */
233 void *pvExtension;
234 /** The HGCM client ID currently assigned to this service extension.
235 * At the moment only one HGCM client can be assigned per extension. */
236 uint32_t uClientID;
237 /** Whether the host service is reading clipboard data currently. */
238 bool fReadingData;
239 /** Whether the service extension has sent the clipboard formats while
240 * the the host service is reading clipboard data from it. */
241 bool fDelayedAnnouncement;
242 /** The actual clipboard formats announced while the host service
243 * is reading clipboard data from the extension. */
244 uint32_t fDelayedFormats;
245} SHCLEXTSTATE, *PSHCLEXTSTATE;
246
247int shClSvcSetSource(PSHCLCLIENT pClient, SHCLSOURCE enmSource);
248
249void shClSvcMsgQueueReset(PSHCLCLIENT pClient);
250PSHCLCLIENTMSG shClSvcMsgAlloc(PSHCLCLIENT pClient, uint32_t uMsg, uint32_t cParms);
251void shClSvcMsgFree(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg);
252void shClSvcMsgAdd(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg, bool fAppend);
253int shClSvcMsgAddAndWakeupClient(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg);
254
255int shClSvcClientInit(PSHCLCLIENT pClient, uint32_t uClientID);
256void shClSvcClientDestroy(PSHCLCLIENT pClient);
257void shClSvcClientReset(PSHCLCLIENT pClient);
258
259int shClSvcClientStateInit(PSHCLCLIENTSTATE pClientState, uint32_t uClientID);
260int shClSvcClientStateDestroy(PSHCLCLIENTSTATE pClientState);
261void shclSvcClientStateReset(PSHCLCLIENTSTATE pClientState);
262
263int shClSvcClientWakeup(PSHCLCLIENT pClient);
264
265# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
266int shClSvcTransferModeSet(uint32_t fMode);
267int shClSvcTransferStart(PSHCLCLIENT pClient, SHCLTRANSFERDIR enmDir, SHCLSOURCE enmSource, PSHCLTRANSFER *ppTransfer);
268int shClSvcTransferStop(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
269bool shClSvcTransferMsgIsAllowed(uint32_t uMode, uint32_t uMsg);
270void shClSvcClientTransfersReset(PSHCLCLIENT pClient);
271#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
272
273/** @name Service functions, accessible by the backends.
274 * Locking is between the (host) service thread and the platform-dependent (window) thread.
275 * @{
276 */
277int ShClSvcGuestDataRequest(PSHCLCLIENT pClient, SHCLFORMATS fFormats, PSHCLEVENTID pidEvent);
278int ShClSvcGuestDataSignal(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat, void *pvData, uint32_t cbData);
279int ShClSvcHostReportFormats(PSHCLCLIENT pClient, SHCLFORMATS fFormats);
280uint32_t ShClSvcGetMode(void);
281bool ShClSvcGetHeadless(void);
282bool ShClSvcLock(void);
283void ShClSvcUnlock(void);
284/** @} */
285
286
287/** @name Platform-dependent implementations for the Shared Clipboard host service, called *only* by the host service.
288 * @{
289 */
290/**
291 * Called on initialization.
292 */
293int ShClBackendInit(void);
294/**
295 * Called on destruction.
296 */
297void ShClBackendDestroy(void);
298/**
299 * Called when a new HGCM client connects.
300 *
301 * @returns VBox status code.
302 * @param pClient Shared Clipboard client context.
303 * @param fHeadless Whether this is a headless connection or not.
304 */
305int ShClBackendConnect(PSHCLCLIENT pClient, bool fHeadless);
306/**
307 * Called when a HGCM client disconnects.
308 *
309 * @returns VBox status code.
310 * @param pClient Shared Clipboard client context.
311 */
312int ShClBackendDisconnect(PSHCLCLIENT pClient);
313/**
314 * Called when the guest reported available clipboard formats to the host OS.
315 *
316 * @returns VBox status code.
317 * @param pClient Shared Clipboard client context.
318 * @param fFormats The announced formats from the guest,
319 * VBOX_SHCL_FMT_XXX.
320 */
321int ShClBackendFormatAnnounce(PSHCLCLIENT pClient, SHCLFORMATS fFormats);
322/** @todo Document: Can return VINF_HGCM_ASYNC_EXECUTE to defer returning read data.*/
323/**
324 * Called when the guest wants to read host clipboard data.
325 *
326 * @returns VBox status code.
327 * @param pClient Shared Clipboard client context.
328 * @param pCmdCtx Shared Clipboard command context.
329 * @param uFormat Clipboard format to read.
330 * @param pvData Where to return the read clipboard data.
331 * @param cbData Size (in bytes) of buffer where to return the clipboard data.
332 * @param pcbActual Where to return the amount of bytes read.
333 */
334int ShClBackendReadData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat, void *pvData, uint32_t cbData, uint32_t *pcbActual);
335/**
336 * Called when the guest writes clipboard data to the host.
337 *
338 * @returns VBox status code.
339 * @param pClient Shared Clipboard client context.
340 * @param pCmdCtx Shared Clipboard command context.
341 * @param uFormat Clipboard format to write.
342 * @param pvData Clipboard data to write.
343 * @param cbData Size (in bytes) of buffer clipboard data to write.
344 */
345int ShClBackendWriteData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat, void *pvData, uint32_t cbData);
346/**
347 * Called when synchronization of the clipboard contents of the host clipboard with the guest is needed.
348 *
349 * @returns VBox status code.
350 * @param pClient Shared Clipboard client context.
351 */
352int ShClBackendSync(PSHCLCLIENT pClient);
353/** @} */
354
355#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
356/** @name Host implementations for Shared Clipboard transfers.
357 * @{
358 */
359/**
360 * Called when a transfer gets created.
361 *
362 * @returns VBox status code.
363 * @param pClient Shared Clipboard client context.
364 * @param pTransfer Shared Clipboard transfer created.
365 */
366int ShClBackendTransferCreate(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
367/**
368 * Called when a transfer gets destroyed.
369 *
370 * @returns VBox status code.
371 * @param pClient Shared Clipboard client context.
372 * @param pTransfer Shared Clipboard transfer to destroy.
373 */
374int ShClBackendTransferDestroy(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
375/**
376 * Called when getting (determining) the transfer roots on the host side.
377 *
378 * @returns VBox status code.
379 * @param pClient Shared Clipboard client context.
380 * @param pTransfer Shared Clipboard transfer to get roots for.
381 */
382int ShClBackendTransferGetRoots(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
383/** @} */
384#endif
385
386#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
387/** @name Internal Shared Clipboard transfer host service functions.
388 * @{
389 */
390int shClSvcTransferAreaDetach(PSHCLCLIENTSTATE pClientState, PSHCLTRANSFER pTransfer);
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.

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