VirtualBox

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

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

Shared Clipboard: Renaming. bugref:9437

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