1 | /** @file
|
---|
2 | * Shared Clipboard - Common guest and host Code.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2019 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef VBOX_INCLUDED_GuestHost_SharedClipboard_h
|
---|
27 | #define VBOX_INCLUDED_GuestHost_SharedClipboard_h
|
---|
28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
29 | # pragma once
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <iprt/cdefs.h>
|
---|
33 | #include <iprt/list.h>
|
---|
34 | #include <iprt/types.h>
|
---|
35 |
|
---|
36 | /** A single Shared Clipboard format. */
|
---|
37 | typedef uint32_t SHCLFORMAT;
|
---|
38 | /** Pointer to a single Shared Clipboard format. */
|
---|
39 | typedef SHCLFORMAT *PSHCLFORMAT;
|
---|
40 |
|
---|
41 | /** Bit map of Shared Clipboard formats. */
|
---|
42 | typedef uint32_t SHCLFORMATS;
|
---|
43 | /** Pointer to a bit map of Shared Clipboard formats. */
|
---|
44 | typedef SHCLFORMATS *PSHCLFORMATS;
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Supported data formats for Shared Clipboard. Bit mask.
|
---|
48 | */
|
---|
49 | /** No format set. */
|
---|
50 | #define VBOX_SHARED_CLIPBOARD_FMT_NONE 0
|
---|
51 | /** Shared Clipboard format is an Unicode text. */
|
---|
52 | #define VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT RT_BIT(0)
|
---|
53 | /** Shared Clipboard format is bitmap (BMP / DIB). */
|
---|
54 | #define VBOX_SHARED_CLIPBOARD_FMT_BITMAP RT_BIT(1)
|
---|
55 | /** Shared Clipboard format is HTML. */
|
---|
56 | #define VBOX_SHARED_CLIPBOARD_FMT_HTML RT_BIT(2)
|
---|
57 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
|
---|
58 | /** Shared Clipboard format is an URI list. */
|
---|
59 | #define VBOX_SHARED_CLIPBOARD_FMT_URI_LIST RT_BIT(3)
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Structure for keeping a generic Shared Clipboard data block.
|
---|
64 | */
|
---|
65 | typedef struct _SHCLDATABLOCK
|
---|
66 | {
|
---|
67 | /** Clipboard format this data block represents. */
|
---|
68 | SHCLFORMAT uFormat;
|
---|
69 | /** Pointer to actual data block. */
|
---|
70 | void *pvData;
|
---|
71 | /** Size (in bytes) of actual data block. */
|
---|
72 | uint32_t cbData;
|
---|
73 | } SHCLDATABLOCK, *PSHCLDATABLOCK;
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Structure for keeping a Shared Clipboard data read request.
|
---|
77 | */
|
---|
78 | typedef struct _SHCLDATAREQ
|
---|
79 | {
|
---|
80 | /** In which format the data needs to be sent. */
|
---|
81 | SHCLFORMAT uFmt;
|
---|
82 | /** Read flags; currently unused. */
|
---|
83 | uint32_t fFlags;
|
---|
84 | /** Maximum data (in byte) can be sent. */
|
---|
85 | uint32_t cbSize;
|
---|
86 | } SHCLDATAREQ, *PSHCLDATAREQ;
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Structure for keeping Shared Clipboard formats specifications.
|
---|
90 | */
|
---|
91 | typedef struct _SHCLFORMATDATA
|
---|
92 | {
|
---|
93 | /** Available format(s) as bit map. */
|
---|
94 | SHCLFORMATS uFormats;
|
---|
95 | /** Formats flags. Currently unused. */
|
---|
96 | uint32_t fFlags;
|
---|
97 | } SHCLFORMATDATA, *PSHCLFORMATDATA;
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Structure for an (optional) Shared Clipboard event payload.
|
---|
101 | */
|
---|
102 | typedef struct _SHCLEVENTPAYLOAD
|
---|
103 | {
|
---|
104 | /** Payload ID; currently unused. */
|
---|
105 | uint32_t uID;
|
---|
106 | /** Pointer to actual payload data. */
|
---|
107 | void *pvData;
|
---|
108 | /** Size (in bytes) of actual payload data. */
|
---|
109 | uint32_t cbData;
|
---|
110 | } SHCLEVENTPAYLOAD, *PSHCLEVENTPAYLOAD;
|
---|
111 |
|
---|
112 | /** Defines an event source ID. */
|
---|
113 | typedef uint16_t SHCLEVENTSOURCEID;
|
---|
114 | /** Defines a pointer to a event source ID. */
|
---|
115 | typedef SHCLEVENTSOURCEID *PSHCLEVENTSOURCEID;
|
---|
116 |
|
---|
117 | /** Defines an event ID. */
|
---|
118 | typedef uint32_t SHCLEVENTID;
|
---|
119 | /** Defines a pointer to a event source ID. */
|
---|
120 | typedef SHCLEVENTID *PSHCLEVENTID;
|
---|
121 |
|
---|
122 | /** Maximum number of concurrent Shared Clipboard client sessions a VM can have. */
|
---|
123 | #define VBOX_SHARED_CLIPBOARD_MAX_SESSIONS 32
|
---|
124 | /** Maximum number of concurrent Shared Clipboard transfers a single
|
---|
125 | * client can have. */
|
---|
126 | #define VBOX_SHARED_CLIPBOARD_MAX_TRANSFERS _2K
|
---|
127 | /** Maximum number of events a single Shared Clipboard transfer can have. */
|
---|
128 | #define VBOX_SHARED_CLIPBOARD_MAX_EVENTS _64K
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Creates a context ID out of a client ID, a transfer ID and a count.
|
---|
132 | */
|
---|
133 | #define VBOX_SHARED_CLIPBOARD_CONTEXTID_MAKE(uSessionID, uTransferID, uEventID) \
|
---|
134 | ( (uint32_t)((uSessionID) & 0x1f) << 27 \
|
---|
135 | | (uint32_t)((uTransferID) & 0x7ff) << 16 \
|
---|
136 | | (uint32_t)((uEventID) & 0xffff) \
|
---|
137 | )
|
---|
138 | /** Creates a context ID out of a session ID. */
|
---|
139 | #define VBOX__SHARED_CLIPBOARD_CONTEXTID_MAKE_SESSION(uSessionID) \
|
---|
140 | ((uint32_t)((uSessionID) & 0x1f) << 27)
|
---|
141 | /** Gets the session ID out of a context ID. */
|
---|
142 | #define VBOX_SHARED_CLIPBOARD_CONTEXTID_GET_SESSION(uContextID) \
|
---|
143 | (((uContextID) >> 27) & 0x1f)
|
---|
144 | /** Gets the transfer ID out of a context ID. */
|
---|
145 | #define VBO_SHARED_CLIPBOARD_CONTEXTID_GET_TRANSFER(uContextID) \
|
---|
146 | (((uContextID) >> 16) & 0x7ff)
|
---|
147 | /** Gets the transfer event out of a context ID. */
|
---|
148 | #define VBOX_SHARED_CLIPBOARD_CONTEXTID_GET_EVENT(uContextID) \
|
---|
149 | ((uContextID) & 0xffff)
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * Structure for maintaining a Shared Clipboard event.
|
---|
153 | */
|
---|
154 | typedef struct _SHCLEVENT
|
---|
155 | {
|
---|
156 | /** List node. */
|
---|
157 | RTLISTNODE Node;
|
---|
158 | /** The event's ID, for self-reference. */
|
---|
159 | SHCLEVENTID uID;
|
---|
160 | /** Event semaphore for signalling the event. */
|
---|
161 | RTSEMEVENT hEventSem;
|
---|
162 | /** Payload to this event. Optional and can be NULL. */
|
---|
163 | PSHCLEVENTPAYLOAD pPayload;
|
---|
164 | } SHCLEVENT, *PSHCLEVENT;
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * Structure for maintaining a Shared Clipboard event source.
|
---|
168 | *
|
---|
169 | * Each event source maintains an own counter for events, so that
|
---|
170 | * it can be used in different contexts.
|
---|
171 | */
|
---|
172 | typedef struct _SHCLEVENTSOURCE
|
---|
173 | {
|
---|
174 | /** The event source' ID. */
|
---|
175 | SHCLEVENTSOURCEID uID;
|
---|
176 | /** Next upcoming event ID. */
|
---|
177 | SHCLEVENTID uEventIDNext;
|
---|
178 | /** List of events (PSHCLEVENT). */
|
---|
179 | RTLISTANCHOR lstEvents;
|
---|
180 | } SHCLEVENTSOURCE, *PSHCLEVENTSOURCE;
|
---|
181 |
|
---|
182 | int SharedClipboardPayloadAlloc(uint32_t uID, const void *pvData, uint32_t cbData,
|
---|
183 | PSHCLEVENTPAYLOAD *ppPayload);
|
---|
184 | void SharedClipboardPayloadFree(PSHCLEVENTPAYLOAD pPayload);
|
---|
185 |
|
---|
186 | int SharedClipboardEventSourceCreate(PSHCLEVENTSOURCE pSource, SHCLEVENTSOURCEID uID);
|
---|
187 | void SharedClipboardEventSourceDestroy(PSHCLEVENTSOURCE pSource);
|
---|
188 |
|
---|
189 | SHCLEVENTID SharedClipboardEventIDGenerate(PSHCLEVENTSOURCE pSource);
|
---|
190 | SHCLEVENTID SharedClipboardEventGetLast(PSHCLEVENTSOURCE pSource);
|
---|
191 | int SharedClipboardEventRegister(PSHCLEVENTSOURCE pSource, SHCLEVENTID uID);
|
---|
192 | int SharedClipboardEventUnregister(PSHCLEVENTSOURCE pSource, SHCLEVENTID uID);
|
---|
193 | int SharedClipboardEventWait(PSHCLEVENTSOURCE pSource, SHCLEVENTID uID, RTMSINTERVAL uTimeoutMs,
|
---|
194 | PSHCLEVENTPAYLOAD* ppPayload);
|
---|
195 | int SharedClipboardEventSignal(PSHCLEVENTSOURCE pSource, SHCLEVENTID uID, PSHCLEVENTPAYLOAD pPayload);
|
---|
196 | void SharedClipboardEventPayloadDetach(PSHCLEVENTSOURCE pSource, SHCLEVENTID uID);
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * Enumeration to specify the Shared Clipboard URI source type.
|
---|
200 | */
|
---|
201 | typedef enum SHCLSOURCE
|
---|
202 | {
|
---|
203 | /** Invalid source type. */
|
---|
204 | SHCLSOURCE_INVALID = 0,
|
---|
205 | /** Source is local. */
|
---|
206 | SHCLSOURCE_LOCAL,
|
---|
207 | /** Source is remote. */
|
---|
208 | SHCLSOURCE_REMOTE,
|
---|
209 | /** The usual 32-bit hack. */
|
---|
210 | SHCLSOURCE_32Bit_Hack = 0x7fffffff
|
---|
211 | } SHCLSOURCE;
|
---|
212 |
|
---|
213 | /** Opaque data structure for the X11/VBox frontend/glue code. */
|
---|
214 | struct _SHCLCONTEXT;
|
---|
215 | typedef struct _SHCLCONTEXT SHCLCONTEXT;
|
---|
216 | typedef struct _SHCLCONTEXT *PSHCLCONTEXT;
|
---|
217 |
|
---|
218 | /** Opaque data structure for the X11/VBox backend code. */
|
---|
219 | struct _CLIPBACKEND;
|
---|
220 | typedef struct _CLIPBACKEND CLIPBACKEND;
|
---|
221 |
|
---|
222 | /** Opaque request structure for X11 clipboard data.
|
---|
223 | * @todo All use of single and double underscore prefixes is banned! */
|
---|
224 | struct _CLIPREADCBREQ;
|
---|
225 | typedef struct _CLIPREADCBREQ CLIPREADCBREQ;
|
---|
226 |
|
---|
227 | /* APIs exported by the X11 backend */
|
---|
228 | extern CLIPBACKEND *ClipConstructX11(SHCLCONTEXT *pFrontend, bool fHeadless);
|
---|
229 | extern void ClipDestructX11(CLIPBACKEND *pBackend);
|
---|
230 | extern int ClipStartX11(CLIPBACKEND *pBackend, bool grab);
|
---|
231 | extern int ClipStopX11(CLIPBACKEND *pBackend);
|
---|
232 | extern int ClipAnnounceFormatToX11(CLIPBACKEND *pBackend, SHCLFORMATS vboxFormats);
|
---|
233 | extern int ClipRequestDataFromX11(CLIPBACKEND *pBackend, SHCLFORMATS vboxFormat, CLIPREADCBREQ *pReq);
|
---|
234 |
|
---|
235 | /* APIs exported by the X11/VBox frontend */
|
---|
236 | extern int ClipRequestDataForX11(SHCLCONTEXT *pCtx, uint32_t u32Format, void **ppv, uint32_t *pcb);
|
---|
237 | extern void ClipReportX11Formats(SHCLCONTEXT *pCtx, uint32_t u32Formats);
|
---|
238 | extern void ClipRequestFromX11CompleteCallback(SHCLCONTEXT *pCtx, int rc, CLIPREADCBREQ *pReq, void *pv, uint32_t cb);
|
---|
239 | #endif /* !VBOX_INCLUDED_GuestHost_SharedClipboard_h */
|
---|
240 |
|
---|