VirtualBox

source: vbox/trunk/src/VBox/GuestHost/SharedClipboard/ClipboardStreamImpl-win.cpp@ 79630

最後變更 在這個檔案從79630是 79630,由 vboxsync 提交於 6 年 前

Shared Clipboard/URI: Update.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 9.3 KB
 
1/* $Id: ClipboardStreamImpl-win.cpp 79630 2019-07-09 08:14:01Z vboxsync $ */
2/** @file
3 * ClipboardStreamImpl-win.cpp - Shared Clipboard IStream object implementation (guest and host 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.alldomusa.eu.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-win.h>
24
25#include <iprt/asm.h>
26#include <iprt/ldr.h>
27#include <iprt/thread.h>
28
29#include <VBox/GuestHost/SharedClipboard.h>
30#include <VBox/GuestHost/SharedClipboard-win.h>
31#include <strsafe.h>
32
33#include <VBox/log.h>
34
35
36/*********************************************************************************************************************************
37* Structures and Typedefs *
38*********************************************************************************************************************************/
39
40
41
42/*********************************************************************************************************************************
43* Static variables *
44*********************************************************************************************************************************/
45
46
47
48VBoxClipboardWinStreamImpl::VBoxClipboardWinStreamImpl(VBoxClipboardWinDataObject *pParent,
49 PSHAREDCLIPBOARDURITRANSFER pTransfer, SHAREDCLIPBOARDOBJHANDLE hObj)
50 : m_pParent(pParent)
51 , m_lRefCount(1)
52 , m_pURITransfer(pTransfer)
53 , m_hObj(hObj)
54{
55 AssertPtr(m_pURITransfer);
56
57 LogFunc(("m_hObj=%RU64\n", m_hObj));
58}
59
60VBoxClipboardWinStreamImpl::~VBoxClipboardWinStreamImpl(void)
61{
62 LogFlowThisFuncEnter();
63}
64
65/*
66 * IUnknown methods.
67 */
68
69STDMETHODIMP VBoxClipboardWinStreamImpl::QueryInterface(REFIID iid, void **ppvObject)
70{
71 AssertPtrReturn(ppvObject, E_INVALIDARG);
72
73 if (iid == IID_IUnknown)
74 {
75 LogFlowFunc(("IID_IUnknown\n"));
76 *ppvObject = (IUnknown *)(ISequentialStream *)this;
77 }
78 else if (iid == IID_ISequentialStream)
79 {
80 LogFlowFunc(("IID_ISequentialStream\n"));
81 *ppvObject = (ISequentialStream *)this;
82 }
83 else if (iid == IID_IStream)
84 {
85 LogFlowFunc(("IID_IStream\n"));
86 *ppvObject = (IStream *)this;
87 }
88 else
89 {
90 *ppvObject = NULL;
91 return E_NOINTERFACE;
92 }
93
94 AddRef();
95 return S_OK;
96}
97
98STDMETHODIMP_(ULONG) VBoxClipboardWinStreamImpl::AddRef(void)
99{
100 LONG lCount = InterlockedIncrement(&m_lRefCount);
101 LogFlowFunc(("lCount=%RI32\n", lCount));
102 return lCount;
103}
104
105STDMETHODIMP_(ULONG) VBoxClipboardWinStreamImpl::Release(void)
106{
107 LONG lCount = InterlockedDecrement(&m_lRefCount);
108 LogFlowFunc(("lCount=%RI32\n", m_lRefCount));
109 if (lCount == 0)
110 {
111 if (m_pParent)
112 m_pParent->OnTransferComplete();
113
114 delete this;
115 return 0;
116 }
117
118 return lCount;
119}
120
121/*
122 * IStream methods.
123 */
124
125STDMETHODIMP VBoxClipboardWinStreamImpl::Clone(IStream** ppStream)
126{
127 RT_NOREF(ppStream);
128
129 LogFlowFuncEnter();
130 return E_NOTIMPL;
131}
132
133STDMETHODIMP VBoxClipboardWinStreamImpl::Commit(DWORD dwFrags)
134{
135 RT_NOREF(dwFrags);
136
137 LogFlowThisFuncEnter();
138 return E_NOTIMPL;
139}
140
141STDMETHODIMP VBoxClipboardWinStreamImpl::CopyTo(IStream *pDestStream, ULARGE_INTEGER nBytesToCopy, ULARGE_INTEGER *nBytesRead,
142 ULARGE_INTEGER *nBytesWritten)
143{
144 RT_NOREF(pDestStream, nBytesToCopy, nBytesRead, nBytesWritten);
145
146 LogFlowThisFuncEnter();
147 return E_NOTIMPL;
148}
149
150STDMETHODIMP VBoxClipboardWinStreamImpl::LockRegion(ULARGE_INTEGER nStart, ULARGE_INTEGER nBytes,DWORD dwFlags)
151{
152 RT_NOREF(nStart, nBytes, dwFlags);
153
154 LogFlowThisFuncEnter();
155 return STG_E_INVALIDFUNCTION;
156}
157
158STDMETHODIMP VBoxClipboardWinStreamImpl::Read(void *pvBuffer, ULONG nBytesToRead, ULONG *nBytesRead)
159{
160 LogFlowThisFuncEnter();
161
162 const uint64_t cbSize = m_pURITransfer->ProviderIface.pfnObjGetSize(&m_pURITransfer->ProviderCtx, m_hObj);
163 uint64_t cbProcessed = m_pURITransfer->ProviderIface.pfnObjGetProcessed(&m_pURITransfer->ProviderCtx, m_hObj);
164
165 if (cbProcessed == cbSize)
166 {
167 /* There can be 0-byte files. */
168 AssertMsg(cbSize == 0, ("Object is complete -- can't read from it anymore\n"));
169 if (nBytesRead)
170 *nBytesRead = 0; /** @todo If the file size is 0, already return at least 1 byte, else the whole operation will fail. */
171 return S_OK; /* Don't report any failures back to Windows. */
172 }
173
174 const uint32_t cbToRead = RT_MIN(cbSize - cbProcessed, nBytesToRead);
175 uint32_t cbRead = 0;
176
177 int rc = VINF_SUCCESS;
178
179 if (cbToRead)
180 {
181 rc = m_pURITransfer->ProviderIface.pfnObjRead(&m_pURITransfer->ProviderCtx, m_hObj,
182 pvBuffer, cbToRead, 0 /* fFlags */, &cbRead);
183 if (RT_SUCCESS(rc))
184 {
185 cbProcessed += cbRead;
186 Assert(cbProcessed <= cbSize);
187
188 if (cbProcessed == cbSize)
189 m_pParent->OnTransferComplete();
190
191 #if 0
192 m_pObj->State.cbProcessed = cbProcessed;
193 Assert(m_pObj->State.cbProcessed <= m_pObj->objInfo.cbObject);
194 #endif
195 }
196 }
197
198 if (nBytesRead)
199 *nBytesRead = (ULONG)cbRead;
200
201 LogFlowThisFunc(("rc=%Rrc, cbSize=%RU64, cbProcessed=%RU64 -> cbToRead=%zu, cbRead=%zu\n",
202 rc, cbSize, cbProcessed, cbToRead, cbRead));
203 return RT_SUCCESS(rc) ? S_OK : E_FAIL;
204}
205
206STDMETHODIMP VBoxClipboardWinStreamImpl::Revert(void)
207{
208 LogFlowThisFuncEnter();
209 return STG_E_INVALIDFUNCTION;
210}
211
212STDMETHODIMP VBoxClipboardWinStreamImpl::Seek(LARGE_INTEGER nMove, DWORD dwOrigin, ULARGE_INTEGER* nNewPos)
213{
214 RT_NOREF(nMove, dwOrigin, nNewPos);
215
216 LogFlowThisFuncEnter();
217 return STG_E_INVALIDFUNCTION;
218}
219
220STDMETHODIMP VBoxClipboardWinStreamImpl::SetSize(ULARGE_INTEGER nNewSize)
221{
222 RT_NOREF(nNewSize);
223
224 LogFlowThisFuncEnter();
225 return STG_E_INVALIDFUNCTION;
226}
227
228STDMETHODIMP VBoxClipboardWinStreamImpl::Stat(STATSTG *pStatStg, DWORD dwFlags)
229{
230 HRESULT hr = S_OK;
231
232 if (pStatStg)
233 {
234 RT_BZERO(pStatStg, sizeof(STATSTG));
235
236 switch (dwFlags)
237 {
238 case STATFLAG_NONAME:
239 pStatStg->pwcsName = NULL;
240 break;
241
242 case STATFLAG_DEFAULT:
243 {
244 int rc2 = RTStrToUtf16(m_pURITransfer->ProviderIface.pfnObjGetPath(&m_pURITransfer->ProviderCtx, m_hObj),
245 &pStatStg->pwcsName);
246 if (RT_FAILURE(rc2))
247 hr = E_FAIL;
248 break;
249 }
250
251 default:
252 hr = STG_E_INVALIDFLAG;
253 break;
254 }
255
256 if (SUCCEEDED(hr))
257 {
258 pStatStg->type = STGTY_STREAM;
259 pStatStg->grfMode = STGM_READ;
260 pStatStg->grfLocksSupported = 0;
261 pStatStg->cbSize.QuadPart = m_pURITransfer->ProviderIface.pfnObjGetSize(&m_pURITransfer->ProviderCtx, m_hObj);
262 }
263 }
264 else
265 hr = STG_E_INVALIDPOINTER;
266
267 LogFlowThisFunc(("hr=%Rhrc\n", hr));
268 return hr;
269}
270
271STDMETHODIMP VBoxClipboardWinStreamImpl::UnlockRegion(ULARGE_INTEGER nStart, ULARGE_INTEGER nBytes, DWORD dwFlags)
272{
273 RT_NOREF(nStart, nBytes, dwFlags);
274
275 LogFlowThisFuncEnter();
276 return STG_E_INVALIDFUNCTION;
277}
278
279STDMETHODIMP VBoxClipboardWinStreamImpl::Write(const void *pvBuffer, ULONG nBytesToRead, ULONG *nBytesRead)
280{
281 RT_NOREF(pvBuffer, nBytesToRead, nBytesRead);
282
283 LogFlowThisFuncEnter();
284 return E_NOTIMPL;
285}
286
287/*
288 * Own stuff.
289 */
290
291/**
292 * Factory to create our own IStream implementation.
293 *
294 * @returns HRESULT
295 * @param pParent Pointer to the parent data object.
296 * @param pTransfer Pointer to URI transfer object to use.
297 * @param hObj Handle of URI transfer object.
298 * @param ppStream Where to return the created stream object on success.
299 */
300/* static */
301HRESULT VBoxClipboardWinStreamImpl::Create(VBoxClipboardWinDataObject *pParent, PSHAREDCLIPBOARDURITRANSFER pTransfer,
302 SHAREDCLIPBOARDOBJHANDLE hObj, IStream **ppStream)
303{
304 AssertPtrReturn(pTransfer, E_POINTER);
305
306 VBoxClipboardWinStreamImpl *pStream = new VBoxClipboardWinStreamImpl(pParent, pTransfer, hObj);
307 if (pStream)
308 {
309 pStream->AddRef();
310
311 *ppStream = pStream;
312 return S_OK;
313 }
314
315 return E_FAIL;
316}
317
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette