VirtualBox

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

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

DnD: Revamped code to simplify / untangle of internal data handling:

  • C-ifying and renaming classes DnDURIList / DnDURIObject -> DnDTransferList / DnDTransferObject
  • Added testcases for DnDTransferList / DnDTransferObject + DnDPath API
  • Reduced memory footprint
  • Greatly simplified / stripped down internal data flow of Main side
  • More (optional) release logging for further diagnosis

Work in progress.

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