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 | /**
|
---|
37 | * Enumeration specifying an Shared Clipboard transfer direction.
|
---|
38 | */
|
---|
39 | typedef enum _SHCLTRANSFERDIR
|
---|
40 | {
|
---|
41 | /** Unknown transfer directory. */
|
---|
42 | SHCLTRANSFERDIR_UNKNOWN = 0,
|
---|
43 | /** Read transfer (from source). */
|
---|
44 | SHCLTRANSFERDIR_READ,
|
---|
45 | /** Write transfer (to target). */
|
---|
46 | SHCLTRANSFERDIR_WRITE,
|
---|
47 | /** The usual 32-bit hack. */
|
---|
48 | SHCLTRANSFERDIR_32BIT_HACK = 0x7fffffff
|
---|
49 | } SHCLTRANSFERDIR, *PSHCLTRANSFERDIR;
|
---|
50 |
|
---|
51 | struct _SHCLTRANSFER;
|
---|
52 | typedef struct _SHCLTRANSFER SHCLTRANSFER;
|
---|
53 |
|
---|
54 | /** A single Shared Clipboard format. */
|
---|
55 | typedef uint32_t SHCLFORMAT;
|
---|
56 | /** Pointer to a single Shared Clipboard format. */
|
---|
57 | typedef SHCLFORMAT *PSHCLFORMAT;
|
---|
58 |
|
---|
59 | /** Bit map of Shared Clipboard formats. */
|
---|
60 | typedef uint32_t SHCLFORMATS;
|
---|
61 | /** Pointer to a bit map of Shared Clipboard formats. */
|
---|
62 | typedef SHCLFORMATS *PSHCLFORMATS;
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Supported data formats for Shared Clipboard. Bit mask.
|
---|
66 | */
|
---|
67 | /** No format set. */
|
---|
68 | #define VBOX_SHCL_FMT_NONE 0
|
---|
69 | /** Shared Clipboard format is an Unicode text. */
|
---|
70 | #define VBOX_SHCL_FMT_UNICODETEXT RT_BIT(0)
|
---|
71 | /** Shared Clipboard format is bitmap (BMP / DIB). */
|
---|
72 | #define VBOX_SHCL_FMT_BITMAP RT_BIT(1)
|
---|
73 | /** Shared Clipboard format is HTML. */
|
---|
74 | #define VBOX_SHCL_FMT_HTML RT_BIT(2)
|
---|
75 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
76 | /** Shared Clipboard format is a transfer list. */
|
---|
77 | #define VBOX_SHCL_FMT_URI_LIST RT_BIT(3)
|
---|
78 | #endif
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Structure for keeping a generic Shared Clipboard data block.
|
---|
82 | */
|
---|
83 | typedef struct _SHCLDATABLOCK
|
---|
84 | {
|
---|
85 | /** Clipboard format this data block represents. */
|
---|
86 | SHCLFORMAT uFormat;
|
---|
87 | /** Pointer to actual data block. */
|
---|
88 | void *pvData;
|
---|
89 | /** Size (in bytes) of actual data block. */
|
---|
90 | uint32_t cbData;
|
---|
91 | } SHCLDATABLOCK, *PSHCLDATABLOCK;
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Structure for keeping a Shared Clipboard data read request.
|
---|
95 | */
|
---|
96 | typedef struct _SHCLDATAREQ
|
---|
97 | {
|
---|
98 | /** In which format the data needs to be sent. */
|
---|
99 | SHCLFORMAT uFmt;
|
---|
100 | /** Read flags; currently unused. */
|
---|
101 | uint32_t fFlags;
|
---|
102 | /** Maximum data (in byte) can be sent. */
|
---|
103 | uint32_t cbSize;
|
---|
104 | } SHCLDATAREQ, *PSHCLDATAREQ;
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Structure for keeping Shared Clipboard formats specifications.
|
---|
108 | */
|
---|
109 | typedef struct _SHCLFORMATDATA
|
---|
110 | {
|
---|
111 | /** Available format(s) as bit map. */
|
---|
112 | SHCLFORMATS Formats;
|
---|
113 | /** Formats flags. Currently unused. */
|
---|
114 | uint32_t fFlags;
|
---|
115 | } SHCLFORMATDATA, *PSHCLFORMATDATA;
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Structure for an (optional) Shared Clipboard event payload.
|
---|
119 | */
|
---|
120 | typedef struct _SHCLEVENTPAYLOAD
|
---|
121 | {
|
---|
122 | /** Payload ID; currently unused. */
|
---|
123 | uint32_t uID;
|
---|
124 | /** Pointer to actual payload data. */
|
---|
125 | void *pvData;
|
---|
126 | /** Size (in bytes) of actual payload data. */
|
---|
127 | uint32_t cbData;
|
---|
128 | } SHCLEVENTPAYLOAD, *PSHCLEVENTPAYLOAD;
|
---|
129 |
|
---|
130 | /** Defines an event source ID. */
|
---|
131 | typedef uint16_t SHCLEVENTSOURCEID;
|
---|
132 | /** Defines a pointer to a event source ID. */
|
---|
133 | typedef SHCLEVENTSOURCEID *PSHCLEVENTSOURCEID;
|
---|
134 |
|
---|
135 | /** Defines a session ID. */
|
---|
136 | typedef uint16_t SHCLSESSIONID;
|
---|
137 | /** Defines a pointer to a session ID. */
|
---|
138 | typedef SHCLSESSIONID *PSHCLSESSIONID;
|
---|
139 | /** Defines a NIL session ID. */
|
---|
140 | #define NIL_SHCLSESSIONID UINT16_MAX
|
---|
141 |
|
---|
142 | /** Defines a transfer ID. */
|
---|
143 | typedef uint16_t SHCLTRANSFERID;
|
---|
144 | /** Defines a pointer to a transfer ID. */
|
---|
145 | typedef SHCLTRANSFERID *PSHCLTRANSFERID;
|
---|
146 | /** Defines a NIL transfer ID. */
|
---|
147 | #define NIL_SHCLTRANSFERID UINT16_MAX
|
---|
148 |
|
---|
149 | /** Defines an event ID. */
|
---|
150 | typedef uint32_t SHCLEVENTID;
|
---|
151 | /** Defines a pointer to a event source ID. */
|
---|
152 | typedef SHCLEVENTID *PSHCLEVENTID;
|
---|
153 | /** Defines a NIL event ID. */
|
---|
154 | #define NIL_SHCLEVENTID UINT32_MAX
|
---|
155 |
|
---|
156 | /** Maximum number of concurrent Shared Clipboard client sessions a VM can have. */
|
---|
157 | #define VBOX_SHCL_MAX_SESSIONS UINT16_MAX - 1
|
---|
158 | /** Maximum number of concurrent Shared Clipboard transfers a single
|
---|
159 | * client can have. */
|
---|
160 | #define VBOX_SHCL_MAX_TRANSFERS UINT16_MAX - 1
|
---|
161 | /** Maximum number of events a single Shared Clipboard transfer can have. */
|
---|
162 | #define VBOX_SHCL_MAX_EVENTS UINT32_MAX - 1
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * Creates a context ID out of a client ID, a transfer ID and a count (can be an event ID).
|
---|
166 | */
|
---|
167 | #define VBOX_SHCL_CONTEXTID_MAKE(uSessionID, uTransferID, uEventID) \
|
---|
168 | ( (uint64_t)((uSessionID) & 0xffff) << 48 \
|
---|
169 | | (uint64_t)((uTransferID) & 0xffff) << 32 \
|
---|
170 | | (uint32_t)((uEventID) & 0xffffffff) \
|
---|
171 | )
|
---|
172 | /** Creates a context ID out of a session ID. */
|
---|
173 | #define VBOX_SHCL_CONTEXTID_MAKE_SESSION(uSessionID) \
|
---|
174 | ((uint32_t)((uSessionID) & 0xffff) << 48)
|
---|
175 | /** Gets the session ID out of a context ID. */
|
---|
176 | #define VBOX_SHCL_CONTEXTID_GET_SESSION(uContextID) \
|
---|
177 | (((uContextID) >> 48) & 0xffff)
|
---|
178 | /** Gets the transfer ID out of a context ID. */
|
---|
179 | #define VBOX_SHCL_CONTEXTID_GET_TRANSFER(uContextID) \
|
---|
180 | (((uContextID) >> 32) & 0xffff)
|
---|
181 | /** Gets the transfer event out of a context ID. */
|
---|
182 | #define VBOX_SHCL_CONTEXTID_GET_EVENT(uContextID) \
|
---|
183 | ((uContextID) & 0xffffffff)
|
---|
184 |
|
---|
185 | /**
|
---|
186 | * Structure for maintaining a Shared Clipboard event.
|
---|
187 | */
|
---|
188 | typedef struct _SHCLEVENT
|
---|
189 | {
|
---|
190 | /** List node. */
|
---|
191 | RTLISTNODE Node;
|
---|
192 | /** The event's ID, for self-reference. */
|
---|
193 | SHCLEVENTID uID;
|
---|
194 | /** Event semaphore for signalling the event. */
|
---|
195 | RTSEMEVENT hEventSem;
|
---|
196 | /** Payload to this event. Optional and can be NULL. */
|
---|
197 | PSHCLEVENTPAYLOAD pPayload;
|
---|
198 | } SHCLEVENT, *PSHCLEVENT;
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * Structure for maintaining a Shared Clipboard event source.
|
---|
202 | *
|
---|
203 | * Each event source maintains an own counter for events, so that
|
---|
204 | * it can be used in different contexts.
|
---|
205 | */
|
---|
206 | typedef struct _SHCLEVENTSOURCE
|
---|
207 | {
|
---|
208 | /** The event source' ID. */
|
---|
209 | SHCLEVENTSOURCEID uID;
|
---|
210 | /** Next upcoming event ID. */
|
---|
211 | SHCLEVENTID uEventIDNext;
|
---|
212 | /** List of events (PSHCLEVENT). */
|
---|
213 | RTLISTANCHOR lstEvents;
|
---|
214 | } SHCLEVENTSOURCE, *PSHCLEVENTSOURCE;
|
---|
215 |
|
---|
216 | /** @name Shared Clipboard data payload functions.
|
---|
217 | * @{
|
---|
218 | */
|
---|
219 | int ShClPayloadAlloc(uint32_t uID, const void *pvData, uint32_t cbData, PSHCLEVENTPAYLOAD *ppPayload);
|
---|
220 | void ShClPayloadFree(PSHCLEVENTPAYLOAD pPayload);
|
---|
221 | /** @} */
|
---|
222 |
|
---|
223 | /** @name Shared Clipboard event source functions.
|
---|
224 | * @{
|
---|
225 | */
|
---|
226 | int ShClEventSourceCreate(PSHCLEVENTSOURCE pSource, SHCLEVENTSOURCEID uID);
|
---|
227 | void ShClEventSourceDestroy(PSHCLEVENTSOURCE pSource);
|
---|
228 | void ShClEventSourceReset(PSHCLEVENTSOURCE pSource);
|
---|
229 | /** @} */
|
---|
230 |
|
---|
231 | /** @name Shared Clipboard event functions.
|
---|
232 | * @{
|
---|
233 | */
|
---|
234 | SHCLEVENTID ShClEventIDGenerate(PSHCLEVENTSOURCE pSource);
|
---|
235 | SHCLEVENTID ShClEventGetLast(PSHCLEVENTSOURCE pSource);
|
---|
236 | int ShClEventRegister(PSHCLEVENTSOURCE pSource, SHCLEVENTID uID);
|
---|
237 | int ShClEventUnregister(PSHCLEVENTSOURCE pSource, SHCLEVENTID uID);
|
---|
238 | int ShClEventWait(PSHCLEVENTSOURCE pSource, SHCLEVENTID uID, RTMSINTERVAL uTimeoutMs, PSHCLEVENTPAYLOAD* ppPayload);
|
---|
239 | int ShClEventSignal(PSHCLEVENTSOURCE pSource, SHCLEVENTID uID, PSHCLEVENTPAYLOAD pPayload);
|
---|
240 | void ShClEventPayloadDetach(PSHCLEVENTSOURCE pSource, SHCLEVENTID uID);
|
---|
241 | /** @} */
|
---|
242 |
|
---|
243 | /**
|
---|
244 | * Enumeration to specify the Shared Clipboard transfer source type.
|
---|
245 | */
|
---|
246 | typedef enum SHCLSOURCE
|
---|
247 | {
|
---|
248 | /** Invalid source type. */
|
---|
249 | SHCLSOURCE_INVALID = 0,
|
---|
250 | /** Source is local. */
|
---|
251 | SHCLSOURCE_LOCAL,
|
---|
252 | /** Source is remote. */
|
---|
253 | SHCLSOURCE_REMOTE,
|
---|
254 | /** The usual 32-bit hack. */
|
---|
255 | SHCLSOURCE_32Bit_Hack = 0x7fffffff
|
---|
256 | } SHCLSOURCE;
|
---|
257 |
|
---|
258 | /** Opaque data structure for the X11/VBox frontend/glue code. */
|
---|
259 | struct _SHCLCONTEXT;
|
---|
260 | typedef struct _SHCLCONTEXT SHCLCONTEXT;
|
---|
261 | typedef struct _SHCLCONTEXT *PSHCLCONTEXT;
|
---|
262 |
|
---|
263 | /** Opaque request structure for X11 clipboard data.
|
---|
264 | * @todo All use of single and double underscore prefixes is banned! */
|
---|
265 | struct _CLIPREADCBREQ;
|
---|
266 | typedef struct _CLIPREADCBREQ CLIPREADCBREQ;
|
---|
267 |
|
---|
268 | #endif /* !VBOX_INCLUDED_GuestHost_SharedClipboard_h */
|
---|
269 |
|
---|