VirtualBox

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

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

Shared Clipboard/Transfers: Update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.1 KB
Line 
1/* $Id: VBoxSharedClipboardSvc-internal.h 80990 2019-09-25 06:20:09Z 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 uint32_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 keeping generic client state data within the Shared Clipboard host service.
77 * This structure needs to be serializable by SSM (must be a POD type).
78 */
79typedef struct SHCLCLIENTSTATE
80{
81 struct SHCLCLIENTSTATE *pNext;
82 struct SHCLCLIENTSTATE *pPrev;
83
84 SHCLCONTEXT *pCtx;
85
86 /** The client's HGCM ID. Not related to the session ID below! */
87 uint32_t uClientID;
88 /** The client's session ID. */
89 uint32_t uSessionID;
90 /** Optional protocol version the client uses. Set to 0 by default. */
91 uint32_t uProtocolVer;
92 /** Maximum chunk size to use for data transfers. Set to _64K by default. */
93 uint32_t cbChunkSize;
94 SHCLSOURCE enmSource;
95 /** The client's transfers state. */
96 SHCLCLIENTTRANSFERSTATE Transfers;
97} SHCLCLIENTSTATE, *PSHCLCLIENTSTATE;
98
99typedef struct _SHCLCLIENTCMDCTX
100{
101 uint32_t uContextID;
102} SHCLCLIENTCMDCTX, *PSHCLCLIENTCMDCTX;
103
104typedef struct _SHCLCLIENT
105{
106 /** General client state data. */
107 SHCLCLIENTSTATE State;
108 /** The client's message queue (FIFO). */
109 RTCList<SHCLCLIENTMSG *> queueMsg;
110 /** The client's own event source.
111 * Needed for events which are not bound to a specific transfer. */
112 SHCLEVENTSOURCE Events;
113#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
114 /** Transfer contextdata. */
115 SHCLTRANSFERCTX TransferCtx;
116#endif
117 /** Structure for keeping the client's pending (deferred return) state.
118 * A client is in a deferred state when it asks for the next HGCM message,
119 * but the service can't provide it yet. That way a client will block (on the guest side, does not return)
120 * until the service can complete the call. */
121 struct
122 {
123 /** The client's HGCM call handle. Needed for completing a deferred call. */
124 VBOXHGCMCALLHANDLE hHandle;
125 /** Message type (function number) to use when completing the deferred call.
126 * A non-0 value means the client is in pending mode. */
127 uint32_t uType;
128 /** Parameter count to use when completing the deferred call. */
129 uint32_t cParms;
130 /** Parameters to use when completing the deferred call. */
131 PVBOXHGCMSVCPARM paParms;
132 } Pending;
133} SHCLCLIENT, *PSHCLCLIENT;
134
135/**
136 * Structure for keeping a single event source map entry.
137 * Currently empty.
138 */
139typedef struct _SHCLEVENTSOURCEMAPENTRY
140{
141} SHCLEVENTSOURCEMAPENTRY;
142
143/** Map holding information about connected HGCM clients. Key is the (unique) HGCM client ID.
144 * The value is a weak pointer to PSHCLCLIENT, which is owned by HGCM. */
145typedef std::map<uint32_t, PSHCLCLIENT> ClipboardClientMap;
146
147/** Map holding information about event sources. Key is the (unique) event source ID. */
148typedef std::map<SHCLEVENTSOURCEID, SHCLEVENTSOURCEMAPENTRY> ClipboardEventSourceMap;
149
150/** Simple queue (list) which holds deferred (waiting) clients. */
151typedef std::list<uint32_t> ClipboardClientQueue;
152
153/**
154 * Structure for keeping the Shared Clipboard service extension state.
155 *
156 * A service extension is optional, and can be installed by a host component
157 * to communicate with the Shared Clipboard host service.
158 */
159typedef struct _SHCLEXTSTATE
160{
161 /** Pointer to the actual service extension handle. */
162 PFNHGCMSVCEXT pfnExtension;
163 /** Opaque pointer to extension-provided data. Don't touch. */
164 void *pvExtension;
165 /** The HGCM client ID currently assigned to this service extension.
166 * At the moment only one HGCM client can be assigned per extension. */
167 uint32_t uClientID;
168 /** Whether the host service is reading clipboard data currently. */
169 bool fReadingData;
170 /** Whether the service extension has sent the clipboard formats while
171 * the the host service is reading clipboard data from it. */
172 bool fDelayedAnnouncement;
173 /** The actual clipboard formats announced while the host service
174 * is reading clipboard data from the extension. */
175 uint32_t uDelayedFormats;
176} SHCLEXTSTATE, *PSHCLEXTSTATE;
177
178/*
179 * The service functions. Locking is between the service thread and the platform-dependent (window) thread.
180 */
181int sharedClipboardSvcDataReadRequest(PSHCLCLIENT pClient, PSHCLDATAREQ pDataReq, PSHCLEVENTID puEvent);
182int sharedClipboardSvcDataReadSignal(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLDATABLOCK pData);
183int sharedClipboardSvcFormatsReport(PSHCLCLIENT pClient, PSHCLFORMATDATA pFormats);
184
185uint32_t sharedClipboardSvcGetMode(void);
186int sharedClipboardSvcSetSource(PSHCLCLIENT pClient, SHCLSOURCE enmSource);
187
188void sharedClipboardSvcMsgQueueReset(PSHCLCLIENT pClient);
189PSHCLCLIENTMSG sharedClipboardSvcMsgAlloc(uint32_t uMsg, uint32_t cParms);
190void sharedClipboardSvcMsgFree(PSHCLCLIENTMSG pMsg);
191void sharedClipboardSvcMsgSetPeekReturn(PSHCLCLIENTMSG pMsg, PVBOXHGCMSVCPARM paDstParms, uint32_t cDstParms);
192int sharedClipboardSvcMsgAdd(PSHCLCLIENT pClient, PSHCLCLIENTMSG pMsg, bool fAppend);
193int sharedClipboardSvcMsgPeek(PSHCLCLIENT pClient, VBOXHGCMCALLHANDLE hCall, uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool fWait);
194int sharedClipboardSvcMsgGet(PSHCLCLIENT pClient, VBOXHGCMCALLHANDLE hCall, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
195
196int sharedClipboardSvcClientWakeup(PSHCLCLIENT pClient);
197
198# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
199int sharedClipboardSvcTransferStart(PSHCLCLIENT pClient,
200 SHCLTRANSFERDIR enmDir, SHCLSOURCE enmSource,
201 PSHCLTRANSFER *ppTransfer);
202int sharedClipboardSvcTransferStop(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
203bool sharedClipboardSvcTransferMsgIsAllowed(uint32_t uMode, uint32_t uMsg);
204# endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
205
206/*
207 * Platform-dependent implementations.
208 */
209int SharedClipboardSvcImplInit(void);
210void SharedClipboardSvcImplDestroy(void);
211
212int SharedClipboardSvcImplConnect(PSHCLCLIENT pClient, bool fHeadless);
213int SharedClipboardSvcImplDisconnect(PSHCLCLIENT pClient);
214int SharedClipboardSvcImplFormatAnnounce(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLFORMATDATA pFormats);
215/** @todo Document: Can return VINF_HGCM_ASYNC_EXECUTE to defer returning read data.*/
216int SharedClipboardSvcImplReadData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLDATABLOCK pData, uint32_t *pcbActual);
217int SharedClipboardSvcImplWriteData(PSHCLCLIENT pClient, PSHCLCLIENTCMDCTX pCmdCtx, PSHCLDATABLOCK pData);
218/**
219 * Synchronise the contents of the host clipboard with the guest, called by the HGCM layer
220 * after a save and restore of the guest.
221 */
222int SharedClipboardSvcImplSync(PSHCLCLIENT pClient);
223
224#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
225int sharedClipboardSvcTransferIfaceOpen(PSHCLPROVIDERCTX pCtx);
226int sharedClipboardSvcTransferIfaceClose(PSHCLPROVIDERCTX pCtx);
227
228int sharedClipboardSvcTransferIfaceGetRoots(PSHCLPROVIDERCTX pCtx, PSHCLROOTLIST *ppRootList);
229
230int sharedClipboardSvcTransferIfaceListOpen(PSHCLPROVIDERCTX pCtx, PSHCLLISTOPENPARMS pOpenParms, PSHCLLISTHANDLE phList);
231int sharedClipboardSvcTransferIfaceListClose(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList);
232int sharedClipboardSvcTransferIfaceListHdrRead(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
233int sharedClipboardSvcTransferIfaceListHdrWrite(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTHDR pListHdr);
234int sharedClipboardSvcTransferIfaceListEntryRead(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
235int sharedClipboardSvcTransferIfaceListEntryWrite(PSHCLPROVIDERCTX pCtx, SHCLLISTHANDLE hList, PSHCLLISTENTRY pListEntry);
236
237int sharedClipboardSvcTransferIfaceObjOpen(PSHCLPROVIDERCTX pCtx, PSHCLOBJOPENCREATEPARMS pCreateParms,
238 PSHCLOBJHANDLE phObj);
239int sharedClipboardSvcTransferIfaceObjClose(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj);
240int sharedClipboardSvcTransferIfaceObjRead(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
241 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbRead);
242int sharedClipboardSvcTransferIfaceObjWrite(PSHCLPROVIDERCTX pCtx, SHCLOBJHANDLE hObj,
243 void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbWritten);
244
245DECLCALLBACK(void) VBoxSvcClipboardTransferPrepareCallback(PSHCLTRANSFERCALLBACKDATA pData);
246DECLCALLBACK(void) VBoxSvcClipboardDataHeaderCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData);
247DECLCALLBACK(void) VBoxSvcClipboardDataCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData);
248DECLCALLBACK(void) VBoxSvcClipboardTransferCompleteCallback(PSHCLTRANSFERCALLBACKDATA pData, int rc);
249DECLCALLBACK(void) VBoxSvcClipboardTransferCanceledCallback(PSHCLTRANSFERCALLBACKDATA pData);
250DECLCALLBACK(void) VBoxSvcClipboardTransferErrorCallback(PSHCLTRANSFERCALLBACKDATA pData, int rc);
251
252int SharedClipboardSvcImplTransferCreate(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
253int SharedClipboardSvcImplTransferDestroy(PSHCLCLIENT pClient, PSHCLTRANSFER pTransfer);
254#endif /*VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
255
256/* Host unit testing interface */
257#ifdef UNIT_TEST
258uint32_t TestClipSvcGetMode(void);
259#endif
260
261#endif /* !VBOX_INCLUDED_SRC_SharedClipboard_VBoxSharedClipboardSvc_internal_h */
262
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