VirtualBox

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

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

Shared Clipboard: Generalized initial (host to guest) clipboard syncing code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.1 KB
Line 
1/* $Id: VBoxSharedClipboardSvc-internal.h 81824 2019-11-13 13:28:48Z 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 * This mostly is plain text, but also can be stuff like bitmap (BMP) or other binary data.
78 */
79typedef struct SHCLCLIENTPODSTATE
80{
81 /** POD transfer direction. */
82 SHCLTRANSFERDIR enmDir;
83 /** Format of the data to be read / written. */
84 SHCLFORMAT uFormat;
85 /** How much data (in bytes) to read/write for the current operation. */
86 uint64_t cbToReadWriteTotal;
87 /** How much data (in bytes) already has been read/written for the current operation. */
88 uint64_t cbReadWritten;
89 /** Timestamp (in ms) of Last read/write operation. */
90 uint64_t tsLastReadWrittenMs;
91} SHCLCLIENTPODSTATE, *PSHCLCLIENTPODSTATE;
92
93/** No Shared Clipboard client flags defined. */
94#define SHCLCLIENTSTATE_FLAGS_NONE 0
95/** Client has a guest read operation active. */
96#define SHCLCLIENTSTATE_FLAGS_READ_ACTIVE RT_BIT(0)
97/** Client has a guest write operation active. */
98#define SHCLCLIENTSTATE_FLAGS_WRITE_ACTIVE RT_BIT(1)
99
100/**
101 * Structure for keeping generic client state data within the Shared Clipboard host service.
102 * This structure needs to be serializable by SSM (must be a POD type).
103 */
104typedef struct SHCLCLIENTSTATE
105{
106 struct SHCLCLIENTSTATE *pNext;
107 struct SHCLCLIENTSTATE *pPrev;
108
109 SHCLCONTEXT *pCtx;
110
111 /** The client's HGCM ID. Not related to the session ID below! */
112 uint32_t uClientID;
113 /** The client's session ID. */
114 SHCLSESSIONID uSessionID;
115 /** Guest feature flags, VBOX_SHCL_GF_0_XXX. */
116 uint64_t fGuestFeatures0;
117 /** Guest feature flags, VBOX_SHCL_GF_1_XXX. */
118 uint64_t fGuestFeatures1;
119 /** Maximum chunk size to use for data transfers. Set to _64K by default. */
120 uint32_t cbChunkSize;
121 /** Where the transfer sources its data from. */
122 SHCLSOURCE enmSource;
123 /** Client state flags of type SHCLCLIENTSTATE_FLAGS_. */
124 uint32_t fFlags;
125 /** POD (plain old data) state. */
126 SHCLCLIENTPODSTATE POD;
127 /** The client's transfers state. */
128 SHCLCLIENTTRANSFERSTATE Transfers;
129} SHCLCLIENTSTATE, *PSHCLCLIENTSTATE;
130
131typedef struct _SHCLCLIENTCMDCTX
132{
133 uint64_t uContextID;
134} SHCLCLIENTCMDCTX, *PSHCLCLIENTCMDCTX;
135
136typedef struct _SHCLCLIENT
137{
138 /** General client state data. */
139 SHCLCLIENTSTATE State;
140 RTCRITSECT CritSect;
141 /** The client's message queue (FIFO). */
142 RTCList<SHCLCLIENTMSG *> queueMsg;
143 /** The client's own event source.
144 * Needed for events which are not bound to a specific transfer. */
145 SHCLEVENTSOURCE Events;
146#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
147 /** Transfer contextdata. */
148 SHCLTRANSFERCTX TransferCtx;
149#endif
150 /** Structure for keeping the client's pending (deferred return) state.
151 * A client is in a deferred state when it asks for the next HGCM message,
152 * but the service can't provide it yet. That way a client will block (on the guest side, does not return)
153 * until the service can complete the call. */
154 struct
155 {
156 /** The client's HGCM call handle. Needed for completing a deferred call. */
157 VBOXHGCMCALLHANDLE hHandle;
158 /** Message type (function number) to use when completing the deferred call.
159 * A non-0 value means the client is in pending mode. */
160 uint32_t uType;
161 /** Parameter count to use when completing the deferred call. */
162 uint32_t cParms;
163 /** Parameters to use when completing the deferred call. */
164 PVBOXHGCMSVCPARM paParms;
165 } Pending;
166} SHCLCLIENT, *PSHCLCLIENT;
167
168/**
169 * Structure for keeping a single event source map entry.
170 * Currently empty.
171 */
172typedef struct _SHCLEVENTSOURCEMAPENTRY
173{
174} SHCLEVENTSOURCEMAPENTRY;
175
176/** Map holding information about connected HGCM clients. Key is the (unique) HGCM client ID.
177 * The value is a weak pointer to PSHCLCLIENT, which is owned by HGCM. */
178typedef std::map<uint32_t, PSHCLCLIENT> ClipboardClientMap;
179
180/** Map holding information about event sources. Key is the (unique) event source ID. */
181typedef std::map<SHCLEVENTSOURCEID, SHCLEVENTSOURCEMAPENTRY> ClipboardEventSourceMap;
182
183/** Simple queue (list) which holds deferred (waiting) clients. */
184typedef std::list<uint32_t> ClipboardClientQueue;
185
186/**
187 * Structure for keeping the Shared Clipboard service extension state.
188 *
189 * A service extension is optional, and can be installed by a host component
190 * to communicate with the Shared Clipboard host service.
191 */
192typedef struct _SHCLEXTSTATE
193{
194 /** Pointer to the actual service extension handle. */
195 PFNHGCMSVCEXT pfnExtension;
196 /** Opaque pointer to extension-provided data. Don't touch. */
197 void *pvExtension;
198 /** The HGCM client ID currently assigned to this service extension.
199 * At the moment only one HGCM client can be assigned per extension. */
200 uint32_t uClientID;
201 /** Whether the host service is reading clipboard data currently. */
202 bool fReadingData;
203 /** Whether the service extension has sent the clipboard formats while
204 * the the host service is reading clipboard data from it. */
205 bool fDelayedAnnouncement;
206 /** The actual clipboard formats announced while the host service
207 * is reading clipboard data from the extension. */
208 uint32_t uDelayedFormats;
209} SHCLEXTSTATE, *PSHCLEXTSTATE;
210
211int shClSvcSetSource(PSHCLCLIENT pClient, SHCLSOURCE enmSource);
212
213void shClSvcMsgQueueReset(PSHCLCLIENT pClient);
214PSHCLCLIENTMSG shClSvcMsgAlloc(uint32_t uMsg, uint32_t cParms);
215void shClSvcMsgFree(PSHCLCLIENTMSG pMsg);
216void shClSvcMsgSetPeekReturn(PSHCLCLIENTMSG pMsg, PVBOXHGCMSVCPARM paDstParms, uint32_t cDstParms);
217int shClSvcMsgAdd(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg, bool fAppend);
218int shClSvcMsgPeek(PSHCLCLIENT pClient, VBOXHGCMCALLHANDLE hCall, uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool fWait);
219int shClSvcMsgGet(PSHCLCLIENT pClient, VBOXHGCMCALLHANDLE hCall, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
220
221int shClSvcClientInit(PSHCLCLIENT pClient, uint32_t uClientID);
222void shClSvcClientDestroy(PSHCLCLIENT pClient);
223void shClSvcClientReset(PSHCLCLIENT pClient);
224
225int shClSvcClientStateInit(PSHCLCLIENTSTATE pClientState, uint32_t uClientID);
226int shClSvcClientStateDestroy(PSHCLCLIENTSTATE pClientState);
227void shclSvcClientStateReset(PSHCLCLIENTSTATE pClientState);
228
229int shClSvcClientWakeup(PSHCLCLIENT pClient);
230
231# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
232int shClSvcTransferModeSet(uint32_t fMode);
233int shClSvcTransferStart(PSHCLCLIENT pClient, SHCLTRANSFERDIR enmDir, SHCLSOURCE enmSource, PSHCLTRANSFER *ppTransfer);
234int shClSvcTransferStop(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
235bool shClSvcTransferMsgIsAllowed(uint32_t uMode, uint32_t uMsg);
236void shClSvcClientTransfersReset(PSHCLCLIENT pClient);
237#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
238
239/** @name Platform-dependent implementations for the Shared Clipboard host service, called *only* by the host service.
240 * @{
241 */
242/**
243 * Called on initialization.
244 */
245int ShClSvcImplInit(void);
246/**
247 * Called on destruction.
248 */
249void ShClSvcImplDestroy(void);
250/**
251 * Called when a new HGCM client connects.
252 *
253 * @returns VBox status code.
254 * @param pClient Shared Clipboard client context.
255 * @param fHeadless Whether this is a headless connection or not.
256 */
257int ShClSvcImplConnect(PSHCLCLIENT pClient, bool fHeadless);
258/**
259 * Called when a HGCM client disconnects.
260 *
261 * @returns VBox status code.
262 * @param pClient Shared Clipboard client context.
263 */
264int ShClSvcImplDisconnect(PSHCLCLIENT pClient);
265/**
266 * Called when the guest reported available clipboard formats to the host OS.
267 *
268 * @returns VBox status code.
269 * @param pClient Shared Clipboard client context.
270 * @param pCmdCtx Shared Clipboard command context.
271 * @param pFormats Announced formats from the guest.
272 */
273int ShClSvcImplFormatAnnounce(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLFORMATDATA pFormats);
274/** @todo Document: Can return VINF_HGCM_ASYNC_EXECUTE to defer returning read data.*/
275/**
276 * Called when the guest wants to read host clipboard data.
277 *
278 * @returns VBox status code.
279 * @param pClient Shared Clipboard client context.
280 * @param pCmdCtx Shared Clipboard command context.
281 * @param pData Where to return the read clipboard data.
282 * @param pcbActual Where to return the amount of bytes read.
283 */
284int ShClSvcImplReadData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLDATABLOCK pData, uint32_t *pcbActual);
285/**
286 * Called when the guest writes clipboard data to the host.
287 *
288 * @returns VBox status code.
289 * @param pClient Shared Clipboard client context.
290 * @param pCmdCtx Shared Clipboard command context.
291 * @param pData Clipboard data from the guest.
292 */
293int ShClSvcImplWriteData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLDATABLOCK pData);
294/**
295 * Called when synchronization of the clipboard contents of the host clipboard with the guest is needed.
296 *
297 * @returns VBox status code.
298 * @param pClient Shared Clipboard client context.
299 */
300int ShClSvcImplSync(PSHCLCLIENT pClient);
301/** @} */
302
303#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
304/** @name Host implementations for Shared Clipboard transfers.
305 * @{
306 */
307/**
308 * Called when a transfer gets created.
309 *
310 * @returns VBox status code.
311 * @param pClient Shared Clipboard client context.
312 * @param pTransfer Shared Clipboard transfer created.
313 */
314int ShClSvcImplTransferCreate(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
315/**
316 * Called when a transfer gets destroyed.
317 *
318 * @returns VBox status code.
319 * @param pClient Shared Clipboard client context.
320 * @param pTransfer Shared Clipboard transfer to destroy.
321 */
322int ShClSvcImplTransferDestroy(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
323/**
324 * Called when getting (determining) the transfer roots on the host side.
325 *
326 * @returns VBox status code.
327 * @param pClient Shared Clipboard client context.
328 * @param pTransfer Shared Clipboard transfer to get roots for.
329 */
330int ShClSvcImplTransferGetRoots(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
331/** @} */
332#endif
333
334#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
335/** @name Internal Shared Clipboard transfer host service functions.
336 * @{
337 */
338int shClSvcTransferAreaDetach(PSHCLCLIENTSTATE pClientState, PSHCLTRANSFER pTransfer);
339int shClSvcTransferHandler(PSHCLCLIENT pClient, VBOXHGCMCALLHANDLE callHandle, uint32_t u32Function,
340 uint32_t cParms, VBOXHGCMSVCPARM paParms[], uint64_t tsArrival);
341int shClSvcTransferHostHandler(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
342/** @} */
343
344/** @name Shared Clipboard transfer interface implementations for the host service.
345 * @{
346 */
347int shClSvcTransferIfaceOpen(PSHCLPROVIDERCTX pCtx);
348int shClSvcTransferIfaceClose(PSHCLPROVIDERCTX pCtx);
349
350int shClSvcTransferIfaceGetRoots(PSHCLPROVIDERCTX pCtx, PSHCLROOTLIST *ppRootList);
351
352int shClSvcTransferIfaceListOpen(PSHCLPROVIDERCTX pCtx, PSHCLLISTOPENPARMS pOpenParms, PSHCLLISTHANDLE phList);
353int shClSvcTransferIfaceListClose(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList);
354int shClSvcTransferIfaceListHdrRead(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
355int shClSvcTransferIfaceListHdrWrite(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
356int shClSvcTransferIfaceListEntryRead(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
357int shClSvcTransferIfaceListEntryWrite(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
358
359int shClSvcTransferIfaceObjOpen(PSHCLPROVIDERCTX pCtx, PSHCLOBJOPENCREATEPARMS pCreateParms,
360 PSHCLOBJHANDLE phObj);
361int shClSvcTransferIfaceObjClose(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj);
362int shClSvcTransferIfaceObjRead(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
363 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbRead);
364int shClSvcTransferIfaceObjWrite(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
365 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbWritten);
366/** @} */
367
368/** @name Shared Clipboard transfer callbacks for the host service.
369 * @{
370 */
371DECLCALLBACK(void) VBoxSvcClipboardTransferPrepareCallback(PSHCLTRANSFERCALLBACKDATA pData);
372DECLCALLBACK(void) VBoxSvcClipboardDataHeaderCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData);
373DECLCALLBACK(void) VBoxSvcClipboardDataCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData);
374DECLCALLBACK(void) VBoxSvcClipboardTransferCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData, int rc);
375DECLCALLBACK(void) VBoxSvcClipboardTransferCanceledCallback(PSHCLTRANSFERCALLBACKDATA pData);
376DECLCALLBACK(void) VBoxSvcClipboardTransferErrorCallback(PSHCLTRANSFERCALLBACKDATA pData, int rc);
377/** @} */
378#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
379
380/* Host unit testing interface */
381#ifdef UNIT_TEST
382uint32_t TestClipSvcGetMode(void);
383#endif
384
385#endif /* !VBOX_INCLUDED_SRC_SharedClipboard_VBoxSharedClipboardSvc_internal_h */
386
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