VirtualBox

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

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

iprt/cdefs.h,*: Introducing RT_FLEXIBLE_ARRAY_EXTENSION as a g++ hack that allows us to use RT_FLEXIBLE_ARRAY without the compiler going all pendantic on us. Only tested with 10.1.0. bugref:9746

  • 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 84509 2020-05-25 15:09:24Z 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 * 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 /** Chunk size to use for data transfers. */
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 /** The critical section protecting the queue, event source and whatnot. */
141 RTCRITSECT CritSect;
142 /** The client's message queue (SHCLCLIENTMSG). */
143 RTLISTANCHOR MsgQueue;
144 /** Number of allocated messages (updated atomically, not under critsect). */
145 uint32_t volatile cAllocatedMessages;
146 /** The client's own event source.
147 * Needed for events which are not bound to a specific transfer. */
148 SHCLEVENTSOURCE EventSrc;
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 fDelayedFormats;
212} SHCLEXTSTATE, *PSHCLEXTSTATE;
213
214int shClSvcSetSource(PSHCLCLIENT pClient, SHCLSOURCE enmSource);
215
216void shClSvcMsgQueueReset(PSHCLCLIENT pClient);
217PSHCLCLIENTMSG shClSvcMsgAlloc(PSHCLCLIENT pClient, uint32_t uMsg, uint32_t cParms);
218void shClSvcMsgFree(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg);
219void shClSvcMsgAdd(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg, bool fAppend);
220int shClSvcMsgAddAndWakeupClient(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg);
221
222int shClSvcClientInit(PSHCLCLIENT pClient, uint32_t uClientID);
223void shClSvcClientDestroy(PSHCLCLIENT pClient);
224void shClSvcClientReset(PSHCLCLIENT pClient);
225
226int shClSvcClientStateInit(PSHCLCLIENTSTATE pClientState, uint32_t uClientID);
227int shClSvcClientStateDestroy(PSHCLCLIENTSTATE pClientState);
228void shclSvcClientStateReset(PSHCLCLIENTSTATE pClientState);
229
230int shClSvcClientWakeup(PSHCLCLIENT pClient);
231
232# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
233int shClSvcTransferModeSet(uint32_t fMode);
234int shClSvcTransferStart(PSHCLCLIENT pClient, SHCLTRANSFERDIR enmDir, SHCLSOURCE enmSource, PSHCLTRANSFER *ppTransfer);
235int shClSvcTransferStop(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
236bool shClSvcTransferMsgIsAllowed(uint32_t uMode, uint32_t uMsg);
237void shClSvcClientTransfersReset(PSHCLCLIENT pClient);
238#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
239
240/** @name Service functions, accessible by the backends.
241 * Locking is between the (host) service thread and the platform-dependent (window) thread.
242 * @{
243 */
244int ShClSvcDataReadRequest(PSHCLCLIENT pClient, SHCLFORMATS fFormats, PSHCLEVENTID pidEvent);
245int ShClSvcDataReadSignal(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat, void *pvData, uint32_t cbData);
246int ShClSvcHostReportFormats(PSHCLCLIENT pClient, SHCLFORMATS fFormats);
247uint32_t ShClSvcGetMode(void);
248bool ShClSvcGetHeadless(void);
249bool ShClSvcLock(void);
250void ShClSvcUnlock(void);
251/** @} */
252
253
254/** @name Platform-dependent implementations for the Shared Clipboard host service, called *only* by the host service.
255 * @{
256 */
257/**
258 * Called on initialization.
259 */
260int ShClBackendInit(void);
261/**
262 * Called on destruction.
263 */
264void ShClBackendDestroy(void);
265/**
266 * Called when a new HGCM client connects.
267 *
268 * @returns VBox status code.
269 * @param pClient Shared Clipboard client context.
270 * @param fHeadless Whether this is a headless connection or not.
271 */
272int ShClBackendConnect(PSHCLCLIENT pClient, bool fHeadless);
273/**
274 * Called when a HGCM client disconnects.
275 *
276 * @returns VBox status code.
277 * @param pClient Shared Clipboard client context.
278 */
279int ShClBackendDisconnect(PSHCLCLIENT pClient);
280/**
281 * Called when the guest reported available clipboard formats to the host OS.
282 *
283 * @returns VBox status code.
284 * @param pClient Shared Clipboard client context.
285 * @param fFormats The announced formats from the guest,
286 * VBOX_SHCL_FMT_XXX.
287 */
288int ShClBackendFormatAnnounce(PSHCLCLIENT pClient, SHCLFORMATS fFormats);
289/** @todo Document: Can return VINF_HGCM_ASYNC_EXECUTE to defer returning read data.*/
290/**
291 * Called when the guest wants to read host clipboard data.
292 *
293 * @returns VBox status code.
294 * @param pClient Shared Clipboard client context.
295 * @param pCmdCtx Shared Clipboard command context.
296 * @param uFormat Clipboard format to read.
297 * @param pvData Where to return the read clipboard data.
298 * @param cbData Size (in bytes) of buffer where to return the clipboard data.
299 * @param pcbActual Where to return the amount of bytes read.
300 */
301int ShClBackendReadData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat, void *pvData, uint32_t cbData, uint32_t *pcbActual);
302/**
303 * Called when the guest writes clipboard data to the host.
304 *
305 * @returns VBox status code.
306 * @param pClient Shared Clipboard client context.
307 * @param pCmdCtx Shared Clipboard command context.
308 * @param uFormat Clipboard format to write.
309 * @param pvData Clipboard data to write.
310 * @param cbData Size (in bytes) of buffer clipboard data to write.
311 */
312int ShClBackendWriteData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, SHCLFORMAT uFormat, void *pvData, uint32_t cbData);
313/**
314 * Called when synchronization of the clipboard contents of the host clipboard with the guest is needed.
315 *
316 * @returns VBox status code.
317 * @param pClient Shared Clipboard client context.
318 */
319int ShClBackendSync(PSHCLCLIENT pClient);
320/** @} */
321
322#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
323/** @name Host implementations for Shared Clipboard transfers.
324 * @{
325 */
326/**
327 * Called when a transfer gets created.
328 *
329 * @returns VBox status code.
330 * @param pClient Shared Clipboard client context.
331 * @param pTransfer Shared Clipboard transfer created.
332 */
333int ShClBackendTransferCreate(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
334/**
335 * Called when a transfer gets destroyed.
336 *
337 * @returns VBox status code.
338 * @param pClient Shared Clipboard client context.
339 * @param pTransfer Shared Clipboard transfer to destroy.
340 */
341int ShClBackendTransferDestroy(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
342/**
343 * Called when getting (determining) the transfer roots on the host side.
344 *
345 * @returns VBox status code.
346 * @param pClient Shared Clipboard client context.
347 * @param pTransfer Shared Clipboard transfer to get roots for.
348 */
349int ShClBackendTransferGetRoots(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
350/** @} */
351#endif
352
353#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
354/** @name Internal Shared Clipboard transfer host service functions.
355 * @{
356 */
357int shClSvcTransferAreaDetach(PSHCLCLIENTSTATE pClientState, PSHCLTRANSFER pTransfer);
358int shClSvcTransferHandler(PSHCLCLIENT pClient, VBOXHGCMCALLHANDLE callHandle, uint32_t u32Function,
359 uint32_t cParms, VBOXHGCMSVCPARM paParms[], uint64_t tsArrival);
360int shClSvcTransferHostHandler(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
361/** @} */
362
363/** @name Shared Clipboard transfer interface implementations for the host service.
364 * @{
365 */
366int shClSvcTransferIfaceOpen(PSHCLPROVIDERCTX pCtx);
367int shClSvcTransferIfaceClose(PSHCLPROVIDERCTX pCtx);
368
369int shClSvcTransferIfaceGetRoots(PSHCLPROVIDERCTX pCtx, PSHCLROOTLIST *ppRootList);
370
371int shClSvcTransferIfaceListOpen(PSHCLPROVIDERCTX pCtx, PSHCLLISTOPENPARMS pOpenParms, PSHCLLISTHANDLE phList);
372int shClSvcTransferIfaceListClose(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList);
373int shClSvcTransferIfaceListHdrRead(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
374int shClSvcTransferIfaceListHdrWrite(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
375int shClSvcTransferIfaceListEntryRead(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
376int shClSvcTransferIfaceListEntryWrite(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
377
378int shClSvcTransferIfaceObjOpen(PSHCLPROVIDERCTX pCtx, PSHCLOBJOPENCREATEPARMS pCreateParms,
379 PSHCLOBJHANDLE phObj);
380int shClSvcTransferIfaceObjClose(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj);
381int shClSvcTransferIfaceObjRead(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
382 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbRead);
383int shClSvcTransferIfaceObjWrite(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
384 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbWritten);
385/** @} */
386
387/** @name Shared Clipboard transfer callbacks for the host service.
388 * @{
389 */
390DECLCALLBACK(void) VBoxSvcClipboardTransferPrepareCallback(PSHCLTRANSFERCALLBACKDATA pData);
391DECLCALLBACK(void) VBoxSvcClipboardDataHeaderCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData);
392DECLCALLBACK(void) VBoxSvcClipboardDataCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData);
393DECLCALLBACK(void) VBoxSvcClipboardTransferCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData, int rc);
394DECLCALLBACK(void) VBoxSvcClipboardTransferCanceledCallback(PSHCLTRANSFERCALLBACKDATA pData);
395DECLCALLBACK(void) VBoxSvcClipboardTransferErrorCallback(PSHCLTRANSFERCALLBACKDATA pData, int rc);
396/** @} */
397#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
398
399/* Host unit testing interface */
400#ifdef UNIT_TEST
401uint32_t TestClipSvcGetMode(void);
402#endif
403
404#endif /* !VBOX_INCLUDED_SRC_SharedClipboard_VBoxSharedClipboardSvc_internal_h */
405
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