VirtualBox

source: vbox/trunk/src/VBox/Main/include/GuestDnDPrivate.h@ 85537

Last change on this file since 85537 was 85537, checked in by vboxsync, 4 years ago

DnD/Main: More fixes and cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.6 KB
Line 
1/* $Id: GuestDnDPrivate.h 85537 2020-07-30 06:55:32Z vboxsync $ */
2/** @file
3 * Private guest drag and drop code, used by GuestDnDTarget +
4 * GuestDnDSource.
5 */
6
7/*
8 * Copyright (C) 2011-2020 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#ifndef MAIN_INCLUDED_GuestDnDPrivate_h
20#define MAIN_INCLUDED_GuestDnDPrivate_h
21#ifndef RT_WITHOUT_PRAGMA_ONCE
22# pragma once
23#endif
24
25#include <iprt/dir.h>
26#include <iprt/file.h>
27#include <iprt/path.h>
28
29#include <VBox/hgcmsvc.h> /* For PVBOXHGCMSVCPARM. */
30#include <VBox/GuestHost/DragAndDrop.h>
31#include <VBox/GuestHost/DragAndDropDefs.h>
32#include <VBox/HostServices/DragAndDropSvc.h>
33
34/**
35 * Forward prototype declarations.
36 */
37class Guest;
38class GuestDnDBase;
39class GuestDnDResponse;
40class GuestDnDSource;
41class GuestDnDTarget;
42class Progress;
43
44/**
45 * Type definitions.
46 */
47
48/** List (vector) of MIME types. */
49typedef std::vector<com::Utf8Str> GuestDnDMIMEList;
50
51/*
52 ** @todo Put most of the implementations below in GuestDnDPrivate.cpp!
53 */
54
55class GuestDnDCallbackEvent
56{
57public:
58
59 GuestDnDCallbackEvent(void)
60 : m_SemEvent(NIL_RTSEMEVENT)
61 , m_Rc(VINF_SUCCESS) { }
62
63 virtual ~GuestDnDCallbackEvent(void);
64
65public:
66
67 int Reset(void);
68
69 int Notify(int rc = VINF_SUCCESS);
70
71 int Result(void) const { return m_Rc; }
72
73 int Wait(RTMSINTERVAL msTimeout);
74
75protected:
76
77 /** Event semaphore to notify on error/completion. */
78 RTSEMEVENT m_SemEvent;
79 /** Callback result. */
80 int m_Rc;
81};
82
83/**
84 * Struct for handling the (raw) meta data.
85 */
86struct GuestDnDMetaData
87{
88 GuestDnDMetaData(void)
89 : pvData(NULL)
90 , cbData(0)
91 , cbAllocated(0)
92 , cbAnnounced(0) { }
93
94 virtual ~GuestDnDMetaData(void)
95 {
96 reset();
97 }
98
99 size_t add(const void *pvDataAdd, size_t cbDataAdd)
100 {
101 LogFlowThisFunc(("cbAllocated=%zu, cbAnnounced=%zu, pvDataAdd=%p, cbDataAdd=%zu\n",
102 cbAllocated, cbAnnounced, pvDataAdd, cbDataAdd));
103 if (!cbDataAdd)
104 return 0;
105 AssertPtrReturn(pvDataAdd, 0);
106
107 const size_t cbAllocatedTmp = cbData + cbDataAdd;
108 if (cbAllocatedTmp > cbAllocated)
109 {
110 int rc = resize(cbAllocatedTmp);
111 if (RT_FAILURE(rc))
112 return 0;
113 }
114
115 Assert(cbAllocated >= cbData + cbDataAdd);
116 memcpy((uint8_t *)pvData + cbData, pvDataAdd, cbDataAdd);
117
118 cbData += cbDataAdd;
119
120 return cbData;
121 }
122
123 size_t add(const std::vector<BYTE> &vecAdd)
124 {
125 if (!vecAdd.size())
126 return 0;
127
128 if (vecAdd.size() > UINT32_MAX) /* Paranoia. */
129 return 0;
130
131 return add(&vecAdd.front(), (uint32_t)vecAdd.size());
132 }
133
134 void reset(void)
135 {
136 strFmt = "";
137
138 if (pvData)
139 {
140 Assert(cbAllocated);
141 RTMemFree(pvData);
142 pvData = NULL;
143 }
144
145 cbData = 0;
146 cbAllocated = 0;
147 cbAnnounced = 0;
148 }
149
150 int resize(size_t cbSize)
151 {
152 if (!cbSize)
153 {
154 reset();
155 return VINF_SUCCESS;
156 }
157
158 if (cbSize == cbAllocated)
159 return VINF_SUCCESS;
160
161 if (cbSize > _32M) /* Meta data can be up to 32MB. */
162 return VERR_BUFFER_OVERFLOW;
163
164 void *pvTmp = NULL;
165 if (!cbAllocated)
166 {
167 Assert(cbData == 0);
168 pvTmp = RTMemAllocZ(RT_ALIGN_Z(cbSize, 4096));
169 }
170 else
171 {
172 AssertPtr(pvData);
173 pvTmp = RTMemRealloc(pvData, RT_ALIGN_Z(cbSize, 4096));
174 RT_BZERO(pvTmp, cbSize);
175 }
176
177 if (pvTmp)
178 {
179 pvData = pvTmp;
180 cbAllocated = cbSize;
181 return VINF_SUCCESS;
182 }
183
184 return VERR_NO_MEMORY;
185 }
186
187 /** Format string of this meta data. */
188 com::Utf8Str strFmt;
189 /** Pointer to allocated meta data. */
190 void *pvData;
191 /** Used bytes of meta data. Must not exceed cbAllocated. */
192 size_t cbData;
193 /** Size (in bytes) of allocated meta data. */
194 size_t cbAllocated;
195 /** Size (in bytes) of announced meta data. */
196 size_t cbAnnounced;
197};
198
199/**
200 * Struct for accounting shared DnD data to be sent/received.
201 */
202struct GuestDnDData
203{
204 GuestDnDData(void)
205 : cbExtra(0)
206 , cbProcessed(0) { }
207
208 virtual ~GuestDnDData(void)
209 {
210 reset();
211 }
212
213 size_t addProcessed(size_t cbDataAdd)
214 {
215 const size_t cbTotal = getTotalAnnounced(); RT_NOREF(cbTotal);
216 AssertReturn(cbProcessed + cbDataAdd <= cbTotal, 0);
217 cbProcessed += cbDataAdd;
218 return cbProcessed;
219 }
220
221 bool isComplete(void) const
222 {
223 const size_t cbTotal = getTotalAnnounced();
224 LogFlowFunc(("cbProcessed=%zu, cbTotal=%zu\n", cbProcessed, cbTotal));
225 AssertReturn(cbProcessed <= cbTotal, true);
226 return (cbProcessed == cbTotal);
227 }
228
229 uint8_t getPercentComplete(void) const
230 {
231 const size_t cbTotal = getTotalAnnounced();
232 return (uint8_t)(cbProcessed * 100 / RT_MAX(cbTotal, 1));
233 }
234
235 size_t getRemaining(void) const
236 {
237 const size_t cbTotal = getTotalAnnounced();
238 AssertReturn(cbProcessed <= cbTotal, 0);
239 return cbTotal - cbProcessed;
240 }
241
242 size_t getTotalAnnounced(void) const
243 {
244 return Meta.cbAnnounced + cbExtra;
245 }
246
247 size_t getTotalAvailable(void) const
248 {
249 return Meta.cbData + cbExtra;
250 }
251
252 void reset(void)
253 {
254 Meta.reset();
255
256 cbExtra = 0;
257 cbProcessed = 0;
258 }
259
260 /** For storing the actual meta data.
261 * This might be an URI list or just plain raw data,
262 * according to the format being sent. */
263 GuestDnDMetaData Meta;
264 /** Extra data to send/receive (in bytes). Can be 0 for raw data.
265 * For (file) transfers this is the total size for all files. */
266 size_t cbExtra;
267 /** Overall size (in bytes) of processed data. */
268 size_t cbProcessed;
269};
270
271/** Initial object context state / no state set. */
272#define DND_OBJ_STATE_NONE 0
273/** The header was received / sent. */
274#define DND_OBJ_STATE_HAS_HDR RT_BIT(0)
275/** Validation mask for object context state. */
276#define DND_OBJ_STATE_VALID_MASK UINT32_C(0x00000001)
277
278/**
279 * Class for keeping around DnD (file) transfer data.
280 */
281struct GuestDnDTransferData
282{
283
284public:
285
286 GuestDnDTransferData(void)
287 : cObjToProcess(0)
288 , cObjProcessed(0)
289 , pvScratchBuf(NULL)
290 , cbScratchBuf(0) { }
291
292 virtual ~GuestDnDTransferData(void)
293 {
294 destroy();
295 }
296
297 int init(size_t cbBuf = _64K)
298 {
299 reset();
300
301 pvScratchBuf = RTMemAlloc(cbBuf);
302 if (!pvScratchBuf)
303 return VERR_NO_MEMORY;
304
305 cbScratchBuf = cbBuf;
306 return VINF_SUCCESS;
307 }
308
309 void destroy(void)
310 {
311 reset();
312
313 if (pvScratchBuf)
314 {
315 Assert(cbScratchBuf);
316 RTMemFree(pvScratchBuf);
317 pvScratchBuf = NULL;
318 }
319 cbScratchBuf = 0;
320 }
321
322 void reset(void)
323 {
324 LogFlowFuncEnter();
325
326 cObjToProcess = 0;
327 cObjProcessed = 0;
328 }
329
330 bool isComplete(void) const
331 {
332 return (cObjProcessed == cObjToProcess);
333 }
334
335 /** Number of objects to process. */
336 uint64_t cObjToProcess;
337 /** Number of objects already processed. */
338 uint64_t cObjProcessed;
339 /** Pointer to an optional scratch buffer to use for
340 * doing the actual chunk transfers. */
341 void *pvScratchBuf;
342 /** Size (in bytes) of scratch buffer. */
343 size_t cbScratchBuf;
344};
345
346struct GuestDnDTransferSendData : public GuestDnDTransferData
347{
348 GuestDnDTransferSendData()
349 : fObjState(0)
350 {
351 RT_ZERO(List);
352 int rc2 = DnDTransferListInit(&List);
353 AssertRC(rc2);
354 }
355
356 virtual ~GuestDnDTransferSendData()
357 {
358 destroy();
359 }
360
361 void destroy(void)
362 {
363 DnDTransferListDestroy(&List);
364 }
365
366 void reset(void)
367 {
368 DnDTransferListReset(&List);
369 fObjState = 0;
370
371 GuestDnDTransferData::reset();
372 }
373
374 /** Transfer List to handle. */
375 DNDTRANSFERLIST List;
376 /** Current state of object in transfer.
377 * This is needed for keeping compatibility to old(er) DnD HGCM protocols.
378 *
379 * At the moment we only support transferring one object at a time. */
380 uint32_t fObjState;
381};
382
383/**
384 * Context structure for sending data to the guest.
385 */
386struct GuestDnDSendCtx : public GuestDnDData
387{
388 GuestDnDSendCtx(void);
389
390 void reset(void);
391
392 /** Pointer to guest target class this context belongs to. */
393 GuestDnDTarget *pTarget;
394 /** Pointer to guest response class this context belongs to. */
395 GuestDnDResponse *pResp;
396 /** Target (VM) screen ID. */
397 uint32_t uScreenID;
398 /** Transfer data structure. */
399 GuestDnDTransferSendData Transfer;
400 /** Callback event to use. */
401 GuestDnDCallbackEvent EventCallback;
402};
403
404struct GuestDnDTransferRecvData : public GuestDnDTransferData
405{
406 GuestDnDTransferRecvData()
407 {
408 RT_ZERO(DroppedFiles);
409 int rc2 = DnDDroppedFilesInit(&DroppedFiles);
410 AssertRC(rc2);
411
412 RT_ZERO(List);
413 rc2 = DnDTransferListInit(&List);
414 AssertRC(rc2);
415
416 RT_ZERO(ObjCur);
417 rc2 = DnDTransferObjectInit(&ObjCur);
418 AssertRC(rc2);
419 }
420
421 virtual ~GuestDnDTransferRecvData()
422 {
423 destroy();
424 }
425
426 void destroy(void)
427 {
428 DnDTransferListDestroy(&List);
429 }
430
431 void reset(void)
432 {
433 DnDDroppedFilesClose(&DroppedFiles);
434 DnDTransferListReset(&List);
435 DnDTransferObjectReset(&ObjCur);
436
437 GuestDnDTransferData::reset();
438 }
439
440 /** The "VirtualBox Dropped Files" directory on the host we're going
441 * to utilize for transferring files from guest to the host. */
442 DNDDROPPEDFILES DroppedFiles;
443 /** Transfer List to handle.
444 * Currently we only support one transfer list at a time. */
445 DNDTRANSFERLIST List;
446 /** Current transfer object being handled.
447 * Currently we only support one transfer object at a time. */
448 DNDTRANSFEROBJECT ObjCur;
449};
450
451/**
452 * Context structure for receiving data from the guest.
453 */
454struct GuestDnDRecvCtx : public GuestDnDData
455{
456 GuestDnDRecvCtx(void);
457
458 void reset(void);
459
460 /** Pointer to guest source class this context belongs to. */
461 GuestDnDSource *pSource;
462 /** Pointer to guest response class this context belongs to. */
463 GuestDnDResponse *pResp;
464 /** Formats offered by the guest (and supported by the host). */
465 GuestDnDMIMEList lstFmtOffered;
466 /** Original drop format requested to receive from the guest. */
467 com::Utf8Str strFmtReq;
468 /** Intermediate drop format to be received from the guest.
469 * Some original drop formats require a different intermediate
470 * drop format:
471 *
472 * Receiving a file link as "text/plain" requires still to
473 * receive the file from the guest as "text/uri-list" first,
474 * then pointing to the file path on the host with the data
475 * in "text/plain" format returned. */
476 com::Utf8Str strFmtRecv;
477 /** Desired drop action to perform on the host.
478 * Needed to tell the guest if data has to be
479 * deleted e.g. when moving instead of copying. */
480 VBOXDNDACTION enmAction;
481 /** Transfer data structure. */
482 GuestDnDTransferRecvData Transfer;
483 /** Callback event to use. */
484 GuestDnDCallbackEvent EventCallback;
485};
486
487/**
488 * Simple structure for a buffered guest DnD message.
489 */
490class GuestDnDMsg
491{
492public:
493
494 GuestDnDMsg(void)
495 : uMsg(0)
496 , cParms(0)
497 , cParmsAlloc(0)
498 , paParms(NULL) { }
499
500 virtual ~GuestDnDMsg(void)
501 {
502 reset();
503 }
504
505public:
506
507 PVBOXHGCMSVCPARM getNextParam(void)
508 {
509 if (cParms >= cParmsAlloc)
510 {
511 if (!paParms)
512 paParms = (PVBOXHGCMSVCPARM)RTMemAlloc(4 * sizeof(VBOXHGCMSVCPARM));
513 else
514 paParms = (PVBOXHGCMSVCPARM)RTMemRealloc(paParms, (cParmsAlloc + 4) * sizeof(VBOXHGCMSVCPARM));
515 if (!paParms)
516 throw VERR_NO_MEMORY;
517 RT_BZERO(&paParms[cParmsAlloc], 4 * sizeof(VBOXHGCMSVCPARM));
518 cParmsAlloc += 4;
519 }
520
521 return &paParms[cParms++];
522 }
523
524 uint32_t getCount(void) const { return cParms; }
525 PVBOXHGCMSVCPARM getParms(void) const { return paParms; }
526 uint32_t getType(void) const { return uMsg; }
527
528 void reset(void)
529 {
530 if (paParms)
531 {
532 /* Remove deep copies. */
533 for (uint32_t i = 0; i < cParms; i++)
534 {
535 if ( paParms[i].type == VBOX_HGCM_SVC_PARM_PTR
536 && paParms[i].u.pointer.size)
537 {
538 AssertPtr(paParms[i].u.pointer.addr);
539 RTMemFree(paParms[i].u.pointer.addr);
540 }
541 }
542
543 RTMemFree(paParms);
544 paParms = NULL;
545 }
546
547 uMsg = cParms = cParmsAlloc = 0;
548 }
549
550 int setNextPointer(void *pvBuf, uint32_t cbBuf)
551 {
552 PVBOXHGCMSVCPARM pParm = getNextParam();
553 if (!pParm)
554 return VERR_NO_MEMORY;
555
556 void *pvTmp = NULL;
557 if (cbBuf)
558 {
559 AssertPtr(pvBuf);
560 pvTmp = RTMemDup(pvBuf, cbBuf);
561 if (!pvTmp)
562 return VERR_NO_MEMORY;
563 }
564
565 HGCMSvcSetPv(pParm, pvTmp, cbBuf);
566 return VINF_SUCCESS;
567 }
568
569 int setNextString(const char *pszString)
570 {
571 PVBOXHGCMSVCPARM pParm = getNextParam();
572 if (!pParm)
573 return VERR_NO_MEMORY;
574
575 char *pszTemp = RTStrDup(pszString);
576 if (!pszTemp)
577 return VERR_NO_MEMORY;
578
579 HGCMSvcSetStr(pParm, pszTemp);
580 return VINF_SUCCESS;
581 }
582
583 int setNextUInt32(uint32_t u32Val)
584 {
585 PVBOXHGCMSVCPARM pParm = getNextParam();
586 if (!pParm)
587 return VERR_NO_MEMORY;
588
589 HGCMSvcSetU32(pParm, u32Val);
590 return VINF_SUCCESS;
591 }
592
593 int setNextUInt64(uint64_t u64Val)
594 {
595 PVBOXHGCMSVCPARM pParm = getNextParam();
596 if (!pParm)
597 return VERR_NO_MEMORY;
598
599 HGCMSvcSetU64(pParm, u64Val);
600 return VINF_SUCCESS;
601 }
602
603 void setType(uint32_t uMsgType) { uMsg = uMsgType; }
604
605protected:
606
607 /** Message type. */
608 uint32_t uMsg;
609 /** Message parameters. */
610 uint32_t cParms;
611 /** Size of array. */
612 uint32_t cParmsAlloc;
613 /** Array of HGCM parameters */
614 PVBOXHGCMSVCPARM paParms;
615};
616
617/** Guest DnD callback function definition. */
618typedef DECLCALLBACKPTR(int, PFNGUESTDNDCALLBACK,(uint32_t uMsg, void *pvParms, size_t cbParms, void *pvUser));
619
620/**
621 * Structure for keeping a guest DnD callback.
622 * Each callback can handle one HGCM message, however, multiple HGCM messages can be registered
623 * to the same callback (function).
624 */
625typedef struct GuestDnDCallback
626{
627 GuestDnDCallback(void)
628 : uMessgage(0)
629 , pfnCallback(NULL)
630 , pvUser(NULL) { }
631
632 GuestDnDCallback(PFNGUESTDNDCALLBACK pvCB, uint32_t uMsg, void *pvUsr = NULL)
633 : uMessgage(uMsg)
634 , pfnCallback(pvCB)
635 , pvUser(pvUsr) { }
636
637 /** The HGCM message ID to handle. */
638 uint32_t uMessgage;
639 /** Pointer to callback function. */
640 PFNGUESTDNDCALLBACK pfnCallback;
641 /** Pointer to user-supplied data. */
642 void *pvUser;
643} GuestDnDCallback;
644
645/** Contains registered callback pointers for specific HGCM message types. */
646typedef std::map<uint32_t, GuestDnDCallback> GuestDnDCallbackMap;
647
648/** @todo r=andy This class needs to go, as this now is too inflexible when it comes to all
649 * the callback handling/dispatching. It's part of the initial code and only adds
650 * unnecessary complexity. */
651class GuestDnDResponse
652{
653
654public:
655
656 GuestDnDResponse(const ComObjPtr<Guest>& pGuest);
657 virtual ~GuestDnDResponse(void);
658
659public:
660
661 int notifyAboutGuestResponse(void) const;
662 int waitForGuestResponse(RTMSINTERVAL msTimeout = 500) const;
663
664 void setActionsAllowed(VBOXDNDACTIONLIST a) { m_dndLstActionsAllowed = a; }
665 VBOXDNDACTIONLIST getActionsAllowed(void) const { return m_dndLstActionsAllowed; }
666
667 void setActionDefault(VBOXDNDACTION a) { m_dndActionDefault = a; }
668 VBOXDNDACTION getActionDefault(void) const { return m_dndActionDefault; }
669
670 void setFormats(const GuestDnDMIMEList &lstFormats) { m_lstFormats = lstFormats; }
671 GuestDnDMIMEList formats(void) const { return m_lstFormats; }
672
673 void reset(void);
674
675 bool isProgressCanceled(void) const;
676 int setCallback(uint32_t uMsg, PFNGUESTDNDCALLBACK pfnCallback, void *pvUser = NULL);
677 int setProgress(unsigned uPercentage, uint32_t uState, int rcOp = VINF_SUCCESS, const Utf8Str &strMsg = "");
678 HRESULT resetProgress(const ComObjPtr<Guest>& pParent);
679 HRESULT queryProgressTo(IProgress **ppProgress);
680
681public:
682
683 /** @name HGCM callback handling.
684 @{ */
685 int onDispatch(uint32_t u32Function, void *pvParms, uint32_t cbParms);
686 /** @} */
687
688protected:
689
690 /** Pointer to context this class is tied to. */
691 void *m_pvCtx;
692 /** Event for waiting for response. */
693 RTSEMEVENT m_EventSem;
694 /** Default action to perform in case of a
695 * successful drop. */
696 VBOXDNDACTION m_dndActionDefault;
697 /** Actions supported by the guest in case of a successful drop. */
698 VBOXDNDACTIONLIST m_dndLstActionsAllowed;
699 /** Format(s) requested/supported from the guest. */
700 GuestDnDMIMEList m_lstFormats;
701 /** Pointer to IGuest parent object. */
702 ComObjPtr<Guest> m_pParent;
703 /** Pointer to associated progress object. Optional. */
704 ComObjPtr<Progress> m_pProgress;
705 /** Callback map. */
706 GuestDnDCallbackMap m_mapCallbacks;
707};
708
709/**
710 * Private singleton class for the guest's DnD implementation.
711 *
712 * Can't be instanciated directly, only via the factory pattern.
713 * Keeps track of all ongoing DnD transfers.
714 */
715class GuestDnD
716{
717public:
718
719 static GuestDnD *createInstance(const ComObjPtr<Guest>& pGuest)
720 {
721 Assert(NULL == GuestDnD::s_pInstance);
722 GuestDnD::s_pInstance = new GuestDnD(pGuest);
723 return GuestDnD::s_pInstance;
724 }
725
726 static void destroyInstance(void)
727 {
728 if (GuestDnD::s_pInstance)
729 {
730 delete GuestDnD::s_pInstance;
731 GuestDnD::s_pInstance = NULL;
732 }
733 }
734
735 static inline GuestDnD *getInstance(void)
736 {
737 AssertPtr(GuestDnD::s_pInstance);
738 return GuestDnD::s_pInstance;
739 }
740
741protected:
742
743 /** List of registered DnD sources. */
744 typedef std::list< ComObjPtr<GuestDnDSource> > GuestDnDSrcList;
745 /** List of registered DnD targets. */
746 typedef std::list< ComObjPtr<GuestDnDTarget> > GuestDnDTgtList;
747
748 /** Constructor; will throw rc on failure. */
749 GuestDnD(const ComObjPtr<Guest>& pGuest);
750 virtual ~GuestDnD(void);
751
752public:
753
754 /** @name Public helper functions.
755 * @{ */
756 HRESULT adjustScreenCoordinates(ULONG uScreenId, ULONG *puX, ULONG *puY) const;
757 int hostCall(uint32_t u32Function, uint32_t cParms, PVBOXHGCMSVCPARM paParms) const;
758 GuestDnDResponse *response(void) { return m_pResponse; }
759 GuestDnDMIMEList defaultFormats(void) const { return m_strDefaultFormats; }
760 /** @} */
761
762 /** @name Source / target management. */
763 int registerSource(const ComObjPtr<GuestDnDSource> &Source);
764 int unregisterSource(const ComObjPtr<GuestDnDSource> &Source);
765 size_t getSourceCount(void);
766
767 int registerTarget(const ComObjPtr<GuestDnDTarget> &Target);
768 int unregisterTarget(const ComObjPtr<GuestDnDTarget> &Target);
769 size_t getTargetCount(void);
770 /** @} */
771
772public:
773
774 /** @name Static low-level HGCM callback handler.
775 * @{ */
776 static DECLCALLBACK(int) notifyDnDDispatcher(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms);
777 /** @} */
778
779 /** @name Static helper methods.
780 * @{ */
781 static bool isFormatInFormatList(const com::Utf8Str &strFormat, const GuestDnDMIMEList &lstFormats);
782 static GuestDnDMIMEList toFormatList(const com::Utf8Str &strFormats);
783 static com::Utf8Str toFormatString(const GuestDnDMIMEList &lstFormats);
784 static GuestDnDMIMEList toFilteredFormatList(const GuestDnDMIMEList &lstFormatsSupported, const GuestDnDMIMEList &lstFormatsWanted);
785 static GuestDnDMIMEList toFilteredFormatList(const GuestDnDMIMEList &lstFormatsSupported, const com::Utf8Str &strFormatsWanted);
786 static DnDAction_T toMainAction(VBOXDNDACTION dndAction);
787 static std::vector<DnDAction_T> toMainActions(VBOXDNDACTIONLIST dndActionList);
788 static VBOXDNDACTION toHGCMAction(DnDAction_T enmAction);
789 static void toHGCMActions(DnDAction_T enmDefAction, VBOXDNDACTION *pDefAction, const std::vector<DnDAction_T> vecAllowedActions, VBOXDNDACTIONLIST *pLstAllowedActions);
790 /** @} */
791
792protected:
793
794 /** @name Singleton properties.
795 * @{ */
796 /** List of supported default MIME/Content-type formats. */
797 GuestDnDMIMEList m_strDefaultFormats;
798 /** Pointer to guest implementation. */
799 const ComObjPtr<Guest> m_pGuest;
800 /** The current (last) response from the guest. At the
801 * moment we only support only response a time (ARQ-style). */
802 GuestDnDResponse *m_pResponse;
803 /** Critical section to serialize access. */
804 RTCRITSECT m_CritSect;
805 /** Number of active transfers (guest->host or host->guest). */
806 uint32_t m_cTransfersPending;
807 GuestDnDSrcList m_lstSrc;
808 GuestDnDTgtList m_lstTgt;
809 /** @} */
810
811private:
812
813 /** Static pointer to singleton instance. */
814 static GuestDnD *s_pInstance;
815};
816
817/** Access to the GuestDnD's singleton instance. */
818#define GuestDnDInst() GuestDnD::getInstance()
819
820/** List of pointers to guest DnD Messages. */
821typedef std::list<GuestDnDMsg *> GuestDnDMsgList;
822
823/**
824 * IDnDBase class implementation for sharing code between
825 * IGuestDnDSource and IGuestDnDTarget implementation.
826 */
827class GuestDnDBase
828{
829protected:
830
831 GuestDnDBase(void);
832
833protected:
834
835 /** Shared (internal) IDnDBase method implementations.
836 * @{ */
837 HRESULT i_isFormatSupported(const com::Utf8Str &aFormat, BOOL *aSupported);
838 HRESULT i_getFormats(GuestDnDMIMEList &aFormats);
839 HRESULT i_addFormats(const GuestDnDMIMEList &aFormats);
840 HRESULT i_removeFormats(const GuestDnDMIMEList &aFormats);
841
842 HRESULT i_getProtocolVersion(ULONG *puVersion);
843 /** @} */
844
845protected:
846
847 int getProtocolVersion(uint32_t *puVersion);
848
849 /** @name Functions for handling a simple host HGCM message queue.
850 * @{ */
851 int msgQueueAdd(GuestDnDMsg *pMsg);
852 GuestDnDMsg *msgQueueGetNext(void);
853 void msgQueueRemoveNext(void);
854 void msgQueueClear(void);
855 /** @} */
856
857 int sendCancel(void);
858 int updateProgress(GuestDnDData *pData, GuestDnDResponse *pResp, size_t cbDataAdd = 0);
859 int waitForEvent(GuestDnDCallbackEvent *pEvent, GuestDnDResponse *pResp, RTMSINTERVAL msTimeout);
860
861protected:
862
863 /** @name Public attributes (through getters/setters).
864 * @{ */
865 /** Pointer to guest implementation. */
866 const ComObjPtr<Guest> m_pGuest;
867 /** List of supported MIME types by the source. */
868 GuestDnDMIMEList m_lstFmtSupported;
869 /** List of offered MIME types to the counterpart. */
870 GuestDnDMIMEList m_lstFmtOffered;
871 /** Whether the object still is in pending state. */
872 bool m_fIsPending;
873 /** @} */
874
875 /**
876 * Internal stuff.
877 */
878 struct
879 {
880 /** The DnD protocol version to use, depending on the
881 * installed Guest Additions. See DragAndDropSvc.h for
882 * a protocol changelog. */
883 uint32_t uProtocolVersion;
884 /** Outgoing message queue (FIFO). */
885 GuestDnDMsgList lstMsgOut;
886 } m_DataBase;
887};
888#endif /* !MAIN_INCLUDED_GuestDnDPrivate_h */
889
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