VirtualBox

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

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

Shared Clipboard/HostService: Renaming to match terminology (*SvcImpl* -> *Backend*).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.1 KB
Line 
1/* $Id: VBoxSharedClipboardSvc-internal.h 84142 2020-05-05 07:13:00Z 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 VBOXHGCMSVCPARM aParms[RT_FLEXIBLE_ARRAY];
60} SHCLCLIENTMSG;
61/** Pointer to a queue message for the guest. */
62typedef SHCLCLIENTMSG *PSHCLCLIENTMSG;
63
64typedef struct SHCLCLIENTTRANSFERSTATE
65{
66 /** Directory of the transfer to start. */
67 SHCLTRANSFERDIR enmTransferDir;
68} SHCLCLIENTTRANSFERSTATE, *PSHCLCLIENTTRANSFERSTATE;
69
70/**
71 * Structure for holding a single POD (plain old data) transfer.
72 *
73 * This mostly is plain text, but also can be stuff like bitmap (BMP) or other binary data.
74 */
75typedef struct SHCLCLIENTPODSTATE
76{
77 /** POD transfer direction. */
78 SHCLTRANSFERDIR enmDir;
79 /** Format of the data to be read / written. */
80 SHCLFORMAT uFormat;
81 /** How much data (in bytes) to read/write for the current operation. */
82 uint64_t cbToReadWriteTotal;
83 /** How much data (in bytes) already has been read/written for the current operation. */
84 uint64_t cbReadWritten;
85 /** Timestamp (in ms) of Last read/write operation. */
86 uint64_t tsLastReadWrittenMs;
87} SHCLCLIENTPODSTATE, *PSHCLCLIENTPODSTATE;
88
89/** @name SHCLCLIENTSTATE_FLAGS_XXX
90 * @note Part of saved state! */
91/** No Shared Clipboard client flags defined. */
92#define SHCLCLIENTSTATE_FLAGS_NONE 0
93/** Client has a guest read operation active. Currently unused. */
94#define SHCLCLIENTSTATE_FLAGS_READ_ACTIVE RT_BIT(0)
95/** Client has a guest write operation active. Currently unused. */
96#define SHCLCLIENTSTATE_FLAGS_WRITE_ACTIVE RT_BIT(1)
97/** @} */
98
99/**
100 * Structure for keeping generic client state data within the Shared Clipboard host service.
101 * This structure needs to be serializable by SSM (must be a POD type).
102 */
103typedef struct SHCLCLIENTSTATE
104{
105 struct SHCLCLIENTSTATE *pNext;
106 struct SHCLCLIENTSTATE *pPrev;
107
108 SHCLCONTEXT *pCtx;
109
110 /** The client's HGCM ID. Not related to the session ID below! */
111 uint32_t uClientID;
112 /** The client's session ID. */
113 SHCLSESSIONID uSessionID;
114 /** Guest feature flags, VBOX_SHCL_GF_0_XXX. */
115 uint64_t fGuestFeatures0;
116 /** Guest feature flags, VBOX_SHCL_GF_1_XXX. */
117 uint64_t fGuestFeatures1;
118 /** Chunk size to use for data transfers. */
119 uint32_t cbChunkSize;
120 /** Where the transfer sources its data from. */
121 SHCLSOURCE enmSource;
122 /** Client state flags of type SHCLCLIENTSTATE_FLAGS_. */
123 uint32_t fFlags;
124 /** POD (plain old data) state. */
125 SHCLCLIENTPODSTATE POD;
126 /** The client's transfers state. */
127 SHCLCLIENTTRANSFERSTATE Transfers;
128} SHCLCLIENTSTATE, *PSHCLCLIENTSTATE;
129
130typedef struct _SHCLCLIENTCMDCTX
131{
132 uint64_t uContextID;
133} SHCLCLIENTCMDCTX, *PSHCLCLIENTCMDCTX;
134
135typedef struct _SHCLCLIENT
136{
137 /** General client state data. */
138 SHCLCLIENTSTATE State;
139 /** The critical section protecting the queue, event source and whatnot. */
140 RTCRITSECT CritSect;
141 /** The client's message queue (SHCLCLIENTMSG). */
142 RTLISTANCHOR MsgQueue;
143 /** Number of allocated messages (updated atomically, not under critsect). */
144 uint32_t volatile cAllocatedMessages;
145 /** The client's own event source.
146 * Needed for events which are not bound to a specific transfer. */
147 SHCLEVENTSOURCE EventSrc;
148#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
149 /** Transfer contextdata. */
150 SHCLTRANSFERCTX TransferCtx;
151#endif
152 /** Structure for keeping the client's pending (deferred return) state.
153 * A client is in a deferred state when it asks for the next HGCM message,
154 * but the service can't provide it yet. That way a client will block (on the guest side, does not return)
155 * until the service can complete the call. */
156 struct
157 {
158 /** The client's HGCM call handle. Needed for completing a deferred call. */
159 VBOXHGCMCALLHANDLE hHandle;
160 /** Message type (function number) to use when completing the deferred call.
161 * A non-0 value means the client is in pending mode. */
162 uint32_t uType;
163 /** Parameter count to use when completing the deferred call. */
164 uint32_t cParms;
165 /** Parameters to use when completing the deferred call. */
166 PVBOXHGCMSVCPARM paParms;
167 } Pending;
168} SHCLCLIENT, *PSHCLCLIENT;
169
170/**
171 * Structure for keeping a single event source map entry.
172 * Currently empty.
173 */
174typedef struct _SHCLEVENTSOURCEMAPENTRY
175{
176} SHCLEVENTSOURCEMAPENTRY;
177
178/** Map holding information about connected HGCM clients. Key is the (unique) HGCM client ID.
179 * The value is a weak pointer to PSHCLCLIENT, which is owned by HGCM. */
180typedef std::map<uint32_t, PSHCLCLIENT> ClipboardClientMap;
181
182/** Map holding information about event sources. Key is the (unique) event source ID. */
183typedef std::map<SHCLEVENTSOURCEID, SHCLEVENTSOURCEMAPENTRY> ClipboardEventSourceMap;
184
185/** Simple queue (list) which holds deferred (waiting) clients. */
186typedef std::list<uint32_t> ClipboardClientQueue;
187
188/**
189 * Structure for keeping the Shared Clipboard service extension state.
190 *
191 * A service extension is optional, and can be installed by a host component
192 * to communicate with the Shared Clipboard host service.
193 */
194typedef struct _SHCLEXTSTATE
195{
196 /** Pointer to the actual service extension handle. */
197 PFNHGCMSVCEXT pfnExtension;
198 /** Opaque pointer to extension-provided data. Don't touch. */
199 void *pvExtension;
200 /** The HGCM client ID currently assigned to this service extension.
201 * At the moment only one HGCM client can be assigned per extension. */
202 uint32_t uClientID;
203 /** Whether the host service is reading clipboard data currently. */
204 bool fReadingData;
205 /** Whether the service extension has sent the clipboard formats while
206 * the the host service is reading clipboard data from it. */
207 bool fDelayedAnnouncement;
208 /** The actual clipboard formats announced while the host service
209 * is reading clipboard data from the extension. */
210 uint32_t fDelayedFormats;
211} SHCLEXTSTATE, *PSHCLEXTSTATE;
212
213int shClSvcSetSource(PSHCLCLIENT pClient, SHCLSOURCE enmSource);
214
215void shClSvcMsgQueueReset(PSHCLCLIENT pClient);
216PSHCLCLIENTMSG shClSvcMsgAlloc(PSHCLCLIENT pClient, uint32_t uMsg, uint32_t cParms);
217void shClSvcMsgFree(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg);
218void shClSvcMsgAdd(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg, bool fAppend);
219int shClSvcMsgAddAndWakeupClient(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg);
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 Service functions, accessible by the backends.
240 * Locking is between the (host) service thread and the platform-dependent (window) thread.
241 * @{
242 */
243int ShClSvcDataReadRequest(PSHCLCLIENT pClient, SHCLFORMATS fFormats, PSHCLEVENTID pidEvent);
244int ShClSvcDataReadSignal(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat, void *pvData, uint32_t cbData);
245int ShClSvcHostReportFormats(PSHCLCLIENT pClient, SHCLFORMATS fFormats);
246uint32_t ShClSvcGetMode(void);
247bool ShClSvcGetHeadless(void);
248bool ShClSvcLock(void);
249void ShClSvcUnlock(void);
250/** @} */
251
252
253/** @name Platform-dependent implementations for the Shared Clipboard host service, called *only* by the host service.
254 * @{
255 */
256/**
257 * Called on initialization.
258 */
259int ShClBackendInit(void);
260/**
261 * Called on destruction.
262 */
263void ShClBackendDestroy(void);
264/**
265 * Called when a new HGCM client connects.
266 *
267 * @returns VBox status code.
268 * @param pClient Shared Clipboard client context.
269 * @param fHeadless Whether this is a headless connection or not.
270 */
271int ShClBackendConnect(PSHCLCLIENT pClient, bool fHeadless);
272/**
273 * Called when a HGCM client disconnects.
274 *
275 * @returns VBox status code.
276 * @param pClient Shared Clipboard client context.
277 */
278int ShClBackendDisconnect(PSHCLCLIENT pClient);
279/**
280 * Called when the guest reported available clipboard formats to the host OS.
281 *
282 * @returns VBox status code.
283 * @param pClient Shared Clipboard client context.
284 * @param fFormats The announced formats from the guest,
285 * VBOX_SHCL_FMT_XXX.
286 */
287int ShClBackendFormatAnnounce(PSHCLCLIENT pClient, SHCLFORMATS fFormats);
288/** @todo Document: Can return VINF_HGCM_ASYNC_EXECUTE to defer returning read data.*/
289/**
290 * Called when the guest wants to read host clipboard data.
291 *
292 * @returns VBox status code.
293 * @param pClient Shared Clipboard client context.
294 * @param pCmdCtx Shared Clipboard command context.
295 * @param uFormat Clipboard format to read.
296 * @param pvData Where to return the read clipboard data.
297 * @param cbData Size (in bytes) of buffer where to return the clipboard data.
298 * @param pcbActual Where to return the amount of bytes read.
299 */
300int ShClBackendReadData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat, void *pvData, uint32_t cbData, 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 uFormat Clipboard format to write.
308 * @param pvData Clipboard data to write.
309 * @param cbData Size (in bytes) of buffer clipboard data to write.
310 */
311int ShClBackendWriteData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat, void *pvData, uint32_t cbData);
312/**
313 * Called when synchronization of the clipboard contents of the host clipboard with the guest is needed.
314 *
315 * @returns VBox status code.
316 * @param pClient Shared Clipboard client context.
317 */
318int ShClBackendSync(PSHCLCLIENT pClient);
319/** @} */
320
321#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
322/** @name Host implementations for Shared Clipboard transfers.
323 * @{
324 */
325/**
326 * Called when a transfer gets created.
327 *
328 * @returns VBox status code.
329 * @param pClient Shared Clipboard client context.
330 * @param pTransfer Shared Clipboard transfer created.
331 */
332int ShClBackendTransferCreate(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
333/**
334 * Called when a transfer gets destroyed.
335 *
336 * @returns VBox status code.
337 * @param pClient Shared Clipboard client context.
338 * @param pTransfer Shared Clipboard transfer to destroy.
339 */
340int ShClBackendTransferDestroy(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
341/**
342 * Called when getting (determining) the transfer roots on the host side.
343 *
344 * @returns VBox status code.
345 * @param pClient Shared Clipboard client context.
346 * @param pTransfer Shared Clipboard transfer to get roots for.
347 */
348int ShClBackendTransferGetRoots(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
349/** @} */
350#endif
351
352#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
353/** @name Internal Shared Clipboard transfer host service functions.
354 * @{
355 */
356int shClSvcTransferAreaDetach(PSHCLCLIENTSTATE pClientState, PSHCLTRANSFER pTransfer);
357int shClSvcTransferHandler(PSHCLCLIENT pClient, VBOXHGCMCALLHANDLE callHandle, uint32_t u32Function,
358 uint32_t cParms, VBOXHGCMSVCPARM paParms[], uint64_t tsArrival);
359int shClSvcTransferHostHandler(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
360/** @} */
361
362/** @name Shared Clipboard transfer interface implementations for the host service.
363 * @{
364 */
365int shClSvcTransferIfaceOpen(PSHCLPROVIDERCTX pCtx);
366int shClSvcTransferIfaceClose(PSHCLPROVIDERCTX pCtx);
367
368int shClSvcTransferIfaceGetRoots(PSHCLPROVIDERCTX pCtx, PSHCLROOTLIST *ppRootList);
369
370int shClSvcTransferIfaceListOpen(PSHCLPROVIDERCTX pCtx, PSHCLLISTOPENPARMS pOpenParms, PSHCLLISTHANDLE phList);
371int shClSvcTransferIfaceListClose(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList);
372int shClSvcTransferIfaceListHdrRead(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
373int shClSvcTransferIfaceListHdrWrite(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
374int shClSvcTransferIfaceListEntryRead(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
375int shClSvcTransferIfaceListEntryWrite(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
376
377int shClSvcTransferIfaceObjOpen(PSHCLPROVIDERCTX pCtx, PSHCLOBJOPENCREATEPARMS pCreateParms,
378 PSHCLOBJHANDLE phObj);
379int shClSvcTransferIfaceObjClose(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj);
380int shClSvcTransferIfaceObjRead(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
381 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbRead);
382int shClSvcTransferIfaceObjWrite(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
383 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbWritten);
384/** @} */
385
386/** @name Shared Clipboard transfer callbacks for the host service.
387 * @{
388 */
389DECLCALLBACK(void) VBoxSvcClipboardTransferPrepareCallback(PSHCLTRANSFERCALLBACKDATA pData);
390DECLCALLBACK(void) VBoxSvcClipboardDataHeaderCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData);
391DECLCALLBACK(void) VBoxSvcClipboardDataCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData);
392DECLCALLBACK(void) VBoxSvcClipboardTransferCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData, int rc);
393DECLCALLBACK(void) VBoxSvcClipboardTransferCanceledCallback(PSHCLTRANSFERCALLBACKDATA pData);
394DECLCALLBACK(void) VBoxSvcClipboardTransferErrorCallback(PSHCLTRANSFERCALLBACKDATA pData, int rc);
395/** @} */
396#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
397
398/* Host unit testing interface */
399#ifdef UNIT_TEST
400uint32_t TestClipSvcGetMode(void);
401#endif
402
403#endif /* !VBOX_INCLUDED_SRC_SharedClipboard_VBoxSharedClipboardSvc_internal_h */
404
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