VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibClipboard.cpp@ 15606

Last change on this file since 15606 was 10552, checked in by vboxsync, 16 years ago

More IOCTLs.

  • Property svn:eol-style set to native
  • Property svn:keyword set to Id
  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
Line 
1/* $Id: VBoxGuestR3LibClipboard.cpp 10552 2008-07-11 20:05:12Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Clipboard.
4 */
5
6/*
7 * Copyright (C) 2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#include <VBox/HostServices/VBoxClipboardSvc.h>
27#include <VBox/VBoxGuest.h>
28#include <iprt/string.h>
29#include <iprt/assert.h>
30#include "VBGLR3Internal.h"
31
32
33
34
35/**
36 * Connects to the clipboard service.
37 *
38 * @returns VBox status code
39 * @param pu32ClientId Where to put the client id on success. The client id
40 * must be passed to all the other clipboard calls.
41 */
42VBGLR3DECL(int) VbglR3ClipboardConnect(uint32_t *pu32ClientId)
43{
44 VBoxGuestHGCMConnectInfo Info;
45 Info.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
46 Info.Loc.type = VMMDevHGCMLoc_LocalHost_Existing;
47 memset(&Info.Loc.u, 0, sizeof(Info.Loc.u));
48 strcpy(Info.Loc.u.host.achName, "VBoxSharedClipboard");
49 Info.u32ClientID = UINT32_MAX; /* try make valgrid shut up. */
50
51 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CONNECT, &Info, sizeof(Info));
52 if (RT_SUCCESS(rc))
53 {
54 rc = Info.result;
55 if (RT_SUCCESS(rc))
56 *pu32ClientId = Info.u32ClientID;
57 }
58 return rc;
59}
60
61
62/**
63 * Disconnect from the clipboard service.
64 *
65 * @returns VBox status code.
66 * @param u32ClientId The client id returned by VbglR3ClipboardConnect().
67 */
68VBGLR3DECL(int) VbglR3ClipboardDisconnect(uint32_t u32ClientId)
69{
70 VBoxGuestHGCMDisconnectInfo Info;
71 Info.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
72 Info.u32ClientID = u32ClientId;
73
74 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_DISCONNECT, &Info, sizeof(Info));
75 if (RT_SUCCESS(rc))
76 rc = Info.result;
77 return rc;
78}
79
80
81/**
82 * Get a host message.
83 *
84 * This will block until a message becomes available.
85 *
86 * @returns VBox status code.
87 * @param u32ClientId The client id returned by VbglR3ClipboardConnect().
88 * @param pMsg Where to store the message id.
89 * @param pfFormats Where to store the format(s) the message applies to.
90 */
91VBGLR3DECL(int) VbglR3ClipboardGetHostMsg(uint32_t u32ClientId, uint32_t *pMsg, uint32_t *pfFormats)
92{
93 VBoxClipboardGetHostMsg Msg;
94
95 Msg.hdr.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
96 Msg.hdr.u32ClientID = u32ClientId;
97 Msg.hdr.u32Function = VBOX_SHARED_CLIPBOARD_FN_GET_HOST_MSG;
98 Msg.hdr.cParms = 2;
99 VbglHGCMParmUInt32Set(&Msg.msg, 0);
100 VbglHGCMParmUInt32Set(&Msg.formats, 0);
101
102 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
103 if (RT_SUCCESS(rc))
104 {
105 rc = Msg.hdr.result;
106 if (RT_SUCCESS(rc))
107 {
108 uint32_t u32Msg;
109 rc = VbglHGCMParmUInt32Get(&Msg.msg, &u32Msg);
110 if (RT_SUCCESS(rc))
111 {
112 uint32_t fFormats;
113 rc = VbglHGCMParmUInt32Get(&Msg.formats, &fFormats);
114 if (RT_SUCCESS(rc))
115 {
116 *pMsg = u32Msg;
117 *pfFormats = fFormats;
118 return Msg.hdr.result;
119 }
120 }
121 }
122 }
123
124 return rc;
125}
126
127
128/**
129 * Reads data from the host clipboard.
130 *
131 * @returns VBox status code.
132 * @retval VINF_BUFFER_OVERFLOW If there is more data available than the caller provided buffer space for.
133 *
134 * @param u32ClientId The client id returned by VbglR3ClipboardConnect().
135 * @param fFormat The format we're requesting the data in.
136 * @param pv Where to store the data.
137 * @param cb The size of the buffer pointed to by pv.
138 * @param pcb The actual size of the host clipboard data. May be larger than cb.
139 */
140VBGLR3DECL(int) VbglR3ClipboardReadData(uint32_t u32ClientId, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcb)
141{
142 VBoxClipboardReadData Msg;
143
144 Msg.hdr.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
145 Msg.hdr.u32ClientID = u32ClientId;
146 Msg.hdr.u32Function = VBOX_SHARED_CLIPBOARD_FN_READ_DATA;
147 Msg.hdr.cParms = 3;
148 VbglHGCMParmUInt32Set(&Msg.format, fFormat);
149 VbglHGCMParmPtrSet(&Msg.ptr, pv, cb);
150 VbglHGCMParmUInt32Set(&Msg.size, 0);
151
152 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
153 if (RT_SUCCESS(rc))
154 {
155 rc = Msg.hdr.result;
156 if (RT_SUCCESS(rc))
157 {
158 uint32_t cbActual;
159 rc = VbglHGCMParmUInt32Get(&Msg.size, &cbActual);
160 if (RT_SUCCESS(rc))
161 {
162 *pcb = cbActual;
163 if (cbActual > cb)
164 return VINF_BUFFER_OVERFLOW;
165 return Msg.hdr.result;
166 }
167 }
168 }
169 return rc;
170}
171
172
173/**
174 * Advertises guest clipboard formats to the host.
175 *
176 * @returns VBox status code.
177 * @param u32ClientId The client id returned by VbglR3ClipboardConnect().
178 * @param fFormats The formats to advertise.
179 */
180VBGLR3DECL(int) VbglR3ClipboardReportFormats(uint32_t u32ClientId, uint32_t fFormats)
181{
182 VBoxClipboardFormats Msg;
183
184 Msg.hdr.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
185 Msg.hdr.u32ClientID = u32ClientId;
186 Msg.hdr.u32Function = VBOX_SHARED_CLIPBOARD_FN_FORMATS;
187 Msg.hdr.cParms = 1;
188 VbglHGCMParmUInt32Set(&Msg.formats, fFormats);
189
190 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
191 if (RT_SUCCESS(rc))
192 rc = Msg.hdr.result;
193 return rc;
194}
195
196
197/**
198 * Send guest clipboard data to the host.
199 *
200 * This is usually called in reply to a VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA message
201 * from the host.
202 *
203 * @returns VBox status code.
204 * @param u32ClientId The client id returned by VbglR3ClipboardConnect().
205 * @param fFormat The format of the data.
206 * @param pv The data.
207 * @param cb The size of the data.
208 */
209VBGLR3DECL(int) VbglR3ClipboardWriteData(uint32_t u32ClientId, uint32_t fFormat, void *pv, uint32_t cb)
210{
211 VBoxClipboardWriteData Msg;
212 Msg.hdr.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
213 Msg.hdr.u32ClientID = u32ClientId;
214 Msg.hdr.u32Function = VBOX_SHARED_CLIPBOARD_FN_WRITE_DATA;
215 Msg.hdr.cParms = 2;
216 VbglHGCMParmUInt32Set(&Msg.format, fFormat);
217 VbglHGCMParmPtrSet(&Msg.ptr, pv, cb);
218
219 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
220 if (RT_SUCCESS(rc))
221 rc = Msg.hdr.result;
222 return rc;
223}
224
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