VirtualBox

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

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

Shared Clipboard/HostServices: Resolved more todos (removed READ_ACTIVE + WRITE_ACTIVE flag handling, too buggy for now).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.7 KB
Line 
1/* $Id: VBoxSharedClipboardSvc-internal.h 82872 2020-01-27 12:43: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 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, SHCLFORMAT fFormat, PSHCLEVENTID pidEvent);
244int ShClSvcDataReadSignal(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLDATABLOCK pData);
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 ShClSvcImplInit(void);
260/**
261 * Called on destruction.
262 */
263void ShClSvcImplDestroy(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 ShClSvcImplConnect(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 ShClSvcImplDisconnect(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 pCmdCtx Shared Clipboard command context.
285 * @param pFormats Announced formats from the guest.
286 */
287int ShClSvcImplFormatAnnounce(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLFORMATDATA pFormats);
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 pData Where to return the read clipboard data.
296 * @param pcbActual Where to return the amount of bytes read.
297 */
298int ShClSvcImplReadData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLDATABLOCK pData, uint32_t *pcbActual);
299/**
300 * Called when the guest writes clipboard data to the host.
301 *
302 * @returns VBox status code.
303 * @param pClient Shared Clipboard client context.
304 * @param pCmdCtx Shared Clipboard command context.
305 * @param pData Clipboard data from the guest.
306 */
307int ShClSvcImplWriteData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLDATABLOCK pData);
308/**
309 * Called when synchronization of the clipboard contents of the host clipboard with the guest is needed.
310 *
311 * @returns VBox status code.
312 * @param pClient Shared Clipboard client context.
313 */
314int ShClSvcImplSync(PSHCLCLIENT pClient);
315/** @} */
316
317#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
318/** @name Host implementations for Shared Clipboard transfers.
319 * @{
320 */
321/**
322 * Called when a transfer gets created.
323 *
324 * @returns VBox status code.
325 * @param pClient Shared Clipboard client context.
326 * @param pTransfer Shared Clipboard transfer created.
327 */
328int ShClSvcImplTransferCreate(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
329/**
330 * Called when a transfer gets destroyed.
331 *
332 * @returns VBox status code.
333 * @param pClient Shared Clipboard client context.
334 * @param pTransfer Shared Clipboard transfer to destroy.
335 */
336int ShClSvcImplTransferDestroy(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
337/**
338 * Called when getting (determining) the transfer roots on the host side.
339 *
340 * @returns VBox status code.
341 * @param pClient Shared Clipboard client context.
342 * @param pTransfer Shared Clipboard transfer to get roots for.
343 */
344int ShClSvcImplTransferGetRoots(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
345/** @} */
346#endif
347
348#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
349/** @name Internal Shared Clipboard transfer host service functions.
350 * @{
351 */
352int shClSvcTransferAreaDetach(PSHCLCLIENTSTATE pClientState, PSHCLTRANSFER pTransfer);
353int shClSvcTransferHandler(PSHCLCLIENT pClient, VBOXHGCMCALLHANDLE callHandle, uint32_t u32Function,
354 uint32_t cParms, VBOXHGCMSVCPARM paParms[], uint64_t tsArrival);
355int shClSvcTransferHostHandler(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
356/** @} */
357
358/** @name Shared Clipboard transfer interface implementations for the host service.
359 * @{
360 */
361int shClSvcTransferIfaceOpen(PSHCLPROVIDERCTX pCtx);
362int shClSvcTransferIfaceClose(PSHCLPROVIDERCTX pCtx);
363
364int shClSvcTransferIfaceGetRoots(PSHCLPROVIDERCTX pCtx, PSHCLROOTLIST *ppRootList);
365
366int shClSvcTransferIfaceListOpen(PSHCLPROVIDERCTX pCtx, PSHCLLISTOPENPARMS pOpenParms, PSHCLLISTHANDLE phList);
367int shClSvcTransferIfaceListClose(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList);
368int shClSvcTransferIfaceListHdrRead(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
369int shClSvcTransferIfaceListHdrWrite(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
370int shClSvcTransferIfaceListEntryRead(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
371int shClSvcTransferIfaceListEntryWrite(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
372
373int shClSvcTransferIfaceObjOpen(PSHCLPROVIDERCTX pCtx, PSHCLOBJOPENCREATEPARMS pCreateParms,
374 PSHCLOBJHANDLE phObj);
375int shClSvcTransferIfaceObjClose(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj);
376int shClSvcTransferIfaceObjRead(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
377 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbRead);
378int shClSvcTransferIfaceObjWrite(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
379 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbWritten);
380/** @} */
381
382/** @name Shared Clipboard transfer callbacks for the host service.
383 * @{
384 */
385DECLCALLBACK(void) VBoxSvcClipboardTransferPrepareCallback(PSHCLTRANSFERCALLBACKDATA pData);
386DECLCALLBACK(void) VBoxSvcClipboardDataHeaderCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData);
387DECLCALLBACK(void) VBoxSvcClipboardDataCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData);
388DECLCALLBACK(void) VBoxSvcClipboardTransferCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData, int rc);
389DECLCALLBACK(void) VBoxSvcClipboardTransferCanceledCallback(PSHCLTRANSFERCALLBACKDATA pData);
390DECLCALLBACK(void) VBoxSvcClipboardTransferErrorCallback(PSHCLTRANSFERCALLBACKDATA pData, int rc);
391/** @} */
392#endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
393
394/* Host unit testing interface */
395#ifdef UNIT_TEST
396uint32_t TestClipSvcGetMode(void);
397#endif
398
399#endif /* !VBOX_INCLUDED_SRC_SharedClipboard_VBoxSharedClipboardSvc_internal_h */
400
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