VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibClipboard.cpp@ 76553

Last change on this file since 76553 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keyword set to Id
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1/* $Id: VBoxGuestR3LibClipboard.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Clipboard.
4 */
5
6/*
7 * Copyright (C) 2007-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 * 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 <VBox/err.h>
33#include <iprt/assert.h>
34#include <iprt/string.h>
35#include "VBoxGuestR3LibInternal.h"
36
37
38/**
39 * Connects to the clipboard service.
40 *
41 * @returns VBox status code
42 * @param pidClient Where to put the client id on success. The client id
43 * must be passed to all the other clipboard calls.
44 */
45VBGLR3DECL(int) VbglR3ClipboardConnect(HGCMCLIENTID *pidClient)
46{
47 int rc = VbglR3HGCMConnect("VBoxSharedClipboard", pidClient);
48 if (rc == VERR_HGCM_SERVICE_NOT_FOUND)
49 rc = VINF_PERMISSION_DENIED;
50 return rc;
51}
52
53
54/**
55 * Disconnect from the clipboard service.
56 *
57 * @returns VBox status code.
58 * @param idClient The client id returned by VbglR3ClipboardConnect().
59 */
60VBGLR3DECL(int) VbglR3ClipboardDisconnect(HGCMCLIENTID idClient)
61{
62 return VbglR3HGCMDisconnect(idClient);
63}
64
65
66/**
67 * Get a host message.
68 *
69 * This will block until a message becomes available.
70 *
71 * @returns VBox status code.
72 * @param idClient The client id returned by VbglR3ClipboardConnect().
73 * @param pidMsg Where to store the message id.
74 * @param pfFormats Where to store the format(s) the message applies to.
75 */
76VBGLR3DECL(int) VbglR3ClipboardGetHostMsg(HGCMCLIENTID idClient, uint32_t *pidMsg, uint32_t *pfFormats)
77{
78 VBoxClipboardGetHostMsg Msg;
79
80 VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, VBOX_SHARED_CLIPBOARD_FN_GET_HOST_MSG, 2);
81 VbglHGCMParmUInt32Set(&Msg.msg, 0);
82 VbglHGCMParmUInt32Set(&Msg.formats, 0);
83
84 int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
85 if (RT_SUCCESS(rc))
86 {
87 int rc2 = VbglHGCMParmUInt32Get(&Msg.msg, pidMsg);
88 if (RT_SUCCESS(rc))
89 {
90 rc2 = VbglHGCMParmUInt32Get(&Msg.formats, pfFormats);
91 if (RT_SUCCESS(rc2))
92 return rc;
93 }
94 rc = rc2;
95 }
96 *pidMsg = UINT32_MAX - 1;
97 *pfFormats = UINT32_MAX;
98 return rc;
99}
100
101
102/**
103 * Reads data from the host clipboard.
104 *
105 * @returns VBox status code.
106 * @retval VINF_BUFFER_OVERFLOW If there is more data available than the caller provided buffer space for.
107 *
108 * @param idClient The client id returned by VbglR3ClipboardConnect().
109 * @param fFormat The format we're requesting the data in.
110 * @param pv Where to store the data.
111 * @param cb The size of the buffer pointed to by pv.
112 * @param pcb The actual size of the host clipboard data. May be larger than cb.
113 */
114VBGLR3DECL(int) VbglR3ClipboardReadData(HGCMCLIENTID idClient, uint32_t fFormat, void *pv, uint32_t cb, uint32_t *pcb)
115{
116 VBoxClipboardReadData Msg;
117
118 VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, VBOX_SHARED_CLIPBOARD_FN_READ_DATA, 3);
119 VbglHGCMParmUInt32Set(&Msg.format, fFormat);
120 VbglHGCMParmPtrSet(&Msg.ptr, pv, cb);
121 VbglHGCMParmUInt32Set(&Msg.size, 0);
122
123 int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
124 if (RT_SUCCESS(rc))
125 {
126 uint32_t cbActual;
127 int rc2 = VbglHGCMParmUInt32Get(&Msg.size, &cbActual);
128 if (RT_SUCCESS(rc2))
129 {
130 *pcb = cbActual;
131 if (cbActual > cb)
132 return VINF_BUFFER_OVERFLOW;
133 return rc;
134 }
135 rc = rc2;
136 }
137 return rc;
138}
139
140
141/**
142 * Advertises guest clipboard formats to the host.
143 *
144 * @returns VBox status code.
145 * @param idClient The client id returned by VbglR3ClipboardConnect().
146 * @param fFormats The formats to advertise.
147 */
148VBGLR3DECL(int) VbglR3ClipboardReportFormats(HGCMCLIENTID idClient, uint32_t fFormats)
149{
150 VBoxClipboardFormats Msg;
151
152 VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, VBOX_SHARED_CLIPBOARD_FN_FORMATS, 1);
153 VbglHGCMParmUInt32Set(&Msg.formats, fFormats);
154
155 return VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
156}
157
158
159/**
160 * Send guest clipboard data to the host.
161 *
162 * This is usually called in reply to a VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA message
163 * from the host.
164 *
165 * @returns VBox status code.
166 * @param idClient The client id returned by VbglR3ClipboardConnect().
167 * @param fFormat The format of the data.
168 * @param pv The data.
169 * @param cb The size of the data.
170 */
171VBGLR3DECL(int) VbglR3ClipboardWriteData(HGCMCLIENTID idClient, uint32_t fFormat, void *pv, uint32_t cb)
172{
173 VBoxClipboardWriteData Msg;
174 VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, VBOX_SHARED_CLIPBOARD_FN_WRITE_DATA, 2);
175 VbglHGCMParmUInt32Set(&Msg.format, fFormat);
176 VbglHGCMParmPtrSet(&Msg.ptr, pv, cb);
177
178 return VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
179}
180
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