1 | /** @file
|
---|
2 | * Drag and Drop manager.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2011-2012 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef ___VBox_HostService_DnD_dndmanager_h
|
---|
18 | #define ___VBox_HostService_DnD_dndmanager_h
|
---|
19 |
|
---|
20 | #include <VBox/HostServices/Service.h>
|
---|
21 | #include <VBox/HostServices/DragAndDropSvc.h>
|
---|
22 |
|
---|
23 | #include <iprt/cpp/ministring.h>
|
---|
24 | #include <iprt/cpp/list.h>
|
---|
25 |
|
---|
26 | typedef DECLCALLBACK(int) FNDNDPROGRESS(unsigned uPercentage, uint32_t uState, void *pvUser);
|
---|
27 | typedef FNDNDPROGRESS *PFNDNDPROGRESS;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * DnD message class. This class forms the base of all other more specialized
|
---|
31 | * message classes.
|
---|
32 | */
|
---|
33 | class DnDMessage
|
---|
34 | {
|
---|
35 | public:
|
---|
36 | DnDMessage()
|
---|
37 | : m_pNextMsg(NULL)
|
---|
38 | {
|
---|
39 | }
|
---|
40 | virtual ~DnDMessage()
|
---|
41 | {
|
---|
42 | clearNextMsg();
|
---|
43 | }
|
---|
44 |
|
---|
45 | virtual HGCM::Message* nextHGCMMessage()
|
---|
46 | {
|
---|
47 | return m_pNextMsg;
|
---|
48 | }
|
---|
49 | virtual int currentMessageInfo(uint32_t *puMsg, uint32_t *pcParms)
|
---|
50 | {
|
---|
51 | AssertPtrReturn(puMsg, VERR_INVALID_POINTER);
|
---|
52 | AssertPtrReturn(pcParms, VERR_INVALID_POINTER);
|
---|
53 |
|
---|
54 | if (!m_pNextMsg)
|
---|
55 | return VERR_NO_DATA;
|
---|
56 |
|
---|
57 | *puMsg = m_pNextMsg->message();
|
---|
58 | *pcParms = m_pNextMsg->paramsCount();
|
---|
59 |
|
---|
60 | return VINF_SUCCESS;
|
---|
61 | }
|
---|
62 | virtual int currentMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
|
---|
63 | {
|
---|
64 | if (!m_pNextMsg)
|
---|
65 | return VERR_NO_DATA;
|
---|
66 |
|
---|
67 | int rc = m_pNextMsg->getData(uMsg, cParms, paParms);
|
---|
68 |
|
---|
69 | clearNextMsg();
|
---|
70 |
|
---|
71 | return rc;
|
---|
72 | }
|
---|
73 | virtual void clearNextMsg()
|
---|
74 | {
|
---|
75 | if (m_pNextMsg)
|
---|
76 | {
|
---|
77 | delete m_pNextMsg;
|
---|
78 | m_pNextMsg = NULL;
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | virtual bool isMessageWaiting() const { return m_pNextMsg != NULL; }
|
---|
83 |
|
---|
84 | protected:
|
---|
85 | HGCM::Message *m_pNextMsg;
|
---|
86 | };
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * DnD message class for generic messages which didn't need any special
|
---|
90 | * handling.
|
---|
91 | */
|
---|
92 | class DnDGenericMessage: public DnDMessage
|
---|
93 | {
|
---|
94 | public:
|
---|
95 | DnDGenericMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
|
---|
96 | {
|
---|
97 | m_pNextMsg = new HGCM::Message(uMsg, cParms, paParms);
|
---|
98 | }
|
---|
99 | };
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * DnD message class for informing the guest about a new drop data event.
|
---|
103 | */
|
---|
104 | class DnDHGSendDataMessage: public DnDMessage
|
---|
105 | {
|
---|
106 | public:
|
---|
107 | DnDHGSendDataMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[], PFNDNDPROGRESS pfnProgressCallback, void *pvProgressUser);
|
---|
108 | ~DnDHGSendDataMessage();
|
---|
109 |
|
---|
110 | HGCM::Message* nextHGCMMessage();
|
---|
111 | int currentMessageInfo(uint32_t *puMsg, uint32_t *pcParms);
|
---|
112 | int currentMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
|
---|
113 |
|
---|
114 | bool isMessageWaiting() const { return !!m_pNextPathMsg; }
|
---|
115 |
|
---|
116 | protected:
|
---|
117 | struct PathEntry
|
---|
118 | {
|
---|
119 | PathEntry(const RTCString &strHostPath, const RTCString &strGuestPath, uint32_t fMode, uint64_t cbSize)
|
---|
120 | : m_strHostPath(strHostPath)
|
---|
121 | , m_strGuestPath(strGuestPath)
|
---|
122 | , m_fMode(fMode)
|
---|
123 | , m_cbSize(cbSize) {}
|
---|
124 | RTCString m_strHostPath;
|
---|
125 | RTCString m_strGuestPath;
|
---|
126 | uint32_t m_fMode;
|
---|
127 | uint64_t m_cbSize;
|
---|
128 | };
|
---|
129 |
|
---|
130 | bool hasFileUrls(const char *pcszFormat, size_t cbMax) const;
|
---|
131 | int buildFileTree(const char *pcszPath, size_t cbBaseLen);
|
---|
132 | static DECLCALLBACK(int) progressCallback(size_t cbDone, void *pvUser);
|
---|
133 |
|
---|
134 | RTCList<PathEntry> m_uriList;
|
---|
135 | DnDMessage *m_pNextPathMsg;
|
---|
136 |
|
---|
137 | /* Progress stuff */
|
---|
138 | size_t m_cbAll;
|
---|
139 | size_t m_cbTransfered;
|
---|
140 | PFNDNDPROGRESS m_pfnProgressCallback;
|
---|
141 | void *m_pvProgressUser;
|
---|
142 | };
|
---|
143 |
|
---|
144 | /**
|
---|
145 | * DnD message class for informing the guest to cancel any currently and
|
---|
146 | * pending activities.
|
---|
147 | */
|
---|
148 | class DnDHGCancelMessage: public DnDMessage
|
---|
149 | {
|
---|
150 | public:
|
---|
151 | DnDHGCancelMessage()
|
---|
152 | {
|
---|
153 | m_pNextMsg = new HGCM::Message(DragAndDropSvc::HOST_DND_HG_EVT_CANCEL, 0, 0);
|
---|
154 | }
|
---|
155 | };
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * DnD manager. Manage creation and queuing of messages for the various DnD
|
---|
159 | * messages types.
|
---|
160 | */
|
---|
161 | class DnDManager
|
---|
162 | {
|
---|
163 | public:
|
---|
164 | DnDManager(PFNDNDPROGRESS pfnProgressCallback, void *pvProgressUser)
|
---|
165 | : m_pCurMsg(0)
|
---|
166 | , m_fOpInProcess(false)
|
---|
167 | , m_pfnProgressCallback(pfnProgressCallback)
|
---|
168 | , m_pvProgressUser(pvProgressUser)
|
---|
169 | {}
|
---|
170 | ~DnDManager()
|
---|
171 | {
|
---|
172 | clear();
|
---|
173 | }
|
---|
174 |
|
---|
175 | int addMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
|
---|
176 |
|
---|
177 | HGCM::Message *nextHGCMMessage();
|
---|
178 | int nextMessageInfo(uint32_t *puMsg, uint32_t *pcParms);
|
---|
179 | int nextMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
|
---|
180 |
|
---|
181 | void clear();
|
---|
182 |
|
---|
183 | bool hasActiveOperation() const { return m_fOpInProcess; }
|
---|
184 |
|
---|
185 | private:
|
---|
186 | DnDMessage *m_pCurMsg;
|
---|
187 | RTCList<DnDMessage*> m_dndMessageQueue;
|
---|
188 |
|
---|
189 | bool m_fOpInProcess;
|
---|
190 |
|
---|
191 | /* Progress stuff */
|
---|
192 | PFNDNDPROGRESS m_pfnProgressCallback;
|
---|
193 | void *m_pvProgressUser;
|
---|
194 | };
|
---|
195 |
|
---|
196 | #endif /* ___VBox_HostService_DnD_dndmanager_h */
|
---|
197 |
|
---|