1 | /* $Id: VBoxSharedClipboardSvc-internal.h 79631 2019-07-09 08:23: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/list.h>
|
---|
29 | #include <iprt/cpp/list.h> /* For RTCList. */
|
---|
30 |
|
---|
31 | #include <VBox/hgcmsvc.h>
|
---|
32 | #include <VBox/log.h>
|
---|
33 |
|
---|
34 | #include <VBox/HostServices/Service.h>
|
---|
35 | #include <VBox/GuestHost/SharedClipboard.h>
|
---|
36 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
|
---|
37 | # include <iprt/semaphore.h>
|
---|
38 | # include <VBox/GuestHost/SharedClipboard-uri.h>
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | using namespace HGCM;
|
---|
42 |
|
---|
43 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
|
---|
44 | struct VBOXCLIPBOARDCLIENTSTATE;
|
---|
45 | #endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
|
---|
46 |
|
---|
47 | typedef struct _VBOXCLIPBOARDCLIENTMSG
|
---|
48 | {
|
---|
49 | /** Stored message type. */
|
---|
50 | uint32_t m_uMsg;
|
---|
51 | /** Number of stored HGCM parameters. */
|
---|
52 | uint32_t m_cParms;
|
---|
53 | /** Stored HGCM parameters. */
|
---|
54 | PVBOXHGCMSVCPARM m_paParms;
|
---|
55 | } VBOXCLIPBOARDCLIENTMSG, *PVBOXCLIPBOARDCLIENTMSG;
|
---|
56 |
|
---|
57 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
|
---|
58 | typedef struct VBOXCLIPBOARDCLIENTURISTATE
|
---|
59 | {
|
---|
60 | /** Whether to start a new transfer. */
|
---|
61 | bool fTransferStart;
|
---|
62 | /** Directory of the transfer to start. */
|
---|
63 | SHAREDCLIPBOARDURITRANSFERDIR enmTransferDir;
|
---|
64 | } VBOXCLIPBOARDCLIENTURISTATE, *PVBOXCLIPBOARDCLIENTURISTATE;
|
---|
65 | #endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Structure for keeping generic client state data within the Shared Clipboard host service.
|
---|
69 | * This structure needs to be serializable by SSM (must be a POD type).
|
---|
70 | */
|
---|
71 | typedef struct VBOXCLIPBOARDCLIENTSTATE
|
---|
72 | {
|
---|
73 | struct VBOXCLIPBOARDCLIENTSTATE *pNext;
|
---|
74 | struct VBOXCLIPBOARDCLIENTSTATE *pPrev;
|
---|
75 |
|
---|
76 | VBOXCLIPBOARDCONTEXT *pCtx;
|
---|
77 |
|
---|
78 | uint32_t u32ClientID;
|
---|
79 |
|
---|
80 | SHAREDCLIPBOARDSOURCE enmSource;
|
---|
81 |
|
---|
82 | /** The guest is waiting for a message. */
|
---|
83 | bool fAsync;
|
---|
84 | /** The guest is waiting for data from the host */
|
---|
85 | bool fReadPending;
|
---|
86 | /** Whether the host host has sent a quit message. */
|
---|
87 | bool fHostMsgQuit;
|
---|
88 | /** Whether the host host has requested reading clipboard data from the guest. */
|
---|
89 | bool fHostMsgReadData;
|
---|
90 | /** Whether the host host has reported its available formats. */
|
---|
91 | bool fHostMsgFormats;
|
---|
92 |
|
---|
93 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
|
---|
94 | /** The client's URI state. */
|
---|
95 | VBOXCLIPBOARDCLIENTURISTATE URI;
|
---|
96 | #endif
|
---|
97 |
|
---|
98 | struct {
|
---|
99 | VBOXHGCMCALLHANDLE callHandle;
|
---|
100 | uint32_t cParms;
|
---|
101 | VBOXHGCMSVCPARM *paParms;
|
---|
102 | } async;
|
---|
103 |
|
---|
104 | struct {
|
---|
105 | VBOXHGCMCALLHANDLE callHandle;
|
---|
106 | uint32_t cParms;
|
---|
107 | VBOXHGCMSVCPARM *paParms;
|
---|
108 | } asyncRead;
|
---|
109 |
|
---|
110 | struct {
|
---|
111 | void *pv;
|
---|
112 | uint32_t cb;
|
---|
113 | uint32_t u32Format;
|
---|
114 | } data;
|
---|
115 |
|
---|
116 | uint32_t u32AvailableFormats;
|
---|
117 | uint32_t u32RequestedFormat;
|
---|
118 | } VBOXCLIPBOARDCLIENTSTATE, *PVBOXCLIPBOARDCLIENTSTATE;
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Structure for keeping a HGCM client state within the Shared Clipboard host service.
|
---|
122 | */
|
---|
123 | typedef struct _VBOXCLIPBOARDCLIENTDATA
|
---|
124 | {
|
---|
125 | /** General client state data. */
|
---|
126 | VBOXCLIPBOARDCLIENTSTATE State;
|
---|
127 | /** The client's message queue (FIFO). */
|
---|
128 | RTCList<VBOXCLIPBOARDCLIENTMSG *> queueMsg;
|
---|
129 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
|
---|
130 | /** URI context data. */
|
---|
131 | SHAREDCLIPBOARDURICTX URI;
|
---|
132 | #endif
|
---|
133 | } VBOXCLIPBOARDCLIENTDATA, *PVBOXCLIPBOARDCLIENTDATA;
|
---|
134 |
|
---|
135 | typedef struct _VBOXCLIPBOARDCLIENT
|
---|
136 | {
|
---|
137 | /** The client's HGCM client ID. */
|
---|
138 | uint32_t uClientID;
|
---|
139 | /** Pointer to the client'data, owned by HGCM. */
|
---|
140 | PVBOXCLIPBOARDCLIENTDATA pData;
|
---|
141 | /** Optional protocol version the client uses. Set to 0 by default. */
|
---|
142 | uint32_t uProtocolVer;
|
---|
143 | /** Structure for keeping the client's pending (deferred return) state.
|
---|
144 | * A client is in a deferred state when it asks for the next HGCM message,
|
---|
145 | * but the service can't provide it yet. That way a client will block (on the guest side, does not return)
|
---|
146 | * until the service can complete the call. */
|
---|
147 | struct
|
---|
148 | {
|
---|
149 | /** The client's HGCM call handle. Needed for completing a deferred call. */
|
---|
150 | VBOXHGCMCALLHANDLE hHandle;
|
---|
151 | /** Message type (function number) to use when completing the deferred call.
|
---|
152 | * A non-0 value means the client is in pending mode. */
|
---|
153 | uint32_t uType;
|
---|
154 | /** Parameter count to use when completing the deferred call. */
|
---|
155 | uint32_t cParms;
|
---|
156 | /** Parameters to use when completing the deferred call. */
|
---|
157 | PVBOXHGCMSVCPARM paParms;
|
---|
158 | } Pending;
|
---|
159 | } VBOXCLIPBOARDCLIENT, *PVBOXCLIPBOARDCLIENT;
|
---|
160 |
|
---|
161 | /** Map holding pointers to drag and drop clients. Key is the (unique) HGCM client ID. */
|
---|
162 | typedef std::map<uint32_t, VBOXCLIPBOARDCLIENT *> ClipboardClientMap;
|
---|
163 |
|
---|
164 | /** Simple queue (list) which holds deferred (waiting) clients. */
|
---|
165 | typedef std::list<uint32_t> ClipboardClientQueue;
|
---|
166 |
|
---|
167 | /*
|
---|
168 | * The service functions. Locking is between the service thread and the platform-dependent (window) thread.
|
---|
169 | */
|
---|
170 | int vboxSvcClipboardCompleteReadData(PVBOXCLIPBOARDCLIENTDATA pClientData, int rc, uint32_t cbActual);
|
---|
171 | uint32_t vboxSvcClipboardGetMode(void);
|
---|
172 | int vboxSvcClipboardReportMsg(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t uMsg, uint32_t uFormats);
|
---|
173 | int vboxSvcClipboardSetSource(PVBOXCLIPBOARDCLIENTDATA pClientData, SHAREDCLIPBOARDSOURCE enmSource);
|
---|
174 |
|
---|
175 | void vboxSvcClipboardMsgQueueReset(PVBOXCLIPBOARDCLIENTDATA pClientData);
|
---|
176 | PVBOXCLIPBOARDCLIENTMSG vboxSvcClipboardMsgAlloc(uint32_t uMsg, uint32_t cParms);
|
---|
177 | void vboxSvcClipboardMsgFree(PVBOXCLIPBOARDCLIENTMSG pMsg);
|
---|
178 | void vboxSvcClipboardMsgSetPeekReturn(PVBOXCLIPBOARDCLIENTMSG pMsg, PVBOXHGCMSVCPARM paDstParms, uint32_t cDstParms);
|
---|
179 | int vboxSvcClipboardMsgAdd(PVBOXCLIPBOARDCLIENTDATA pClientData, PVBOXCLIPBOARDCLIENTMSG pMsg, bool fAppend);
|
---|
180 | int vboxSvcClipboardMsgPeek(PVBOXCLIPBOARDCLIENT pClient, VBOXHGCMCALLHANDLE hCall, uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool fWait);
|
---|
181 | int vboxSvcClipboardMsgGet(PVBOXCLIPBOARDCLIENT pClient, VBOXHGCMCALLHANDLE hCall, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
|
---|
182 |
|
---|
183 | int vboxSvcClipboardClientWakeup(PVBOXCLIPBOARDCLIENT pClient);
|
---|
184 |
|
---|
185 | # ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
|
---|
186 | bool vboxSvcClipboardURIMsgIsAllowed(uint32_t uMode, uint32_t uMsg);
|
---|
187 | int vboxSvcClipboardURIReportMsg(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t u32Msg, uint32_t u32Formats);
|
---|
188 | bool vboxSvcClipboardURIReturnMsg(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
|
---|
189 | # endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
|
---|
190 |
|
---|
191 | /*
|
---|
192 | * Platform-dependent implementations.
|
---|
193 | */
|
---|
194 | int VBoxClipboardSvcImplInit(void);
|
---|
195 | void VBoxClipboardSvcImplDestroy(void);
|
---|
196 |
|
---|
197 | int VBoxClipboardSvcImplConnect(PVBOXCLIPBOARDCLIENTDATA pClientData, bool fHeadless);
|
---|
198 | int VBoxClipboardSvcImplDisconnect(PVBOXCLIPBOARDCLIENTDATA pClientData);
|
---|
199 | int VBoxClipboardSvcImplFormatAnnounce(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t u32Formats);
|
---|
200 | int VBoxClipboardSvcImplReadData(PVBOXCLIPBOARDCLIENTDATA pClientData, uint32_t u32Format, void *pv, uint32_t cb, uint32_t *pcbActual);
|
---|
201 | int VBoxClipboardSvcImplWriteData(PVBOXCLIPBOARDCLIENTDATA pClientData, void *pv, uint32_t cb, uint32_t u32Format);
|
---|
202 | /**
|
---|
203 | * Synchronise the contents of the host clipboard with the guest, called by the HGCM layer
|
---|
204 | * after a save and restore of the guest.
|
---|
205 | */
|
---|
206 | int VBoxClipboardSvcImplSync(PVBOXCLIPBOARDCLIENTDATA pClientData);
|
---|
207 |
|
---|
208 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
|
---|
209 | int vboxSvcClipboardURITransferOpen(PSHAREDCLIPBOARDPROVIDERCTX pCtx);
|
---|
210 | int vboxSvcClipboardURITransferClose(PSHAREDCLIPBOARDPROVIDERCTX pCtx);
|
---|
211 |
|
---|
212 | int vboxSvcClipboardURIListOpen(PSHAREDCLIPBOARDPROVIDERCTX pCtx,
|
---|
213 | PVBOXCLIPBOARDLISTHDR pListHdr, PSHAREDCLIPBOARDLISTHANDLE phList);
|
---|
214 | int vboxSvcClipboardURIListClose(PSHAREDCLIPBOARDPROVIDERCTX pCtx, SHAREDCLIPBOARDLISTHANDLE hList);
|
---|
215 | int vboxSvcClipboardURIListHdrRead(PSHAREDCLIPBOARDPROVIDERCTX pCtx, SHAREDCLIPBOARDLISTHANDLE hList,
|
---|
216 | PVBOXCLIPBOARDLISTHDR pListHdr);
|
---|
217 | int vboxSvcClipboardURIListHdrWrite(PSHAREDCLIPBOARDPROVIDERCTX pCtx, SHAREDCLIPBOARDLISTHANDLE hList,
|
---|
218 | PVBOXCLIPBOARDLISTHDR pListHdr);
|
---|
219 | int vboxSvcClipboardURIListEntryRead(PSHAREDCLIPBOARDPROVIDERCTX pCtx, SHAREDCLIPBOARDLISTHANDLE hList,
|
---|
220 | PVBOXCLIPBOARDLISTENTRY pListEntry);
|
---|
221 | int vboxSvcClipboardURIListEntryWrite(PSHAREDCLIPBOARDPROVIDERCTX pCtx, SHAREDCLIPBOARDLISTHANDLE hList,
|
---|
222 | PVBOXCLIPBOARDLISTENTRY pListEntry);
|
---|
223 |
|
---|
224 | int vboxSvcClipboardURIObjOpen(PSHAREDCLIPBOARDPROVIDERCTX pCtx, const char *pszPath,
|
---|
225 | PVBOXCLIPBOARDCREATEPARMS pCreateParms, PSHAREDCLIPBOARDOBJHANDLE phObj);
|
---|
226 | int vboxSvcClipboardURIObjClose(PSHAREDCLIPBOARDPROVIDERCTX pCtx, SHAREDCLIPBOARDOBJHANDLE hObj);
|
---|
227 | int vboxSvcClipboardURIObjRead(PSHAREDCLIPBOARDPROVIDERCTX pCtx, SHAREDCLIPBOARDOBJHANDLE hObj,
|
---|
228 | void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbRead);
|
---|
229 | int vboxSvcClipboardURIObjWrite(PSHAREDCLIPBOARDPROVIDERCTX pCtx, SHAREDCLIPBOARDOBJHANDLE hObj,
|
---|
230 | void *pvData, uint32_t cbData, uint32_t fFlags, uint32_t *pcbWritten);
|
---|
231 |
|
---|
232 | DECLCALLBACK(void) VBoxSvcClipboardURITransferPrepareCallback(PSHAREDCLIPBOARDURITRANSFERCALLBACKDATA pData);
|
---|
233 | DECLCALLBACK(void) VBoxSvcClipboardURIDataHeaderCompleteCallback(PSHAREDCLIPBOARDURITRANSFERCALLBACKDATA pData);
|
---|
234 | DECLCALLBACK(void) VBoxSvcClipboardURIDataCompleteCallback(PSHAREDCLIPBOARDURITRANSFERCALLBACKDATA pData);
|
---|
235 | DECLCALLBACK(void) VBoxSvcClipboardURITransferCompleteCallback(PSHAREDCLIPBOARDURITRANSFERCALLBACKDATA pData, int rc);
|
---|
236 | DECLCALLBACK(void) VBoxSvcClipboardURITransferCanceledCallback(PSHAREDCLIPBOARDURITRANSFERCALLBACKDATA pData);
|
---|
237 | DECLCALLBACK(void) VBoxSvcClipboardURITransferErrorCallback(PSHAREDCLIPBOARDURITRANSFERCALLBACKDATA pData, int rc);
|
---|
238 |
|
---|
239 | int VBoxClipboardSvcImplURITransferCreate(PVBOXCLIPBOARDCLIENTDATA pClientData, PSHAREDCLIPBOARDURITRANSFER pTransfer);
|
---|
240 | int VBoxClipboardSvcImplURITransferDestroy(PVBOXCLIPBOARDCLIENTDATA pClientData, PSHAREDCLIPBOARDURITRANSFER pTransfer);
|
---|
241 | #endif
|
---|
242 |
|
---|
243 | /* Host unit testing interface */
|
---|
244 | #ifdef UNIT_TEST
|
---|
245 | uint32_t TestClipSvcGetMode(void);
|
---|
246 | #endif
|
---|
247 |
|
---|
248 | #endif /* !VBOX_INCLUDED_SRC_SharedClipboard_VBoxSharedClipboardSvc_internal_h */
|
---|
249 |
|
---|