VirtualBox

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

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

SharedClipboardSvc,Vbgl: Started looking over the host message handling, adding missing locking and fixing docs. bugref:9437

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.5 KB
Line 
1/* $Id: VBoxSharedClipboardSvc-internal.h 82526 2019-12-09 21:48:53Z 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 SHCLEVENTSOURCE EventSrc;
150#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
151 /** Transfer contextdata. */
152 SHCLTRANSFERCTX TransferCtx;
153#endif
154 /** Structure for keeping the client's pending (deferred return) state.
155 * A client is in a deferred state when it asks for the next HGCM message,
156 * but the service can't provide it yet. That way a client will block (on the guest side, does not return)
157 * until the service can complete the call. */
158 struct
159 {
160 /** The client's HGCM call handle. Needed for completing a deferred call. */
161 VBOXHGCMCALLHANDLE hHandle;
162 /** Message type (function number) to use when completing the deferred call.
163 * A non-0 value means the client is in pending mode. */
164 uint32_t uType;
165 /** Parameter count to use when completing the deferred call. */
166 uint32_t cParms;
167 /** Parameters to use when completing the deferred call. */
168 PVBOXHGCMSVCPARM paParms;
169 } Pending;
170} SHCLCLIENT, *PSHCLCLIENT;
171
172/**
173 * Structure for keeping a single event source map entry.
174 * Currently empty.
175 */
176typedef struct _SHCLEVENTSOURCEMAPENTRY
177{
178} SHCLEVENTSOURCEMAPENTRY;
179
180/** Map holding information about connected HGCM clients. Key is the (unique) HGCM client ID.
181 * The value is a weak pointer to PSHCLCLIENT, which is owned by HGCM. */
182typedef std::map<uint32_t, PSHCLCLIENT> ClipboardClientMap;
183
184/** Map holding information about event sources. Key is the (unique) event source ID. */
185typedef std::map<SHCLEVENTSOURCEID, SHCLEVENTSOURCEMAPENTRY> ClipboardEventSourceMap;
186
187/** Simple queue (list) which holds deferred (waiting) clients. */
188typedef std::list<uint32_t> ClipboardClientQueue;
189
190/**
191 * Structure for keeping the Shared Clipboard service extension state.
192 *
193 * A service extension is optional, and can be installed by a host component
194 * to communicate with the Shared Clipboard host service.
195 */
196typedef struct _SHCLEXTSTATE
197{
198 /** Pointer to the actual service extension handle. */
199 PFNHGCMSVCEXT pfnExtension;
200 /** Opaque pointer to extension-provided data. Don't touch. */
201 void *pvExtension;
202 /** The HGCM client ID currently assigned to this service extension.
203 * At the moment only one HGCM client can be assigned per extension. */
204 uint32_t uClientID;
205 /** Whether the host service is reading clipboard data currently. */
206 bool fReadingData;
207 /** Whether the service extension has sent the clipboard formats while
208 * the the host service is reading clipboard data from it. */
209 bool fDelayedAnnouncement;
210 /** The actual clipboard formats announced while the host service
211 * is reading clipboard data from the extension. */
212 uint32_t uDelayedFormats;
213} SHCLEXTSTATE, *PSHCLEXTSTATE;
214
215int shClSvcSetSource(PSHCLCLIENT pClient, SHCLSOURCE enmSource);
216
217void shClSvcMsgQueueReset(PSHCLCLIENT pClient);
218PSHCLCLIENTMSG shClSvcMsgAlloc(uint32_t uMsg, uint32_t cParms);
219void shClSvcMsgFree(PSHCLCLIENTMSG pMsg);
220void shClSvcMsgSetPeekReturn(PSHCLCLIENTMSG pMsg, PVBOXHGCMSVCPARM paDstParms, uint32_t cDstParms);
221int shClSvcMsgAdd(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg, bool fAppend);
222
223int shClSvcClientInit(PSHCLCLIENT pClient, uint32_t uClientID);
224void shClSvcClientDestroy(PSHCLCLIENT pClient);
225void shClSvcClientReset(PSHCLCLIENT pClient);
226
227int shClSvcClientStateInit(PSHCLCLIENTSTATE pClientState, uint32_t uClientID);
228int shClSvcClientStateDestroy(PSHCLCLIENTSTATE pClientState);
229void shclSvcClientStateReset(PSHCLCLIENTSTATE pClientState);
230
231int shClSvcClientWakeup(PSHCLCLIENT pClient);
232
233# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
234int shClSvcTransferModeSet(uint32_t fMode);
235int shClSvcTransferStart(PSHCLCLIENT pClient, SHCLTRANSFERDIR enmDir, SHCLSOURCE enmSource, PSHCLTRANSFER *ppTransfer);
236int shClSvcTransferStop(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
237bool shClSvcTransferMsgIsAllowed(uint32_t uMode, uint32_t uMsg);
238void shClSvcClientTransfersReset(PSHCLCLIENT pClient);
239#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
240
241/** @name Service functions, accessible by the backends.
242 * Locking is between the (host) service thread and the platform-dependent (window) thread.
243 * @{
244 */
245int ShClSvcDataReadRequest(PSHCLCLIENT pClient, PSHCLDATAREQ pDataReq, PSHCLEVENTID puEvent);
246int ShClSvcDataReadSignal(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLDATABLOCK pData);
247int ShClSvcFormatsReport(PSHCLCLIENT pClient, PSHCLFORMATDATA pFormats);
248uint32_t ShClSvcGetMode(void);
249bool ShClSvcGetHeadless(void);
250bool ShClSvcLock(void);
251void ShClSvcUnlock(void);
252/** @} */
253
254
255/** @name Platform-dependent implementations for the Shared Clipboard host service, called *only* by the host service.
256 * @{
257 */
258/**
259 * Called on initialization.
260 */
261int ShClSvcImplInit(void);
262/**
263 * Called on destruction.
264 */
265void ShClSvcImplDestroy(void);
266/**
267 * Called when a new HGCM client connects.
268 *
269 * @returns VBox status code.
270 * @param pClient Shared Clipboard client context.
271 * @param fHeadless Whether this is a headless connection or not.
272 */
273int ShClSvcImplConnect(PSHCLCLIENT pClient, bool fHeadless);
274/**
275 * Called when a HGCM client disconnects.
276 *
277 * @returns VBox status code.
278 * @param pClient Shared Clipboard client context.
279 */
280int ShClSvcImplDisconnect(PSHCLCLIENT pClient);
281/**
282 * Called when the guest reported available clipboard formats to the host OS.
283 *
284 * @returns VBox status code.
285 * @param pClient Shared Clipboard client context.
286 * @param pCmdCtx Shared Clipboard command context.
287 * @param pFormats Announced formats from the guest.
288 */
289int ShClSvcImplFormatAnnounce(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLFORMATDATA pFormats);
290/** @todo Document: Can return VINF_HGCM_ASYNC_EXECUTE to defer returning read data.*/
291/**
292 * Called when the guest wants to read host clipboard data.
293 *
294 * @returns VBox status code.
295 * @param pClient Shared Clipboard client context.
296 * @param pCmdCtx Shared Clipboard command context.
297 * @param pData Where to return the read clipboard data.
298 * @param pcbActual Where to return the amount of bytes read.
299 */
300int ShClSvcImplReadData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLDATABLOCK pData, uint32_t *pcbActual);
301/**
302 * Called when the guest writes clipboard data to the host.
303 *
304 * @returns VBox status code.
305 * @param pClient Shared Clipboard client context.
306 * @param pCmdCtx Shared Clipboard command context.
307 * @param pData Clipboard data from the guest.
308 */
309int ShClSvcImplWriteData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLDATABLOCK pData);
310/**
311 * Called when synchronization of the clipboard contents of the host clipboard with the guest is needed.
312 *
313 * @returns VBox status code.
314 * @param pClient Shared Clipboard client context.
315 */
316int ShClSvcImplSync(PSHCLCLIENT pClient);
317/** @} */
318
319#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
320/** @name Host implementations for Shared Clipboard transfers.
321 * @{
322 */
323/**
324 * Called when a transfer gets created.
325 *
326 * @returns VBox status code.
327 * @param pClient Shared Clipboard client context.
328 * @param pTransfer Shared Clipboard transfer created.
329 */
330int ShClSvcImplTransferCreate(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
331/**
332 * Called when a transfer gets destroyed.
333 *
334 * @returns VBox status code.
335 * @param pClient Shared Clipboard client context.
336 * @param pTransfer Shared Clipboard transfer to destroy.
337 */
338int ShClSvcImplTransferDestroy(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
339/**
340 * Called when getting (determining) the transfer roots on the host side.
341 *
342 * @returns VBox status code.
343 * @param pClient Shared Clipboard client context.
344 * @param pTransfer Shared Clipboard transfer to get roots for.
345 */
346int ShClSvcImplTransferGetRoots(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
347/** @} */
348#endif
349
350#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
351/** @name Internal Shared Clipboard transfer host service functions.
352 * @{
353 */
354int shClSvcTransferAreaDetach(PSHCLCLIENTSTATE pClientState, PSHCLTRANSFER pTransfer);
355int shClSvcTransferHandler(PSHCLCLIENT pClient, VBOXHGCMCALLHANDLE callHandle, uint32_t u32Function,
356 uint32_t cParms, VBOXHGCMSVCPARM paParms[], uint64_t tsArrival);
357int shClSvcTransferHostHandler(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
358/** @} */
359
360/** @name Shared Clipboard transfer interface implementations for the host service.
361 * @{
362 */
363int shClSvcTransferIfaceOpen(PSHCLPROVIDERCTX pCtx);
364int shClSvcTransferIfaceClose(PSHCLPROVIDERCTX pCtx);
365
366int shClSvcTransferIfaceGetRoots(PSHCLPROVIDERCTX pCtx, PSHCLROOTLIST *ppRootList);
367
368int shClSvcTransferIfaceListOpen(PSHCLPROVIDERCTX pCtx, PSHCLLISTOPENPARMS pOpenParms, PSHCLLISTHANDLE phList);
369int shClSvcTransferIfaceListClose(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList);
370int shClSvcTransferIfaceListHdrRead(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
371int shClSvcTransferIfaceListHdrWrite(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
372int shClSvcTransferIfaceListEntryRead(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
373int shClSvcTransferIfaceListEntryWrite(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
374
375int shClSvcTransferIfaceObjOpen(PSHCLPROVIDERCTX pCtx, PSHCLOBJOPENCREATEPARMS pCreateParms,
376 PSHCLOBJHANDLE phObj);
377int shClSvcTransferIfaceObjClose(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj);
378int shClSvcTransferIfaceObjRead(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
379 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbRead);
380int shClSvcTransferIfaceObjWrite(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
381 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbWritten);
382/** @} */
383
384/** @name Shared Clipboard transfer callbacks for the host service.
385 * @{
386 */
387DECLCALLBACK(void) VBoxSvcClipboardTransferPrepareCallback(PSHCLTRANSFERCALLBACKDATA pData);
388DECLCALLBACK(void) VBoxSvcClipboardDataHeaderCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData);
389DECLCALLBACK(void) VBoxSvcClipboardDataCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData);
390DECLCALLBACK(void) VBoxSvcClipboardTransferCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData, int rc);
391DECLCALLBACK(void) VBoxSvcClipboardTransferCanceledCallback(PSHCLTRANSFERCALLBACKDATA pData);
392DECLCALLBACK(void) VBoxSvcClipboardTransferErrorCallback(PSHCLTRANSFERCALLBACKDATA pData, int rc);
393/** @} */
394#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
395
396/* Host unit testing interface */
397#ifdef UNIT_TEST
398uint32_t TestClipSvcGetMode(void);
399#endif
400
401#endif /* !VBOX_INCLUDED_SRC_SharedClipboard_VBoxSharedClipboardSvc_internal_h */
402
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