VirtualBox

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

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

VBoxClipboardSvc: More save state cleanup. bugref:9437

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