VirtualBox

source: vbox/trunk/src/VBox/GuestHost/SharedClipboard/ClipboardProvider-VbglR3.cpp@ 79268

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

Shared Clipboard/URI: Update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1/* $Id: ClipboardProvider-VbglR3.cpp 79267 2019-06-21 10:11:59Z vboxsync $ */
2/** @file
3 * Shared Clipboard - Provider implementation for VbglR3 (guest side).
4 */
5
6/*
7 * Copyright (C) 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
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_SHARED_CLIPBOARD
23#include <VBox/GuestHost/SharedClipboard-uri.h>
24#include <VBox/VBoxGuestLib.h>
25
26#include <iprt/asm.h>
27#include <iprt/assert.h>
28#include <iprt/dir.h>
29#include <iprt/errcore.h>
30#include <iprt/file.h>
31#include <iprt/path.h>
32#include <iprt/string.h>
33
34#include <VBox/log.h>
35
36
37SharedClipboardProviderVbglR3::SharedClipboardProviderVbglR3(uint32_t uClientID)
38 : m_uClientID(uClientID)
39{
40 LogFlowFunc(("m_uClientID=%RU32\n", m_uClientID));
41}
42
43SharedClipboardProviderVbglR3::~SharedClipboardProviderVbglR3(void)
44{
45}
46
47int SharedClipboardProviderVbglR3::ReadDataHdr(PVBOXCLIPBOARDDATAHDR *ppDataHdr)
48{
49 LogFlowFuncEnter();
50
51 VBOXCLIPBOARDDATAHDR dataHdr;
52 int rc = VbglR3ClipboardReadDataHdr(m_uClientID, &dataHdr);
53 if (RT_SUCCESS(rc))
54 {
55 *ppDataHdr = SharedClipboardURIDataHdrDup(&dataHdr);
56 }
57
58 LogFlowFuncLeaveRC(rc);
59 return rc;
60}
61
62int SharedClipboardProviderVbglR3::WriteDataHdr(const PVBOXCLIPBOARDDATAHDR pDataHdr)
63{
64 LogFlowFuncEnter();
65
66 int rc = VbglR3ClipboardWriteDataHdr(m_uClientID, pDataHdr);
67
68 LogFlowFuncLeaveRC(rc);
69 return rc;
70}
71
72int SharedClipboardProviderVbglR3::ReadDataChunk(const PVBOXCLIPBOARDDATAHDR pDataHdr, void *pvChunk, uint32_t cbChunk,
73 uint32_t fFlags /* = 0 */, uint32_t *pcbRead /* = NULL */)
74{
75 RT_NOREF(fFlags);
76
77 LogFlowFuncEnter();
78
79 int rc = VINF_SUCCESS;
80
81 uint32_t cbReadTotal = 0;
82 uint32_t cbToRead = RT_MIN(pDataHdr->cbMeta, cbChunk);
83
84 while (cbToRead)
85 {
86 uint32_t cbRead;
87 rc = VbglR3ClipboardReadMetaData(m_uClientID, pDataHdr, (uint8_t *)pvChunk + cbReadTotal, cbToRead, &cbRead);
88 if (RT_FAILURE(rc))
89 break;
90
91 cbReadTotal += cbRead;
92 Assert(cbToRead >= cbRead);
93 cbToRead -= cbRead;
94 }
95
96 if (RT_SUCCESS(rc))
97 {
98 if (pcbRead)
99 *pcbRead = cbReadTotal;
100 }
101
102 LogFlowFuncLeaveRC(rc);
103 return rc;
104}
105
106int SharedClipboardProviderVbglR3::WriteDataChunk(const PVBOXCLIPBOARDDATAHDR pDataHdr, const void *pvChunk, uint32_t cbChunk,
107 uint32_t fFlags /* = 0 */, uint32_t *pcbWritten /* = NULL */)
108{
109 RT_NOREF(fFlags);
110
111 LogFlowFuncEnter();
112
113 int rc = VINF_SUCCESS;
114
115 uint32_t cbWrittenTotal = 0;
116 uint32_t cbToWrite = RT_MIN(pDataHdr->cbMeta, cbChunk);
117
118 while (cbToWrite)
119 {
120 uint32_t cbWritten;
121 rc = VbglR3ClipboardWriteMetaData(m_uClientID, pDataHdr, (uint8_t *)pvChunk + cbWrittenTotal, cbToWrite, &cbWritten);
122 if (RT_FAILURE(rc))
123 break;
124
125 cbWrittenTotal += cbWritten;
126 Assert(cbToWrite >= cbWritten);
127 cbToWrite -= cbWritten;
128 }
129
130 if (RT_SUCCESS(rc))
131 {
132 if (pcbWritten)
133 *pcbWritten = cbWrittenTotal;
134 }
135
136 LogFlowFunc(("cbWrittenTotal=%RU32, rc=%Rrc\n", cbWrittenTotal, rc));
137 return rc;
138}
139
140int SharedClipboardProviderVbglR3::ReadDirectory(PVBOXCLIPBOARDDIRDATA *ppDirData)
141{
142 LogFlowFuncEnter();
143
144 VBOXCLIPBOARDDIRDATA dirData;
145 int rc = VbglR3ClipboardReadDir(m_uClientID, dirData.pszPath, dirData.cbPath, &dirData.cbPath, &dirData.fMode);
146 if (RT_SUCCESS(rc))
147 {
148 *ppDirData = SharedClipboardURIDirDataDup(&dirData);
149 }
150
151 LogFlowFuncLeaveRC(rc);
152 return rc;
153}
154
155int SharedClipboardProviderVbglR3::WriteDirectory(const PVBOXCLIPBOARDDIRDATA pDirData)
156{
157 LogFlowFuncEnter();
158
159 int rc = VbglR3ClipboardWriteDir(m_uClientID, pDirData->pszPath, pDirData->cbPath, pDirData->fMode);
160
161 LogFlowFuncLeaveRC(rc);
162 return rc;
163}
164
165int SharedClipboardProviderVbglR3::ReadFileHdr(PVBOXCLIPBOARDFILEHDR *ppFileHdr)
166{
167 LogFlowFuncEnter();
168
169 VBOXCLIPBOARDFILEHDR fileHdr;
170 int rc = VbglR3ClipboardReadFileHdr(m_uClientID, fileHdr.pszFilePath, fileHdr.cbFilePath,
171 &fileHdr.fFlags, &fileHdr.fMode, &fileHdr.cbSize);
172 if (RT_SUCCESS(rc))
173 {
174 *ppFileHdr = SharedClipboardURIFileHdrDup(&fileHdr);
175 }
176
177 LogFlowFuncLeaveRC(rc);
178 return rc;
179}
180
181int SharedClipboardProviderVbglR3::WriteFileHdr(const PVBOXCLIPBOARDFILEHDR pFileHdr)
182{
183 LogFlowFuncEnter();
184
185 int rc = VbglR3ClipboardWriteFileHdr(m_uClientID, pFileHdr->pszFilePath, pFileHdr->cbFilePath,
186 pFileHdr->fFlags, pFileHdr->fMode, pFileHdr->cbSize);
187 LogFlowFuncLeaveRC(rc);
188 return rc;
189}
190
191int SharedClipboardProviderVbglR3::ReadFileData(void *pvData, uint32_t cbData, uint32_t fFlags /* = 0 */,
192 uint32_t *pcbRead /* = NULL */)
193{
194 RT_NOREF(fFlags);
195
196 AssertPtrReturn(pcbRead, VERR_INVALID_POINTER);
197
198 LogFlowFuncEnter();
199
200 int rc = VbglR3ClipboardReadFileData(m_uClientID, pvData, cbData, pcbRead);
201
202 LogFlowFuncLeaveRC(rc);
203 return rc;
204}
205
206int SharedClipboardProviderVbglR3::WriteFileData(void *pvData, uint32_t cbData, uint32_t fFlags /* = 0 */,
207 uint32_t *pcbWritten /* = NULL */)
208{
209 RT_NOREF(fFlags);
210
211 AssertPtrReturn(pcbWritten, VERR_INVALID_POINTER);
212
213 LogFlowFuncEnter();
214
215 int rc = VbglR3ClipboardWriteFileData(m_uClientID, pvData, cbData, pcbWritten);
216
217 LogFlowFuncLeaveRC(rc);
218 return rc;
219}
220
221void SharedClipboardProviderVbglR3::Reset(void)
222{
223 LogFlowFuncEnter();
224
225 /* Don't clear the refcount here. */
226}
227
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