VirtualBox

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

Last change on this file since 38114 was 33540, checked in by vboxsync, 14 years ago

*: spelling fixes, thanks Timeless!

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