VirtualBox

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

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

DnD/Main: Use PAGE_SIZE for meta data block alignment.

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