1 | /** @file
|
---|
2 | * Drag and Drop manager.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2011-2014 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/GuestHost/DragAndDrop.h>
|
---|
21 | #include <VBox/HostServices/Service.h>
|
---|
22 | #include <VBox/HostServices/DragAndDropSvc.h>
|
---|
23 |
|
---|
24 | #include <iprt/cpp/ministring.h>
|
---|
25 | #include <iprt/cpp/list.h>
|
---|
26 |
|
---|
27 | typedef DECLCALLBACK(int) FNDNDPROGRESS(unsigned uPercentage, uint32_t uState, int rc, void *pvUser);
|
---|
28 | typedef FNDNDPROGRESS *PFNDNDPROGRESS;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * DnD message class. This class forms the base of all other more specialized
|
---|
32 | * message classes.
|
---|
33 | */
|
---|
34 | class DnDMessage
|
---|
35 | {
|
---|
36 | public:
|
---|
37 |
|
---|
38 | DnDMessage(void)
|
---|
39 | : m_pNextMsg(NULL)
|
---|
40 | {
|
---|
41 | }
|
---|
42 |
|
---|
43 | virtual ~DnDMessage(void)
|
---|
44 | {
|
---|
45 | clearNextMsg();
|
---|
46 | }
|
---|
47 |
|
---|
48 | virtual HGCM::Message* nextHGCMMessage(void)
|
---|
49 | {
|
---|
50 | return m_pNextMsg;
|
---|
51 | }
|
---|
52 |
|
---|
53 | virtual int currentMessageInfo(uint32_t *puMsg, uint32_t *pcParms)
|
---|
54 | {
|
---|
55 | AssertPtrReturn(puMsg, VERR_INVALID_POINTER);
|
---|
56 | AssertPtrReturn(pcParms, VERR_INVALID_POINTER);
|
---|
57 |
|
---|
58 | if (!m_pNextMsg)
|
---|
59 | return VERR_NO_DATA;
|
---|
60 |
|
---|
61 | *puMsg = m_pNextMsg->message();
|
---|
62 | *pcParms = m_pNextMsg->paramsCount();
|
---|
63 |
|
---|
64 | return VINF_SUCCESS;
|
---|
65 | }
|
---|
66 |
|
---|
67 | virtual int currentMessage(uint32_t uMsg, uint32_t cParms,
|
---|
68 | VBOXHGCMSVCPARM paParms[])
|
---|
69 | {
|
---|
70 | if (!m_pNextMsg)
|
---|
71 | return VERR_NO_DATA;
|
---|
72 |
|
---|
73 | int rc = m_pNextMsg->getData(uMsg, cParms, paParms);
|
---|
74 |
|
---|
75 | clearNextMsg();
|
---|
76 |
|
---|
77 | return rc;
|
---|
78 | }
|
---|
79 |
|
---|
80 | virtual void clearNextMsg(void)
|
---|
81 | {
|
---|
82 | if (m_pNextMsg)
|
---|
83 | {
|
---|
84 | delete m_pNextMsg;
|
---|
85 | m_pNextMsg = NULL;
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | virtual bool isMessageWaiting(void) const { return m_pNextMsg != NULL; }
|
---|
90 |
|
---|
91 | protected:
|
---|
92 |
|
---|
93 | HGCM::Message *m_pNextMsg;
|
---|
94 | };
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * DnD message class for generic messages which didn't need any special
|
---|
98 | * handling.
|
---|
99 | */
|
---|
100 | class DnDGenericMessage: public DnDMessage
|
---|
101 | {
|
---|
102 | public:
|
---|
103 | DnDGenericMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
|
---|
104 | {
|
---|
105 | m_pNextMsg = new HGCM::Message(uMsg, cParms, paParms);
|
---|
106 | }
|
---|
107 | };
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * DnD message class for informing the guest about a new drop data event.
|
---|
111 | */
|
---|
112 | class DnDHGSendDataMessage: public DnDMessage
|
---|
113 | {
|
---|
114 | public:
|
---|
115 |
|
---|
116 | DnDHGSendDataMessage(uint32_t uMsg, uint32_t cParms,
|
---|
117 | VBOXHGCMSVCPARM paParms[],
|
---|
118 | PFNDNDPROGRESS pfnProgressCallback, void *pvProgressUser);
|
---|
119 |
|
---|
120 | virtual ~DnDHGSendDataMessage(void);
|
---|
121 |
|
---|
122 | HGCM::Message* nextHGCMMessage(void);
|
---|
123 | int currentMessageInfo(uint32_t *puMsg, uint32_t *pcParms);
|
---|
124 | int currentMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
|
---|
125 |
|
---|
126 | bool isMessageWaiting(void) const { return !!m_pNextPathMsg; }
|
---|
127 |
|
---|
128 | protected:
|
---|
129 |
|
---|
130 | static DECLCALLBACK(int) progressCallback(size_t cbDone, void *pvUser);
|
---|
131 |
|
---|
132 | DnDMessage *m_pNextPathMsg;
|
---|
133 |
|
---|
134 | DnDURIList m_lstURI;
|
---|
135 | /* Total message size (in bytes). */
|
---|
136 | size_t m_cbTotal;
|
---|
137 | /* Transferred message size (in bytes). */
|
---|
138 | size_t m_cbTransfered;
|
---|
139 |
|
---|
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 |
|
---|
152 | DnDHGCancelMessage(void)
|
---|
153 | {
|
---|
154 | m_pNextMsg
|
---|
155 | = new HGCM::Message(DragAndDropSvc::HOST_DND_HG_EVT_CANCEL,
|
---|
156 | 0 /* cParms */, 0 /* aParms */);
|
---|
157 | }
|
---|
158 | };
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * DnD manager. Manage creation and queuing of messages for the various DnD
|
---|
162 | * messages types.
|
---|
163 | */
|
---|
164 | class DnDManager
|
---|
165 | {
|
---|
166 | public:
|
---|
167 |
|
---|
168 | DnDManager(PFNDNDPROGRESS pfnProgressCallback, void *pvProgressUser)
|
---|
169 | : m_pCurMsg(0)
|
---|
170 | , m_fOpInProcess(false)
|
---|
171 | , m_pfnProgressCallback(pfnProgressCallback)
|
---|
172 | , m_pvProgressUser(pvProgressUser)
|
---|
173 | {}
|
---|
174 |
|
---|
175 | virtual ~DnDManager(void)
|
---|
176 | {
|
---|
177 | clear();
|
---|
178 | }
|
---|
179 |
|
---|
180 | int addMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
|
---|
181 |
|
---|
182 | HGCM::Message *nextHGCMMessage(void);
|
---|
183 | int nextMessageInfo(uint32_t *puMsg, uint32_t *pcParms);
|
---|
184 | int nextMessage(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
|
---|
185 |
|
---|
186 | void clear(void);
|
---|
187 |
|
---|
188 | bool hasActiveOperation(void) const { return m_fOpInProcess; }
|
---|
189 |
|
---|
190 | private:
|
---|
191 | DnDMessage *m_pCurMsg;
|
---|
192 | RTCList<DnDMessage*> m_dndMessageQueue;
|
---|
193 |
|
---|
194 | bool m_fOpInProcess;
|
---|
195 |
|
---|
196 | /* Progress stuff */
|
---|
197 | PFNDNDPROGRESS m_pfnProgressCallback;
|
---|
198 | void *m_pvProgressUser;
|
---|
199 | };
|
---|
200 | #endif /* ___VBox_HostService_DnD_dndmanager_h */
|
---|
201 |
|
---|