VirtualBox

source: vbox/trunk/src/VBox/GuestHost/SharedClipboard/ClipboardDataObjectImpl-win.cpp@ 100538

Last change on this file since 100538 was 100538, checked in by vboxsync, 18 months ago

Shared Clipboard: Use a dedicated worker thread wrapper for transfer threads, so that we have more control for the thread creation / destruction. bugref:9437

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 42.4 KB
Line 
1/* $Id: ClipboardDataObjectImpl-win.cpp 100538 2023-07-12 08:53:20Z vboxsync $ */
2/** @file
3 * ClipboardDataObjectImpl-win.cpp - Shared Clipboard IDataObject implementation.
4 */
5
6/*
7 * Copyright (C) 2019-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_SHARED_CLIPBOARD
33#include <VBox/GuestHost/SharedClipboard-win.h>
34#include <VBox/GuestHost/SharedClipboard-transfers.h>
35
36#include <iprt/win/windows.h>
37#include <iprt/win/shlobj.h>
38#include <iprt/win/shlwapi.h>
39
40#include <iprt/thread.h> // REMOVE
41
42#include <iprt/asm.h>
43#include <iprt/errcore.h>
44#include <iprt/path.h>
45#include <iprt/semaphore.h>
46#include <iprt/uri.h>
47#include <iprt/utf16.h>
48
49#include <iprt/errcore.h>
50#include <VBox/log.h>
51
52/** @todo Also handle Unicode entries.
53 * !!! WARNING: Buggy, doesn't work yet (some memory corruption / garbage in the file name descriptions) !!! */
54//#define VBOX_CLIPBOARD_WITH_UNICODE_SUPPORT 1
55
56SharedClipboardWinDataObject::SharedClipboardWinDataObject(void)
57 : m_pCtx(NULL)
58 , m_enmStatus(Uninitialized)
59 , m_rcStatus(VERR_IPE_UNINITIALIZED_STATUS)
60 , m_lRefCount(0)
61 , m_cFormats(0)
62 , m_pTransfer(NULL)
63 , m_pStream(NULL)
64 , m_uObjIdx(0)
65 , m_EventListComplete(NIL_RTSEMEVENT)
66 , m_EventStatusChanged(NIL_RTSEMEVENT)
67{
68}
69
70SharedClipboardWinDataObject::~SharedClipboardWinDataObject(void)
71{
72 Destroy();
73
74 LogFlowFunc(("mRefCount=%RI32\n", m_lRefCount));
75}
76
77/**
78 * Initializes a data object instance.
79 *
80 * @returns VBox status code.
81 * @param pCtx Opaque Shared Clipboard context to use.
82 * @param pCallbacks Callbacks table to use.
83 * @param pFormatEtc FormatETC to use. Optional.
84 * @param pStgMed Storage medium to use. Optional.
85 * @param cFormats Number of formats in \a pFormatEtc and \a pStgMed. Optional.
86 */
87int SharedClipboardWinDataObject::Init(PSHCLCONTEXT pCtx, SharedClipboardWinDataObject::PCALLBACKS pCallbacks,
88 LPFORMATETC pFormatEtc /* = NULL */, LPSTGMEDIUM pStgMed /* = NULL */,
89 ULONG cFormats /* = 0 */)
90{
91 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
92 AssertPtrReturn(pCallbacks, VERR_INVALID_POINTER);
93 AssertReturn(cFormats == 0 || (RT_VALID_PTR(pFormatEtc) && RT_VALID_PTR(pStgMed)), VERR_INVALID_POINTER);
94
95 int rc = VINF_SUCCESS;
96
97 m_pCtx = pCtx; /* Save opaque context. */
98
99 /*
100 * Set up callback context + table.
101 */
102 memcpy(&m_Callbacks, pCallbacks, sizeof(SharedClipboardWinDataObject::CALLBACKS));
103 m_CallbackCtx.pvUser = pCtx;
104 m_CallbackCtx.pThis = this;
105
106 /*
107 * Set up / register handled formats.
108 */
109 ULONG cFixedFormats = 3; /* CFSTR_FILEDESCRIPTORA + CFSTR_FILECONTENTS + CFSTR_PERFORMEDDROPEFFECT */
110#ifdef VBOX_CLIPBOARD_WITH_UNICODE_SUPPORT
111 cFixedFormats++; /* CFSTR_FILEDESCRIPTORW */
112#endif
113 const ULONG cAllFormats = cFormats + cFixedFormats;
114
115 m_pFormatEtc = new FORMATETC[cAllFormats];
116 AssertPtrReturn(m_pFormatEtc, VERR_NO_MEMORY);
117 RT_BZERO(m_pFormatEtc, sizeof(FORMATETC) * cAllFormats);
118 m_pStgMedium = new STGMEDIUM[cAllFormats];
119 AssertPtrReturn(m_pStgMedium, VERR_NO_MEMORY);
120 RT_BZERO(m_pStgMedium, sizeof(STGMEDIUM) * cAllFormats);
121
122 /** @todo Do we need CFSTR_FILENAME / CFSTR_SHELLIDLIST here? */
123
124 /*
125 * Register fixed formats.
126 */
127 unsigned uIdx = 0;
128
129 LogFlowFunc(("Registering CFSTR_FILEDESCRIPTORA ...\n"));
130 m_cfFileDescriptorA = RegisterClipboardFormat(CFSTR_FILEDESCRIPTORA);
131 registerFormat(&m_pFormatEtc[uIdx++], m_cfFileDescriptorA);
132#ifdef VBOX_CLIPBOARD_WITH_UNICODE_SUPPORT
133 LogFlowFunc(("Registering CFSTR_FILEDESCRIPTORW ...\n"));
134 m_cfFileDescriptorW = RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW);
135 registerFormat(&m_pFormatEtc[uIdx++], m_cfFileDescriptorW);
136#endif
137
138 /* IStream interface, implemented in ClipboardStreamImpl-win.cpp. */
139 LogFlowFunc(("Registering CFSTR_FILECONTENTS ...\n"));
140 m_cfFileContents = RegisterClipboardFormat(CFSTR_FILECONTENTS);
141 registerFormat(&m_pFormatEtc[uIdx++], m_cfFileContents, TYMED_ISTREAM, 0 /* lIndex */);
142
143 /* We want to know from the target what the outcome of the operation was to react accordingly (e.g. abort a transfer). */
144 LogFlowFunc(("Registering CFSTR_PERFORMEDDROPEFFECT ...\n"));
145 m_cfPerformedDropEffect = RegisterClipboardFormat(CFSTR_PERFORMEDDROPEFFECT);
146 registerFormat(&m_pFormatEtc[uIdx++], m_cfPerformedDropEffect, TYMED_HGLOBAL, -1 /* lIndex */, DVASPECT_CONTENT);
147
148 /*
149 * Registration of dynamic formats needed?
150 */
151 LogFlowFunc(("%RU32 dynamic formats\n", cFormats));
152 if (cFormats)
153 {
154 for (ULONG i = 0; i < cFormats; i++)
155 {
156 LogFlowFunc(("Format %RU32: cfFormat=%RI16, tyMed=%RU32, dwAspect=%RU32\n",
157 i, pFormatEtc[i].cfFormat, pFormatEtc[i].tymed, pFormatEtc[i].dwAspect));
158 m_pFormatEtc[cFixedFormats + i] = pFormatEtc[i];
159 m_pStgMedium[cFixedFormats + i] = pStgMed[i];
160 }
161 }
162
163 if (RT_SUCCESS(rc))
164 {
165 m_cFormats = cAllFormats;
166 m_enmStatus = Initialized;
167
168 rc = RTCritSectInit(&m_CritSect);
169 if (RT_SUCCESS(rc))
170 {
171 rc = RTSemEventCreate(&m_EventListComplete);
172 if (RT_SUCCESS(rc))
173 rc = RTSemEventCreate(&m_EventStatusChanged);
174 }
175 }
176
177 LogFlowFunc(("cAllFormats=%RU32, rc=%Rrc\n", cAllFormats, rc));
178 return rc;
179}
180
181/**
182 * Uninitialized a data object instance, internal version.
183 */
184void SharedClipboardWinDataObject::uninitInternal(void)
185{
186 LogFlowFuncEnter();
187
188 /* Let waiters know. */
189 setStatusLocked(Uninitialized, VINF_SUCCESS);
190
191 /* Make sure to release the transfer. */
192 setTransferLocked(NULL);
193}
194
195/**
196 * Uninitialized a data object instance.
197 */
198void SharedClipboardWinDataObject::Uninit(void)
199{
200 LogFlowFuncEnter();
201
202 lock();
203
204 uninitInternal();
205
206 unlock();
207}
208
209/**
210 * Destroys a data object instance.
211 */
212void SharedClipboardWinDataObject::Destroy(void)
213{
214 LogFlowFuncEnter();
215
216 if (m_enmStatus == Uninitialized) /* Crit sect not available anymore. */
217 return;
218
219 lock();
220
221 uninitInternal();
222
223 unlock();
224
225 int rc = RTCritSectDelete(&m_CritSect);
226 AssertRC(rc);
227
228 if (m_EventListComplete != NIL_RTSEMEVENT)
229 {
230 rc = RTSemEventDestroy(m_EventListComplete);
231 AssertRC(rc);
232 m_EventListComplete = NIL_RTSEMEVENT;
233 }
234
235 if (m_EventStatusChanged != NIL_RTSEMEVENT)
236 {
237 rc = RTSemEventDestroy(m_EventStatusChanged);
238 AssertRC(rc);
239 m_EventStatusChanged = NIL_RTSEMEVENT;
240 }
241
242 if (m_pStream)
243 {
244 m_pStream->Release();
245 m_pStream = NULL;
246 }
247
248 if (m_pFormatEtc)
249 {
250 delete[] m_pFormatEtc;
251 m_pFormatEtc = NULL;
252 }
253
254 if (m_pStgMedium)
255 {
256 delete[] m_pStgMedium;
257 m_pStgMedium = NULL;
258 }
259
260 if (m_pTransfer)
261 ShClTransferRelease(m_pTransfer);
262
263 FsObjEntryList::const_iterator itRoot = m_lstEntries.cbegin();
264 while (itRoot != m_lstEntries.end())
265 {
266 RTStrFree(itRoot->pszPath);
267 ++itRoot;
268 }
269 m_lstEntries.clear();
270}
271
272
273/*********************************************************************************************************************************
274 * IUnknown methods.
275 ********************************************************************************************************************************/
276
277STDMETHODIMP_(ULONG) SharedClipboardWinDataObject::AddRef(void)
278{
279 ULONG ulCount = InterlockedIncrement(&m_lRefCount);
280 LogFlowFunc(("lCount=%RU32\n", ulCount));
281 return ulCount;
282}
283
284STDMETHODIMP_(ULONG) SharedClipboardWinDataObject::Release(void)
285{
286 ULONG ulCount = InterlockedDecrement(&m_lRefCount);
287 LogFlowFunc(("lCount=%RU32\n", ulCount));
288 if (ulCount == 0)
289 {
290 delete this;
291 return 0;
292 }
293
294 return ulCount;
295}
296
297STDMETHODIMP SharedClipboardWinDataObject::QueryInterface(REFIID iid, void **ppvObject)
298{
299 AssertPtrReturn(ppvObject, E_INVALIDARG);
300
301 if ( iid == IID_IDataObject
302 || iid == IID_IUnknown)
303 {
304 AddRef();
305 *ppvObject = this;
306 return S_OK;
307 }
308
309 *ppvObject = 0;
310 return E_NOINTERFACE;
311}
312
313/**
314 * Copies a chunk of data into a HGLOBAL object.
315 *
316 * @returns VBox status code.
317 * @param pvData Data to copy.
318 * @param cbData Size (in bytes) to copy.
319 * @param fFlags GlobalAlloc flags, used for allocating the HGLOBAL block.
320 * @param phGlobal Where to store the allocated HGLOBAL object.
321 */
322int SharedClipboardWinDataObject::copyToHGlobal(const void *pvData, size_t cbData, UINT fFlags, HGLOBAL *phGlobal)
323{
324 AssertPtrReturn(phGlobal, VERR_INVALID_POINTER);
325
326 HGLOBAL hGlobal = GlobalAlloc(fFlags, cbData);
327 if (!hGlobal)
328 return VERR_NO_MEMORY;
329
330 void *pvAlloc = GlobalLock(hGlobal);
331 if (pvAlloc)
332 {
333 CopyMemory(pvAlloc, pvData, cbData);
334 GlobalUnlock(hGlobal);
335
336 *phGlobal = hGlobal;
337
338 return VINF_SUCCESS;
339 }
340
341 GlobalFree(hGlobal);
342 return VERR_ACCESS_DENIED;
343}
344
345inline int SharedClipboardWinDataObject::lock(void)
346{
347 int rc = RTCritSectEnter(&m_CritSect);
348 AssertRCReturn(rc, rc);
349
350 return rc;
351}
352
353inline int SharedClipboardWinDataObject::unlock(void)
354{
355 int rc = RTCritSectLeave(&m_CritSect);
356 AssertRCReturn(rc, rc);
357
358 return rc;
359}
360
361/**
362 * Reads (handles) a specific directory reursively and inserts its entry into the
363 * objects's entry list.
364 *
365 * @returns VBox status code.
366 * @param pTransfer Shared Clipboard transfer object to handle.
367 * @param strDir Directory path to handle.
368 */
369int SharedClipboardWinDataObject::readDir(PSHCLTRANSFER pTransfer, const Utf8Str &strDir)
370{
371 LogFlowFunc(("strDir=%s\n", strDir.c_str()));
372
373 SHCLLISTOPENPARMS openParmsList;
374 int rc = ShClTransferListOpenParmsInit(&openParmsList);
375 if (RT_SUCCESS(rc))
376 {
377 rc = RTStrCopy(openParmsList.pszPath, openParmsList.cbPath, strDir.c_str());
378 if (RT_SUCCESS(rc))
379 {
380 SHCLLISTHANDLE hList;
381 rc = ShClTransferListOpen(pTransfer, &openParmsList, &hList);
382 if (RT_SUCCESS(rc))
383 {
384 LogFlowFunc(("strDir=%s -> hList=%RU64\n", strDir.c_str(), hList));
385
386 SHCLLISTHDR hdrList;
387 rc = ShClTransferListGetHeader(pTransfer, hList, &hdrList);
388 if (RT_SUCCESS(rc))
389 {
390 LogFlowFunc(("cTotalObjects=%RU64, cbTotalSize=%RU64\n\n",
391 hdrList.cEntries, hdrList.cbTotalSize));
392
393 for (uint64_t o = 0; o < hdrList.cEntries; o++)
394 {
395 SHCLLISTENTRY entryList;
396 rc = ShClTransferListEntryInit(&entryList);
397 if (RT_SUCCESS(rc))
398 {
399 rc = ShClTransferListRead(pTransfer, hList, &entryList);
400 if (RT_SUCCESS(rc))
401 {
402 if (ShClTransferListEntryIsValid(&entryList))
403 {
404 PSHCLFSOBJINFO pFsObjInfo = (PSHCLFSOBJINFO)entryList.pvInfo;
405 Assert(entryList.cbInfo == sizeof(SHCLFSOBJINFO));
406
407 Utf8Str strPath = strDir + Utf8Str("\\") + Utf8Str(entryList.pszName);
408
409 LogFlowFunc(("\t%s (%RU64 bytes) -> %s\n",
410 entryList.pszName, pFsObjInfo->cbObject, strPath.c_str()));
411
412 if ( RTFS_IS_DIRECTORY(pFsObjInfo->Attr.fMode)
413 || RTFS_IS_FILE (pFsObjInfo->Attr.fMode))
414 {
415 FSOBJENTRY objEntry;
416 objEntry.pszPath = RTStrDup(strPath.c_str());
417 AssertPtrBreakStmt(objEntry.pszPath, rc = VERR_NO_MEMORY);
418 objEntry.objInfo = *pFsObjInfo;
419
420 lock();
421 m_lstEntries.push_back(objEntry); /** @todo Can this throw? */
422 unlock();
423 }
424 else /* Not fatal, just skip. */
425 LogRel(("Shared Clipboard: Warning: File system object '%s' of type %#x not supported, skipping\n",
426 strPath.c_str(), pFsObjInfo->Attr.fMode & RTFS_TYPE_MASK));
427
428 /** @todo Handle symlinks. */
429 }
430 else
431 rc = VERR_INVALID_PARAMETER;
432 }
433
434 ShClTransferListEntryDestroy(&entryList);
435 }
436
437 if ( RT_FAILURE(rc)
438 && pTransfer->Thread.fStop)
439 break;
440 }
441 }
442
443 ShClTransferListClose(pTransfer, hList);
444 }
445 }
446
447 ShClTransferListOpenParmsDestroy(&openParmsList);
448 }
449
450 if (RT_FAILURE(rc))
451 LogRel(("Shared Clipboard: Reading directory '%s' failed with %Rrc\n", strDir.c_str(), rc));
452
453 LogFlowFuncLeaveRC(rc);
454 return rc;
455}
456
457/**
458 * Thread for reading transfer data.
459 * The data object needs the (high level, root) transfer listing at the time of ::GetData(), so we need
460 * to block and wait until we have this data (via this thread) and continue.
461 *
462 * @returns VBox status code.
463 * @param ThreadSelf Thread handle. Unused at the moment.
464 * @param pvUser Pointer to user-provided data. Of type SharedClipboardWinDataObject.
465 */
466/* static */
467DECLCALLBACK(int) SharedClipboardWinDataObject::readThread(PSHCLTRANSFER pTransfer, void *pvUser)
468{
469 RT_NOREF(pTransfer);
470
471 LogFlowFuncEnter();
472
473 SharedClipboardWinDataObject *pThis = (SharedClipboardWinDataObject *)pvUser;
474
475 LogRel2(("Shared Clipboard: Calculating transfer ...\n"));
476
477 int rc = ShClTransferRootListRead(pTransfer);
478 if (RT_SUCCESS(rc))
479 {
480 uint64_t const cRoots = ShClTransferRootsCount(pTransfer);
481
482 LogFlowFunc(("cRoots=%RU64\n\n", cRoots));
483
484 for (uint32_t i = 0; i < cRoots; i++)
485 {
486 PCSHCLLISTENTRY pRootEntry = ShClTransferRootsEntryGet(pTransfer, i);
487
488 AssertBreakStmt(pRootEntry->cbInfo == sizeof(SHCLFSOBJINFO), rc = VERR_INVALID_PARAMETER);
489 PSHCLFSOBJINFO const pFsObjInfo = (PSHCLFSOBJINFO)pRootEntry->pvInfo;
490
491 LogFlowFunc(("pszRoot=%s, fMode=0x%x (type %#x)\n",
492 pRootEntry->pszName, pFsObjInfo->Attr.fMode, (pFsObjInfo->Attr.fMode & RTFS_TYPE_MASK)));
493
494 if (RTFS_IS_DIRECTORY(pFsObjInfo->Attr.fMode))
495 {
496 FSOBJENTRY objEntry;
497 objEntry.pszPath = RTStrDup(pRootEntry->pszName);
498 AssertPtrBreakStmt(objEntry.pszPath, rc = VERR_NO_MEMORY);
499 objEntry.objInfo = *pFsObjInfo;
500
501 pThis->lock();
502 pThis->m_lstEntries.push_back(objEntry); /** @todo Can this throw? */
503 pThis->unlock();
504
505 rc = pThis->readDir(pTransfer, pRootEntry->pszName);
506 }
507 else if (RTFS_IS_FILE(pFsObjInfo->Attr.fMode))
508 {
509 FSOBJENTRY objEntry;
510 objEntry.pszPath = RTStrDup(pRootEntry->pszName);
511 AssertPtrBreakStmt(objEntry.pszPath, rc = VERR_NO_MEMORY);
512 objEntry.objInfo = *pFsObjInfo;
513
514 pThis->lock();
515 pThis->m_lstEntries.push_back(objEntry); /** @todo Can this throw? */
516 pThis->unlock();
517 }
518 else
519 {
520 LogRel(("Shared Clipboard: Root entry '%s': File type %#x not supported\n",
521 pRootEntry->pszName, (pFsObjInfo->Attr.fMode & RTFS_TYPE_MASK)));
522 rc = VERR_NOT_SUPPORTED;
523 }
524
525 if (ASMAtomicReadBool(&pTransfer->Thread.fStop))
526 {
527 LogRel2(("Shared Clipboard: Stopping transfer calculation ...\n"));
528 break;
529 }
530
531 if (RT_FAILURE(rc))
532 break;
533 }
534
535 if ( RT_SUCCESS(rc)
536 && !ASMAtomicReadBool(&pTransfer->Thread.fStop))
537 {
538 LogRel2(("Shared Clipboard: Transfer calculation complete (%zu root entries)\n", pThis->m_lstEntries.size()));
539
540 /*
541 * Signal the "list complete" event so that this data object can return (valid) data via ::GetData().
542 * This in turn then will create IStream instances (by the OS) for each file system object to handle.
543 */
544 rc = RTSemEventSignal(pThis->m_EventListComplete);
545 if (RT_SUCCESS(rc))
546 {
547 pThis->lock();
548
549 AssertReleaseMsg(pThis->m_lstEntries.size(),
550 ("Shared Clipboard: No transfer root entries found -- should not happen, please file a bug report\n"));
551
552 LogRel2(("Shared Clipboard: Waiting for transfer to complete ...\n"));
553
554 for (;;)
555 {
556 pThis->unlock();
557
558 /* Transferring stuff can take a while, so don't use any timeout here. */
559 rc = RTSemEventWait(pThis->m_EventStatusChanged, RT_INDEFINITE_WAIT);
560
561 pThis->lock();
562
563 if (RT_FAILURE(rc))
564 break;
565
566 switch (pThis->m_enmStatus)
567 {
568 case Uninitialized: /* Can happen due to transfer erros. */
569 LogRel2(("Shared Clipboard: Data object was unitialized\n"));
570 break;
571
572 case Initialized:
573 AssertFailed(); /* State machine error -- debug this! */
574 break;
575
576 case Running:
577 continue;
578
579 case Completed:
580 LogRel2(("Shared Clipboard: Data object: Transfer complete\n"));
581 break;
582
583 case Canceled:
584 LogRel2(("Shared Clipboard: Data object: Transfer canceled\n"));
585 break;
586
587 case Error:
588 LogRel(("Shared Clipboard: Data object: Transfer error %Rrc occurred\n", pThis->m_rcStatus));
589 break;
590
591 default:
592 AssertFailed();
593 break;
594 }
595
596 break;
597 }
598
599 pThis->unlock();
600 }
601 }
602 }
603
604 if (RT_FAILURE(rc))
605 LogRel(("Shared Clipboard: Transfer failed with %Rrc\n", rc));
606
607 LogFlowFuncLeaveRC(rc);
608 return rc;
609}
610
611/**
612 * Creates a FILEGROUPDESCRIPTOR object from a given Shared Clipboard transfer and stores the result into an HGLOBAL object.
613 *
614 * @returns VBox status code.
615 * @param pTransfer Shared Clipboard transfer to create file grou desciprtor for.
616 * @param fUnicode Whether the FILEGROUPDESCRIPTOR object shall contain Unicode data or not.
617 * @param phGlobal Where to store the allocated HGLOBAL object on success.
618 */
619int SharedClipboardWinDataObject::createFileGroupDescriptorFromTransfer(PSHCLTRANSFER pTransfer,
620 bool fUnicode, HGLOBAL *phGlobal)
621{
622 AssertPtrReturn(pTransfer, VERR_INVALID_POINTER);
623 AssertPtrReturn(phGlobal, VERR_INVALID_POINTER);
624
625 LogFlowFuncEnter();
626
627 const size_t cbFileGroupDescriptor = fUnicode ? sizeof(FILEGROUPDESCRIPTORW) : sizeof(FILEGROUPDESCRIPTORA);
628 const size_t cbFileDescriptor = fUnicode ? sizeof(FILEDESCRIPTORW) : sizeof(FILEDESCRIPTORA);
629
630 const UINT cItems = (UINT)m_lstEntries.size(); /** UINT vs. size_t. */
631 if (!cItems)
632 return VERR_NOT_FOUND;
633
634 UINT curIdx = 0; /* Current index of the handled file group descriptor (FGD). */
635
636 const size_t cbFGD = cbFileGroupDescriptor + (cbFileDescriptor * (cItems - 1));
637
638 LogFunc(("fUnicode=%RTbool, cItems=%u, cbFileDescriptor=%zu\n", fUnicode, cItems, cbFileDescriptor));
639
640 /* FILEGROUPDESCRIPTORA / FILEGROUPDESCRIPTOR matches except the cFileName member (TCHAR vs. WCHAR). */
641 FILEGROUPDESCRIPTOR *pFGD = (FILEGROUPDESCRIPTOR *)RTMemAllocZ(cbFGD);
642 if (!pFGD)
643 return VERR_NO_MEMORY;
644
645 int rc = VINF_SUCCESS;
646
647 pFGD->cItems = cItems;
648
649 char *pszFileSpec = NULL;
650
651 FsObjEntryList::const_iterator itRoot = m_lstEntries.cbegin();
652 while (itRoot != m_lstEntries.end())
653 {
654 FILEDESCRIPTOR *pFD = &pFGD->fgd[curIdx];
655 RT_BZERO(pFD, cbFileDescriptor);
656
657 const char *pszFile = itRoot->pszPath;
658 AssertPtr(pszFile);
659
660 pszFileSpec = RTStrDup(pszFile);
661 AssertBreakStmt(pszFileSpec != NULL, rc = VERR_NO_MEMORY);
662
663 if (fUnicode)
664 {
665 PRTUTF16 pwszFileSpec;
666 rc = RTStrToUtf16(pszFileSpec, &pwszFileSpec);
667 if (RT_SUCCESS(rc))
668 {
669 rc = RTUtf16CopyEx((PRTUTF16 )pFD->cFileName, sizeof(pFD->cFileName) / sizeof(WCHAR),
670 pwszFileSpec, RTUtf16Len(pwszFileSpec));
671 RTUtf16Free(pwszFileSpec);
672
673 LogFlowFunc(("pFD->cFileNameW=%ls\n", pFD->cFileName));
674 }
675 }
676 else
677 {
678 rc = RTStrCopy(pFD->cFileName, sizeof(pFD->cFileName), pszFileSpec);
679 LogFlowFunc(("pFD->cFileNameA=%s\n", pFD->cFileName));
680 }
681
682 RTStrFree(pszFileSpec);
683 pszFileSpec = NULL;
684
685 if (RT_FAILURE(rc))
686 break;
687
688 pFD->dwFlags = FD_PROGRESSUI | FD_ATTRIBUTES;
689 if (fUnicode) /** @todo Only >= Vista. */
690 pFD->dwFlags |= FD_UNICODE;
691 pFD->dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
692
693 const SHCLFSOBJINFO *pObjInfo = &itRoot->objInfo;
694
695 if (RTFS_IS_DIRECTORY(pObjInfo->Attr.fMode))
696 {
697 pFD->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
698 }
699 else if (RTFS_IS_FILE(pObjInfo->Attr.fMode))
700 {
701 pFD->dwFlags |= FD_FILESIZE;
702
703 const uint64_t cbObjSize = pObjInfo->cbObject;
704
705 pFD->nFileSizeHigh = RT_HI_U32(cbObjSize);
706 pFD->nFileSizeLow = RT_LO_U32(cbObjSize);
707 }
708 else if (RTFS_IS_SYMLINK(pObjInfo->Attr.fMode))
709 {
710 /** @todo Implement. */
711 }
712#if 0 /** @todo Implement this. */
713 pFD->dwFlags = FD_ATTRIBUTES | FD_CREATETIME | FD_ACCESSTIME | FD_WRITESTIME | FD_FILESIZE;
714 pFD->dwFileAttributes =
715 pFD->ftCreationTime =
716 pFD->ftLastAccessTime =
717 pFD->ftLastWriteTime =
718#endif
719 ++curIdx;
720 ++itRoot;
721 }
722
723 if (pszFileSpec)
724 RTStrFree(pszFileSpec);
725
726 if (RT_SUCCESS(rc))
727 rc = copyToHGlobal(pFGD, cbFGD, GMEM_MOVEABLE, phGlobal);
728
729 RTMemFree(pFGD);
730
731 LogFlowFuncLeaveRC(rc);
732 return rc;
733}
734
735/**
736 * Retrieves the data stored in this object and store the result in pMedium.
737 *
738 * @return HRESULT
739 * @param pFormatEtc Format to retrieve.
740 * @param pMedium Where to store the data on success.
741 *
742 * @thread Windows event thread.
743 */
744STDMETHODIMP SharedClipboardWinDataObject::GetData(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium)
745{
746 AssertPtrReturn(pFormatEtc, DV_E_FORMATETC);
747 AssertPtrReturn(pMedium, DV_E_FORMATETC);
748
749 lock();
750
751 LogFlowFunc(("lIndex=%RI32, enmStatus=%#x\n", pFormatEtc->lindex, m_enmStatus));
752
753 /* If the object is not ready (anymore), bail out early. */
754 if ( m_enmStatus != Initialized
755 && m_enmStatus != Running)
756 {
757 unlock();
758 return E_UNEXPECTED;
759 }
760
761 /*
762 * Initialize default values.
763 */
764 RT_BZERO(pMedium, sizeof(STGMEDIUM));
765
766 HRESULT hr = DV_E_FORMATETC; /* Play safe. */
767
768 int rc = VINF_SUCCESS;
769
770 /* Pre-check -- see if the data object still is alive. */
771 if (m_enmStatus == Uninitialized)
772 rc = VERR_OBJECT_DESTROYED;
773
774 if ( RT_SUCCESS(rc)
775 && ( pFormatEtc->cfFormat == m_cfFileDescriptorA
776#ifdef VBOX_CLIPBOARD_WITH_UNICODE_SUPPORT
777 || pFormatEtc->cfFormat == m_cfFileDescriptorW
778#endif
779 )
780 )
781 {
782 switch (m_enmStatus)
783 {
784 case Initialized:
785 {
786 LogRel2(("Shared Clipboard: Requesting data for IDataObject ...\n"));
787
788 /* Leave lock while requesting + waiting. */
789 unlock();
790
791 /* Start the transfer. */
792 AssertPtrBreak(m_Callbacks.pfnTransferStart);
793 rc = m_Callbacks.pfnTransferStart(&m_CallbackCtx);
794 AssertRCBreak(rc);
795
796 LogRel2(("Shared Clipboard: Waiting for IDataObject started status ...\n"));
797
798 /* Note: Keep the timeout low here (instead of using SHCL_TIMEOUT_DEFAULT_MS), as this will make
799 * Windows Explorer unresponsive (i.e. "ghost window") when waiting for too long. */
800 rc = RTSemEventWait(m_EventStatusChanged, RT_MS_10SEC);
801
802 /* Re-acquire lock. */
803 lock();
804
805 if (RT_FAILURE(rc))
806 {
807 LogRel(("Shared Clipboard: Waiting for IDataObject status status failed, rc=%Rrc\n", rc));
808 break;
809 }
810
811 if (m_enmStatus != Running)
812 {
813 LogRel(("Shared Clipboard: Received wrong IDataObject status (%#x)\n", m_enmStatus));
814 rc = VERR_WRONG_ORDER;
815 break;
816 }
817
818 /* There now must be a transfer assigned. */
819 AssertPtrBreakStmt(m_pTransfer, rc = VERR_WRONG_ORDER);
820
821 RT_FALL_THROUGH();
822 }
823
824 case Running:
825 {
826 const bool fUnicode = pFormatEtc->cfFormat == m_cfFileDescriptorW;
827
828 SHCLTRANSFERSTATUS const enmTransferStatus = ShClTransferGetStatus(m_pTransfer);
829 RT_NOREF(enmTransferStatus);
830
831 LogFlowFunc(("FormatIndex_FileDescriptor%s, enmTransferStatus=%s\n",
832 fUnicode ? "W" : "A", ShClTransferStatusToStr(enmTransferStatus)));
833
834 /* The caller can call GetData() several times, so make sure we don't do the same transfer multiple times. */
835 if (ShClTransferGetStatus(m_pTransfer) != SHCLTRANSFERSTATUS_STARTED)
836 {
837 /* Start the transfer + run it asynchronously in a separate thread. */
838 rc = ShClTransferStart(m_pTransfer);
839 if (RT_SUCCESS(rc))
840 {
841 rc = ShClTransferRun(m_pTransfer, &SharedClipboardWinDataObject::readThread, this /* pvUser */);
842 if (RT_SUCCESS(rc))
843 {
844 /* Leave lock while waiting. */
845 unlock();
846
847 /* Don't block for too long here, as this also will screw other apps running on the OS. */
848 LogRel2(("Shared Clipboard: Waiting for IDataObject listing to arrive ...\n"));
849 rc = RTSemEventWait(m_EventListComplete, RT_MS_10SEC);
850
851 /* Re-acquire lock. */
852 lock();
853
854 if ( m_pTransfer == NULL
855 || m_enmStatus != Running) /* Still in running state? */
856 {
857 rc = VERR_OBJECT_DESTROYED;
858 break;
859 }
860 }
861 }
862 }
863
864 if (RT_SUCCESS(rc))
865 {
866 HGLOBAL hGlobal;
867 rc = createFileGroupDescriptorFromTransfer(m_pTransfer, fUnicode, &hGlobal);
868 if (RT_SUCCESS(rc))
869 {
870 pMedium->tymed = TYMED_HGLOBAL;
871 pMedium->hGlobal = hGlobal;
872 /* Note: hGlobal now is being owned by pMedium / the caller. */
873
874 hr = S_OK;
875 }
876 }
877
878 break;
879 }
880
881 default:
882 AssertFailedStmt(rc = VERR_STATE_CHANGED);
883 break;
884 }
885
886 if (RT_FAILURE(rc))
887 {
888 LogRel(("Shared Clipboard: Error getting data for IDataObject, rc=%Rrc\n", rc));
889 hr = E_UNEXPECTED; /* We can't tell any better to the caller, unfortunately. */
890 }
891 }
892
893 Log2Func(("enmStatus=%#x, pTransfer=%p, rc=%Rrc\n", m_enmStatus, m_pTransfer, rc));
894
895 if (RT_SUCCESS(rc))
896 {
897 if (pFormatEtc->cfFormat == m_cfFileContents)
898 {
899 if ( pFormatEtc->lindex >= 0
900 && (ULONG)pFormatEtc->lindex < m_lstEntries.size())
901 {
902 m_uObjIdx = pFormatEtc->lindex; /* lIndex of FormatEtc contains the actual index to the object being handled. */
903
904 FSOBJENTRY &fsObjEntry = m_lstEntries.at(m_uObjIdx);
905
906 LogFlowFunc(("FormatIndex_FileContents: m_uObjIdx=%u (entry '%s')\n", m_uObjIdx, fsObjEntry.pszPath));
907
908 LogRel2(("Shared Clipboard: Receiving object '%s' ...\n", fsObjEntry.pszPath));
909
910 /* Hand-in the provider so that our IStream implementation can continue working with it. */
911 hr = SharedClipboardWinStreamImpl::Create(this /* pParent */, m_pTransfer,
912 fsObjEntry.pszPath /* File name */, &fsObjEntry.objInfo /* PSHCLFSOBJINFO */,
913 &m_pStream);
914 if (SUCCEEDED(hr))
915 {
916 /* Hand over the stream to the caller. */
917 pMedium->tymed = TYMED_ISTREAM;
918 pMedium->pstm = m_pStream;
919 }
920 }
921 }
922 else if (pFormatEtc->cfFormat == m_cfPerformedDropEffect)
923 {
924 HGLOBAL hGlobal = GlobalAlloc(GHND, sizeof(DWORD));
925
926 DWORD* pdwDropEffect = (DWORD*)GlobalLock(hGlobal);
927 *pdwDropEffect = DROPEFFECT_COPY;
928
929 GlobalUnlock(hGlobal);
930
931 pMedium->tymed = TYMED_HGLOBAL;
932 pMedium->hGlobal = hGlobal;
933 pMedium->pUnkForRelease = NULL;
934 }
935
936 if ( FAILED(hr)
937 && hr != DV_E_FORMATETC) /* Can happen if the caller queries unknown / unhandled formats. */
938 {
939 LogRel(("Shared Clipboard: Error returning data from data object (%Rhrc)\n", hr));
940 }
941 }
942
943 unlock();
944
945 LogFlowFunc(("LEAVE hr=%Rhrc\n", hr));
946 return hr;
947}
948
949/**
950 * Only required for IStream / IStorage interfaces.
951 *
952 * @return IPRT status code.
953 * @return HRESULT
954 * @param pFormatEtc
955 * @param pMedium
956 */
957STDMETHODIMP SharedClipboardWinDataObject::GetDataHere(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium)
958{
959 RT_NOREF(pFormatEtc, pMedium);
960 LogFlowFunc(("\n"));
961 return E_NOTIMPL;
962}
963
964/**
965 * Query if this objects supports a specific format.
966 *
967 * @return IPRT status code.
968 * @return HRESULT
969 * @param pFormatEtc
970 */
971STDMETHODIMP SharedClipboardWinDataObject::QueryGetData(LPFORMATETC pFormatEtc)
972{
973 LogFlowFunc(("\n"));
974 return lookupFormatEtc(pFormatEtc, NULL /* puIndex */) ? S_OK : DV_E_FORMATETC;
975}
976
977STDMETHODIMP SharedClipboardWinDataObject::GetCanonicalFormatEtc(LPFORMATETC pFormatEtc, LPFORMATETC pFormatEtcOut)
978{
979 RT_NOREF(pFormatEtc);
980 LogFlowFunc(("\n"));
981
982 /* Set this to NULL in any case. */
983 pFormatEtcOut->ptd = NULL;
984 return E_NOTIMPL;
985}
986
987STDMETHODIMP SharedClipboardWinDataObject::SetData(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium, BOOL fRelease)
988{
989 if ( pFormatEtc == NULL
990 || pMedium == NULL)
991 return E_INVALIDARG;
992
993 if (pFormatEtc->lindex != -1)
994 return DV_E_LINDEX;
995
996 if (pFormatEtc->tymed != TYMED_HGLOBAL)
997 return DV_E_TYMED;
998
999 if (pFormatEtc->dwAspect != DVASPECT_CONTENT)
1000 return DV_E_DVASPECT;
1001
1002 LogFlowFunc(("cfFormat=%RU16, lookupFormatEtc=%RTbool\n",
1003 pFormatEtc->cfFormat, lookupFormatEtc(pFormatEtc, NULL /* puIndex */)));
1004
1005 /* CFSTR_PERFORMEDDROPEFFECT is used by the drop target (caller of this IDataObject) to communicate
1006 * the outcome of the overall operation. */
1007 if ( pFormatEtc->cfFormat == m_cfPerformedDropEffect
1008 && pMedium->tymed == TYMED_HGLOBAL)
1009 {
1010 DWORD dwEffect = *(DWORD *)GlobalLock(pMedium->hGlobal);
1011 GlobalUnlock(pMedium->hGlobal);
1012
1013 LogFlowFunc(("dwEffect=%RI32\n", dwEffect));
1014
1015 /* Did the user cancel the operation via UI (shell)? This also might happen when overwriting an existing file
1016 * and the user doesn't want to allow this. */
1017 if (dwEffect == DROPEFFECT_NONE)
1018 {
1019 LogRel2(("Shared Clipboard: Transfer canceled by user interaction\n"));
1020
1021 SetStatus(Canceled);
1022 }
1023 /** @todo Detect move / overwrite actions here. */
1024
1025 if (fRelease)
1026 ReleaseStgMedium(pMedium);
1027
1028 return S_OK;
1029 }
1030
1031 return E_NOTIMPL;
1032}
1033
1034STDMETHODIMP SharedClipboardWinDataObject::EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC **ppEnumFormatEtc)
1035{
1036 LogFlowFunc(("dwDirection=%RI32, mcFormats=%RI32, mpFormatEtc=%p\n", dwDirection, m_cFormats, m_pFormatEtc));
1037
1038 HRESULT hr;
1039 if (dwDirection == DATADIR_GET)
1040 hr = SharedClipboardWinEnumFormatEtc::CreateEnumFormatEtc(m_cFormats, m_pFormatEtc, ppEnumFormatEtc);
1041 else
1042 hr = E_NOTIMPL;
1043
1044 LogFlowFunc(("hr=%Rhrc\n", hr));
1045 return hr;
1046}
1047
1048STDMETHODIMP SharedClipboardWinDataObject::DAdvise(LPFORMATETC pFormatEtc, DWORD fAdvise, IAdviseSink *pAdvSink, DWORD *pdwConnection)
1049{
1050 RT_NOREF(pFormatEtc, fAdvise, pAdvSink, pdwConnection);
1051 return OLE_E_ADVISENOTSUPPORTED;
1052}
1053
1054STDMETHODIMP SharedClipboardWinDataObject::DUnadvise(DWORD dwConnection)
1055{
1056 RT_NOREF(dwConnection);
1057 return OLE_E_ADVISENOTSUPPORTED;
1058}
1059
1060STDMETHODIMP SharedClipboardWinDataObject::EnumDAdvise(IEnumSTATDATA **ppEnumAdvise)
1061{
1062 RT_NOREF(ppEnumAdvise);
1063 return OLE_E_ADVISENOTSUPPORTED;
1064}
1065
1066#ifdef VBOX_WITH_SHARED_CLIPBOARD_WIN_ASYNC
1067/*
1068 * IDataObjectAsyncCapability methods.
1069 */
1070
1071STDMETHODIMP SharedClipboardWinDataObject::EndOperation(HRESULT hResult, IBindCtx *pbcReserved, DWORD dwEffects)
1072{
1073 RT_NOREF(hResult, pbcReserved, dwEffects);
1074 return E_NOTIMPL;
1075}
1076
1077STDMETHODIMP SharedClipboardWinDataObject::GetAsyncMode(BOOL *pfIsOpAsync)
1078{
1079 RT_NOREF(pfIsOpAsync);
1080 return E_NOTIMPL;
1081}
1082
1083STDMETHODIMP SharedClipboardWinDataObject::InOperation(BOOL *pfInAsyncOp)
1084{
1085 RT_NOREF(pfInAsyncOp);
1086 return E_NOTIMPL;
1087}
1088
1089STDMETHODIMP SharedClipboardWinDataObject::SetAsyncMode(BOOL fDoOpAsync)
1090{
1091 RT_NOREF(fDoOpAsync);
1092 return E_NOTIMPL;
1093}
1094
1095STDMETHODIMP SharedClipboardWinDataObject::StartOperation(IBindCtx *pbcReserved)
1096{
1097 RT_NOREF(pbcReserved);
1098 return E_NOTIMPL;
1099}
1100#endif /* VBOX_WITH_SHARED_CLIPBOARD_WIN_ASYNC */
1101
1102/*
1103 * Own stuff.
1104 */
1105
1106/**
1107 * Assigns a transfer object for the data object, internal version.
1108 *
1109 * @returns VBox status code.
1110 * @param pTransfer Transfer to assign.
1111 * Must be in INITIALIZED state.
1112 * When set to NULL, the transfer will be released from the object.
1113 */
1114int SharedClipboardWinDataObject::setTransferLocked(PSHCLTRANSFER pTransfer)
1115{
1116 AssertReturn(RTCritSectIsOwned(&m_CritSect), VERR_WRONG_ORDER);
1117
1118 LogFlowFunc(("pTransfer=%p\n", pTransfer));
1119
1120 int rc = VINF_SUCCESS;
1121
1122 if (pTransfer) /* Set */
1123 {
1124 Assert(m_pTransfer == NULL); /* Transfer already set? */
1125
1126 if (m_enmStatus == Initialized)
1127 {
1128 SHCLTRANSFERSTATUS const enmSts = ShClTransferGetStatus(pTransfer);
1129 AssertMsgStmt(enmSts == SHCLTRANSFERSTATUS_INITIALIZED, /* Transfer must not be started yet. */
1130 ("Transfer has wrong status (%#x)\n", enmSts), rc = VERR_WRONG_ORDER);
1131 if (RT_SUCCESS(rc))
1132 {
1133 m_pTransfer = pTransfer;
1134
1135 SharedClipboardWinTransferCtx *pWinURITransferCtx = (SharedClipboardWinTransferCtx *)pTransfer->pvUser;
1136 AssertPtr(pWinURITransferCtx);
1137
1138 pWinURITransferCtx->pDataObj = this; /* Save a backref to this object. */
1139
1140 ShClTransferAcquire(pTransfer);
1141 }
1142 }
1143 else
1144 AssertFailedStmt(rc = VERR_WRONG_ORDER);
1145 }
1146 else /* Unset */
1147 {
1148 if (m_pTransfer)
1149 {
1150 SharedClipboardWinTransferCtx *pWinURITransferCtx = (SharedClipboardWinTransferCtx *)m_pTransfer->pvUser;
1151 AssertPtr(pWinURITransferCtx);
1152
1153 pWinURITransferCtx->pDataObj = NULL; /* Release backref to this object. */
1154
1155 ShClTransferRelease(m_pTransfer);
1156 m_pTransfer = NULL;
1157
1158 /* Make sure to notify any waiters. */
1159 rc = RTSemEventSignal(m_EventListComplete);
1160 AssertRC(rc);
1161 }
1162 }
1163
1164 return rc;
1165}
1166
1167/**
1168 * Assigns a transfer object for the data object.
1169 *
1170 * @returns VBox status code.
1171 * @param pTransfer Transfer to assign.
1172 * Must be in INITIALIZED state.
1173 * When set to NULL, the transfer will be released from the object.
1174 */
1175int SharedClipboardWinDataObject::SetTransfer(PSHCLTRANSFER pTransfer)
1176{
1177 lock();
1178
1179 int rc = setTransferLocked(pTransfer);
1180
1181 unlock();
1182
1183 return rc;
1184}
1185
1186/**
1187 * Sets a new status to the data object and signals its waiter.
1188 *
1189 * @returns VBox status code.
1190 * @param enmStatus New status to signal.
1191 * @param rcSts Result code. Optional.
1192 *
1193 * @note Called by the main clipboard thread + SharedClipboardWinStreamImpl.
1194 */
1195int SharedClipboardWinDataObject::SetStatus(Status enmStatus, int rcSts /* = VINF_SUCCESS */)
1196{
1197 lock();
1198
1199 int rc = setStatusLocked(enmStatus, rcSts);
1200
1201 unlock();
1202 return rc;
1203}
1204
1205/* static */
1206void SharedClipboardWinDataObject::logFormat(CLIPFORMAT fmt)
1207{
1208 char szFormat[128];
1209 if (GetClipboardFormatName(fmt, szFormat, sizeof(szFormat)))
1210 {
1211 LogFlowFunc(("clipFormat=%RI16 -> %s\n", fmt, szFormat));
1212 }
1213 else
1214 LogFlowFunc(("clipFormat=%RI16 is unknown\n", fmt));
1215}
1216
1217bool SharedClipboardWinDataObject::lookupFormatEtc(LPFORMATETC pFormatEtc, ULONG *puIndex)
1218{
1219 AssertReturn(pFormatEtc, false);
1220 /* puIndex is optional. */
1221
1222 for (ULONG i = 0; i < m_cFormats; i++)
1223 {
1224 if( (pFormatEtc->tymed & m_pFormatEtc[i].tymed)
1225 && pFormatEtc->cfFormat == m_pFormatEtc[i].cfFormat)
1226 /* Note: Do *not* compare dwAspect here, as this can be dynamic, depending on how the object should be represented. */
1227 //&& pFormatEtc->dwAspect == m_pFormatEtc[i].dwAspect)
1228 {
1229 LogRel2(("Shared Clipboard: Format found: tyMed=%RI32, cfFormat=%RI16, dwAspect=%RI32, ulIndex=%RU32\n",
1230 pFormatEtc->tymed, pFormatEtc->cfFormat, pFormatEtc->dwAspect, i));
1231 if (puIndex)
1232 *puIndex = i;
1233 return true;
1234 }
1235 }
1236
1237 LogRel2(("Shared Clipboard: Format NOT found: tyMed=%RI32, cfFormat=%RI16, dwAspect=%RI32\n",
1238 pFormatEtc->tymed, pFormatEtc->cfFormat, pFormatEtc->dwAspect));
1239
1240 logFormat(pFormatEtc->cfFormat);
1241
1242 return false;
1243}
1244
1245void SharedClipboardWinDataObject::registerFormat(LPFORMATETC pFormatEtc, CLIPFORMAT clipFormat,
1246 TYMED tyMed, LONG lIndex, DWORD dwAspect,
1247 DVTARGETDEVICE *pTargetDevice)
1248{
1249 AssertPtr(pFormatEtc);
1250
1251 pFormatEtc->cfFormat = clipFormat;
1252 pFormatEtc->tymed = tyMed;
1253 pFormatEtc->lindex = lIndex;
1254 pFormatEtc->dwAspect = dwAspect;
1255 pFormatEtc->ptd = pTargetDevice;
1256
1257 LogFlowFunc(("Registered format=%ld\n", pFormatEtc->cfFormat));
1258
1259 logFormat(pFormatEtc->cfFormat);
1260}
1261
1262/**
1263 * Sets a new status to the data object and signals its waiter.
1264 *
1265 * @returns VBox status code.
1266 * @param enmStatus New status to signal.
1267 * @param rc Result code. Optional.
1268 * Errors only accepted when status also is 'Error'.
1269 *
1270 * @note Caller must have taken the critical section.
1271 */
1272int SharedClipboardWinDataObject::setStatusLocked(Status enmStatus, int rc /* = VINF_SUCCESS */)
1273{
1274 AssertReturn(enmStatus == Error || RT_SUCCESS(rc), VERR_INVALID_PARAMETER);
1275 AssertReturn(RTCritSectIsOwned(&m_CritSect), VERR_WRONG_ORDER);
1276
1277 LogFlowFunc(("enmStatus=%#x, rc=%Rrc (current is: %#x)\n", enmStatus, rc, m_enmStatus));
1278
1279 int rc2 = VINF_SUCCESS;
1280
1281 m_rcStatus = rc;
1282
1283 switch (enmStatus)
1284 {
1285 case Completed:
1286 {
1287 LogFlowFunc(("m_uObjIdx=%RU32 (total: %zu)\n", m_uObjIdx, m_lstEntries.size()));
1288
1289 const bool fComplete = m_uObjIdx == m_lstEntries.size() - 1 /* Object index is zero-based */;
1290 if (fComplete)
1291 m_enmStatus = Completed;
1292 break;
1293 }
1294
1295 default:
1296 {
1297 m_enmStatus = enmStatus;
1298 break;
1299 }
1300 }
1301
1302 if (RT_FAILURE(rc))
1303 LogRel(("Shared Clipboard: Data object received error %Rrc (status %#x)\n", rc, enmStatus));
1304
1305 if (m_EventStatusChanged != NIL_RTSEMEVENT)
1306 rc2 = RTSemEventSignal(m_EventStatusChanged);
1307
1308 return rc2;
1309}
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